def simulate_params(n_groups):
    var1 = Variable('constant_one', lambda x: x, 0.0, 0.0, fe_bounds=[-np.inf, 0.0])
    var2 = Variable('constant_one', np.exp, 0.0, 0.0, fe_bounds=[-np.inf, 0.0])

    if n_groups == 1:
        var1.re_bounds = [0.0, 0.0]
        var2.re_bounds = [0.0, 0.0]
    else:
        var1.re_bounds = [-1.0, 1.0]
        var2.re_bounds = [-1.0, 1.0]

    param1 = Parameter('p1', np.exp, [var1])
    param2 = Parameter('p2', lambda x: x, [var1, var2])
    param3 = Parameter('p3', np.exp, [var1])

    n_var = 4
    fe_true = -np.random.rand(n_var) * 3
    if n_groups == 1:
        re_true = np.zeros((n_groups, n_var))
    else:
        re_true = np.random.randn(n_groups, n_var)

    x_true = re_true + fe_true
    param_true = np.zeros((n_groups, 3))
    param_true[:, 0] = np.exp(x_true[:, 0])
    param_true[:, 1] = x_true[:, 1] + np.exp(x_true[:, 2])
    param_true[:, 2] = np.exp(x_true[:, 3])

    return ParameterSet([param1, param2, param3]), param_true, x_true
Example #2
0
def parameter_set():
    var1 = Variable(covariate='intercept',
                    var_link_fun=lambda x: x,
                    fe_init=0.,
                    re_init=0.)
    var2 = Variable(covariate='intercept',
                    var_link_fun=lambda x: x,
                    fe_init=0.,
                    re_init=0.)
    alpha = Parameter(param_name='alpha',
                      link_fun=lambda x: x,
                      variables=[var1])
    beta = Parameter(param_name='beta', link_fun=lambda x: x, variables=[var2])
    ln_alpha_beta = ParameterFunction(
        param_function_name='ln-alpha-beta',
        param_function=lambda params: np.log(params[0] * params[1]))
    param_set = ParameterSet(parameters=[alpha, beta],
                             parameter_functions=[ln_alpha_beta])
    return param_set
def param_set():
    variable1 = Variable('intercept',
                         lambda x: x,
                         0.0,
                         0.3,
                         re_bounds=[0.0, 1.0])
    variable2 = Variable('intercept',
                         lambda x: x,
                         0.1,
                         0.4,
                         re_bounds=[0.0, 2.0])
    variable3 = Variable('intercept',
                         lambda x: x,
                         0.2,
                         0.5,
                         re_bounds=[0.0, 3.0])
    parameter1 = Parameter('p1', np.exp, [variable1])
    parameter2 = Parameter('p2', np.exp, [variable2])
    parameter3 = Parameter('p3', np.exp, [variable3] * 2)
    parameter_set = ParameterSet([parameter1, parameter2, parameter3])
    assert parameter_set.num_fe == 4
    return parameter_set
Example #4
0
phi_intercept = Variable(covariate='cov_one',
                         var_link_fun=identity_fun,
                         fe_init=p_true / 3,
                         re_init=0.0,
                         fe_bounds=[-numpy.inf, numpy.inf],
                         re_bounds=[0.0, 0.0])

alpha = Parameter(param_name='alpha',
                  link_fun=exp_fun,
                  variables=[a_intercept])
beta = Parameter(param_name='beta',
                 link_fun=identity_fun,
                 variables=[b_intercept, b_social_distance])
p = Parameter(param_name='p', link_fun=exp_fun, variables=[phi_intercept])

parameters = ParameterSet([alpha, beta, p])

optimizer_options = {
    'ftol': 1e-12,
    'gtol': 1e-12,
}

model = CoreModel(param_set=parameters,
                  curve_fun=gaussian_cdf,
                  loss_fun=normal_loss)
solver = ScipyOpt(model)
solver.fit(data=data._get_df(copy=True, return_specs=True),
           options=optimizer_options)
params_estimate = model.get_params(solver.x_opt, expand=True)

# -------------------------------------------------------------------------
Example #5
0
def parameter_set(param1, param2, parameter_function):
    return ParameterSet(
        parameters=[param1, param2],
        parameter_functions=[parameter_function],
    )
Example #6
0
def test_parameter_set_duplicates(param1):
    with pytest.raises(RuntimeError):
        ParameterSet(
            parameters=[param1, param1]
        )