From e0eb4f7f095c8bb38aa3e628d5cdf4561ca1a092 Mon Sep 17 00:00:00 2001
From: Thomas Purcell <purcell@fhi-berlin.mpg.de>
Date: Wed, 19 Aug 2020 19:45:56 +0200
Subject: [PATCH] Upadte tests to initialize node value storage

Don't always reuse
---
 src/python/__init__.py                        |  2 ++
 src/python/bindings_docstring_keyed.cpp       |  1 +
 .../test_abs_diff_node.py                     | 10 +++++++-
 tests/test_feat_generation/test_abs_node.py   |  3 ++-
 tests/test_feat_generation/test_add_node.py   |  3 ++-
 tests/test_feat_generation/test_cb_node.py    | 12 +++++++++-
 tests/test_feat_generation/test_cbrt_node.py  |  2 ++
 tests/test_feat_generation/test_cos_node.py   |  3 ++-
 tests/test_feat_generation/test_div_node.py   | 10 +++++++-
 tests/test_feat_generation/test_exp_node.py   | 13 +++++++++-
 tests/test_feat_generation/test_inv_node.py   | 12 +++++++++-
 tests/test_feat_generation/test_log_node.py   |  3 +++
 tests/test_feat_generation/test_mult_node.py  | 11 ++++++++-
 .../test_feat_generation/test_neg_exp_node.py | 13 +++++++++-
 tests/test_feat_generation/test_sin_node.py   |  4 +++-
 .../test_feat_generation/test_six_pow_node.py |  3 +++
 tests/test_feat_generation/test_sq_node.py    | 15 +++++++++---
 tests/test_feat_generation/test_sqrt_node.py  |  3 +++
 tests/test_feat_generation/test_sub_node.py   |  4 +++-
 tests/test_parameterize/test_param_add.py     | 24 +++++++++++++++++++
 20 files changed, 136 insertions(+), 15 deletions(-)
 create mode 100644 tests/test_parameterize/test_param_add.py

diff --git a/src/python/__init__.py b/src/python/__init__.py
index d196314c..f169e2f2 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 bf672548..93924906 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 cb3afab0..2fb3683a 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 1a674870..cd48dbec 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 821f7bbe..117f7d1a 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 1e4ebc8c..c0fcab35 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 815e7d24..d68dd324 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 63ef07ff..3325e6b1 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 1bc81bdc..78305227 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 da250382..7cb6ff84 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 bda6b405..ba81bef8 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 04870cc7..7dd93ef4 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 d4e28c00..09e32f8f 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 9c60576a..7201d715 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 d840ccda..d69c8059 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 55ed2bbe..d9a6a089 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 a13f7526..50512913 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 4154c3d9..531f731b 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 35886d08..08e59c12 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 00000000..f684d1a1
--- /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()
-- 
GitLab