Changeset 194
- Timestamp:
- 05/23/08 15:04:33 (8 months ago)
- Files:
-
- projects/AsynCluster/trunk/svpmc/params.py (modified) (1 diff)
- projects/AsynCluster/trunk/svpmc/pmc.py (modified) (1 diff)
- projects/AsynCluster/trunk/svpmc/test/test_params.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
projects/AsynCluster/trunk/svpmc/params.py
r193 r194 63 63 corresponding element of the original instance. 64 64 """ 65 @classmethod 66 def concatenate(cls, FA_list): 67 """ 68 Returns an instance of me that is a concatentation of the instances in 69 the supplied list I{FA_list}. Analogous to SciPy's C{concatenate} 70 function. 71 """ 72 length = 0 73 shape = None 74 for FA in FA_list: 75 length += len(FA) 76 if shape is None: 77 shape = FA.shape 78 elif FA.shape != shape: 79 raise ValueError( 80 "FlexArray dimensions must agree except for d_0") 81 shape = list(shape) 82 shape[0] = length 83 newVersion = cls(*shape) 84 k = 0 85 for FA in FA_list: 86 for FA_sub in FA: 87 newVersion[k] = FA_sub 88 k += 1 89 return newVersion 90 65 91 def __init__(self, *shape): 66 92 self._shape = tuple([int(x) for x in shape]) projects/AsynCluster/trunk/svpmc/pmc.py
r192 r194 208 208 print "%6.4f\t%+12.2f\t%s" % (self.pm.V[vIndex], L, info) 209 209 return L 210 211 def evaluateChunk(XP): 212 XP_list.append(XP) 213 # Here's where the vast majority of the CPU time is expended! 214 dList = [ 215 self.mm.likelihood(XPk).addCallback(weight) for XPk in XP] 216 return defer.gatherResults(dList) 210 217 211 218 j = 0 212 219 N = len(X) 220 XP_list = [] 213 221 W = s.empty(len(X)) 214 wfd = defer.waitForDeferred(self.queue.call(self.proposals, X, vIndex))215 yield wfd216 XP = wfd.getResult()217 222 while j < N: 218 223 N_this = min([self.chunkSize, N-j]) 219 # Here's where the vast majority of the CPU time is expended! 220 dList = [ 221 self.mm.likelihood(XP[k]).addCallback(weight) 222 for k in xrange(j, j+N_this)] 223 wfd = defer.waitForDeferred(defer.gatherResults(dList)) 224 X_this = X[j:j+N_this] 225 # Generate a chunk of proposals (somewhat time-consuming, done 226 # locally in a thread)... 227 d = self.queue.call(self.proposals, X_this, vIndex) 228 # ...and then evaluate the proposals (really time-consuming, done 229 # either locally in a thread or in the cluster) 230 d.addCallback(evaluateChunk) 231 wfd = defer.waitForDeferred(d) 224 232 yield wfd 225 233 W[j:j+N_this] = wfd.getResult() 226 234 j += N_this 227 yield XP, W235 yield params.FlexArray.concatenate(XP_list), W 228 236 229 237 @defer.deferredGenerator projects/AsynCluster/trunk/svpmc/test/test_params.py
r193 r194 108 108 self.failUnlessEqual(xj[k], "%d:%d" % (j, k)) 109 109 self.failUnlessEqual(j, 2) 110 111 def test_concatenate_1d(self): 112 x = self._make_stringArray(3, 1) 113 y = params.FlexArray.concatenate([x, x]) 114 self.failUnlessEqual(len(y), 6) 115 self.failUnlessEqual(y[0,0], '0:0') 116 self.failUnlessEqual(y[3,0], '0:0') 110 117 111 118
