1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
|
def demo_named_product():
import ubelt as ub
import pandas as pd
import numpy as np
def some_function(thresh1, thresh2):
x, y = thresh1, thresh2
z = ((x ** 2 + y ** 2 - 1) ** 3 - x ** 2 * y ** 3)
return np.log(z)
s = 2.5
basis = {
'thresh1': np.linspace(-s, s, 128),
'thresh2': np.linspace(-s, s, 128),
}
grid_iter = ub.named_product(basis)
rows = []
for params in grid_iter:
key = ub.repr2(params, compact=1)
row = {
'key': key,
**params,
}
score = some_function(**ub.compatible(params, some_function))
row['score'] = score
rows.append(row)
data = pd.DataFrame(rows)
print(data)
# import seaborn as sns
import kwplot
sns = kwplot.autosns()
sns.scatterplot(data=data, x='thresh1', y='thresh2', hue='score')
|