-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:zeyiwen/thundergbm
update docs
- Loading branch information
Showing
32 changed files
with
702 additions
and
665 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// | ||
// Created by ss on 19-1-17. | ||
// | ||
|
||
#ifndef THUNDERGBM_BOOSTER_H | ||
#define THUNDERGBM_BOOSTER_H | ||
|
||
#include <thundergbm/objective/objective_function.h> | ||
#include <thundergbm/metric/metric.h> | ||
#include <thundergbm/updater/function_builder.h> | ||
#include <thundergbm/updater/hist_tree_builder.h> | ||
#include <thundergbm/updater/exact_tree_builder.h> | ||
#include "thundergbm/common.h" | ||
#include "syncarray.h" | ||
#include "tree.h" | ||
|
||
class Booster { | ||
public: | ||
void init(const DataSet &dataSet, const GBMParam ¶m); | ||
|
||
void boost(vector<vector<Tree>> &boosted_model); | ||
|
||
private: | ||
MSyncArray<GHPair> gradients; | ||
std::unique_ptr<ObjectiveFunction> obj; | ||
std::unique_ptr<Metric> metric; | ||
MSyncArray<float_type> y; | ||
std::unique_ptr<FunctionBuilder> fbuilder; | ||
GBMParam param; | ||
int n_devices; | ||
}; | ||
|
||
void Booster::init(const DataSet &dataSet, const GBMParam ¶m) { | ||
this->param = param; | ||
fbuilder.reset(FunctionBuilder::create(param.tree_method)); | ||
fbuilder->init(dataSet, param); | ||
obj.reset(ObjectiveFunction::create(param.objective)); | ||
obj->configure(param, dataSet); | ||
metric.reset(Metric::create(obj->default_metric_name())); | ||
metric->configure(param, dataSet); | ||
|
||
n_devices = param.n_device; | ||
int n_outputs = param.num_class * dataSet.n_instances(); | ||
gradients = MSyncArray<GHPair>(n_devices, n_outputs); | ||
y = MSyncArray<float_type>(n_devices, dataSet.n_instances()); | ||
|
||
DO_ON_MULTI_DEVICES(n_devices, [&](int device_id) { | ||
y[device_id].copy_from(dataSet.y.data(), dataSet.n_instances()); | ||
}); | ||
} | ||
|
||
void Booster::boost(vector<vector<Tree>> &boosted_model) { | ||
//update gradients | ||
DO_ON_MULTI_DEVICES(n_devices, [&](int device_id) { | ||
obj->get_gradient(y[device_id], fbuilder->get_y_predict()[device_id], gradients[device_id]); | ||
}); | ||
|
||
//build new model/approximate function | ||
boosted_model.push_back(fbuilder->build_approximate(gradients)); | ||
|
||
//show metric on training set | ||
LOG(INFO) << metric->get_name() << " = " << metric->get_score(fbuilder->get_y_predict().front()); | ||
} | ||
|
||
#endif //THUNDERGBM_BOOSTER_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// | ||
// Created by ss on 19-1-19. | ||
// | ||
|
||
#ifndef THUNDERGBM_EXACT_TREE_BUILDER_H | ||
#define THUNDERGBM_EXACT_TREE_BUILDER_H | ||
|
||
#include <thundergbm/util/multi_device.h> | ||
#include "thundergbm/common.h" | ||
#include "function_builder.h" | ||
#include "shard.h" | ||
|
||
|
||
class ExactTreeBuilder : public FunctionBuilder { | ||
public: | ||
vector<Tree> build_approximate(const MSyncArray<GHPair> &gradients) override; | ||
|
||
void init(const DataSet &dataset, const GBMParam ¶m) override; | ||
|
||
const MSyncArray<float_type>& get_y_predict() override; | ||
|
||
struct InternalShard: public Shard { | ||
int rank; | ||
|
||
void find_split(int level); | ||
|
||
void update_ins2node_id(); | ||
}; | ||
|
||
template<typename L> | ||
static void for_each_shard(vector<InternalShard> &shards, L lambda) { | ||
DO_ON_MULTI_DEVICES(shards.size(), [&](int device_id) { | ||
lambda(shards[device_id]); | ||
}); | ||
} | ||
|
||
vector<InternalShard> shards; | ||
|
||
void split_point_all_reduce(int depth, vector<InternalShard> &shards); | ||
|
||
void ins2node_id_all_reduce(vector<InternalShard> &shards, int depth); | ||
GBMParam param; | ||
private: | ||
MSyncArray<float_type> y_predict; | ||
}; | ||
|
||
|
||
#endif //THUNDERGBM_EXACT_TREE_BUILDER_H |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// | ||
// Created by ss on 19-1-17. | ||
// | ||
|
||
#ifndef THUNDERGBM_FUNCTION_BUILDER_H | ||
#define THUNDERGBM_FUNCTION_BUILDER_H | ||
|
||
#include <thundergbm/tree.h> | ||
#include "thundergbm/common.h" | ||
#include "thundergbm/sparse_columns.h" | ||
|
||
class FunctionBuilder { | ||
public: | ||
virtual vector<Tree> build_approximate(const MSyncArray<GHPair> &gradients) = 0; | ||
|
||
virtual void init(const DataSet &dataset, const GBMParam ¶m) {}; | ||
|
||
virtual const MSyncArray<float_type> &get_y_predict() = 0; | ||
|
||
static FunctionBuilder *create(std::string name); | ||
}; | ||
|
||
#endif //THUNDERGBM_FUNCTION_BUILDER_H |
Oops, something went wrong.