Changeset 194

Show
Ignore:
Timestamp:
05/23/08 15:04:33 (7 months ago)
Author:
edsuom
Message:

PMC now running with more efficient proposal code and sequencing of said code in chunks

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • projects/AsynCluster/trunk/svpmc/params.py

    r193 r194  
    6363    corresponding element of the original instance. 
    6464    """ 
     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 
    6591    def __init__(self, *shape): 
    6692        self._shape = tuple([int(x) for x in shape]) 
  • projects/AsynCluster/trunk/svpmc/pmc.py

    r192 r194  
    208208            print "%6.4f\t%+12.2f\t%s" % (self.pm.V[vIndex], L, info) 
    209209            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) 
    210217         
    211218        j = 0 
    212219        N = len(X) 
     220        XP_list = [] 
    213221        W = s.empty(len(X)) 
    214         wfd = defer.waitForDeferred(self.queue.call(self.proposals, X, vIndex)) 
    215         yield wfd 
    216         XP = wfd.getResult() 
    217222        while j < N: 
    218223            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) 
    224232            yield wfd 
    225233            W[j:j+N_this] = wfd.getResult() 
    226234            j += N_this 
    227         yield XP, W 
     235        yield params.FlexArray.concatenate(XP_list), W 
    228236 
    229237    @defer.deferredGenerator 
  • projects/AsynCluster/trunk/svpmc/test/test_params.py

    r193 r194  
    108108                self.failUnlessEqual(xj[k], "%d:%d" % (j, k)) 
    109109        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') 
    110117 
    111118