class BaseMaker: public TreeUpdater {
TrainParam param; //訓(xùn)練參數(shù)
vector<int> qexpand; //queue of nodes to be expanded
vector<int> node2workindex; //map active node to its working index offset in qexpand, can be -1, which means the node is node actively expanding
vector<int> position; //position of each instance in the tree, can be negative, which means this position is no longer expanding, see also Decode/EncodePosition
struct FMetaHelper { //采集feature的元數(shù)據(jù)
vector<float> fminmax; //大小為2*num_feature返干,偶數(shù)位存某個feature最大值
int Type(int fid); //返回指定feature的數(shù)據(jù)類型兽叮,0為空挑围,1為binary,2為real
float MaxValue(int fid); //返回指定feature的最大值
SampleCol(float p, vector<int> *p_findex); //根據(jù)概率p亡嫌,從所有的feature中隨機(jī)sample出p*num_feature個,存在p_findex中
}
//helper for row-based data
int NextLevel(RowBatch &inst, RegTree &tree, int nid); //nid是樹中Node的編號,inst是一條sample沟启,根據(jù)Node上的split信息返回左樹還是右樹
int get_nthread(); //返回線程數(shù)
//gpair是一階和二階導(dǎo)數(shù),fmat是數(shù)據(jù)
void InitData(vector<gpair> &gpair,DMatrix &fmat,RegTree &tree) {
//setup position犹菇,position的大小等于gpair的size
//fmat.info.root_index是每個sample的當(dāng)前index德迹,用它來初始化position
//mark delete for the deleted datas
if (gpair[i].hess < 0.0f) position[i] = ~position[i]; //如果二階導(dǎo)數(shù)為負(fù),position設(shè)為負(fù)
//mark subsample揭芍,如果要對數(shù)據(jù)進(jìn)行sample胳搞,根據(jù)伯努利分布采樣,沒采樣到的position設(shè)為負(fù)
// expand query,將樹中待處理節(jié)點(diǎn)放入隊列肌毅,可以并行處理
for (int i = 0; i < tree.param.num_roots; ++i) {
qexpand.push_back(i);
}
this->UpdateNode2WorkIndex(tree); //更新Tree node到queue index的映射
}
//update queue expand add in new leaves币厕,遍歷queue中對應(yīng)的tree node,如果不是leaf芽腾,則將左樹和右樹加入queue
void UpdateQueueExpand(RegTree &tree);
//return decoded position旦装,rindex是數(shù)據(jù)的index
int DecodePosition(int ridx) {
pid = position[ridx]; //tree中node的位置
return pid < 0 ? ~pid : pid; //如果pid為負(fù),表示此node不再expand
}
//encode the encoded position value for ridx摊滔,nid是正整數(shù)阴绢,如果當(dāng)前position是負(fù),則設(shè)為~nid
void SetEncodePosition(int ridx, int nid);
//this is helper function uses column based data structure to reset the positions艰躺,根據(jù)樹結(jié)構(gòu)呻袭,把新的數(shù)據(jù)放在樹中
//nodes: the set of nodes that contains the split to be used
//p_fmat: feature matrix needed for tree construction
void ResetPositionCol(vector<int> &nodes,DMatrix *p_fmat,RegTree &tree) {
SetNonDefaultPositionCol(nodes, p_fmat, tree);
SetDefaultPostion(p_fmat, tree);
}
//helper function to set the non-leaf positions to default direction. 把不能分到leaf上的數(shù)據(jù)(比如missing value)分配到default的方向
void SetDefaultPostion(DMatrix *p_fmat, RegTree &tree);
//helper function uses column based data structure to CORRECT the positions of non-default directions that WAS set to default before calling this function.
//batch: The column batch
//sorted_split_set: The set of index that contains split solutions.
void CorrectNonDefaultPositionByBatch(ColBatch& batch,vector<int> &sorted_split_set,RegTree &tree);
//helper function uses column based data structure,從給定的nodes中獲取split的feature id的集合
//nodes: the set of nodes that contains the split to be used
//out_split_set: The split index set
void GetSplitSet(vector<int> &nodes,RegTree &tree, vector<unsigned>* out_split_set);
//helper function uses column based data structure,update all positions into nondefault branch, if any, ignore the default branch
void SetNonDefaultPositionCol(vector<int> &nodes,DMatrix *p_fmat,RegTree &tree) {
//helper function to get statistics from a tree
void GetNodeStats(vector<bst_gpair> &gpair, DMatrix &fmat, RegTree &tree, vector<vector<TStats>> *p_thread_temp, vector<TStats> *p_node_stats)
//common helper data structure to build sketch,構(gòu)建sketch
struct SketchEntry {
//total sum of amount to be met
double sum_total;
//statistics used in the sketch
double rmin, wmin;
//last seen feature value
float last_fvalue;
//current size of sketch
double next_goal;
//pointer to the sketch to put things in
WXQuantileSketch<float, float> *sketch;
// initialize the space
void Init(max_size);
//push a new element to sketch
//fvalue: feature value, comes in sorted ascending order
//w: weight
void Push(float fvalue, float w, unsigned max_size);
//更新node2workerindex
void UpdateNode2WorkIndex(RegTree &tree) {
}
}
updater_basemaker-inl.h
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
- 文/潘曉璐 我一進(jìn)店門没陡,熙熙樓的掌柜王于貴愁眉苦臉地迎上來涩哟,“玉大人,你說我怎么就攤上這事盼玄√耍” “怎么了?”我有些...
- 文/不壞的土叔 我叫張陵埃儿,是天一觀的道長器仗。 經(jīng)常有香客問我,道長蝌箍,這世上最難降的妖魔是什么青灼? 我笑而不...
- 正文 為了忘掉前任暴心,我火速辦了婚禮妓盲,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘专普。我一直安慰自己悯衬,他們只是感情好,可當(dāng)我...
- 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著筋粗,像睡著了一般策橘。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上娜亿,一...
- 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼躲舌!你這毒婦竟也來了丑婿?” 一聲冷哼從身側(cè)響起,我...
- 序言:老撾萬榮一對情侶失蹤没卸,失蹤者是張志新(化名)和其女友劉穎羹奉,沒想到半個月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體约计,經(jīng)...
- 正文 獨(dú)居荒郊野嶺守林人離奇死亡尘奏,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
- 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了病蛉。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片炫加。...
- 正文 年R本政府宣布赋铝,位于F島的核電站,受9級特大地震影響沽瘦,放射性物質(zhì)發(fā)生泄漏革骨。R本人自食惡果不足惜,卻給世界環(huán)境...
- 文/蒙蒙 一析恋、第九天 我趴在偏房一處隱蔽的房頂上張望良哲。 院中可真熱鬧,春花似錦助隧、人聲如沸筑凫。這莊子的主人今日做“春日...
- 文/蒼蘭香墨 我抬頭看了看天上的太陽巍实。三九已至滓技,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間棚潦,已是汗流浹背令漂。 一陣腳步聲響...
- 正文 我出身青樓,卻偏偏與公主長得像原环,于是被迫代替她去往敵國和親挠唆。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當(dāng)晚...
推薦閱讀更多精彩內(nèi)容
- 新愛蓮說Hélène, je m'appelle Hélène/Hélène Rollès 蓍草填詞/江北客@伏羲...
- objc-runtime.h 中代碼: #include <objc/runtime.h> #include<ob...
- 沉默的時候嘱吗, 你的心湖一片平靜玄组, 那是一個人最好的狀態(tài)。 你努力保持這種狀態(tài)谒麦, 在塵世的喧囂中俄讹, 活出一個真實(shí)的自我。