Basic Usage¶
Here, we demonstrate how to filter conditions where we suspect the model to be undefined
In [1]:
Copied!
import math
import numpy as np
from autora.experimentalist.prediction_filter import prediction_filter
import pandas as pd
import math
import numpy as np
from autora.experimentalist.prediction_filter import prediction_filter
import pandas as pd
Create a model:
In [2]:
Copied!
class ModelWithNans:
def predict(self, x):
try:
return math.sqrt((x**2 - 4))
except:
return None
model = ModelWithNans()
class ModelWithNans:
def predict(self, x):
try:
return math.sqrt((x**2 - 4))
except:
return None
model = ModelWithNans()
Let's create our pool:
In [3]:
Copied!
pool = pd.DataFrame({'x': np.linspace(-5, 5, 11)})
pool
pool = pd.DataFrame({'x': np.linspace(-5, 5, 11)})
pool
Out[3]:
x | |
---|---|
0 | -5.0 |
1 | -4.0 |
2 | -3.0 |
3 | -2.0 |
4 | -1.0 |
5 | 0.0 |
6 | 1.0 |
7 | 2.0 |
8 | 3.0 |
9 | 4.0 |
10 | 5.0 |
Let's create our filter function. This is a function that returns True if a value should be included
In [4]:
Copied!
def filter_function(x):
return x is not None
def filter_function(x):
return x is not None
Now, let's use our filter on the conditions:
In [5]:
Copied!
filtered_conditions = prediction_filter(pool, model, filter_function)
filtered_conditions
filtered_conditions = prediction_filter(pool, model, filter_function)
filtered_conditions
--------------------------------------------------------------------------- AxisError Traceback (most recent call last) Cell In[5], line 1 ----> 1 filtered_conditions = prediction_filter(pool, model, filter_function) 2 filtered_conditions File ~/Documents/GitHub/AutoResearch/autora-experimentalist-prediction-filter/src/autora/experimentalist/prediction_filter/__init__.py:71, in filter(conditions, model, filter_function) 16 """ 17 Filter conditions based on the expected outcome io the mdeol 18 (...) 68 0 1 1 69 """ 70 _pred = model.predict(conditions) ---> 71 _filter = np.apply_along_axis(filter_function, 1, _pred) 72 _filter = _filter.reshape(1, -1) 74 new_conditions = conditions[list(_filter[0])] File ~/Documents/GitHub/AutoResearch/autora-experimentalist-prediction-filter/venv/lib/python3.11/site-packages/numpy/lib/shape_base.py:361, in apply_along_axis(func1d, axis, arr, *args, **kwargs) 359 arr = asanyarray(arr) 360 nd = arr.ndim --> 361 axis = normalize_axis_index(axis, nd) 363 # arr, with the iteration axis at the end 364 in_dims = list(range(nd)) AxisError: axis 1 is out of bounds for array of dimension 0
In [5]:
Copied!
In [ ]:
Copied!