objective_function.cpp 3.62 KB
Newer Older
Guolin Ke's avatar
Guolin Ke committed
1
2
3
4
#include <LightGBM/objective_function.h>
#include "regression_objective.hpp"
#include "binary_objective.hpp"
#include "rank_objective.hpp"
5
#include "multiclass_objective.hpp"
6
#include "xentropy_objective.hpp"
Guolin Ke's avatar
Guolin Ke committed
7
8
9
10

namespace LightGBM {

ObjectiveFunction* ObjectiveFunction::CreateObjectiveFunction(const std::string& type, const ObjectiveConfig& config) {
11
  if (type == std::string("regression") || type == std::string("regression_l2")
12
13
      || type == std::string("mean_squared_error") || type == std::string("mse") 
      || type == std::string("l2_root") || type == std::string("root_mean_squared_error") || type == std::string("rmse")) {
Guolin Ke's avatar
Guolin Ke committed
14
    return new RegressionL2loss(config);
15
16
  } else if (type == std::string("regression_l1") || type == std::string("mean_absolute_error")  || type == std::string("mae")) {
    return new RegressionL1loss(config);
17
18
  } else if (type == std::string("quantile")) {
    return new RegressionQuantileloss(config);
Tsukasa OMOTO's avatar
Tsukasa OMOTO committed
19
  } else if (type == std::string("huber")) {
Tsukasa OMOTO's avatar
Tsukasa OMOTO committed
20
    return new RegressionHuberLoss(config);
Tsukasa OMOTO's avatar
Tsukasa OMOTO committed
21
22
  } else if (type == std::string("fair")) {
    return new RegressionFairLoss(config);
23
24
  } else if (type == std::string("poisson")) {
    return new RegressionPoissonLoss(config);
Guolin Ke's avatar
Guolin Ke committed
25
  } else if (type == std::string("binary")) {
Guolin Ke's avatar
Guolin Ke committed
26
    return new BinaryLogloss(config);
Guolin Ke's avatar
Guolin Ke committed
27
  } else if (type == std::string("lambdarank")) {
Guolin Ke's avatar
Guolin Ke committed
28
    return new LambdarankNDCG(config);
Guolin Ke's avatar
Guolin Ke committed
29
  } else if (type == std::string("multiclass")) {
Guolin Ke's avatar
Guolin Ke committed
30
31
32
    return new MulticlassSoftmax(config);
  } else if (type == std::string("multiclassova")) {
    return new MulticlassOVA(config);
33
34
35
36
  } else if (type == std::string("xentropy") || type == std::string("cross_entropy")) {
    return new CrossEntropy(config);
  } else if (type == std::string("xentlambda") || type == std::string("cross_entropy_lambda")) {
    return new CrossEntropyLambda(config);
37
38
  } else if (type == std::string("mean_absolute_percentage_error") || type == std::string("mape")) {
    return new RegressionMAPELOSS(config);
Guolin Ke's avatar
Guolin Ke committed
39
40
41
42
  } else if (type == std::string("gamma")) {
    return new RegressionGammaLoss(config);
  } else if (type == std::string("tweedie")) {
    return new RegressionTweedieLoss(config);
Guolin Ke's avatar
Guolin Ke committed
43
44
45
  }
  return nullptr;
}
46
47

ObjectiveFunction* ObjectiveFunction::CreateObjectiveFunction(const std::string& str) {
Guolin Ke's avatar
Guolin Ke committed
48
  auto strs = Common::Split(str.c_str(), ' ');
49
50
51
52
53
  auto type = strs[0];
  if (type == std::string("regression")) {
    return new RegressionL2loss(strs);
  } else if (type == std::string("regression_l1")) {
    return new RegressionL1loss(strs);
54
55
  } else if (type == std::string("quantile")) {
    return new RegressionQuantileloss(strs);
56
57
58
59
60
61
62
63
64
65
66
67
68
69
  } else if (type == std::string("huber")) {
    return new RegressionHuberLoss(strs);
  } else if (type == std::string("fair")) {
    return new RegressionFairLoss(strs);
  } else if (type == std::string("poisson")) {
    return new RegressionPoissonLoss(strs);
  } else if (type == std::string("binary")) {
    return new BinaryLogloss(strs);
  } else if (type == std::string("lambdarank")) {
    return new LambdarankNDCG(strs);
  } else if (type == std::string("multiclass")) {
    return new MulticlassSoftmax(strs);
  } else if (type == std::string("multiclassova")) {
    return new MulticlassOVA(strs);
70
71
72
73
  } else if (type == std::string("xentropy") || type == std::string("cross_entropy")) {
    return new CrossEntropy(strs);
  } else if (type == std::string("xentlambda") || type == std::string("cross_entropy_lambda")) {
    return new CrossEntropyLambda(strs);
Guolin Ke's avatar
Guolin Ke committed
74
75
76
77
  } else if (type == std::string("gamma")) {
    return new RegressionGammaLoss(strs);
  } else if (type == std::string("tweedie")) {
    return new RegressionTweedieLoss(strs);
78
79
80
81
  }
  return nullptr;
}

Guolin Ke's avatar
Guolin Ke committed
82
}  // namespace LightGBM