def logistic_warp(alpha,
                  nu,
                  q,
                  y,
                  deltaO=.1,
                  deltag=.05,
                  max_itr=8000,
                  tol=1e-4,
                  display=0,
                  method=1):
    """
    calculates optimal warping for function 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

    :rtype: numpy array
    :return gamma: warping function

    """
    if method == 1:
        tau = 0
        # q, scale = cf.scale_curve(q)
        q = q / norm(q)
        # nu, scale = cf.scale_curve(nu)
        # alpha = alpha/scale

        gam_old, O_old = lw.oclogit_warp(
            np.ascontiguousarray(alpha), np.ascontiguousarray(nu),
            np.ascontiguousarray(q), np.ascontiguousarray(y, dtype=np.int32),
            max_itr, tol, deltaO, deltag, display)
    elif method == 2:
        betanu = cf.q_to_curve(nu)
        beta = cf.q_to_curve(q)
        T = beta.shape[1]
        if y == 1:
            beta1, O_old, tau = cf.find_rotation_and_seed_coord(betanu, beta)
            q = cf.curve_to_q(beta1)[0]
            gam_old = cf.optimum_reparam_curve(nu, q)
        elif y == -1:
            beta1, O_old, tau = cf.find_rotation_and_seed_coord(
                -1 * betanu, beta)
            q = cf.curve_to_q(beta1)[0]
            gam_old = cf.optimum_reparam_curve(-1 * nu, q)

    return (gam_old, O_old, tau)
Beispiel #2
0
def logistic_warp(alpha, nu, q, y, deltaO=.1, deltag=.05, max_itr=8000,
                  tol=1e-4, display=0, method=1):
    """
    calculates optimal warping for function 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

    :rtype: numpy array
    :return gamma: warping function

    """
    if method == 1:
        tau = 0
        # q, scale = cf.scale_curve(q)
        q = q/norm(q)
        # nu, scale = cf.scale_curve(nu)
        # alpha = alpha/scale

        gam_old, O_old = lw.oclogit_warp(np.ascontiguousarray(alpha),
                                         np.ascontiguousarray(nu),
                                         np.ascontiguousarray(q),
                                         np.ascontiguousarray(y, dtype=np.int32),
                                         max_itr, tol, deltaO, deltag, display)
    elif method == 2:
        betanu = cf.q_to_curve(nu)
        beta = cf.q_to_curve(q)
        T = beta.shape[1]
        if y == 1:
            beta1, O_old, tau = cf.find_rotation_and_seed_coord(betanu, beta)
            q = cf.curve_to_q(beta1)
            gam_old = cf.optimum_reparam_curve(nu, q)
        elif y == -1:
            beta1, O_old, tau = cf.find_rotation_and_seed_coord(-1 * betanu, beta)
            q = cf.curve_to_q(beta1)
            gam_old = cf.optimum_reparam_curve(-1 * nu, q)


    return (gam_old, O_old, tau)
Beispiel #3
0
import numpy as np
from scipy.linalg import norm
import fdasrsf as fs
import oclogit_warp as lw
import h5py

fun = h5py.File('/home/dtucker/fdasrsf/debug/debug_data_oc_logit.h5')
q = fun['q'][:]
y = fun['y'].value
alpha = fun['alpha'].value
nu = fun['nu'][:]

max_itr = 9000  # 4000
tol = 1e-4
deltag = .05
deltaO = .1
display = 1

q, scale = fs.scale_curve(q)  # q/norm(q)
nu, scale = fs.scale_curve(nu)  # nu/norm(nu)

gam_old, O_old = lw.oclogit_warp(np.ascontiguousarray(alpha),
                                 np.ascontiguousarray(nu),
                                 np.ascontiguousarray(q),
                                 np.ascontiguousarray(y, dtype=np.int32),
                                 max_itr, tol, deltaO, deltag, display)