예제 #1
0
 def test_dcost(self):
     state_grid = np.arange ( 1, 365*10, 5 )
     gamma = 100
     lag = 1
     N = len(state_grid)
     state_config = OrderedDict ({'magnitude':3})
     I = np.identity( N )
     D = np.matrix(I - np.roll( I, lag ))
     x = np.ones_like(state_grid)*3.
     a = TemporalSmoother ( state_grid, gamma, lag=lag, required_params=['magnitude'] )
     x_dict = OrderedDict ({'magnitude':x})
     cost = gamma*(D.dot(x)).T.dot(D.dot(x))
     assert_equal ( np.squeeze(a.der_cost( x_dict, state_config)[1]), np.zeros(N) )
예제 #2
0
 def test_cost(self):
     state_grid = np.arange ( 1, 365*10, 5 )
     gamma = 100
     lag = 1
     N = len(state_grid)
     state_config = OrderedDict ({'magnitude':3})
     I = np.identity( N )
     D = np.matrix(I - np.roll( I, lag ))
     x = np.ones_like(state_grid)*3.
     a = TemporalSmoother ( state_grid, gamma, lag=lag, required_params=['magnitude'] )
     x_dict = OrderedDict ({'magnitude':x})
     cost = x.dot ( D*D.T).dot(x)
     cost = 0.5*gamma*cost
     #import pdb; pdb.set_trace()
     assert_equal ( np.squeeze(a.der_cost( x_dict, state_config)[0]), cost )
예제 #3
0
 def test_dcost(self):
     state_grid = np.arange(1, 365 * 10, 5)
     gamma = 100
     lag = 1
     N = len(state_grid)
     state_config = OrderedDict({'magnitude': 3})
     I = np.identity(N)
     D = np.matrix(I - np.roll(I, lag))
     x = np.ones_like(state_grid) * 3.
     a = TemporalSmoother(state_grid,
                          gamma,
                          lag=lag,
                          required_params=['magnitude'])
     x_dict = OrderedDict({'magnitude': x})
     cost = gamma * (D.dot(x)).T.dot(D.dot(x))
     assert_equal(np.squeeze(a.der_cost(x_dict, state_config)[1]),
                  np.zeros(N))
예제 #4
0
 def test_cost(self):
     state_grid = np.arange(1, 365 * 10, 5)
     gamma = 100
     lag = 1
     N = len(state_grid)
     state_config = OrderedDict({'magnitude': 3})
     I = np.identity(N)
     D = np.matrix(I - np.roll(I, lag))
     x = np.ones_like(state_grid) * 3.
     a = TemporalSmoother(state_grid,
                          gamma,
                          lag=lag,
                          required_params=['magnitude'])
     x_dict = OrderedDict({'magnitude': x})
     cost = x.dot(D * D.T).dot(x)
     cost = 0.5 * gamma * cost
     #import pdb; pdb.set_trace()
     assert_equal(np.squeeze(a.der_cost(x_dict, state_config)[0]), cost)