Skip to content

Commit

Permalink
fixed fabolas'initial design
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronkl committed Aug 23, 2016
1 parent b25257d commit 6f133b8
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 23 deletions.
2 changes: 1 addition & 1 deletion examples/example_fmin_fabolas.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,4 @@ def objective_function(x, s):
x_best = fabolas_fmin(objective_function, X_lower, X_upper, num_iterations=100)

print x_best
print objective_function(x_best[:, :-1], s=x_best[:, None, -1])
print objective_function(x_best[:, :-1], s=x_best[:, None, -1])
28 changes: 16 additions & 12 deletions robo/initial_design/extrapolative_initial_design.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,23 @@
from robo.initial_design.init_random_uniform import init_random_uniform


def extrapolative_initial_design(X_lower, X_upper, is_env, task, N):

# Create grid for the system size
idx = is_env == 1
X_upper_re = np.exp(task.retransform(X_upper))

g = np.array([X_upper_re[idx] / float(i) for i in [4, 8, 16, 32]])[:, 0]
g = np.true_divide((np.log(g) - task.original_X_lower[idx]),
def extrapolative_initial_design(task, N):

# Index of the environmental variable
idx = task.is_env == 1
# Upper bound of the dataset size on a linear scale
X_upper_re = np.exp(task.retransform(task.X_upper))[idx]
# Compute the dataset size on a linear scale for a 1/4, 1/8, 1/16 and 1/32 of the data
s = np.array([X_upper_re / float(i) for i in [4, 8, 16, 32]])[:, 0]
log_s = np.log(s)

# Transform it back to [0, 1] space
s = np.true_divide((log_s - task.original_X_lower[idx]),
(task.original_X_upper[idx] - task.original_X_lower[idx]))

X = init_random_uniform(X_lower, X_upper, N)

X[:, is_env == 1] = \
np.tile(g, np.ceil(X.shape[0] / 4.))[:X.shape[0], np.newaxis]
# Draw random points in the configuration space and evaluate them on the predifined data subsets
X = init_random_uniform(task.X_lower, task.X_upper, N)
X[:, task.is_env == 1] = \
np.tile(s, np.ceil(X.shape[0] / 4.))[:X.shape[0], np.newaxis]

return X
7 changes: 2 additions & 5 deletions robo/solver/fabolas.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,8 @@ def run(self, num_iterations=10, X=None, Y=None, C=None):
self.Y = np.zeros([1, 1])
self.C = np.zeros([1, 1])

init = extrapolative_initial_design(self.task.X_lower,
self.task.X_upper,
self.task.is_env,
self.task,
N=self.init_points)
init = extrapolative_initial_design(self.task,
N=self.init_points)

for i, x in enumerate(init):
x = x[np.newaxis, :]
Expand Down
18 changes: 13 additions & 5 deletions robo/test/test_extrapolative_init_design.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,31 @@
import unittest
import numpy as np

from robo.task.base_task import BaseTask
from robo.initial_design.extrapolative_initial_design import extrapolative_initial_design

class DemoTask(BaseTask):
def __init__(self):
X_lower = np.array([0, np.log(10)])
X_upper = np.array([1, np.log(1000)])
self.is_env = np.array([0, 1])

super(DemoTask, self).__init__(X_lower, X_upper)


class TestEnvInitDesign(unittest.TestCase):

def test(self):
l = np.array([0, 0])
u = np.array([1, 1])
is_env = np.array([0, 1])
task = DemoTask()
N = 100
X = extrapolative_initial_design(l, u, is_env, N)
X = extrapolative_initial_design(task, N)

assert len(X.shape) == 2
assert X.shape[0] == N
assert X.shape[1] == 2
for i in range(N):
assert X[i, 1] == 1 / float(2 ** (i % 4 + 2))
s = np.exp(task.retransform(X[i])[-1])
assert np.round(s, 0) == np.round(1000. / float(2 ** (i % 4 + 2)), 0)

if __name__ == "__main__":
unittest.main()

0 comments on commit 6f133b8

Please sign in to comment.