Example #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) )
Example #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 )
Example #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))
Example #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)
Example #5
0
    def test_gamma(self):
        state_grid = np.arange(1, 365 * 10, 5)
        gamma = 100
        #self.class = TemporalSmoother ( state_grid, gamma )
        state_config = OrderedDict({'magnitude': 3})

        a = TemporalSmoother(state_grid, gamma, required_params=['magnitude'])

        assert_equal(a.gamma, gamma)
Example #6
0
    def test_Dmatrix_lag(self):
        state_grid = np.arange(1, 365 * 10, 5)
        gamma = 100
        lag = 1
        N = len(state_grid)
        state_config = OrderedDict({'magnitude': 3})

        a = TemporalSmoother(state_grid,
                             gamma,
                             lag=lag,
                             required_params=['magnitude'])
        # Create constraint matrix as main diagonal of ones
        # and off diagonal shifted by lag of -1s
        I = np.identity(N)
        D1 = np.matrix(I - np.roll(I, lag))
        D1 = D1 * D1.T
        assert_equal(a.D1.todense(), D1)