def mlogit_warp_grad(alpha, nu, q, y, max_itr=8000, tol=1e-4, deltaO=0.008, deltag=0.008, display=0): """ calculates optimal warping for functional multinomial logistic regression :param alpha: scalar :param nu: numpy ndarray of shape (M,N) of M functions with N samples :param q: numpy ndarray of shape (M,N) of M functions with N samples :param y: numpy ndarray of shape (1,N) of M functions with N samples responses :param max_itr: maximum number of iterations (Default=8000) :param tol: stopping tolerance (Default=1e-10) :param deltaO: gradient step size for rotation (Default=0.008) :param deltag: gradient step size for warping (Default=0.008) :param display: display iterations (Default=0) :rtype: tuple of numpy array :return gam_old: warping function """ alpha = alpha/norm(alpha) q, scale = cf.scale_curve(q) # q/norm(q) for ii in range(0, nu.shape[2]): nu[:, :, ii], scale = cf.scale_curve(nu[:, :, ii]) # nu/norm(nu) gam_old, O_old = mw.ocmlogit_warp(np.ascontiguousarray(alpha), np.ascontiguousarray(nu), np.ascontiguousarray(q), np.ascontiguousarray(y, dtype=np.int32), max_itr, tol, deltaO, deltag, display) return (gam_old, O_old)
import numpy as np from scipy.linalg import norm import fdasrsf as fs import ocmlogit_warp as mw import h5py fun = h5py.File('/home/dtucker/fdasrsf/debug_data_oc_mlogit.h5') q = fun['q'][:] y = fun['y'][:] alpha = fun['alpha'][:] nu = fun['nu'][:] max_itr = 8000 # 4000 tol = 1e-4 deltag = .05 deltaO = .08 display = 1 alpha = alpha / norm(alpha) q, scale = fs.scale_curve(q) # q/norm(q) for ii in range(0, nu.shape[2]): nu[:, :, ii], scale = fs.scale_curve(nu[:, :, ii]) # nu/norm(nu) gam_old, O_old = mw.ocmlogit_warp(np.ascontiguousarray(alpha), np.ascontiguousarray(nu), np.ascontiguousarray(q), np.ascontiguousarray(y, dtype=np.int32), max_itr, tol, deltaO, deltag, display)
import numpy as np from scipy.linalg import norm import fdasrsf as fs import ocmlogit_warp as mw import h5py fun = h5py.File('/home/dtucker/fdasrsf/debug_data_oc_mlogit.h5') q = fun['q'][:] y = fun['y'][:] alpha = fun['alpha'][:] nu = fun['nu'][:] max_itr = 8000 # 4000 tol = 1e-4 deltag = .05 deltaO = .08 display = 1 alpha = alpha/norm(alpha) q, scale = fs.scale_curve(q) # q/norm(q) for ii in range(0, nu.shape[2]): nu[:, :, ii], scale = fs.scale_curve(nu[:, :, ii]) # nu/norm(nu) gam_old, O_old = mw.ocmlogit_warp(np.ascontiguousarray(alpha), np.ascontiguousarray(nu), np.ascontiguousarray(q), np.ascontiguousarray(y, dtype=np.int32), max_itr, tol, deltaO, deltag, display)