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

TSEMO no samples #218

Merged
merged 6 commits into from
Dec 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions summit/experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ def run_experiments(self, conditions, computation_time=None, **kwargs):
for i, condition in conditions.iterrows():
start = time.time()
res, extras = self._run(condition, **kwargs)
# res = add_metadata_columns(res, conditions[conditions.metadata_columns])
experiment_time = time.time() - start
self._data = self._data.append(res)
res = DataSet(res).T
self._data = pd.concat([self._data, res], axis=0)
self._data["experiment_t"].iat[-1] = float(experiment_time)
self._data["computation_t"].iat[-1] = float(diff)
if condition.get("strategy") is not None:
Expand Down
8 changes: 4 additions & 4 deletions summit/strategies/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def transform_inputs_outputs(self, ds: DataSet, **kwargs):
elif isinstance(variable, ContinuousVariable):
if standardize_inputs:
values, mean, std = self.standardize_column(
new_ds[variable.name].astype(np.float)
new_ds[variable.name].astype(float)
)
self.input_means[variable.name] = mean
self.input_stds[variable.name] = std
Expand All @@ -192,7 +192,7 @@ def transform_inputs_outputs(self, ds: DataSet, **kwargs):
)
if standardize_outputs:
values, mean, std = self.standardize_column(
new_ds[variable.name].astype(np.float)
new_ds[variable.name].astype(float)
)
self.output_means[variable.name] = mean
self.output_stds[variable.name] = std
Expand All @@ -204,7 +204,7 @@ def transform_inputs_outputs(self, ds: DataSet, **kwargs):
) / (var_max - var_min)
output_columns.append(variable.name)
# Ensure continuous variables are floats
new_ds[variable.name] = new_ds[variable.name].astype(np.float)
new_ds[variable.name] = new_ds[variable.name].astype(float)
else:
raise DomainError(f"Variable {variable.name} is not in the dataset.")

Expand Down Expand Up @@ -348,7 +348,7 @@ def un_transform(self, ds, **kwargs):
new_ds[variable.name, "DATA"] = (
new_ds[variable.name] * (var_max - var_min) + var_min
)
new_ds[variable.name, "DATA"] = new_ds[variable.name].astype(np.float)
new_ds[variable.name, "DATA"] = new_ds[variable.name].astype(float)
else:
raise DomainError(f"Variable {variable.name} is not in the dataset.")

Expand Down
2 changes: 1 addition & 1 deletion summit/strategies/factorial_doe.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def suggest_experiments(self, levels_dict, **kwargs) -> DataSet:
doe = fullfact(levels)
for i, v in enumerate(self.domain.input_variables):
indices = doe[:, i]
indices = indices.astype(np.int)
indices = indices.astype(int)
values = np.array([levels_dict[v.name][i] for i in indices])
values = np.atleast_2d(values)
design.add_variable(v.name, values, indices=indices[:, np.newaxis])
Expand Down
10 changes: 5 additions & 5 deletions summit/strategies/multitask.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from botorch.acquisition import ExpectedImprovement as EI

# from botorch.acquisition import qExpectedImprovement as qEI

import pandas as pd
import numpy as np
from typing import Type, Tuple, Union, Optional

Expand Down Expand Up @@ -149,15 +149,15 @@ def suggest_experiments(self, num_experiments, prev_res: DataSet = None, **kwarg
elif prev_res is not None and self.all_experiments is None:
self.all_experiments = prev_res
elif prev_res is not None and self.all_experiments is not None:
self.all_experiments = self.all_experiments.append(prev_res)
self.all_experiments = pd.concat([self.all_experiments, prev_res], axis=0)
self.iterations += 1

# Combine pre-training and experiment data
if "task" not in self.pretraining_data.metadata_columns:
raise ValueError(
"""The pretraining data must have a METADATA column called "task" with the task number."""
)
data = self.all_experiments.append(self.pretraining_data)
data = pd.concat([self.all_experiments, self.pretraining_data], axis=0)

# Get inputs (decision variables) and outputs (objectives)
inputs, output = self.transform.transform_inputs_outputs(
Expand Down Expand Up @@ -407,7 +407,7 @@ def suggest_experiments(self, num_experiments, prev_res: DataSet = None, **kwarg
elif prev_res is not None and self.all_experiments is None:
self.all_experiments = prev_res
elif prev_res is not None and self.all_experiments is not None:
self.all_experiments = self.all_experiments.append(prev_res)
self.all_experiments = pd.concat([self.all_experiments, prev_res], axis=0)
self.iterations += 1
data = self.all_experiments

Expand Down Expand Up @@ -481,7 +481,7 @@ def reset(self):
"""Reset MTBO state"""
self.all_experiments = None
self.iterations = 0

@staticmethod
def standardize(X):
mean, std = X.mean(), X.std()
Expand Down
4 changes: 2 additions & 2 deletions summit/strategies/neldermead.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def suggest_experiments(self, prev_res: DataSet = None, **kwargs):
inner_prev_param = self.prev_param[0]
# recover invalid experiments from previous iteration
if self.prev_param[1] is not None:
invalid_res = self.prev_param[1].drop(("constraint", "DATA"), 1)
invalid_res = self.prev_param[1].drop(("constraint", "DATA"), axis=1)
prev_res = pd.concat([prev_res, invalid_res])

## Generation of new suggested experiments.
Expand Down Expand Up @@ -192,7 +192,7 @@ def suggest_experiments(self, prev_res: DataSet = None, **kwargs):
)

# return only valid experiments (invalid experiments are stored in param[1])
next_experiments = next_experiments.drop(("constraint", "DATA"), 1)
next_experiments = next_experiments.drop(("constraint", "DATA"), axis=1)
objective_dir = -1.0 if obj_maximize else 1.0
self.fbest = objective_dir * fbest
self.xbest = xbest
Expand Down
4 changes: 2 additions & 2 deletions summit/strategies/snobfit.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def suggest_experiments(
inner_prev_param = self.prev_param[0]
# recover invalid experiments from previous iteration
if self.prev_param[1] is not None:
invalid_res = self.prev_param[1][0].drop(("constraint", "DATA"), 1)
invalid_res = self.prev_param[1][0].drop(("constraint", "DATA"), axis=1)
prev_res = pd.concat([prev_res, invalid_res])

## Generation of new suggested experiments.
Expand Down Expand Up @@ -172,7 +172,7 @@ def suggest_experiments(
)

# return only valid experiments (invalid experiments are stored in param[1])
next_experiments = next_experiments.drop(("constraint", "DATA"), 1)
next_experiments = next_experiments.drop(("constraint", "DATA"), axis=1)
objective_dir = -1.0 if obj_maximize else 1.0
self.fbest = objective_dir * fbest
self.prev_param = param
Expand Down
19 changes: 6 additions & 13 deletions summit/strategies/tsemo.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def suggest_experiments(self, num_experiments, prev_res: DataSet = None, **kwarg
elif prev_res is not None and self.all_experiments is None:
self.all_experiments = prev_res
elif prev_res is not None and self.all_experiments is not None:
self.all_experiments = self.all_experiments.append(prev_res)
self.all_experiments = pd.concat([self.all_experiments, prev_res], axis=0)

if self.all_experiments.shape[0] <= 3:
lhs = LHS(self.domain, categorical_method=cat_method)
Expand Down Expand Up @@ -210,7 +210,10 @@ def suggest_experiments(self, num_experiments, prev_res: DataSet = None, **kwarg
# Training
models[i] = ThompsonSampledModel(v.name)
train_results[i] = models[i].fit(
inputs, outputs[[v.name]], n_retries=self.n_retries, n_spectral_points=self.n_spectral_points,
inputs,
outputs[[v.name]],
n_retries=self.n_retries,
n_spectral_points=self.n_spectral_points,
)

# Evaluate spectral sampled functions
Expand Down Expand Up @@ -379,7 +382,6 @@ def reset(self):
"""Reset TSEMO state"""
self.all_experiments = None
self.iterations = 0
self.samples = [] # Samples drawn using NSGA-II
self.sample_fs = [0 for i in range(len(self.domain.output_variables))]
self.uuid_val = uuid.uuid4()

Expand Down Expand Up @@ -475,15 +477,6 @@ def _select_max_hvi(self, y, samples, num_evals=1):
mask[original_index] = False
indices.append(original_index)

# Append current estimate of the pareto front to sample_paretos
samples_new = samples_next.copy()
mean = self.transform.output_means[v.name]
std = self.transform.output_stds[v.name]
samples_new = samples_new * std + mean
samples_new[("hvi", "DATA")] = hv_improvement
self.samples.append(samples_new)
samples_next = samples_original.loc[mask]

if len(hv_improvement) == 0:
hv_imp = 0
elif len(indices) == 0:
Expand Down Expand Up @@ -582,7 +575,7 @@ def fit(self, X: DataSet, y: DataSet, **kwargs):
)

def predict(self, X: DataSet, **kwargs):
"""Predict the values of a """
"""Predict the values of a"""
X = X[self.input_columns_ordered].to_numpy()
return self.rff(X)

Expand Down
5 changes: 0 additions & 5 deletions summit/tests/test_strategies.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
from fastprogress.fastprogress import progress_bar
import numpy as np
import os
import warnings
import pkg_resources


def test_strategy():
class MockStrategy(Strategy):
Expand Down Expand Up @@ -701,8 +698,6 @@ def test_tsemo(batch_size, test_num_improve_iter=2, save=False):
lab = VLMOP2()
strategy = TSEMO(lab.domain)
experiments = strategy.suggest_experiments(5 * num_inputs)
warnings.filterwarnings("ignore", category=RuntimeWarning)
warnings.filterwarnings("ignore", category=DeprecationWarning)

num_improve_iter = 0
best_hv = None
Expand Down