Exemplo n.º 1
0
def test_rt_minimize():
    def func(x, theta1, theta2):
        f = ((x - theta1 - theta2) ** 2).sum()
        df = 2 * (x - theta1 - theta2)
        return (f, df)

    X = normal(0, 1.0, (3,))
    x0 = X[:]
    theta1 = asarray([2.3, 1.1, -4.4])
    theta2 = asarray([1.0, 2.0, 3.0])

    (x, fx, i) = rt_minimize(X, func, -100, theta1, theta2)
    assert allclose(x, theta1 + theta2)
    assert allclose(fx[-1], 0.0)
Exemplo n.º 2
0
def test_rt_minimize():
    def func(x, theta1, theta2):
        f = ((x - theta1 - theta2)**2).sum()
        df = 2 * (x - theta1 - theta2)
        return (f, df)

    X = normal(0, 1.0, (3, ))
    x0 = X[:]
    theta1 = asarray([2.3, 1.1, -4.4])
    theta2 = asarray([1., 2., 3.])

    (x, fx, i) = rt_minimize(X, func, -100, theta1, theta2)
    assert allclose(x, theta1 + theta2)
    assert allclose(fx[-1], 0.0)
Exemplo n.º 3
0
def learn_bocpd(X, model_f, hazard_f, conversion):
  max_minimize_iter = 30

  theta = hazard_f.hazard_params
  theta.extend(model_f.post_params)

  theta, nlml, _ = rt_minimize(theta, bocpd_dwrap1D, -max_minimize_iter, X, model_f, hazard_f, conversion, hazard_f.num_hazard_params)
  print "we make it to here!"

  hazard_f.hazard_params = theta[0:num_hazard_params]
  model_f.model_params   = theta[num_hazard_params:]

  hazard_f.hazard_params[0] = logistic(hazard_f.hazard_params[0])
  model_f.model_params[1:]  = np.exp(model_f.model_params[1:])
  return hazard_params, model_params, nlml
Exemplo n.º 4
0
def learn_bocpd(X, model_f, hazard_f, conversion):
    max_minimize_iter = 30

    theta = hazard_f.hazard_params
    theta.extend(model_f.post_params)

    theta, nlml, _ = rt_minimize(theta, bocpd_dwrap1D, -max_minimize_iter, X,
                                 model_f, hazard_f, conversion,
                                 hazard_f.num_hazard_params)
    print "we make it to here!"

    hazard_f.hazard_params = theta[0:num_hazard_params]
    model_f.model_params = theta[num_hazard_params:]

    hazard_f.hazard_params[0] = logistic(hazard_f.hazard_params[0])
    model_f.model_params[1:] = np.exp(model_f.model_params[1:])
    return hazard_params, model_params, nlml