Exemple #1
0
    def test_smolyak(self):

        import numpy

        f = lambda x: numpy.row_stack([
            x[0,:] * x[1,:]**0.5,
            x[1,:] * x[1,:] - x[0,:] * x[0,:]
        ])

        bounds = numpy.row_stack([
            [0.5,0.1],
            [2,3]
        ])

        from dolo.numeric.smolyak import SmolyakGrid
        sg = SmolyakGrid(bounds,3)

        values = f(sg.grid)
        sg.fit_values(values)
        theta_0 = sg.theta.copy()

        def fobj(theta):
            sg.theta = theta
            return sg(sg.grid)

        fobj(theta_0)
Exemple #2
0
    def test_smolyak_2(self):

        import numpy
        from dolo.numeric.smolyak import SmolyakGrid
        d = 8
        l = 4

        bounds = numpy.row_stack([[-0.5]*6, [0.7]*6])
        sg = SmolyakGrid(bounds,l)
        f = lambda x: numpy.row_stack([
                    x[0,:] * x[1,:],
                    x[1,:] * x[1,:] - x[0,:] * x[0,:]
                ])
        values = f(sg.grid)

        import time
        t = time.time()
        for i in range(5):
            sg.fit_values(sg.grid)

            val = sg(sg.grid)
        s = time.time()
        print(s-t)
s0 = dr.S_bar
bounds = numpy.row_stack([-std,std])
bounds[:,0] += s0[0]
bounds[:,1] += s0[1]
print('bounds')
print bounds

P = eigs[1]

sg = SmolyakGrid( bounds, 5, P)

[y,x,parms] = model.read_calibration()

xinit = dr( sg.grid)
sg.fit_values(xinit)


from dolo.compiler.compiler_global import CModel, time_iteration, deterministic_residuals

gc = CModel(model)




res = deterministic_residuals(sg.grid, xinit, sg, gc.f, gc.g, dr.sigma, parms)


n_e = 5
epsilons = np.zeros((1,n_e))
weights = np.ones(n_e)/n_e
Exemple #4
0
s0 = dr.S_bar
bounds = numpy.row_stack([-std, std])
bounds[:, 0] += s0[0]
bounds[:, 1] += s0[1]
print('bounds')
print bounds

P = eigs[1]

sg = SmolyakGrid(bounds, 5, P)

[y, x, parms] = model.read_calibration()

xinit = dr(sg.grid)
sg.fit_values(xinit)

from dolo.compiler.compiler_global import CModel, time_iteration, deterministic_residuals

gc = CModel(model)

res = deterministic_residuals(sg.grid, xinit, sg, gc.f, gc.g, dr.sigma, parms)

n_e = 5
epsilons = np.zeros((1, n_e))
weights = np.ones(n_e) / n_e

dr_smol = time_iteration(sg.grid,
                         sg,
                         xinit,
                         gc.f,
Exemple #5
0
    import numpy
    from dolo.numeric.smolyak import SmolyakGrid
    d = 8
    l = 4

    bounds = numpy.row_stack([[-0.5]*6, [0.7]*6])
    sg = SmolyakGrid(bounds,l)
    f = lambda x: numpy.row_stack([
                x[0,:] * x[1,:],
                x[1,:] * x[1,:] - x[0,:] * x[0,:]
            ])
    values = f(sg.grid)
    tt = numpy.repeat(sg.grid,40,axis=1)

    print tt.shape
    import time
    t = time.time()
    sg.fit_values(sg.grid)

    for i in range(5):

        val = sg(tt)
    s = time.time()
    print(s-t)
#    unittest.main()
#    tt = TestInterpolation()
#    #    tt.test_2d_interpolation()
#    tt.test_smolyak_2()