Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speed up conditional hyperparameter imputation #170

Merged
merged 2 commits into from
Feb 13, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions smac/smbo/local_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import random
import numpy as np

from smac.configspace import impute_inactive_values, get_one_exchange_neighbourhood, Configuration
from smac.configspace import get_one_exchange_neighbourhood

__author__ = "Aaron Klein, Marius Lindauer"
__copyright__ = "Copyright 2015, ML4AAD"
Expand Down Expand Up @@ -71,10 +71,9 @@ def maximize(self, start_point, *args):
"""
incumbent = start_point
# Compute the acquisition value of the incumbent
incumbent_ = impute_inactive_values(incumbent)
acq_val_incumbent = self.acquisition_function(
incumbent_.get_array(),
*args)
incumbent_ = incumbent.get_array()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Distinguishing between two variables with only "_" can cause a lot of confusion or needs at least a comment in the code.

incumbent_[~np.isfinite(incumbent_)] = -1
acq_val_incumbent = self.acquisition_function(incumbent_, *args)

local_search_steps = 0
neighbors_looked_at = 0
Expand All @@ -96,10 +95,10 @@ def maximize(self, start_point, *args):

for neighbor in all_neighbors:
s_time = time.time()
neighbor_ = impute_inactive_values(neighbor)
n_array = neighbor_.get_array()
neighbor_ = neighbor.get_array()
neighbor_[~np.isfinite(neighbor_)] = -1

acq_val = self.acquisition_function(n_array, *args)
acq_val = self.acquisition_function(neighbor_, *args)

neighbors_looked_at += 1

Expand Down
18 changes: 5 additions & 13 deletions smac/smbo/smbo.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import itertools
import logging
import numpy as np
import os
import random
import sys
import time
import typing
import math

import ConfigSpace.util

from smac.smbo.acquisition import AbstractAcquisitionFunction
from smac.smbo.base_solver import BaseSolver
Expand All @@ -23,7 +20,6 @@
from smac.scenario.scenario import Scenario
from smac.configspace import Configuration

from smac.epm.rfr_imputator import RFRImputator

__author__ = "Aaron Klein, Marius Lindauer, Matthias Feurer"
__copyright__ = "Copyright 2015, ML4AAD"
Expand Down Expand Up @@ -307,13 +303,10 @@ def _sort_configs_by_acq_value(self, configs):

"""

imputed_configs = map(ConfigSpace.util.impute_inactive_values,
configs)
imputed_configs = [x.get_array()
for x in imputed_configs]
imputed_configs = np.array(imputed_configs,
dtype=np.float64)
acq_values = self.acquisition_func(imputed_configs)
config_array = np.array([x.get_array() for x in configs], dtype=np.float64)
# This imputes inactive values!
config_array[~np.isfinite(config_array)] = -1
acq_values = self.acquisition_func(config_array)

# From here
# http://stackoverflow.com/questions/20197990/how-to-make-argsort-result-to-be-random-between-equal-values
Expand All @@ -323,5 +316,4 @@ def _sort_configs_by_acq_value(self, configs):

# Cannot use zip here because the indices array cannot index the
# rand_configs list, because the second is a pure python list
return [(acq_values[ind][0], configs[ind])
for ind in indices[::-1]]
return [(acq_values[ind][0], configs[ind]) for ind in indices[::-1]]
4 changes: 2 additions & 2 deletions test/test_runhistory/test_rfr_imputor.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def testRandomImputation(self):
cutoff=cutoff,
threshold=cutoff*10,
change_threshold=0.01,
max_iter=10,
max_iter=5,
model=self.model)

imp_y = imputor.impute(censored_X=cen_X, censored_y=cen_y,
Expand All @@ -159,4 +159,4 @@ def testRealImputation(self):
success_states=[StatusType.SUCCESS, ],
impute_censored_data=True, impute_state=[StatusType.TIMEOUT],
imputor=imputor, rs=rs)
print("%s" % str(r2e.transform(self.rh)[0]))
print("%s" % str(r2e.transform(self.rh)[0]))