File: example_named_product.py

package info (click to toggle)
ubelt 1.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,180 kB
  • sloc: python: 15,487; sh: 807; makefile: 24
file content (36 lines) | stat: -rw-r--r-- 889 bytes parent folder | download | duplicates (3)
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')