Skip to content

Commit 7715e27

Browse files
small bugfix and more efficient calculation of some loss functions
1 parent 3f997a8 commit 7715e27

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

API_REFERENCE.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ The learning rate. Must be greater than zero and not more than one. The higher t
1414
Used to randomly split training observations into training and validation if ***validation_set_indexes*** is not specified when fitting.
1515

1616
#### family (default = "gaussian")
17-
Determines the loss function used. Allowed values are "gaussian", "binomial", "poisson", "gamma" and "tweedie". This is used together with ***link_function***.
17+
Determines the loss function used. Allowed values are "gaussian", "binomial", "poisson", "gamma" and "tweedie". This is used together with ***link_function***. Please note that this is not a tuning parameter because it defines how the loss function is calculated.
1818

1919
#### link_function (default = "identity")
2020
Determines how the linear predictor is transformed to predictions. Allowed values are "identity", "logit" and "log". For an ordinary regression model use ***family*** "gaussian" and ***link_function*** "identity". For logistic regression use ***family*** "binomial" and ***link_function*** "logit". For a multiplicative model use the "log" ***link_function***. The "log" ***link_function*** often works best with a "poisson", "gamma" or "tweedie" ***family***, depending on the data. The ***family*** "poisson", "gamma" or "tweedie" should only be used with the "log" ***link_function***. Inappropriate combinations of ***family*** and ***link_function*** may result in a warning message when fitting the model and/or a poor model fit. Please note that values other than "identity" typically require a significantly higher ***m*** (or ***v***) in order to converge.
@@ -50,7 +50,7 @@ Limits 1) the number of terms already in the model that can be considered as int
5050
***0*** does not print progress reports during fitting. ***1*** prints a summary after running the ***fit*** method. ***2*** prints a summary after each boosting step.
5151

5252
#### tweedie_power (default = 1.5)
53-
Species the variance power for the "tweedie" ***family*** and ***link_function***.
53+
Species the variance power for the "tweedie" ***family*** and ***link_function***. Please note that this is not a tuning parameter because it defines how the loss function is calculated.
5454

5555

5656
## Method: fit(X:npt.ArrayLike, y:npt.ArrayLike, sample_weight:npt.ArrayLike = np.empty(0), X_names:List[str]=[], validation_set_indexes:List[int]=[])

cpp/functions.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ static bool is_approximately_zero(TReal a, TReal tolerance = std::numeric_limits
4242

4343
double set_error_to_infinity_if_invalid(double error)
4444
{
45-
bool error_is_invalid{std::isless(error,0) || std::isnan(error) || std::isinf(error)};
45+
bool error_is_invalid{!std::isfinite(error)};
4646
if(error_is_invalid)
4747
error=std::numeric_limits<double>::infinity();
4848

@@ -70,13 +70,13 @@ VectorXd calculate_poisson_errors(const VectorXd &y,const VectorXd &predicted)
7070

7171
VectorXd calculate_gamma_errors(const VectorXd &y,const VectorXd &predicted)
7272
{
73-
VectorXd errors{predicted.array().log() - y.array().log() + y.array()/predicted.array()-1};
73+
VectorXd errors{predicted.array().log() + y.array()/predicted.array()-1};
7474
return errors;
7575
}
7676

7777
VectorXd calculate_tweedie_errors(const VectorXd &y,const VectorXd &predicted,double tweedie_power=1.5)
7878
{
79-
VectorXd errors{y.array().pow(2-tweedie_power).array() / (1-tweedie_power) / (2-tweedie_power) - y.array()*predicted.array().pow(1-tweedie_power) / (1-tweedie_power) + predicted.array().pow(2-tweedie_power) / (2-tweedie_power)};
79+
VectorXd errors{-y.array()*predicted.array().pow(1-tweedie_power) / (1-tweedie_power) + predicted.array().pow(2-tweedie_power) / (2-tweedie_power)};
8080
return errors;
8181
}
8282

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
setuptools.setup(
1717
name='aplr',
18-
version='1.6.1',
18+
version='1.6.2',
1919
description='Automatic Piecewise Linear Regression',
2020
ext_modules=[sfc_module],
2121
author="Mathias von Ottenbreit",

0 commit comments

Comments
 (0)