Import Modules¶
In [ ]:
Copied!
# Uncomment the following line when running on Google Colab
# !pip install "autora[experimentalist-nearest-value]"
# Uncomment the following line when running on Google Colab
# !pip install "autora[experimentalist-nearest-value]"
In [3]:
Copied!
import numpy as np
import matplotlib.pyplot as plt
from autora.experimentalist.nearest_value import nearest_values_sample
import numpy as np
import matplotlib.pyplot as plt
from autora.experimentalist.nearest_value import nearest_values_sample
--------------------------------------------------------------------------- ImportError Traceback (most recent call last) Cell In[3], line 3 1 import numpy as np 2 import matplotlib.pyplot as plt ----> 3 from .src.autora.experimentalist.sampler.nearest_value_sampler import nearest_values_sampler ImportError: attempted relative import with no known parent package
Define Meta-Space¶
We will here define X values of interest as well as a ground truth model to derive y values.
In [8]:
Copied!
#Define meta-parameters
X_allowed = np.linspace(-3, 6, 10)
X = np.random.choice(X_allowed,10)
#Define ground truth model
def ground_truth(xs):
y = (xs ** 2.0)
y[xs < 0] = 0
return y
#Define meta-parameters
X_allowed = np.linspace(-3, 6, 10)
X = np.random.choice(X_allowed,10)
#Define ground truth model
def ground_truth(xs):
y = (xs ** 2.0)
y[xs < 0] = 0
return y
Plot The Data¶
Let's plot the data to see what we are working with.
In [9]:
Copied!
plt.plot(X, ground_truth(X), 'o')
plt.show()
plt.plot(X, ground_truth(X), 'o')
plt.show()
Run And Report Uncertainty Samples¶
Now we will get a proposal from the experimentalist as to which datapoints to investigate next. We will retrieve 5 new datapoints in this example.
In [10]:
Copied!
sampler_proposal = nearest_values_sample(X, X_allowed, 5)
print('New datapoints:\n' + str(sampler_proposal) + '\n')
sampler_proposal = nearest_values_sample(X, X_allowed, 5)
print('New datapoints:\n' + str(sampler_proposal) + '\n')
New datapoints: [[-1.] [ 6.] [-3.] [-2.] [ 1.]]
Plot New Datapoints With Old¶
We can then plot our new datapoints with our previous ones to demonstrate our new dataset of investigation for then next cycle.
In [11]:
Copied!
plt.plot(X, ground_truth(X), 'o', alpha = .5, label = 'Original Datapoints')
plt.plot(sampler_proposal, ground_truth(sampler_proposal), 'o', alpha = .5, label = 'New Datapoints')
plt.legend()
plt.show()
plt.plot(X, ground_truth(X), 'o', alpha = .5, label = 'Original Datapoints')
plt.plot(sampler_proposal, ground_truth(sampler_proposal), 'o', alpha = .5, label = 'New Datapoints')
plt.legend()
plt.show()