Elastic Regression#
Warping Invariant Regression using SRSF
moduleauthor:: J. Derek Tucker <jdtuck@sandia.gov>
- class regression.elastic_logistic(f, y, time)[source]#
This class provides elastic logistic regression for functional data using the SRVF framework accounting for warping
Usage: obj = elastic_logistic(f,y,time)
- Parameters:
f (np.ndarray) – numpy ndarray of shape (M,N) of N functions with M samples
y – numpy array of N responses
time (np.ndarray) – vector of size M describing the sample points
B – optional matrix describing Basis elements
alpha – alpha parameter of model
beta – beta(t) of model
fn – aligned functions - numpy ndarray of shape (M,N) of M functions with N samples
qn – aligned srvfs - similar structure to fn
gamma – calculated warping functions
q – original training SRSFs
b – basis coefficients
Loss – logistic loss
Author : J. D. Tucker (JDT) <jdtuck AT sandia.gov> Date : 29-Oct-2021
- calc_model(B=None, lam=0, df=20, max_itr=20, cores=-1, smooth=False)[source]#
This function identifies a regression model with phase-variability using elastic pca
- Parameters:
B – optional matrix describing Basis elements
lam – regularization parameter (default 0)
df – number of degrees of freedom B-spline (default 20)
max_itr – maximum number of iterations (default 20)
cores – number of cores for parallel processing (default all)
- predict(newdata=None)[source]#
This function performs prediction on regression model on new data if available or current stored data in object Usage: obj.predict(newdata)
- Parameters:
newdata (dict) – dict containing new data for prediction (needs the keys below, if None predicts on training data)
f – (M,N) matrix of functions
time – vector of time points
y – truth if available
smooth – smooth data if needed
sparam – number of times to run filter
- class regression.elastic_mlogistic(f, y, time)[source]#
This class provides elastic multinomial logistic regression for functional data using the SRVF framework accounting for warping
Usage: obj = elastic_mlogistic(f,y,time)
- Parameters:
f (np.ndarray) – numpy ndarray of shape (M,N) of N functions with M samples
y – numpy array of N responses
time (np.ndarray) – vector of size M describing the sample points
B – optional matrix describing Basis elements
alpha – alpha parameter of model
beta – beta(t) of model
fn – aligned functions - numpy ndarray of shape (M,N) of N functions with M samples
qn – aligned srvfs - similar structure to fn
gamma – calculated warping functions
q – original training SRSFs
b – basis coefficients
Loss – logistic loss
Author : J. D. Tucker (JDT) <jdtuck AT sandia.gov> Date : 29-Oct-2021
- calc_model(B=None, lam=0, df=20, max_itr=20, delta=0.01, cores=-1, smooth=False)[source]#
This function identifies a regression model with phase-variability using elastic pca
- Parameters:
B – optional matrix describing Basis elements
lam – regularization parameter (default 0)
df – number of degrees of freedom B-spline (default 20)
max_itr – maximum number of iterations (default 20)
cores – number of cores for parallel processing (default all)
- predict(newdata=None)[source]#
This function performs prediction on regression model on new data if available or current stored data in object Usage: obj.predict(newdata)
- Parameters:
newdata (dict) – dict containing new data for prediction (needs the keys below, if None predicts on training data)
f – (M,N) matrix of functions
time – vector of time points
y – truth if available
smooth – smooth data if needed
sparam – number of times to run filter
- class regression.elastic_regression(f, y, time)[source]#
This class provides elastic regression for functional data using the SRVF framework accounting for warping
Usage: obj = elastic_regression(f,y,time)
- Parameters:
f – numpy ndarray of shape (M,N) of N functions with M samples
y – numpy array of N responses
time – vector of size M describing the sample points
B – optional matrix describing Basis elements
alpha – alpha parameter of model
beta – beta(t) of model
fn – aligned functions - numpy ndarray of shape (M,N) of M functions with N samples
qn – aligned srvfs - similar structure to fn
gamma – calculated warping functions
q – original training SRSFs
b – basis coefficients
SSE – sum of squared error
Author : J. D. Tucker (JDT) <jdtuck AT sandia.gov> Date : 29-Oct-2021
- calc_model(B=None, lam=0, df=20, max_itr=20, cores=-1, smooth=False)[source]#
This function identifies a regression model with phase-variability using elastic pca
- Parameters:
B – optional matrix describing Basis elements
lam – regularization parameter (default 0)
df – number of degrees of freedom B-spline (default 20)
max_itr – maximum number of iterations (default 20)
cores – number of cores for parallel processing (default all)
- predict(newdata=None)[source]#
This function performs prediction on regression model on new data if available or current stored data in object Usage: obj.predict(newdata)
- Parameters:
newdata (dict) – dict containing new data for prediction (needs the keys below, if None predicts on training data)
f – (M,N) matrix of functions
time – vector of time points
y – truth if available
smooth – smooth data if needed
sparam – number of times to run filter
- regression.logistic_warp(beta, time, q, y)[source]#
calculates optimal warping for function logistic regression
- Parameters:
beta – numpy ndarray of shape (M,N) of N functions with M samples
time – vector of size N describing the sample points
q – numpy ndarray of shape (M,N) of N functions with M samples
y – numpy ndarray of shape (1,N) responses
- Return type:
numpy array
- Return gamma:
warping function
- regression.logit_gradient(b, X, y)[source]#
calculates gradient of the logistic loss
- Parameters:
b – numpy ndarray of shape (M,N) of N functions with M samples
X – numpy ndarray of shape (M,N) of N functions with M samples
y – numpy ndarray of shape (1,N) responses
- Return type:
numpy array
- Return grad:
gradient of logistic loss
- regression.logit_hessian(s, b, X, y)[source]#
calculates hessian of the logistic loss
- Parameters:
s – numpy ndarray of shape (M,N) of N functions with M samples
b – numpy ndarray of shape (M,N) of N functions with M samples
X – numpy ndarray of shape (M,N) of N functions with M samples
y – numpy ndarray of shape (1,N) responses
- Return type:
numpy array
- Return out:
hessian of logistic loss
- regression.logit_loss(b, X, y)[source]#
logistic loss function, returns Sum{-log(phi(t))}
- Parameters:
b – numpy ndarray of shape (M,N) of N functions with M samples
X – numpy ndarray of shape (M,N) of N functions with M samples
y – numpy ndarray of shape (1,N) of N responses
- Return type:
numpy array
- Return out:
loss value
- regression.mlogit_gradient(b, X, Y)[source]#
calculates gradient of the multinomial logistic loss
- Parameters:
b – numpy ndarray of shape (M,N) of N functions with M samples
X – numpy ndarray of shape (M,N) of N functions with M samples
y – numpy ndarray of shape (1,N) responses
- Return type:
numpy array
- Return grad:
gradient
- regression.mlogit_loss(b, X, Y)[source]#
calculates multinomial logistic loss (negative log-likelihood)
- Parameters:
b – numpy ndarray of shape (M,N) of N functions with M samples
X – numpy ndarray of shape (M,N) of N functions with M samples
y – numpy ndarray of shape (1,N) responses
- Return type:
numpy array
- Return nll:
negative log-likelihood
- regression.mlogit_warp_grad(alpha, beta, time, q, y, max_itr=8000, tol=1e-10, delta=0.008, display=0)[source]#
calculates optimal warping for functional multinomial logistic regression
- Parameters:
alpha – scalar
beta – numpy ndarray of shape (M,N) of N functions with M samples
time – vector of size M describing the sample points
q – numpy ndarray of shape (M,N) of N functions with M samples
y – numpy ndarray of shape (1,N) responses
max_itr – maximum number of iterations (Default=8000)
tol – stopping tolerance (Default=1e-10)
delta – gradient step size (Default=0.008)
display – display iterations (Default=0)
- Return type:
tuple of numpy array
- Return gam_old:
warping function
- regression.phi(t)[source]#
calculates logistic function, returns 1 / (1 + exp(-t))
- Parameters:
t – scalar
- Return type:
numpy array
- Return out:
return value
- regression.regression_warp(beta, time, q, y, alpha)[source]#
calculates optimal warping for function linear regression
- Parameters:
beta – numpy ndarray of shape (M,N) of M functions with N samples
time – vector of size N describing the sample points
q – numpy ndarray of shape (M,N) of M functions with N samples
y – numpy ndarray of shape (1,N) of M functions with N samples responses
alpha – numpy scalar
- Return type:
numpy array
- Return gamma_new:
warping function