diff --git a/src/python/__init__.py b/src/python/__init__.py index d196314ce88da7bad113845b02ec871830335b0f..f169e2f2f459c3c780a8fd6a7c5fd85428c6d21b 100644 --- a/src/python/__init__.py +++ b/src/python/__init__.py @@ -111,6 +111,8 @@ def generate_phi_0_from_csv( exprs = list([col.split("(")[0] for col in columns]) units = list([get_unit(col) for col in columns]) + initialize_values_arr(len(train_inds), len(leave_out_inds), len(columns)) + test_values = df.to_numpy().T[:, leave_out_inds] values = df.to_numpy().T[:, train_inds] feat_ind = 0 diff --git a/src/python/bindings_docstring_keyed.cpp b/src/python/bindings_docstring_keyed.cpp index bf672548b3c56a7d79e388b25f93456e1a6750ab..9392490632bb11cf0ef12a18109e70753bd00152 100644 --- a/src/python/bindings_docstring_keyed.cpp +++ b/src/python/bindings_docstring_keyed.cpp @@ -32,6 +32,7 @@ void sisso::register_all() sisso::feature_creation::node::registerSixPowNode(); def("phi_selected_from_file", &str2node::phi_selected_from_file_py); + def("initialize_values_arr", &node_value_arrs::initialize_values_arr); } void sisso::feature_creation::registerFeatureSpace() diff --git a/tests/test_feat_generation/test_abs_diff_node.py b/tests/test_feat_generation/test_abs_diff_node.py index cb3afab0491155dd95a8b9011129c0fdd581407f..2fb3683a8586d83f9a2752758d55cd8c58435abd 100644 --- a/tests/test_feat_generation/test_abs_diff_node.py +++ b/tests/test_feat_generation/test_abs_diff_node.py @@ -1,4 +1,11 @@ -from cpp_sisso import FeatureNode, AddNode, SubNode, AbsDiffNode, Unit +from cpp_sisso import ( + FeatureNode, + AddNode, + SubNode, + AbsDiffNode, + Unit, + initialize_values_arr, +) import numpy as np @@ -8,6 +15,7 @@ class InvalidFeatureMade(Exception): def test_abs_diff_node(): + initialize_values_arr(90, 10, 4) data_1 = np.random.random(90) * 1e4 + 1e-10 test_data_1 = np.random.random(10) * 1e4 + 1e-10 diff --git a/tests/test_feat_generation/test_abs_node.py b/tests/test_feat_generation/test_abs_node.py index 1a6748709d74562cafd8d27b029618a13594e92f..cd48dbec8bfb58fedf95fa547b10452464ecdb17 100644 --- a/tests/test_feat_generation/test_abs_node.py +++ b/tests/test_feat_generation/test_abs_node.py @@ -1,4 +1,4 @@ -from cpp_sisso import FeatureNode, AbsNode, AbsDiffNode, Unit +from cpp_sisso import FeatureNode, AbsNode, AbsDiffNode, Unit, initialize_values_arr import numpy as np @@ -8,6 +8,7 @@ class InvalidFeatureMade(Exception): def test_abs_node(): + initialize_values_arr(90, 10, 2) data_1 = np.random.random(90) * 1e4 + 1e-10 test_data_1 = np.random.random(10) * 1e4 + 1e-10 diff --git a/tests/test_feat_generation/test_add_node.py b/tests/test_feat_generation/test_add_node.py index 821f7bbec006b4122ed377d774eb1578b0e48387..117f7d1a46f34cae2554f2bbfdee89689b6a9551 100644 --- a/tests/test_feat_generation/test_add_node.py +++ b/tests/test_feat_generation/test_add_node.py @@ -1,4 +1,4 @@ -from cpp_sisso import FeatureNode, AddNode, SubNode, Unit +from cpp_sisso import FeatureNode, AddNode, SubNode, Unit, initialize_values_arr import numpy as np @@ -8,6 +8,7 @@ class InvalidFeatureMade(Exception): def test_add_node(): + initialize_values_arr(90, 10, 4) data_1 = np.random.random(90) * 1e4 + 1e-10 test_data_1 = np.random.random(10) * 1e4 + 1e-10 diff --git a/tests/test_feat_generation/test_cb_node.py b/tests/test_feat_generation/test_cb_node.py index 1e4ebc8c7070a52863853d06a3cdd246988083f6..c0fcab356ceb63a154c946f9ef4ad3225855b32b 100644 --- a/tests/test_feat_generation/test_cb_node.py +++ b/tests/test_feat_generation/test_cb_node.py @@ -1,4 +1,13 @@ -from cpp_sisso import FeatureNode, InvNode, SqNode, CbNode, SixPowNode, CbrtNode, Unit +from cpp_sisso import ( + FeatureNode, + InvNode, + SqNode, + CbNode, + SixPowNode, + CbrtNode, + Unit, + initialize_values_arr, +) import numpy as np @@ -8,6 +17,7 @@ class InvalidFeatureMade(Exception): def test_cube_node(): + initialize_values_arr(90, 10, 2) data_1 = np.random.random(90) * 1e4 + 1e-10 test_data_1 = np.random.random(10) * 1e4 + 1e-10 diff --git a/tests/test_feat_generation/test_cbrt_node.py b/tests/test_feat_generation/test_cbrt_node.py index 815e7d244582d4e0b864e1d676fbd97dd5bf211f..d68dd32439b75122323ca8edefaca0afd0954edd 100644 --- a/tests/test_feat_generation/test_cbrt_node.py +++ b/tests/test_feat_generation/test_cbrt_node.py @@ -7,6 +7,7 @@ from cpp_sisso import ( SqrtNode, CbrtNode, Unit, + initialize_values_arr, ) import numpy as np @@ -17,6 +18,7 @@ class InvalidFeatureMade(Exception): def test_cbrt_node(): + initialize_values_arr(90, 10, 2) data_1 = np.random.random(90) * 1e4 + 1e-10 test_data_1 = np.random.random(10) * 1e4 + 1e-10 diff --git a/tests/test_feat_generation/test_cos_node.py b/tests/test_feat_generation/test_cos_node.py index 63ef07ff9a80994e7a857eca7f6bf6e71635f7c6..3325e6b13658f699ea263bc0d9e5ab4d7c0a5f52 100644 --- a/tests/test_feat_generation/test_cos_node.py +++ b/tests/test_feat_generation/test_cos_node.py @@ -1,4 +1,4 @@ -from cpp_sisso import FeatureNode, SinNode, CosNode, Unit +from cpp_sisso import FeatureNode, SinNode, CosNode, Unit, initialize_values_arr import numpy as np @@ -8,6 +8,7 @@ class InvalidFeatureMade(Exception): def test_cos_node(): + initialize_values_arr(90, 10, 3) data_1 = np.random.randint(0, 10000, 90) * 2.0 * np.pi test_data_1 = np.random.randint(0, 10000, 10) * 2.0 * np.pi diff --git a/tests/test_feat_generation/test_div_node.py b/tests/test_feat_generation/test_div_node.py index 1bc81bdca33d9ea3bdd79e83394012c668545901..7830522771e7041d93ba7acc0822efbe227af4aa 100644 --- a/tests/test_feat_generation/test_div_node.py +++ b/tests/test_feat_generation/test_div_node.py @@ -1,4 +1,11 @@ -from cpp_sisso import FeatureNode, MultNode, DivNode, InvNode, Unit +from cpp_sisso import ( + FeatureNode, + MultNode, + DivNode, + InvNode, + Unit, + initialize_values_arr, +) import numpy as np @@ -8,6 +15,7 @@ class InvalidFeatureMade(Exception): def test_div_node(): + initialize_values_arr(90, 10, 5) data_1 = np.random.random(90) * 1e4 + 1e-10 test_data_1 = np.random.random(10) * 1e4 + 1e-10 diff --git a/tests/test_feat_generation/test_exp_node.py b/tests/test_feat_generation/test_exp_node.py index da25038287e2dab6ddf409c5762c0ddb1c9f8baa..7cb6ff848c72e1de12f051aaf24abf7815af4936 100644 --- a/tests/test_feat_generation/test_exp_node.py +++ b/tests/test_feat_generation/test_exp_node.py @@ -1,4 +1,13 @@ -from cpp_sisso import FeatureNode, ExpNode, NegExpNode, LogNode, AddNode, SubNode, Unit +from cpp_sisso import ( + FeatureNode, + ExpNode, + NegExpNode, + LogNode, + AddNode, + SubNode, + Unit, + initialize_values_arr, +) import numpy as np @@ -8,6 +17,8 @@ class InvalidFeatureMade(Exception): def test_exp_node(): + initialize_values_arr(90, 10, 3) + data_1 = np.random.random(90) + 1e-10 test_data_1 = np.random.random(10) + 1e-10 diff --git a/tests/test_feat_generation/test_inv_node.py b/tests/test_feat_generation/test_inv_node.py index bda6b405a9cdadfc7637627191f3bc324ace56c2..ba81bef8d5ade236ed67c3b054ce8f213efe521e 100644 --- a/tests/test_feat_generation/test_inv_node.py +++ b/tests/test_feat_generation/test_inv_node.py @@ -1,4 +1,12 @@ -from cpp_sisso import FeatureNode, ExpNode, NegExpNode, DivNode, InvNode, Unit +from cpp_sisso import ( + FeatureNode, + ExpNode, + NegExpNode, + DivNode, + InvNode, + Unit, + initialize_values_arr, +) import numpy as np @@ -8,6 +16,8 @@ class InvalidFeatureMade(Exception): def test_inv_node(): + initialize_values_arr(90, 10, 4) + data_1 = np.random.random(90) * 1e4 + 1e-10 test_data_1 = np.random.random(10) * 1e4 + 1e-10 diff --git a/tests/test_feat_generation/test_log_node.py b/tests/test_feat_generation/test_log_node.py index 04870cc7781e7e3eb3299235ca3adfd339fd3c44..7dd93ef4bddcb68dc129d4730badeaeb578fe37a 100644 --- a/tests/test_feat_generation/test_log_node.py +++ b/tests/test_feat_generation/test_log_node.py @@ -12,6 +12,7 @@ from cpp_sisso import ( SqrtNode, CbrtNode, Unit, + initialize_values_arr, ) import numpy as np @@ -22,6 +23,8 @@ class InvalidFeatureMade(Exception): def test_log_node(): + initialize_values_arr(90, 10, 3) + data_1 = np.random.random(90) * 1e4 + 1e-10 test_data_1 = np.random.random(10) * 1e4 + 1e-10 diff --git a/tests/test_feat_generation/test_mult_node.py b/tests/test_feat_generation/test_mult_node.py index d4e28c00d9093c2b507062bfb87c5f684c5ced38..09e32f8fb36d7be9991396b76dabfa68e147066e 100644 --- a/tests/test_feat_generation/test_mult_node.py +++ b/tests/test_feat_generation/test_mult_node.py @@ -1,4 +1,11 @@ -from cpp_sisso import FeatureNode, MultNode, DivNode, InvNode, Unit +from cpp_sisso import ( + FeatureNode, + MultNode, + DivNode, + InvNode, + Unit, + initialize_values_arr, +) import numpy as np @@ -8,6 +15,8 @@ class InvalidFeatureMade(Exception): def test_mult_node(): + initialize_values_arr(90, 10, 4) + data_1 = np.random.random(90) * 1e4 + 1e-10 test_data_1 = np.random.random(10) * 1e4 + 1e-10 diff --git a/tests/test_feat_generation/test_neg_exp_node.py b/tests/test_feat_generation/test_neg_exp_node.py index 9c60576a9d9ce6c1bebc1152ade0aa6aa4675585..7201d7155dca7d0aaf04de3c54fff48614437214 100644 --- a/tests/test_feat_generation/test_neg_exp_node.py +++ b/tests/test_feat_generation/test_neg_exp_node.py @@ -1,4 +1,13 @@ -from cpp_sisso import FeatureNode, ExpNode, NegExpNode, LogNode, AddNode, SubNode, Unit +from cpp_sisso import ( + FeatureNode, + ExpNode, + NegExpNode, + LogNode, + AddNode, + SubNode, + Unit, + initialize_values_arr, +) import numpy as np @@ -8,6 +17,8 @@ class InvalidFeatureMade(Exception): def test_neg_exp_node(): + initialize_values_arr(90, 10, 3) + data_1 = np.random.random(90) + 1e-10 test_data_1 = np.random.random(10) + 1e-10 diff --git a/tests/test_feat_generation/test_sin_node.py b/tests/test_feat_generation/test_sin_node.py index d840ccdacc24903a65c7a351b63b957e8f2acd52..d69c8059eb25450a99826477c30918ccdec6246f 100644 --- a/tests/test_feat_generation/test_sin_node.py +++ b/tests/test_feat_generation/test_sin_node.py @@ -1,4 +1,4 @@ -from cpp_sisso import FeatureNode, SinNode, CosNode, Unit +from cpp_sisso import FeatureNode, SinNode, CosNode, Unit, initialize_values_arr import numpy as np @@ -8,6 +8,8 @@ class InvalidFeatureMade(Exception): def test_sin_node(): + initialize_values_arr(90, 10, 3) + data_1 = np.random.randint(0, 10000, 90) * (2.0) * np.pi + np.pi / 2.0 test_data_1 = np.random.randint(0, 10000, 10) * (2.0) * np.pi + np.pi / 2.0 diff --git a/tests/test_feat_generation/test_six_pow_node.py b/tests/test_feat_generation/test_six_pow_node.py index 55ed2bbed7a8dc965a15d6fa851a282fa4650dc8..d9a6a089ce78a13872cd9063a7927467f929cc11 100644 --- a/tests/test_feat_generation/test_six_pow_node.py +++ b/tests/test_feat_generation/test_six_pow_node.py @@ -7,6 +7,7 @@ from cpp_sisso import ( SqrtNode, CbrtNode, Unit, + initialize_values_arr, ) import numpy as np @@ -17,6 +18,8 @@ class InvalidFeatureMade(Exception): def test_six_pow_node(): + initialize_values_arr(90, 10, 2) + data_1 = np.random.random(90) * 1e1 + 1e-10 test_data_1 = np.random.random(10) * 1e1 + 1e-10 diff --git a/tests/test_feat_generation/test_sq_node.py b/tests/test_feat_generation/test_sq_node.py index a13f7526eed8c38d5b6e0b3658999bf08d546c75..50512913c4fc64eab0e5f9a478674cf269df44ce 100644 --- a/tests/test_feat_generation/test_sq_node.py +++ b/tests/test_feat_generation/test_sq_node.py @@ -1,4 +1,11 @@ -from cpp_sisso import FeatureNode, InvNode, SqNode, SqrtNode, Unit +from cpp_sisso import ( + FeatureNode, + InvNode, + SqNode, + SqrtNode, + Unit, + initialize_values_arr, +) import numpy as np @@ -7,7 +14,9 @@ class InvalidFeatureMade(Exception): pass -def test_cube_node(): +def test_square_node(): + initialize_values_arr(90, 10, 2) + data_1 = np.random.random(90) * 1e4 + 1e-10 test_data_1 = np.random.random(10) * 1e4 + 1e-10 @@ -59,4 +68,4 @@ def test_cube_node(): if __name__ == "__main__": - test_cube_node() + test_square_node() diff --git a/tests/test_feat_generation/test_sqrt_node.py b/tests/test_feat_generation/test_sqrt_node.py index 4154c3d92159bfe74b3a9244a4644096f307c786..531f731b5765ff816c18545448d55cd8ad8952df 100644 --- a/tests/test_feat_generation/test_sqrt_node.py +++ b/tests/test_feat_generation/test_sqrt_node.py @@ -7,6 +7,7 @@ from cpp_sisso import ( SqrtNode, CbrtNode, Unit, + initialize_values_arr, ) import numpy as np @@ -17,6 +18,8 @@ class InvalidFeatureMade(Exception): def test_sqrt_node(): + initialize_values_arr(90, 10, 2) + data_1 = np.random.random(90) * 1e4 + 1e-10 test_data_1 = np.random.random(10) * 1e4 + 1e-10 diff --git a/tests/test_feat_generation/test_sub_node.py b/tests/test_feat_generation/test_sub_node.py index 35886d08597e7875fc518a28f1aaf91d7a3d6cbf..08e59c12bdedb56275640a5d3f7073f28ede4534 100644 --- a/tests/test_feat_generation/test_sub_node.py +++ b/tests/test_feat_generation/test_sub_node.py @@ -1,4 +1,4 @@ -from cpp_sisso import FeatureNode, AddNode, SubNode, Unit +from cpp_sisso import FeatureNode, AddNode, SubNode, Unit, initialize_values_arr import numpy as np @@ -8,6 +8,8 @@ class InvalidFeatureMade(Exception): def test_sub_node(): + initialize_values_arr(90, 10, 4) + data_1 = np.random.random(90) * 1e4 + 1e-10 test_data_1 = np.random.random(10) * 1e4 + 1e-10 diff --git a/tests/test_parameterize/test_param_add.py b/tests/test_parameterize/test_param_add.py new file mode 100644 index 0000000000000000000000000000000000000000..f684d1a1d8e9e1b9aaf4a3e9b55fb9716f3960b7 --- /dev/null +++ b/tests/test_parameterize/test_param_add.py @@ -0,0 +1,24 @@ +from cpp_sisso import FeatureNode, AddNode, SubNode, Unit + +import numpy as np + + +class InvalidFeatureMade(Exception): + pass + + +def test_param_add_node(): + data_1 = np.random.random(90) * 1e2 + 1e-10 + test_data_1 = np.random.random(10) * 1e2 + 1e-10 + + data_2 = np.random.random(90) * 1e2 + test_data_2 = np.random.random(10) * 1e2 + + prop_alpha_b_c = -2.3 * (data_1 + 1.5 * data_2) - 1.2 + prop_alpha_b = -2.3 * (data_1 + 1.5 * data_2) + prop_alpha_c = (data_1 + 1.5 * data_2) - 1.2 + prop_alpha = data_1 + 1.5 * data_2 + + +if __name__ == "__main__": + test_param_add_node()