def test_markov_chain():

    from dolo import yaml_import
    fname = 'examples/models/rbc_mfga.yaml'
    model = yaml_import(fname)

    from dolo.numeric.discretization import multidimensional_discretization
    import numpy
    sigma = numpy.array([[0.01]])
    rho = 0.01
    [P,Q] = multidimensional_discretization(rho, sigma, 3)

    print(model.markov_chain)
Beispiel #2
0
def AR1(rho, sigma, *pargs, **kwargs):
    rho_array = np.array(rho, dtype=float)
    sigma_array = np.atleast_2d( np.array(sigma, dtype=float) )
    try:
        assert(rho_array.ndim<=1)
    except:
        raise Exception("When discretizing a Vector AR1 process, the autocorrelation coefficient must be as scalar. Found: {}".format(rho_array))
    try:
        assert(sigma_array.shape[0] == sigma_array.shape[1])
    except:
        raise Exception("The covariance matrix for a Vector AR1 process must be square. Found: {}".format())
    from dolo.numeric.discretization import multidimensional_discretization
    [P,Q] = multidimensional_discretization(rho_array, sigma_array, *pargs, **kwargs)
    return P,Q
Beispiel #3
0
def AR1(rho, sigma, *pargs, **kwargs):
    rho_array = np.array(rho, dtype=float)
    sigma_array = np.atleast_2d( np.array(sigma, dtype=float) )
    try:
        assert(rho_array.ndim<=1)
    except:
        raise Exception("When discretizing a Vector AR1 process, the autocorrelation coefficient must be as scalar. Found: {}".format(rho_array))
    try:
        assert(sigma_array.shape[0] == sigma_array.shape[1])
    except:
        raise Exception("The covariance matrix for a Vector AR1 process must be square. Found: {}".format())
    from dolo.numeric.discretization import multidimensional_discretization
    [P,Q] = multidimensional_discretization(rho_array, sigma_array, *pargs, **kwargs)
    return P,Q
Beispiel #4
0
    def discretize(self, N=3):

        rho = self.rho
        Sigma = self.Sigma

        try:
            assert(abs(np.eye(rho.shape[0])*rho[0,0]-rho).max() <= 1)
        except:
            raise Exception("When discretizing a Vector AR1 process, the autocorrelation coefficient must be as scalar. Found: {}".format(rho_array))

        from dolo.numeric.discretization import multidimensional_discretization

        [P,Q] = multidimensional_discretization(rho[0,0], Sigma, N=N)

        return DiscreteMarkovProcess(values=P, transitions=Q)
Beispiel #5
0
    def __init__(self, rho=None, sigma=None, N=2):

        rho_array = np.array(rho, dtype=float)
        sigma_array = np.atleast_2d(np.array(sigma, dtype=float))
        try:
            assert(rho_array.ndim <= 1)
        except:
            raise Exception("When discretizing a Vector AR1 process, the autocorrelation coefficient must be as scalar. Found: {}".format(rho_array))
        try:
            assert(sigma_array.shape[0] == sigma_array.shape[1])
        except:
            raise Exception("The covariance matrix for a Vector AR1 process must be square. Found: {}".format())
        from dolo.numeric.discretization import multidimensional_discretization

        [P,Q] = multidimensional_discretization(rho_array, sigma_array)
        self.P = P
        self.Q = Q
        self.extend([P, Q])
Beispiel #6
0
    def discretize_mc(self, N=3):

        rho = np.array([[self.ρ]])
        Sigma = np.array([[self.σ]])
        μ = np.array([self.μ])

        try:
            assert(abs(np.eye(rho.shape[0])*rho[0,0]-rho).max() <= 1)
        except:
            raise Exception("When discretizing a Vector AR1 process, the autocorrelation coefficient must be as scalar. Found: {}".format(rho_array))

        from dolo.numeric.discretization import multidimensional_discretization

        [P,Q] = multidimensional_discretization(rho[0,0], Sigma, N=N)

        P += μ[None,:]

        return MarkovChain(values=P, transitions=Q)
Beispiel #7
0
    def __init__(self, rho=None, sigma=None, N=2):

        rho_array = np.array(rho, dtype=float)
        sigma_array = np.atleast_2d(np.array(sigma, dtype=float))
        try:
            assert (rho_array.ndim <= 1)
        except:
            raise Exception(
                "When discretizing a Vector AR1 process, the autocorrelation coefficient must be as scalar. Found: {}"
                .format(rho_array))
        try:
            assert (sigma_array.shape[0] == sigma_array.shape[1])
        except:
            raise Exception(
                "The covariance matrix for a Vector AR1 process must be square. Found: {}"
                .format())
        from dolo.numeric.discretization import multidimensional_discretization

        [P, Q] = multidimensional_discretization(rho_array, sigma_array)
        self.P = P
        self.Q = Q
        self.extend([P, Q])