param_class.py 文件源码

python
阅读 33 收藏 0 点赞 0 评论 0

项目:scikit-dataaccess 作者: MITHaystack 项目源码 文件源码
def perturb(self):
        ''' 
        Peturb the paramter by choosing a random value between val_min and val_max. 

        Will choose a random number with precision specified by decimals. Will optionally
        pick the min or the max value after a specified number of perturb calls
        '''

        if self.n == self.n_max - 1:
            # Choose and extreme value
            self.val = random.sample([self.val_min, self.val_max], 1)[0]
            self.n = 0

        else:
            if self.decimals == 0:
                self.val = random.randint(self.val_min,self.val_max)
            else:
                self.val = random.random() * (self.val_max - self.val_min + 10**-self.decimals) + (self.val_min - 0.5 * 10**-self.decimals)
                self.val = round(self.val, ndigits=self.decimals)

            if self.n_max > 0:
                self.n += 1
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号