示例#1
0
文件: abcsmc.py 项目: bcmd/BCMD
    def sampleTheModel(self):
        ret = [0 for it in range(self.nbatch)]
    
        if self.nmodel > 1:
            for i in range(self.nbatch):
                ret[i] = statistics.w_choice( range(self.nmodel), self.margins_prev )

            if( len(self.dead_models) < self.nmodel-1 ):
            #if(0): 
                # perturb models
                for i in range(self.nbatch):
                    u = rnd.uniform(low=0, high=1)
                    if u > self.modelKernel:
                        # sample randomly from other (non dead) models
                        not_available = self.dead_models[:]
                        not_available.append(ret[i])
                        ss = set( not_available )
                        s = set( range(0,self.nmodel) )
                        # print "perturbing model ", set( range(self.nmodel) ), ss, s-ss, list(s-ss), numpy.array( list(s-ss) )
                        ar = numpy.array( list(s-ss) )
                        rnd.shuffle( ar )
                        perturbed_model = ar[0]
                        # print "perturbation ", ret[i], "->", perturbed_model
                        ret[i] = perturbed_model
        return ret[:]
示例#2
0
文件: abcsmc.py 项目: walkymatt/BCMD
    def sampleTheModel(self):
        ret = [0 for it in range(self.nbatch)]

        if self.nmodel > 1:
            for i in range(self.nbatch):
                ret[i] = statistics.w_choice(range(self.nmodel),
                                             self.margins_prev)

            if (len(self.dead_models) < self.nmodel - 1):
                #if(0):
                # perturb models
                for i in range(self.nbatch):
                    u = rnd.uniform(low=0, high=1)
                    if u > self.modelKernel:
                        # sample randomly from other (non dead) models
                        not_available = self.dead_models[:]
                        not_available.append(ret[i])
                        ss = set(not_available)
                        s = set(range(0, self.nmodel))
                        # print "perturbing model ", set( range(self.nmodel) ), ss, s-ss, list(s-ss), numpy.array( list(s-ss) )
                        ar = numpy.array(list(s - ss))
                        rnd.shuffle(ar)
                        perturbed_model = ar[0]
                        # print "perturbation ", ret[i], "->", perturbed_model
                        ret[i] = perturbed_model
        return ret[:]
示例#3
0
文件: abcsmc.py 项目: bcmd/BCMD
 def sampleTheModelFromPrior(self):
     ret = [0 for it in range(self.nbatch)]
     if self.nmodel > 1:
         for i in range(self.nbatch):
             ret[i] = statistics.w_choice( range(self.nmodel), self.modelprior )
     
     return ret[:]
示例#4
0
文件: abcsmc.py 项目: walkymatt/BCMD
    def sampleTheModelFromPrior(self):
        ret = [0 for it in range(self.nbatch)]
        if self.nmodel > 1:
            for i in range(self.nbatch):
                ret[i] = statistics.w_choice(range(self.nmodel),
                                             self.modelprior)

        return ret[:]