Elastic Regression¶
Warping Invariant Regression using SRSF
moduleauthor:: J. Derek Tucker <jdtuck@sandia.gov>
-
regression.
elastic_logistic
(f, y, time, B=None, df=20, max_itr=20, cores=-1, smooth=False)[source]¶ This function identifies a logistic regression model with phase-variability using elastic methods
Parameters: - f (np.ndarray) – numpy ndarray of shape (M,N) of N functions with M samples
- y – numpy array of labels (1/-1)
- time (np.ndarray) – vector of size M describing the sample points
- B – optional matrix describing Basis elements
- 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)
Return type: tuple of numpy array
Return alpha: alpha parameter of model
Return beta: beta(t) of model
Return fn: aligned functions - numpy ndarray of shape (M,N) of M
functions with N samples :return qn: aligned srvfs - similar structure to fn :return gamma: calculated warping functions :return q: original training SRSFs :return B: basis matrix :return b: basis coefficients :return Loss: logistic loss
-
regression.
elastic_mlogistic
(f, y, time, B=None, df=20, max_itr=20, cores=-1, delta=0.01, parallel=True, smooth=False)[source]¶ This function identifies a multinomial logistic regression model with phase-variability using elastic methods
Parameters: - f (np.ndarray) – numpy ndarray of shape (M,N) of N functions with M samples
- y – numpy array of labels {1,2,…,m} for m classes
- time (np.ndarray) – vector of size M describing the sample points
- B – optional matrix describing Basis elements
- 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)
Return type: tuple of numpy array
Return alpha: alpha parameter of model
Return beta: beta(t) of model
Return fn: aligned functions - numpy ndarray of shape (M,N) of N
functions with M samples :return qn: aligned srvfs - similar structure to fn :return gamma: calculated warping functions :return q: original training SRSFs :return B: basis matrix :return b: basis coefficients :return Loss: logistic loss
-
regression.
elastic_prediction
(f, time, model, y=None, smooth=False)[source]¶ This function performs prediction from an elastic regression model with phase-variability
Parameters: - f – numpy ndarray of shape (M,N) of N functions with M samples
- time – vector of size M describing the sample points
- model – identified model from elastic_regression
- y – truth, optional used to calculate SSE
Return type: tuple of numpy array
Return alpha: alpha parameter of model
Return beta: beta(t) of model
Return fn: aligned functions - numpy ndarray of shape (M,N) of N
functions with M samples :return qn: aligned srvfs - similar structure to fn :return gamma: calculated warping functions :return q: original training SRSFs :return B: basis matrix :return b: basis coefficients :return SSE: sum of squared error
-
regression.
elastic_regression
(f, y, time, 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 methods
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
- 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)
Return type: tuple of numpy array
Return alpha: alpha parameter of model
Return beta: beta(t) of model
Return fn: aligned functions - numpy ndarray of shape (M,N) of M
functions with N samples :return qn: aligned srvfs - similar structure to fn :return gamma: calculated warping functions :return q: original training SRSFs :return B: basis matrix :return b: basis coefficients :return SSE: sum of squared error
-
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 :param alpha: numpy scalar
Return type: numpy array Return gamma_new: warping function