Skip to content

Commit 6e6ec50

Browse files
bugfix
1 parent bb207a3 commit 6e6ec50

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

cpp/term.h

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -591,20 +591,23 @@ void Term::estimate_coefficient_and_error(const VectorXd &x, const VectorXd &y,
591591
if (std::isfinite(coefficient))
592592
{
593593
coefficient *= v;
594-
if (coefficient_adheres_to_monotonic_constraint())
594+
double error_penalty;
595+
bool coefficient_does_not_adhere_to_monotonic_constraint{!coefficient_adheres_to_monotonic_constraint()};
596+
if (coefficient_does_not_adhere_to_monotonic_constraint)
595597
{
596-
VectorXd predictions{x * coefficient};
597-
split_point_search_errors_sum = calculate_sum_error(calculate_errors(y, predictions, sample_weight, MSE_LOSS_FUNCTION)) + error_added;
598+
error_penalty = std::abs(coefficient);
599+
coefficient = 0.0;
598600
}
599-
else
601+
VectorXd predictions{x * coefficient};
602+
split_point_search_errors_sum = calculate_sum_error(calculate_errors(y, predictions, sample_weight, MSE_LOSS_FUNCTION)) + error_added;
603+
if (coefficient_does_not_adhere_to_monotonic_constraint)
600604
{
601-
coefficient = 0;
602-
split_point_search_errors_sum = std::numeric_limits<double>::infinity();
605+
split_point_search_errors_sum += error_penalty;
603606
}
604607
}
605608
else
606609
{
607-
coefficient = 0;
610+
coefficient = 0.0;
608611
split_point_search_errors_sum = std::numeric_limits<double>::infinity();
609612
}
610613
}

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="7.6.0",
18+
version="7.6.1",
1919
description="Automatic Piecewise Linear Regression",
2020
ext_modules=[sfc_module],
2121
author="Mathias von Ottenbreit",

0 commit comments

Comments
 (0)