def H_1PL(theta, r, f, P, a, b, c=0, Pstar=None): """Get the Hessian Matrix of the log likelihood for the 1PL model (2nd derivative wrt b) """ theta, r, f = expand_dims(P, theta, r, f) rmfP = r - f * P Q = (1 - P) Pstar, Prat = ((P, 1) if Pstar is None else (Pstar, Pstar / P)) EL22 = -a**2 * f * Prat * Pstar * Q return np.nansum([[EL22]], axis=2)
def H_1PL(theta, r, f, P, zeta, lam, c=0, Pstar=None): """Get the Hessian Matrix of the log likelihood for the 1PL model (2nd derivative wrt zeta) """ theta, r, f = expand_dims(P, theta, r, f) Pstar = P if Pstar is None else Pstar W = Pstar * (1 - Pstar) rP2 = r / P**2 rP2cmf = rP2 * c - f EL11 = rP2cmf * W return np.nansum([[EL11]], axis=2)
def J_1PL(theta, r, f, P, zeta, lam, c=0, Pstar=None): """Get the Jacobian of the log likelihood for the 1PL model (1st derivative wrt zeta) a here is an ARRAY, not a scalar """ theta, r, f = expand_dims(P, theta, r, f) rmfP = r - f * P Prat = 1 if Pstar is None else Pstar / P L1 = Prat * rmfP return np.nansum([L1], axis=1)
def J_3PL(theta, r, f, P, zeta, lam, c, Pstar): """Get the Jacobian of the log likelihood for the 3PL model (1st derivatives wrt zeta, lam, c) a here is an ARRAY, not a scalar """ theta, r, f = expand_dims(P, theta, r, f) rmfP = r - f * P Prat = 1 if Pstar is None else Pstar / P iP1mc = 1 / (P * (1 - c)) L1, L2, L3 = np.array([Prat, Prat * theta, iP1mc]) * rmfP return np.nansum([L1, L2, L3], axis=1)
def J_1PL(theta, r, f, P, a, b, c=0, Pstar=None): """Get the Jacobian of the log likelihood for the 1PL model (1st derivative wrt b) a here is an ARRAY, not a scalar """ a = a * np.ones(P.shape) # force a to be an array theta, r, f = expand_dims(P, theta, r, f) rmfP = r - f * P Prat = 1 if Pstar is None else Pstar / P L2 = -a * rmfP * Prat return np.nansum([L2], axis=1)
def H_2PL(theta, r, f, P, a, b, c=0, Pstar=None): """Get the Hessian Matrix of the log likelihood for the 2PL model (2nd derivative wrt a,b) """ theta, r, f = expand_dims(P, theta, r, f) rmfP = r - f * P Q = (1 - P) Pstar, Prat = ((P, 1) if Pstar is None else (Pstar, Pstar / P)) thmb = theta - b EL11, EL22, EL12 = np.array([thmb**2, -a**2, a * thmb ]) * f * Prat * Pstar * Q return np.nansum([[EL11, EL12], [EL12, EL22]], axis=2)
def J_3PL(theta, r, f, P, a, b, c, Pstar): """Get the Jacobian of the log likelihood for the 3PL model (1st derivatives wrt a,b,c) a here is an ARRAY, not a scalar """ a = a * np.ones(P.shape) # force a to be an array theta, r, f = expand_dims(P, theta, r, f) rmfP = r - f * P iPc = 1 / (P - c) Prat = Pstar / P thmb = theta - b L1, L2, L3 = np.array([thmb, -a, iPc]) * rmfP * Prat return np.nansum([L1, L2, L3], axis=1)
def H_3PL(theta, r, f, P, zeta, lam, c, Pstar): """Get the Hessian Matrix of the log likelihood for the 3PL model (2nd derivative wrt zeta, lam, c) """ theta, r, f = expand_dims(P, theta, r, f) Pstar = P if Pstar is None else Pstar W = Pstar * (1 - Pstar) rP2 = r / P**2 rP2cmf = rP2 * c - f EL11, EL22, EL33 = [ rP2cmf * W, rP2cmf * W * theta**2, (rP2 * (2 * P - 1) - f) / (1 - c)**2 ] EL12, EL13, EL23 = [rP2cmf * W * theta, -rP2 * W, -rP2 * W * theta] return np.nansum( [[EL11, EL12, EL13], [EL12, EL22, EL23], [EL13, EL23, EL33]], axis=2)
def H_3PL(theta, r, f, P, a, b, c, Pstar): """Get the Hessian Matrix of the log likelihood for the 3PL model (2nd derivative wrt a,b,c) """ theta, r, f = expand_dims(P, theta, r, f) rmfP = r - f * P iPc = 1 / (P - c) Q = (1 - P) Qic = Q / (1 - c) Prat = Pstar / P thmb = theta - b EL11, EL22, EL33 = np.array( [-P * Q * thmb**2 * Prat, -a**2 * P * Q * Prat, Qic * iPc]) * f * Prat EL12, EL13, EL23 = np.array( [a * thmb * P * Q * Prat, -thmb * Qic, a * Qic]) * f * Prat return np.nansum( [[EL11, EL12, EL13], [EL12, EL22, EL23], [EL13, EL23, EL33]], axis=2)