src.environment.problem.SOO.COCO_BBOB.kan.hypothesis

Module Contents

Functions

detect_separability

detect function separability

batch_grad_normgrad

get_dependence

test_symmetry

detect function separability

test_separability

test function separability

test_general_separability

test function separability

get_molecule

how variables are combined hierarchically

get_tree_node

get tree nodes

plot_tree

get tree graph

test_symmetry_var

test symmetry

API

src.environment.problem.SOO.COCO_BBOB.kan.hypothesis.detect_separability(model, x, mode='add', score_th=0.01, res_th=0.01, n_clusters=None, bias=0.0, verbose=False)[source]

detect function separability

Args:

model : MultKAN, MLP or python function
x : 2D torch.float
    inputs
mode : str
    mode = 'add' or mode = 'mul'
score_th : float
    threshold of score
res_th : float
    threshold of residue
n_clusters : None or int
    the number of clusters
bias : float
    bias (for multiplicative separability)
verbose : bool

Returns:

results (dictionary)

Example1

from kan.hypothesis import * model = lambda x: x[:,[0]] ** 2 + torch.exp(x[:,[1]]+x[:,[2]]) x = torch.normal(0,1,size=(100,3)) detect_separability(model, x, mode=’add’)

Example2

from kan.hypothesis import * model = lambda x: x[:,[0]] ** 2 * (x[:,[1]]+x[:,[2]]) x = torch.normal(0,1,size=(100,3)) detect_separability(model, x, mode=’mul’)

src.environment.problem.SOO.COCO_BBOB.kan.hypothesis.batch_grad_normgrad(model, x, group, create_graph=False)[source]
src.environment.problem.SOO.COCO_BBOB.kan.hypothesis.get_dependence(model, x, group)[source]
src.environment.problem.SOO.COCO_BBOB.kan.hypothesis.test_symmetry(model, x, group, dependence_th=0.001)[source]

detect function separability

Args:

model : MultKAN, MLP or python function
x : 2D torch.float
    inputs
group : a list of indices
dependence_th : float
    threshold of dependence

Returns:

bool

Example

from kan.hypothesis import * model = lambda x: x[:,[0]] ** 2 * (x[:,[1]]+x[:,[2]]) x = torch.normal(0,1,size=(100,3)) print(test_symmetry(model, x, [1,2])) # True print(test_symmetry(model, x, [0,2])) # False

src.environment.problem.SOO.COCO_BBOB.kan.hypothesis.test_separability(model, x, groups, mode='add', threshold=0.01, bias=0)[source]

test function separability

Args:

model : MultKAN, MLP or python function
x : 2D torch.float
    inputs
mode : str
    mode = 'add' or mode = 'mul'
score_th : float
    threshold of score
res_th : float
    threshold of residue
bias : float
    bias (for multiplicative separability)
verbose : bool

Returns:

bool

Example

from kan.hypothesis import * model = lambda x: x[:,[0]] ** 2 * (x[:,[1]]+x[:,[2]]) x = torch.normal(0,1,size=(100,3)) print(test_separability(model, x, [[0],[1,2]], mode=’mul’)) # True print(test_separability(model, x, [[0],[1,2]], mode=’add’)) # False

src.environment.problem.SOO.COCO_BBOB.kan.hypothesis.test_general_separability(model, x, groups, threshold=0.01)[source]

test function separability

Args:

model : MultKAN, MLP or python function
x : 2D torch.float
    inputs
mode : str
    mode = 'add' or mode = 'mul'
score_th : float
    threshold of score
res_th : float
    threshold of residue
bias : float
    bias (for multiplicative separability)
verbose : bool

Returns:

bool

Example

from kan.hypothesis import * model = lambda x: x[:,[0]] ** 2 * (x[:,[1]]**2+x[:,[2]]**2)**2 x = torch.normal(0,1,size=(100,3)) print(test_general_separability(model, x, [[1],[0,2]])) # False print(test_general_separability(model, x, [[0],[1,2]])) # True

src.environment.problem.SOO.COCO_BBOB.kan.hypothesis.get_molecule(model, x, sym_th=0.001, verbose=True)[source]

how variables are combined hierarchically

Args:

model : MultKAN, MLP or python function
x : 2D torch.float
    inputs
sym_th : float
    threshold of symmetry
verbose : bool

Returns:

list

Example

from kan.hypothesis import * model = lambda x: ((x[:,[0]] ** 2 + x[:,[1]] ** 2) ** 2 + (x[:,[2]] ** 2 + x[:,[3]] ** 2) ** 2) ** 2 + ((x[:,[4]] ** 2 + x[:,[5]] ** 2) ** 2 + (x[:,[6]] ** 2 + x[:,[7]] ** 2) ** 2) ** 2 x = torch.normal(0,1,size=(100,8)) get_molecule(model, x, verbose=False) [[[0], [1], [2], [3], [4], [5], [6], [7]], [[0, 1], [2, 3], [4, 5], [6, 7]], [[0, 1, 2, 3], [4, 5, 6, 7]], [[0, 1, 2, 3, 4, 5, 6, 7]]]

src.environment.problem.SOO.COCO_BBOB.kan.hypothesis.get_tree_node(model, x, moleculess, sep_th=0.01, skip_test=True)[source]

get tree nodes

Args:

model : MultKAN, MLP or python function
x : 2D torch.float
    inputs
sep_th : float
    threshold of separability
skip_test : bool
    if True, don't test the property of each module (to save time)

Returns:

arities : list of numbers
properties : list of strings

Example

from kan.hypothesis import * model = lambda x: ((x[:,[0]] ** 2 + x[:,[1]] ** 2) ** 2 + (x[:,[2]] ** 2 + x[:,[3]] ** 2) ** 2) ** 2 + ((x[:,[4]] ** 2 + x[:,[5]] ** 2) ** 2 + (x[:,[6]] ** 2 + x[:,[7]] ** 2) ** 2) ** 2 x = torch.normal(0,1,size=(100,8)) moleculess = get_molecule(model, x, verbose=False) get_tree_node(model, x, moleculess, skip_test=False)

src.environment.problem.SOO.COCO_BBOB.kan.hypothesis.plot_tree(model, x, in_var=None, style='tree', sym_th=0.001, sep_th=0.1, skip_sep_test=False, verbose=False)[source]

get tree graph

Args:

model : MultKAN, MLP or python function
x : 2D torch.float
    inputs
in_var : list of symbols
    input variables
style : str
    'tree' or 'box'
sym_th : float
    threshold of symmetry
sep_th : float
    threshold of separability
skip_sep_test : bool
    if True, don't test the property of each module (to save time)
verbose : bool

Returns:

a tree graph

Example

from kan.hypothesis import * model = lambda x: ((x[:,[0]] ** 2 + x[:,[1]] ** 2) ** 2 + (x[:,[2]] ** 2 + x[:,[3]] ** 2) ** 2) ** 2 + ((x[:,[4]] ** 2 + x[:,[5]] ** 2) ** 2 + (x[:,[6]] ** 2 + x[:,[7]] ** 2) ** 2) ** 2 x = torch.normal(0,1,size=(100,8)) plot_tree(model, x)

src.environment.problem.SOO.COCO_BBOB.kan.hypothesis.test_symmetry_var(model, x, input_vars, symmetry_var)[source]

test symmetry

Args:

model : MultKAN, MLP or python function
x : 2D torch.float
    inputs
input_vars : list of sympy symbols
symmetry_var : sympy expression

Returns:

cosine similarity

Example

from kan.hypothesis import * from sympy import * model = lambda x: x[:,[0]] * (x[:,[1]] + x[:,[2]]) x = torch.normal(0,1,size=(100,8)) input_vars = a, b, c = symbols(‘a b c’) symmetry_var = b + c test_symmetry_var(model, x, input_vars, symmetry_var); symmetry_var = b * c test_symmetry_var(model, x, input_vars, symmetry_var);