def np_hess(log_like, params, method, log_like_kwargs): """We wrote this function because we did not want to touch the differentiation files. """ numpy_hessian = hessian(log_like, params, method, func_kwargs=log_like_kwargs) return numpy_hessian.to_numpy()
def test_hessian(statsmodels_fixtures, method, extrapolation): fix = statsmodels_fixtures calculated = hessian( logit_loglike, fix["params"], method=method, extrapolation=extrapolation, func_kwargs={ "y": fix["y"], "x": fix["x"] }, ) expected = fix["hessian"] assert_frame_equal(calculated, expected)
def params_hess(params, df, beta, maint_func, repl_4=False): """Calculates the hessian of the cost parameters.""" transition_results = estimate_transitions(df, repl_4=repl_4) ll_trans = transition_results["fun"] states = df.loc[:, "state"].to_numpy() num_obs = df.shape[0] if repl_4: num_states = 90 else: num_states = int(1.2 * np.max(states)) trans_mat = create_transition_matrix(num_states, np.array(transition_results["x"])) state_mat = create_state_matrix(states, num_states, num_obs) endog = df.loc[:, "decision"].to_numpy() decision_mat = np.vstack(((1 - endog), endog)) params_df = pd.DataFrame(index=["RC", "theta_1_1"], columns=["value"], data=params) wrap_func = create_wrap_func(maint_func, num_states, trans_mat, state_mat, decision_mat, beta, ll_trans) return hessian(wrap_func, params_df)