Esempio n. 1
0
    def sample_model(self):
        """
        Returns a list of model numbers, of length self.nbatch, obtained by sampling from a categorical distribution
        with probabilities self.modelprior, and then perturbing with a uniform model perturbation kernel.
        """

        models = [0] * self.nbatch

        if self.nmodel > 1:
            # Sample models from prior distribution
            for i in range(self.nbatch):
                models[i] = statistics.w_choice(self.margins_prev)

            # perturb models
            if len(self.dead_models) < self.nmodel - 1:

                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 = set(self.dead_models[:])
                        not_available.add(models[i])

                        available_indexes = np.array(
                            list(set(range(self.nmodel)) - not_available))
                        rnd.shuffle(available_indexes)
                        perturbed_model = available_indexes[0]

                        models[i] = perturbed_model
        return models[:]
Esempio n. 2
0
    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[:]
Esempio n. 3
0
    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[:]
Esempio n. 4
0
 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[:]
 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[:]
Esempio n. 6
0
    def sample_model_from_prior(self):
        """
        Returns a list of model numbers, of length self.nbatch, drawn from a categorical distribution with probabilities
         self.modelprior

        """
        models = [0] * self.nbatch
        if self.nmodel > 1:
            for i in range(self.nbatch):
                models[i] = statistics.w_choice(self.modelprior)

        return models