mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
36 lines
1.0 KiB
C++
36 lines
1.0 KiB
C++
#include "logistic_model.h"
|
|
#include <math.h>
|
|
#include <assert.h>
|
|
|
|
namespace Regression {
|
|
|
|
double LogisticModel::evaluate(double * modelCoefficients, double x) const {
|
|
double a = modelCoefficients[0];
|
|
double b = modelCoefficients[1];
|
|
double c = modelCoefficients[2];
|
|
return c/(1.0+a*exp(-b*x));
|
|
}
|
|
|
|
double LogisticModel::partialDerivate(double * modelCoefficients, int derivateCoefficientIndex, double x) const {
|
|
double a = modelCoefficients[0];
|
|
double b = modelCoefficients[1];
|
|
double c = modelCoefficients[2];
|
|
double denominator = 1.0+a*exp(-b*x);
|
|
if (derivateCoefficientIndex == 0) {
|
|
// Derivate: exp(-b*x)*(-1 * c/(1.0+a*exp(-b*x))^2)
|
|
return -exp(-b*x) * c/(denominator * denominator);
|
|
}
|
|
if (derivateCoefficientIndex == 1) {
|
|
// Derivate: (-x)*a*exp(-b*x)*(-1/(1.0+a*exp(-b*x))^2)
|
|
return x*a*exp(-b*x)*c/(denominator * denominator);
|
|
}
|
|
if (derivateCoefficientIndex == 2) {
|
|
// Derivate: (-x)*a*exp(-b*x)*(-1/(1.0+a*exp(-b*x))^2)
|
|
return 1.0/denominator;
|
|
}
|
|
assert(false);
|
|
return 0.0;
|
|
}
|
|
|
|
}
|