PoSH-autosklearn源码分析

论文:(2018ICML)
https://ml.informatik.uni-freiburg.de/papers/18-AUTOML-AutoChallenge.pdf

代码:
http://ml.informatik.uni-freiburg.de/downloads/automl_competition_2018.zip

数据:(codalab平台,需要注册)
https://competitions.codalab.org/competitions/17767#participate-get_data

TODO LIST

  1. PoSH对时序数据是怎么处理的?

特别苟的Manual design decisions

  1. 如果特征数>500, 用单变量特征选择(听起来很牛逼,看代码就知道怎么回事了)
  2. 如果样本数<1000, 不采用SuccessiveHaving。并且采用交叉验证的方式,而不是HoldOut

在附录A.3A.4有比较详细的需求。

特征选择

特征选择
logic.project_data_via_feature_selection

imp = sklearn.preprocessing.Imputer(strategy='median')
pca = sklearn.feature_selection.SelectKBest(k=n_keep)
pipeline = sklearn.pipeline.Pipeline((('imp', imp), ('pca', pca)))

如果特征数>500, 强行将为500.
lib/logic.py:114

        D.feat_type = [
            ft for i, ft in enumerate(D.feat_type) if rval[2][i] == True
        ]

更新feat_type


少样本数不采用SH

回到logic
lib/logic.py:227

    if min_budget == max_budget:
        res = SSB.run(len(autosklearn_portfolio), min_n_workers=1)
    else:
        res = SSB.run(1, min_n_workers=1)

如果样本数<1000, 则设置min_budget = max_budget, 且不采用SH,强行迭代16次。

Budget 的计算

    max_budget = 1.0
    min_budget = 1.0 / 16
    eta = 4

eta是什么意思呢?可以回顾我的这篇文章:HpBandSter源码分析

n_iterations是用户指定的,stages是根据max_budget, min_budget, eta决定的,详见hpbandster.optimizers.bohb.BOHB#__init__

hpbandster/optimizers/bohb.py:101

self.max_SH_iter = -int(np.log(min_budget/max_budget)/np.log(eta)) + 1
max_budget=243
min_budget=9
eta=3

s m a x = l o g η ( R ) s_{max}=log_{\eta}(R) smax=logη(R)
B = ( S m a x + 1 ) R B=(S_{max}+1)R B=(Smax+1)R

eta η \eta η 其实是SuccessiveHaving的budget扩增倍数,从9到243,每次增加3倍,即:

9, 27, 81, 243

再看到PoSH的代码

    max_budget = 1.0
    min_budget = 1.0 / 16
    eta = 4

hp_util.SideShowBOHB

self.max_SH_iter = -int(
    np.log(min_budget / max_budget) / np.log(eta)) + 1
self.budgets = max_budget * np.power(eta,
                                     -np.linspace(self.max_SH_iter - 1,
                                                  0, self.max_SH_iter))
self.max_SH_iter
Out[5]: 3
self.budgets
Out[6]: array([0.0625, 0.25  , 1.    ])

1 16 ⇒ 4 16 ⇒ 16 16 \frac{1}{16} \Rightarrow \frac{4}{16} \Rightarrow \frac{16}{16} 1611641616


lib/hp_util.py:62

            self.budget_converter = {
                        'libsvm_svc': lambda b: b,
                     'random_forest': lambda b: int(b*128),
                               'sgd': lambda b: int(b*512),
                'xgradient_boosting': lambda b: int(b*512),
                       'extra_trees': lambda b: int(b*1024)
            }

budget与iterations的转换数与论文也是对应的

lib/logic.py:202

worker.run(background=True)

在用线程跑

portfolio.get_hydra_portfolio
获取混合文件夹

balancing的策略还是存在的

    SSB = hp_util.SideShowBOHB(
        configspace=worker.get_config_space(),
        initial_configs=autosklearn_portfolio,
        run_id=run_id,
        eta=eta, min_budget=min_budget, max_budget=max_budget,
        SH_only=True,       # suppresses Hyperband's outer loop and runs SuccessiveHalving only
        nameserver=ns_host,
        nameserver_port=ns_port,
        ping_interval=sleep,
        job_queue_sizes=(-1, 0),
        dynamic_queue_size=True,
    )
eta
Out[4]: 4
min_budget
Out[5]: 0.0625
max_budget
Out[6]: 1.0
sleep
Out[7]: 5
run_id
Out[8]: '0'

SideShowBOHBMaster, AutoMLWorkerWorker

class PortfolioBOHB(BOHB):
    """ subclasses the config_generator BOHB"""
    def __init__(self, initial_configs=None, *args, **kwargs):
        super().__init__(*args, **kwargs)

        if initial_configs is None:
            # dummy initial portfolio
            self.initial_configs = [self.configspace.sample_configuration().get_dictionary() for i in range(5)]
        else:
            self.initial_configs = initial_configs

继承BOHB,仅仅多个initial_configs

        cg = PortfolioBOHB(
                     initial_configs=initial_configs,
                     configspace=configspace,
                     min_points_in_model=min_points_in_model,
                     top_n_percent=top_n_percent,
                     num_samples=num_samples,
                     random_fraction=random_fraction,
                     bandwidth_factor=bandwidth_factor,
                     )

cg: ConfigGenerate

min_points_in_model
top_n_percent
Out[10]: 15
num_samples
Out[11]: 64
random_fraction
Out[12]: 0.5
bandwidth_factor
Out[13]: 3

min_points_in_model = None

hp_util.SideShowBOHB#get_next_iteration

iteration
Out[2]: 0
s
Out[3]: 2
n0
Out[4]: 16
ns
Out[5]: [16, 4, 1]
self.budgets[(-s - 1):]
Out[6]: array([0.0625, 0.25  , 1.    ])

s是HyperBand的bracket,代表stages数目。
ns代表配置数,依次递减。budgets预算数依次递增。

hpbandster.iterations.base.BaseIteration#add_configuration

self.config_sampler
Out[7]: <bound method PortfolioBOHB.get_config of <hp_util.PortfolioBOHB object at 0x7f1670208208>>

hp_util.PortfolioBOHB#get_config

    def get_config(self, budget):

        # return a portfolio member first
        if len(self.initial_configs) > 0 and True:
            c = self.initial_configs.pop()
            return (c, {'portfolio_member': True})

        return (super().get_config(budget))

用元学习文件夹代替了随机推荐

最后用SH的方法迭代1000次

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值