pypesto/sample/adaptive_parallel_tempering.py
def adjust_betas(self, i_sample: int,
                     in_swapped: Sequence[Union[None, InternalSample]],
                     last_samples: Sequence[Union[None, InternalSample]]):
        """Update temperatures as in Vousden2016."""
        if len(self.betas) == 1:
            return

        # parameters
        nu = self.options['nu']
        eta = self.options['eta']
        betas = self.betas

        # booleans to integer array
        # swapped = np.array([int(swap) for swap in in_swapped])
        swapped = np.zeros_like(in_swapped[:-1], dtype=np.int)

        # original was: [bool(0, 1) ... bool(last-3, last-2), bool(last-2, last-1), bool(last-1, last)]
        for idx in range(swapped.size):
            if np.array_equal(in_swapped[idx].x, last_samples[idx].x):
                swapped[idx] = 0
            else:
                swapped[idx] = 1

        # update betas
        kappa = nu / (i_sample + 1 + nu) / eta
        ds = kappa * (swapped[:-1] - swapped[1:])
        dtemp = np.diff(1. / betas[:-1])
        dtemp = dtemp * np.exp(ds)
        betas[:-1] = 1 / np.cumsum(np.insert(dtemp, obj=0, values=1.))

        # fill in
        self.betas = betas
Update temperatures as in Vousden2016.
Update temperatures as in Vousden2016.
Update temperatures as in Vousden2016 .
def adjust_betas(self, i_sample: int,
                     in_swapped: Sequence[Union[None, InternalSample]],
                     last_samples: Sequence[Union[None, InternalSample]]):
        if len(self.betas) == 1:
            return
        nu = self.options['nu']
        eta = self.options['eta']
        betas = self.betas
        swapped = np.zeros_like(in_swapped[:-1], dtype=np.int)
        for idx in range(swapped.size):
            if np.array_equal(in_swapped[idx].x, last_samples[idx].x):
                swapped[idx] = 0
            else:
                swapped[idx] = 1
        kappa = nu / (i_sample + 1 + nu) / eta
        ds = kappa * (swapped[:-1] - swapped[1:])
        dtemp = np.diff(1. / betas[:-1])
        dtemp = dtemp * np.exp(ds)
        betas[:-1] = 1 / np.cumsum(np.insert(dtemp, obj=0, values=1.))
        self.betas = betas
def adjust_betas ( self , i_sample : int , in_swapped : Sequence [ Union [ None , InternalSample ] ] , last_samples : Sequence [ Union [ None , InternalSample ] ] ) : if len ( self . betas ) == 1 : return nu = self . options [ 'nu' ] eta = self . options [ 'eta' ] betas = self . betas swapped = np . zeros_like ( in_swapped [ : - 1 ] , dtype = np . int ) for idx in range ( swapped . size ) : if np . array_equal ( in_swapped [ idx ] . x , last_samples [ idx ] . x ) : swapped [ idx ] = 0 else : swapped [ idx ] = 1 kappa = nu / ( i_sample + 1 + nu ) / eta ds = kappa * ( swapped [ : - 1 ] - swapped [ 1 : ] ) dtemp = np . diff ( 1. / betas [ : - 1 ] ) dtemp = dtemp * np . exp ( ds ) betas [ : - 1 ] = 1 / np . cumsum ( np . insert ( dtemp , obj = 0 , values = 1. ) ) self . betas = betas
Update temperatures as in Vousden2016.
Update temperatures as in Vousden2016 .
"""Update temperatures as in Vousden2016.""" # parameters # booleans to integer array # swapped = np.array([int(swap) for swap in in_swapped]) # original was: [bool(0, 1) ... bool(last-3, last-2), bool(last-2, last-1), bool(last-1, last)] # update betas # fill in
self
i_sample
int
in_swapped
Sequence[Union[None, InternalSample]]
last_samples
Sequence[Union[None, InternalSample]]