Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minimal Varianсe Sampling booster #4266

Merged
merged 32 commits into from
Mar 12, 2022
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
1af3f3e
Added base for minimal variance sampling booster
kruda Apr 12, 2021
0ad2740
Implemented MVS booster with support for multioutput targets, determi…
kruda May 9, 2021
08462f9
Merge remote-tracking branch 'upstream/master'
kruda May 9, 2021
b067a5b
Updated documentation and fixed some linting errors
kruda May 9, 2021
8229008
fixed python sklearn documentation, tryed to fix R Cran CI
kruda May 9, 2021
0f2620e
Second attempt to fix R pipeline
kruda May 9, 2021
d50769e
Fixed R package build for windows and linting error
kruda May 9, 2021
f531f3a
Revert "Fixed R package build for windows and linting error"
kruda May 9, 2021
ef1a28c
Revert "Revert "Fixed R package build for windows and linting error""
kruda May 9, 2021
c610035
Fixed some documentation
kruda May 9, 2021
4425874
Fixed intendation error in mvs.hpp, fixed some windows build issues, …
kruda May 9, 2021
a5b72f8
Fixed intendation error in mvs.hpp, fixed some windows build issues, …
kruda May 9, 2021
64a99f4
Merge branch 'master' into master
kruda May 9, 2021
fb8ff6e
Update requirements_base.txt
kruda May 9, 2021
d499d15
Update R-package/src/Makevars.in
kruda May 10, 2021
8a01fb8
Update R-package/src/Makevars.win.in
kruda May 10, 2021
4b630a1
Added MVS booster support for dask tests
kruda May 10, 2021
29fc099
Merge remote-tracking branch 'origin/master'
kruda May 10, 2021
49ed4eb
Moved CalculateThresholdSequential to array_args.h and renamed it to …
kruda May 10, 2021
d018ed0
Added cpp tests for ArrayArgs::CalculateThresholdMVS and ArrayArgs::P…
kruda May 10, 2021
d62c98c
Fix linter errors in test_dask.py
kruda May 10, 2021
8cee27e
Fixed UB in ArrayArgs::Partition, when it is called with one element.
kruda May 10, 2021
224ac05
Fixed linter errors
kruda May 10, 2021
5cd4422
Added more cpp tests and fixed linting errors
kruda May 10, 2021
468102b
Fixed linting errors
kruda May 10, 2021
fd3f64a
Updated R-package documentation
kruda May 11, 2021
11df789
Updated MVS Lambda algorithm
kruda May 14, 2021
b489b66
Merge branch 'microsoft:master' into master
kruda May 15, 2021
bab99b3
Merge branch 'master' of https://github.com/microsoft/LightGBM
kruda Jul 6, 2021
ddcab83
Updated documentation, MVS::GetLambda, MVS::GetThreshold, updated MVS…
kruda Jul 6, 2021
31ab4d4
[ci] fix current `master` fails with graphviz-related error (#5068)
StrikerRUS Mar 11, 2022
9ce06ae
sync with LightGBM/master
shiyu1994 Mar 11, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion R-package/R/lgb.cv.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ CVBooster <- R6::R6Class(
#' into a predictor model which frees up memory and the original datasets
#' @param ... other parameters, see Parameters.rst for more information. A few key parameters:
#' \itemize{
#' \item{\code{boosting}: Boosting type. \code{"gbdt"}, \code{"rf"}, \code{"dart"} or \code{"goss"}.}
#' \item{\code{boosting}: Boosting type. \code{"gbdt"}, \code{"rf"}, \code{"dart"}, \code{"goss"}
#' or \code{"mvs"}.}
#' \item{\code{num_leaves}: Maximum number of leaves in one tree.}
#' \item{\code{max_depth}: Limit the max depth for tree model. This is used to deal with
#' overfit when #data is small. Tree still grow by leaf-wise.}
Expand Down
3 changes: 2 additions & 1 deletion R-package/R/lgb.train.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
#' @param ... other parameters, see \href{https://lightgbm.readthedocs.io/en/latest/Parameters.html}{
#' the "Parameters" section of the documentation} for more information. A few key parameters:
#' \itemize{
#' \item{\code{boosting}: Boosting type. \code{"gbdt"}, \code{"rf"}, \code{"dart"} or \code{"goss"}.}
#' \item{\code{boosting}: Boosting type. \code{"gbdt"}, \code{"rf"}, \code{"dart"},
#' \code{"goss"} or \code{"mvs"}.}
#' \item{\code{num_leaves}: Maximum number of leaves in one tree.}
#' \item{\code{max_depth}: Limit the max depth for tree model. This is used to deal with
#' overfitting. Tree still grow by leaf-wise.}
Expand Down
3 changes: 2 additions & 1 deletion R-package/R/lightgbm.R
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ NULL
#' say "the first and tenth columns").}
#' \item{\code{reset_data}: Boolean, setting it to TRUE (not the default value) will transform the booster model
#' into a predictor model which frees up memory and the original datasets}
#' \item{\code{boosting}: Boosting type. \code{"gbdt"}, \code{"rf"}, \code{"dart"} or \code{"goss"}.}
#' \item{\code{boosting}: Boosting type. \code{"gbdt"}, \code{"rf"}, \code{"dart"},
#' \code{"goss"} or \code{"mvs"}.}
#' \item{\code{num_leaves}: Maximum number of leaves in one tree.}
#' \item{\code{max_depth}: Limit the max depth for tree model. This is used to deal with
#' overfit when #data is small. Tree still grow by leaf-wise.}
Expand Down
3 changes: 2 additions & 1 deletion R-package/man/lgb.cv.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion R-package/man/lgb.train.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion R-package/man/lightgbm.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions R-package/src/Makevars.in
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ OBJECTS = \
boosting/gbdt_model_text.o \
boosting/gbdt_prediction.o \
boosting/prediction_early_stop.o \
boosting/mvs.o \
io/bin.o \
io/config.o \
io/config_auto.o \
Expand Down
1 change: 1 addition & 0 deletions R-package/src/Makevars.win.in
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ OBJECTS = \
boosting/gbdt_model_text.o \
boosting/gbdt_prediction.o \
boosting/prediction_early_stop.o \
boosting/mvs.o \
io/bin.o \
io/config.o \
io/config_auto.o \
Expand Down
24 changes: 24 additions & 0 deletions docs/Parameters.rst
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ Core Parameters

- **Note**: internally, LightGBM uses ``gbdt`` mode for the first ``1 / learning_rate`` iterations

- ``mvs``, Minimal variance sampling <https://arxiv.org/abs/1910.13204>__

- ``linear_tree`` :raw-html:`<a id="linear_tree" title="Permalink to this parameter" href="#linear_tree">&#x1F517;&#xFE0E;</a>`, default = ``false``, type = bool, aliases: ``linear_trees``

- fit piecewise linear gradient boosting tree
Expand Down Expand Up @@ -336,6 +338,28 @@ Learning Control Parameters

- **Note**: if balanced bagging is enabled, ``bagging_fraction`` will be ignored

- ``mvs_lambda`` :raw-html:`<a id="mvs_lambda" title="Permalink to this parameter" href="#mvs_lambda">&#x1F517;&#xFE0E;</a>`, default = ``1e-4``, type = double, constraints: ``mvs_lambda > 0.0``

- used in MVS boosting if ``mvs_adaptive == true`` than this value is ignored
kruda marked this conversation as resolved.
Show resolved Hide resolved

- used only in ``mvs``

- ``mvs_adaptive`` :raw-html:`<a id="mvs_adaptive" title="Permalink to this parameter" href="#mvs_adaptive">&#x1F517;&#xFE0E;</a>`, default = ``false``, type = bool

- use adaptive variant of mvs boosting

- used only in ``mvs``

- ``mvs_max_sequential_size`` :raw-html:`<a id="mvs_max_sequential_size" title="Permalink to this parameter" href="#mvs_max_sequential_size">&#x1F517;&#xFE0E;</a>`, default = ``256000``, type = int, constraints: ``mvs_max_sequential_size > 0``

- used in MVS boosting training dataset size is greater than ``mvs_max_sequential_size``, than threshold
kruda marked this conversation as resolved.
Show resolved Hide resolved

- for MVS is chosen for each thread independently.

- used only in ``mvs``

- **Note**: on small dataset setting this parameter less than size of dataset may produce results depending on number of threads

- ``bagging_freq`` :raw-html:`<a id="bagging_freq" title="Permalink to this parameter" href="#bagging_freq">&#x1F517;&#xFE0E;</a>`, default = ``0``, type = int, aliases: ``subsample_freq``

- frequency for bagging
Expand Down
20 changes: 20 additions & 0 deletions include/LightGBM/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ struct Config {
// desc = ``dart``, `Dropouts meet Multiple Additive Regression Trees <https://arxiv.org/abs/1505.01866>`__
// desc = ``goss``, Gradient-based One-Side Sampling
// descl2 = **Note**: internally, LightGBM uses ``gbdt`` mode for the first ``1 / learning_rate`` iterations
// desc = ``mvs``, Minimal variance sampling <https://arxiv.org/abs/1910.13204>__
std::string boosting = "gbdt";

// alias = linear_trees
Expand Down Expand Up @@ -318,6 +319,25 @@ struct Config {
// desc = **Note**: if balanced bagging is enabled, ``bagging_fraction`` will be ignored
double neg_bagging_fraction = 1.0;

// default = 1e-4
// check = >0.0
// desc = used in MVS boosting if ``mvs_adaptive == true`` than this value is ignored
kruda marked this conversation as resolved.
Show resolved Hide resolved
// desc = used only in ``mvs``
double mvs_lambda = 1e-4;

// default = false
// desc = use adaptive variant of mvs boosting
// desc = used only in ``mvs``
bool mvs_adaptive = false;

// default = 256000
// check = >0
// desc = used in MVS boosting training dataset size is greater than ``mvs_max_sequential_size``, than threshold
kruda marked this conversation as resolved.
Show resolved Hide resolved
// desc = for MVS is chosen for each thread independently.
// desc = used only in ``mvs``
// desc = **Note**: on small dataset setting this parameter less than size of dataset may produce results depending on number of threads
int mvs_max_sequential_size = 256000;

// alias = subsample_freq
// desc = frequency for bagging
// desc = ``0`` means disable bagging; ``k`` means perform bagging at every ``k`` iteration. Every ``k``-th iteration, LightGBM will randomly select ``bagging_fraction * 100 %`` of the data to use for the next ``k`` iterations
Expand Down
33 changes: 32 additions & 1 deletion include/LightGBM/utils/array_args.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <LightGBM/utils/threading.h>

#include <algorithm>
#include <numeric>
#include <utility>
#include <vector>

Expand Down Expand Up @@ -103,7 +104,7 @@ class ArrayArgs {
int j = end - 1;
int p = i;
int q = j;
if (start >= end) {
if (start >= end - 1) {
kruda marked this conversation as resolved.
Show resolved Hide resolved
return;
}
std::vector<VAL_T>& ref = *arr;
Expand Down Expand Up @@ -183,6 +184,36 @@ class ArrayArgs {
}
return true;
}

static double CalculateThresholdMVS(std::vector<VAL_T>* gradients, data_size_t begin, data_size_t end,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it more appropriate to move this to mvs.cpp?

const double sample_size) {
double current_sum_small = 0.0;
data_size_t big_grad_size = 0;

while (begin != end) {
data_size_t middle_begin = begin - 1, middle_end = end;
ArrayArgs<score_t>::Partition(gradients, begin, end, &middle_begin, &middle_end);
++middle_begin; // for half intervals
const data_size_t n_middle = middle_end - middle_begin;
const data_size_t large_size = middle_begin - begin;

const double sum_small = std::accumulate(gradients->begin() + middle_end, gradients->begin() + end, 0.0);
const double sum_middle = (*gradients)[middle_begin] * n_middle;

const double
current_sampling_rate = (current_sum_small + sum_small) / (*gradients)[middle_begin] + big_grad_size + n_middle + large_size;

if (current_sampling_rate > sample_size) {
current_sum_small += sum_small + sum_middle;
end = middle_begin;
} else {
big_grad_size += n_middle + large_size;
begin = middle_end;
}
}

return current_sum_small / (sample_size - big_grad_size + kEpsilon);
}
};

} // namespace LightGBM
Expand Down
1 change: 1 addition & 0 deletions python-package/lightgbm/sklearn.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ def __init__(self, boosting_type='gbdt', num_leaves=31, max_depth=-1,
'dart', Dropouts meet Multiple Additive Regression Trees.
'goss', Gradient-based One-Side Sampling.
'rf', Random Forest.
'mvs', Minimal Variance Sampling.
num_leaves : int, optional (default=31)
Maximum tree leaves for base learners.
max_depth : int, optional (default=-1)
Expand Down
5 changes: 5 additions & 0 deletions src/boosting/boosting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "gbdt.h"
#include "goss.hpp"
#include "rf.hpp"
#include "mvs.hpp"

namespace LightGBM {

Expand Down Expand Up @@ -42,6 +43,8 @@ Boosting* Boosting::CreateBoosting(const std::string& type, const char* filename
return new GOSS();
} else if (type == std::string("rf")) {
return new RF();
} else if (type == std::string("mvs")) {
return new MVS();
} else {
return nullptr;
}
Expand All @@ -56,6 +59,8 @@ Boosting* Boosting::CreateBoosting(const std::string& type, const char* filename
ret.reset(new GOSS());
} else if (type == std::string("rf")) {
return new RF();
} else if (type == std::string("mvs")) {
return new MVS();
} else {
Log::Fatal("Unknown boosting type %s", type.c_str());
}
Expand Down
Loading