Python numpy.random.standard_normal() Examples

The following are 16 code examples of numpy.random.standard_normal(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module numpy.random , or try the search function .
Example #1
Source File: step_algorithms.py    From firefly-monte-carlo with MIT License 6 votes vote down vote up
def step(self, th, z):
        s = self.stepsize
        randstep = npr.standard_normal(th.shape)
        th_new = th + 0.5*s**2*self.D_prob(th,z) + randstep*s
        # bonus for probability difference. Using cache-friendly order
        diff_probs = -self.prob(th, z)+self.prob(th_new, z)
        # penalty for having asymmetric proposals:
        randstep_back = (th - (th_new + 0.5*s**2*self.D_prob(th_new,z)))/s
        diff_proposal = 0.5*np.sum(randstep_back**2) - 0.5*np.sum(randstep**2)
        # M-H accept/reject:
        if np.log(npr.rand()) < diff_probs - diff_proposal:
            self.num_rejects = 0
            return th_new
        else:
            self.num_rejects = 1
            return th 
Example #2
Source File: recipe-578867.py    From code with MIT License 6 votes vote down vote up
def initialise(self, context):
        
        self.r0 = 0.05 # current UK funding rate
        self.theta = 0.10 # 1 % long term interest rate
        self.k = 0.3
        self.beta = 0.03
         
        ## simulate short rate paths
        self.n = 1000    # MC simulation trials
        self.T = 24.    # total time
        self.m = 100   # subintervals
        self.dt = self.T/self.m  # difference in time each subinterval
        self.r = np.zeros(shape=(self.n, self.m), dtype=float) # matrix to hold short rate paths
        
        # Tell the engine where to associate the data to security.        
        context['My Simple Model'] = Simulation(self.n, self.m, standard_normal)
    
        self.fig = plt.figure()
        self.ax = self.fig.add_subplot(111)
        self.ax.autoscale_view(True,True,True) 
Example #3
Source File: test_scale.py    From vnpy_crypto with MIT License 5 votes vote down vote up
def setup_class(cls):
        np.random.seed(54321)
        cls.X = standard_normal((40,10)) 
Example #4
Source File: test_scale.py    From vnpy_crypto with MIT License 5 votes vote down vote up
def setup_class(cls):
        np.random.seed(54321)
        cls.X = standard_normal((40,10,30)) 
Example #5
Source File: test_scale.py    From vnpy_crypto with MIT License 5 votes vote down vote up
def setup_class(cls):
        np.random.seed(54321)
        cls.X = standard_normal((40,10)) 
Example #6
Source File: test_scale.py    From vnpy_crypto with MIT License 5 votes vote down vote up
def setup_class(cls):
        np.random.seed(54321)
        cls.X = standard_normal((40,10,30))
        cls.h = scale.Huber(maxiter=1000, tol=1.0e-05) 
Example #7
Source File: test_contrast.py    From vnpy_crypto with MIT License 5 votes vote down vote up
def setup_class(cls):
        R.seed(54321)
        cls.X = R.standard_normal((40,10)) 
Example #8
Source File: test_formula.py    From vnpy_crypto with MIT License 5 votes vote down vote up
def setup(self):
        self.X = R.standard_normal((40,10))
        self.namespace = {}
        self.terms = []
        for i in range(10):
            name = '%s' % string.ascii_uppercase[i]
            self.namespace[name] = self.X[:,i]
            self.terms.append(formula.Term(name))

        self.formula = self.terms[0]
        for i in range(1, 10):
            self.formula += self.terms[i]
        self.formula.namespace = self.namespace 
Example #9
Source File: test_formula.py    From vnpy_crypto with MIT License 5 votes vote down vote up
def test_contrast3(self):
        X = self.formula.design()
        P = np.dot(X, L.pinv(X))

        dummy = formula.Term('noise')
        resid = np.identity(40) - P
        self.namespace['noise'] = np.transpose(np.dot(resid, R.standard_normal((40,5))))
        terms = dummy + self.terms[2]
        terms.namespace = self.formula.namespace
        c = contrast.Contrast(terms, self.formula)
        assert_equal(c.matrix.shape, (10,)) 
Example #10
Source File: test_tools.py    From vnpy_crypto with MIT License 5 votes vote down vote up
def test_extendedpinv(self):
        X = standard_normal((40, 10))
        np_inv = np.linalg.pinv(X)
        np_sing_vals = np.linalg.svd(X, 0, 0)
        sm_inv, sing_vals = pinv_extended(X)
        assert_almost_equal(np_inv, sm_inv)
        assert_almost_equal(np_sing_vals, sing_vals) 
Example #11
Source File: test_tools.py    From vnpy_crypto with MIT License 5 votes vote down vote up
def test_extendedpinv_singular(self):
        X = standard_normal((40, 10))
        X[:, 5] = X[:, 1] + X[:, 3]
        np_inv = np.linalg.pinv(X)
        np_sing_vals = np.linalg.svd(X, 0, 0)
        sm_inv, sing_vals = pinv_extended(X)
        assert_almost_equal(np_inv, sm_inv)
        assert_almost_equal(np_sing_vals, sing_vals) 
Example #12
Source File: test_tools.py    From vnpy_crypto with MIT License 5 votes vote down vote up
def test_fullrank(self):
        import warnings
        with warnings.catch_warnings():
            warnings.simplefilter("ignore")
            X = standard_normal((40,10))
            X[:,0] = X[:,1] + X[:,2]

            Y = tools.fullrank(X)
            assert_equal(Y.shape, (40,9))

            X[:,5] = X[:,3] + X[:,4]
            Y = tools.fullrank(X)
            assert_equal(Y.shape, (40,8))
            warnings.simplefilter("ignore") 
Example #13
Source File: step_algorithms.py    From firefly-monte-carlo with MIT License 5 votes vote down vote up
def step(self, th, z):
        th_new = th + npr.standard_normal(th.shape)*self.stepsize
        # Cache friendly order: evaluate old value first
        if np.log(npr.rand()) < - self.prob(th, z) + self.prob(th_new, z) :
            self.num_rejects = 0
            return th_new
        else:
            self.num_rejects = 1
            return th 
Example #14
Source File: test_fft1d.py    From mkl_fft with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def setUp(self):
        rnd.seed(1234567)
        self.xd1 = rnd.standard_normal(128)
        self.xf1 = self.xd1.astype(np.float32)
        self.xz1 = rnd.standard_normal((128,2)).view(dtype=np.complex128).squeeze()
        self.xc1 = self.xz1.astype(np.complex64) 
Example #15
Source File: test_fft1d.py    From mkl_fft with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def setUp(self):
        rnd.seed(1234567)
        self.ad2 = rnd.standard_normal((4, 3))
        self.af2 = self.ad2.astype(np.float32)
        self.az2 = np.dot(
              rnd.standard_normal((17, 15, 2)),
              np.array([1.0 + 0.0j, 0.0 + 1.0j], dtype=np.complex128)
        )
        self.ac2 = self.az2.astype(np.complex64)
        self.mat = np.matrix(self.az2)
        self.xd1 = rnd.standard_normal(128) 
Example #16
Source File: test_fft1d.py    From mkl_fft with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def setUp(self):
        rnd.seed(1234567)
        self.ad3 = rnd.standard_normal((7, 11, 19))
        self.af3 = self.ad3.astype(np.float32)
        self.az3 = np.dot(
              rnd.standard_normal((17, 13, 15, 2)),
              np.array([1.0 + 0.0j, 0.0 + 1.0j], dtype=np.complex128)
        )
        self.ac3 = self.az3.astype(np.complex64)