Esempio n. 1
0
    def simulate(self,i):
        """ Seed RNG, draw initial values and iterate forward """
        simstates   =   list() # [etat-1 mut deltat-1 
        simpact     =   list()
        simpeff     =   list()

        currstate   =   Matrix([[normal(0,1/(1-self.param.re**2)*self.param.ve,1)],[normal(0,self.param.ve)],[normal(0,self.param.vd)]])
        
        simstates.append(currstate.copy())
        prices          =   self.compute_prices(currstate)
        simpact.append(prices[0])
        simpeff.append(prices[1])
        for i in range(0,self.nper-1):
            laststate       =   currstate.copy()
            currstate       =   currstate.copy()
            currstate[1]    =   normal(0,self.param.ve)
            currstate[0]    =   self.param.re*laststate[0] + currstate[1]            
            m = Matrix([[currstate[1]],[laststate[2]],[0]])
            mm=self.param.theta.transpose()*(self.param.I - self.param.beliefs2['m'])*self.param.Ic
            currstate[2]    =   mm*m
            prices          =   self.compute_prices(currstate)
            simpact.append(prices[0])
            simpeff.append(prices[1])
            simstates.append(currstate)
        
        self.states.append(array(simstates).transpose())
        self.pact.append(array(simpact))
        self.peff.append(array(simpeff))
Esempio n. 2
0
def test_util():
    R = Rational

    v1 = Matrix(1, 3, [1, 2, 3])
    v2 = Matrix(1, 3, [3, 4, 5])
    assert v1.norm() == sqrt(14)
    assert v1.project(v2) == Matrix(1, 3, [R(39) / 25, R(52) / 25, R(13) / 5])
    assert Matrix.zeros(1, 2) == Matrix(1, 2, [0, 0])
    assert ones(1, 2) == Matrix(1, 2, [1, 1])
    assert v1.copy() == v1
    # cofactor
    assert eye(3) == eye(3).cofactor_matrix()
    test = Matrix([[1, 3, 2], [2, 6, 3], [2, 3, 6]])
    assert test.cofactor_matrix() == \
        Matrix([[27, -6, -6], [-12, 2, 3], [-3, 1, 0]])
    test = Matrix([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
    assert test.cofactor_matrix() == \
        Matrix([[-3, 6, -3], [6, -12, 6], [-3, 6, -3]])