Models¶
The package contains different models to capture the voltage signal of the glucose sensor over time. The types of models that are included in the package right now are the following.
Table of Contents
Exponential Decay¶
The model behind exponential decay is
The three parameters are represented in the named tuple
- class glucose_ts.models.exponential_decay.ExpDParameter(A, K, B)¶
The parameter container has all three parameters needed to specify an exponential decay model.
- Parameters
A (float) – the upper asymptote
K (float) – the lower asymptote, for special cases the carrying capacity
B (float) – the growth rate that describles the speed of decay
In order to learn the parameters that are a good fit to your training data we use the following estimator.
- class glucose_ts.models.ExponentialDecay(exp_d_params=None, gaussian_priors=None, variance=None)¶
This Estimator learns the paramters of an exponential decay model. It provides the classic maximum likelihood approach as well as the Bayesian approach maximum posterior.
Moreover it implements the interface of a scikit-learn estimator.
- fit(time, labels)¶
Fits a exponential decay model to training data.
- Parameters
time – points in time or the independent variable here
labels – voltage measurements or the dependent variable
- Returns
the trained exponential decay model
- Return type
- fit_least_squares(features, labels, loss=None)¶
Fits a exponential decay model to training data.
- Parameters
time – points in time or the independent variable here
labels – voltage measurements or the dependent variable
- Returns
the trained exponential decay model
- Return type
- inverse(inputs)¶
computes the inverse function using the model internal parameters
- Parameters
inputs (numpy.array) – points we want to get the inverse values for
- Returns
the inverse function values
- Return type
numpy.array
- predict(time)¶
makes predictions by using the model internal parameters
- Parameters
time (numpy.array) – points in time we want to make predictions for
- Returns
the predictions
- Return type
numpy.array
- time_derivative(time)¶
computes the derivative with respect to time using the model internal parameters
- Parameters
time (numpy.array) – points in time we want to get the derivative for
- Returns
the derivatives
- Return type
numpy.array
Logistic Growth¶
The family of function we refer to as logistic growth models is described by
The four parameters are represented in the named tuple
- class glucose_ts.models.logistic_decrease.LDParameter(A, K, B, M)¶
This data structure contains the four parameter that are needed to identify a logistic function. The notations are identical with the Wikipedia artile with \(\nu = 1\), \(Q = 1\) and \(C = 1\) being set to fixed values.
Please note that we are always dealing with decays in case of the glucose sensor. Therefore we role a lower and upper asymptote is flipped.
- Parameters
A (float) – the upper asymptote
K (float) – the lower asymptote, for the growth case it is the carrying capacity
B (float) – the growth rate
M (float) – the location parameter of the logistic curve
In order to learn the parameters that are a good fit to your training data we use the following estimator.
- class glucose_ts.models.LogisticDecrease(parameter=None, gaussian_priors=None, std=None, time_horizon=None)¶
The Estimator that learns the paramters of a logistic growth model. You can use it for classic maximum likelihood and a Baysian approach.
- fit(time, labels)¶
Finds the logistic growth model parameters that fit the training data
- Parameters
time (np.array) – points in time or the independent variable in this case
labels (np.array) – voltage measurements or the dependent variable
- Returns
the trained generalized logistic model
- Return type
- predict(time)¶
makes predictions for all points in time by using the model internal parameters
- Parameters
time (numpy.array) – points in time we want to make predictions for
- Returns
the predictions
- Return type
numpy.array
- time_derivative(time)¶
computes the derivative with respect to time using the model internal parameters
- Parameters
time (numpy.array) – all the points in time we want to get the derivative for
- Returns
the derivative values
- Return type
numpy.array
Generalized Logistic Growth¶
The formula behind the generalized exponential growth is very similar to the last one.
The Logistic Growth is a special case of this model for \(\nu = 1\) which breaks the symmetry of the curve. The five parameter that are needed to characterize one specific growth curve are stored in the following namedtuple:
- class glucose_ts.models.generalized_logistics.GLParameter(A, K, B, nu, M)¶
The data structure represents all parameters that are needed for a generalized logistic function. The notations are identical with the Wikipedia artile with \(Q=1\) and \(C=1\) being set to fixed values. Please note that we are always dealing with decays in case of the glucose sensor. Therefore we role a lower and upper asymptote is flipped.
- Parameters
A (float) – the upper asymptote
K (float) – the lower asymptote, for special cases the carrying capacity
B (float) – the growth rate
nu (float) – exponent for approximating the growth change
M (float) – the location parameter of the logistic curve
So learn a specific parameter set from training data we use the following estimator.
- class glucose_ts.models.GeneralizedLogisticGrowth(parameter=None, gaussian_priors=None, std_model=None, time_horizon=None)¶
The Estimator that learns the paramters of a generalized logistic growth model. It provides the classic maximum likelihood approach as well as the Bayesian approach maximum posterior.
- fit(time, labels)¶
Fits a generalized logistic model to data.
- Parameters
time (np.array) – points in time or the independent variable here
labels (np.array) – voltage measurements or the dependent variable
- Returns
the trained generalized logistic model
- Return type
- predict(time)¶
makes predictions by using the model internal parameters
- Parameters
time (numpy.array) – points in time we want to make predictions for
- Returns
the predictions
- Return type
numpy.array
- time_derivative(time)¶
computes the derivative with respect to time using the model internal parameters
- Parameters
time (numpy.array) – points in time we want to get the derivative for
- Returns
the derivatives
- Return type
numpy.array