objective_function.cpp 3.57 KB
Newer Older
1
2
3
4
/*!
 * Copyright (c) 2016 Microsoft Corporation. All rights reserved.
 * Licensed under the MIT License. See LICENSE file in the project root for license information.
 */
Guolin Ke's avatar
Guolin Ke committed
5
#include <LightGBM/objective_function.h>
6

Guolin Ke's avatar
Guolin Ke committed
7
#include "binary_objective.hpp"
8
#include "multiclass_objective.hpp"
9
10
#include "rank_objective.hpp"
#include "regression_objective.hpp"
11
#include "xentropy_objective.hpp"
Guolin Ke's avatar
Guolin Ke committed
12
13
14

namespace LightGBM {

Guolin Ke's avatar
Guolin Ke committed
15
ObjectiveFunction* ObjectiveFunction::CreateObjectiveFunction(const std::string& type, const Config& config) {
Guolin Ke's avatar
Guolin Ke committed
16
  if (type == std::string("regression")) {
Guolin Ke's avatar
Guolin Ke committed
17
    return new RegressionL2loss(config);
Guolin Ke's avatar
Guolin Ke committed
18
  } else if (type == std::string("regression_l1")) {
19
    return new RegressionL1loss(config);
20
21
  } else if (type == std::string("quantile")) {
    return new RegressionQuantileloss(config);
Tsukasa OMOTO's avatar
Tsukasa OMOTO committed
22
  } else if (type == std::string("huber")) {
Tsukasa OMOTO's avatar
Tsukasa OMOTO committed
23
    return new RegressionHuberLoss(config);
Tsukasa OMOTO's avatar
Tsukasa OMOTO committed
24
25
  } else if (type == std::string("fair")) {
    return new RegressionFairLoss(config);
26
27
  } else if (type == std::string("poisson")) {
    return new RegressionPoissonLoss(config);
Guolin Ke's avatar
Guolin Ke committed
28
  } else if (type == std::string("binary")) {
Guolin Ke's avatar
Guolin Ke committed
29
    return new BinaryLogloss(config);
Guolin Ke's avatar
Guolin Ke committed
30
  } else if (type == std::string("lambdarank")) {
Guolin Ke's avatar
Guolin Ke committed
31
    return new LambdarankNDCG(config);
Guolin Ke's avatar
Guolin Ke committed
32
  } else if (type == std::string("multiclass")) {
Guolin Ke's avatar
Guolin Ke committed
33
    return new MulticlassSoftmax(config);
Guolin Ke's avatar
Guolin Ke committed
34
  } else if (type == std::string("multiclassova")) {
Guolin Ke's avatar
Guolin Ke committed
35
    return new MulticlassOVA(config);
Guolin Ke's avatar
Guolin Ke committed
36
  } else if (type == std::string("cross_entropy")) {
37
    return new CrossEntropy(config);
Guolin Ke's avatar
Guolin Ke committed
38
  } else if (type == std::string("cross_entropy_lambda")) {
39
    return new CrossEntropyLambda(config);
Guolin Ke's avatar
Guolin Ke committed
40
  } else if (type == std::string("mape")) {
41
    return new RegressionMAPELOSS(config);
Guolin Ke's avatar
Guolin Ke committed
42
43
44
45
  } 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
46
  } else if (type == std::string("custom")) {
47
    return nullptr;
Guolin Ke's avatar
Guolin Ke committed
48
  }
49
  Log::Fatal("Unknown objective type name: %s", type.c_str());
Guolin Ke's avatar
Guolin Ke committed
50
}
51
52

ObjectiveFunction* ObjectiveFunction::CreateObjectiveFunction(const std::string& str) {
Guolin Ke's avatar
Guolin Ke committed
53
  auto strs = Common::Split(str.c_str(), ' ');
54
55
56
57
58
  auto type = strs[0];
  if (type == std::string("regression")) {
    return new RegressionL2loss(strs);
  } else if (type == std::string("regression_l1")) {
    return new RegressionL1loss(strs);
59
60
  } else if (type == std::string("quantile")) {
    return new RegressionQuantileloss(strs);
61
62
63
64
65
66
67
68
69
70
71
72
73
74
  } 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);
Guolin Ke's avatar
Guolin Ke committed
75
  } else if (type == std::string("cross_entropy")) {
76
    return new CrossEntropy(strs);
Guolin Ke's avatar
Guolin Ke committed
77
  } else if (type == std::string("cross_entropy_lambda")) {
78
    return new CrossEntropyLambda(strs);
Guolin Ke's avatar
Guolin Ke committed
79
  } else if (type == std::string("mape")) {
Guolin Ke's avatar
Guolin Ke committed
80
    return new RegressionMAPELOSS(strs);
Guolin Ke's avatar
Guolin Ke committed
81
82
83
84
  } else if (type == std::string("gamma")) {
    return new RegressionGammaLoss(strs);
  } else if (type == std::string("tweedie")) {
    return new RegressionTweedieLoss(strs);
Guolin Ke's avatar
Guolin Ke committed
85
  } else if (type == std::string("custom")) {
86
    return nullptr;
87
  }
88
  Log::Fatal("Unknown objective type name: %s", type.c_str());
89
90
}

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