Changeset 138
- Timestamp:
- 04/05/08 15:45:20 (8 months ago)
- Files:
-
- projects/AsynCluster/trunk/svpmc/sample.py (modified) (1 diff)
- projects/AsynCluster/trunk/svpmc/sample_NormalWalk.c (modified) (1 diff)
- projects/AsynCluster/trunk/svpmc/test/test_sample.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
projects/AsynCluster/trunk/svpmc/sample.py
r137 r138 82 82 """ 83 83 def __init__(self, rows, cols): 84 self.x = s.rand(rows, cols) 84 self.x = s.randn(rows, cols) 85 self.lp_x = 0 85 86 86 87 def __call__(self, w): 87 if s.shape(w) != self. w.shape:88 if s.shape(w) != self.x.shape: 88 89 raise ValueError( 89 90 "Wiggle array must have same dimensions as walker array") projects/AsynCluster/trunk/svpmc/sample_NormalWalk.c
r137 r138 26 26 27 27 int i, j; 28 double xp, pr_x, pr_xp; 28 double xp, dlp, lp_xp; 29 double lp_x = 0; 29 30 30 31 for(i=0; i<Nx[0]; i++) { 31 32 for(j=0; j<Nx[1]; j++) { 32 33 xp = X2(i,j) + W2(i,j)*normal(); 34 lp_xp = -0.5 * pow(xp, 2); 35 dlp = lp_xp - lp_x; 36 if(dlp > 0 || log(drand48()) < dlp) { 37 X2(i,j) = xp; 38 lp_x = lp_xp; 39 } 33 40 } 34 41 } projects/AsynCluster/trunk/svpmc/test/test_sample.py
r137 r138 70 70 def test_univariate(self): 71 71 walker = sample.NormalWalk(1, 1) 72 w = s.array([[0. 2]])73 x = s.array([walker(w)[0 ][0] for k in xrange(50000)])72 w = s.array([[0.1]]) 73 x = s.array([walker(w)[0,0] for k in xrange(100000)]) 74 74 fig = self.fig 75 75 sp = fig.add_subplot(211)
