random_search.py 文件源码

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

项目:pyswarms 作者: ljvmiranda921 项目源码 文件源码
def generate_grid(self):
        """Generates the grid of hyperparameter value combinations."""

        options = dict(self.options)
        params = {}

        # Remove 'p' to hold as a constant in the paramater combinations
        p = options.pop('p')
        params['p'] = [p for _ in xrange(self.n_selection_iters)]

        # Assign generators based on parameter type
        param_generators = {
            'c1': np.random.uniform,
            'c2': np.random.uniform,
            'w': np.random.uniform,
            'k': np.random.randint
        }

        # Generate random values for hyperparameters 'c1', 'c2', 'w', and 'k'
        for idx, bounds in options.items():
            params[idx] = param_generators[idx](
                              *bounds, size=self.n_selection_iters)

        # Return list of dicts of hyperparameter combinations
        return [{'c1': params['c1'][i],
                 'c2': params['c2'][i],
                 'w': params['w'][i],
                 'k': params['k'][i],
                 'p': params['p'][i]}
                for i in xrange(self.n_selection_iters)]
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号