diff --git a/tests/exec_test/reparam/sisso.json b/tests/exec_test/reparam/sisso.json index d90917e122558ad90f6b7dcb206d3a76015d0627..64267ee61bae531b89fa71491fe34d8d68141ce6 100644 --- a/tests/exec_test/reparam/sisso.json +++ b/tests/exec_test/reparam/sisso.json @@ -1,7 +1,7 @@ { "desc_dim": 2, "n_sis_select": 5, - "max_rung": 1, + "max_rung": 2, "n_residual": 5, "data_file": "data.csv", "data_file_relatice_to_json": true, diff --git a/tests/googletest/feature_creation/feature_space/test_feat_space.cc b/tests/googletest/feature_creation/feature_space/test_feat_space.cc index 3d4bc533f772af9f9638ef746d47f54c05bf5eee..7fc4b67a91926f837789f5b63735cfadb2870114 100644 --- a/tests/googletest/feature_creation/feature_space/test_feat_space.cc +++ b/tests/googletest/feature_creation/feature_space/test_feat_space.cc @@ -31,7 +31,7 @@ namespace std::vector<int> task_sizes = {5, 5}; int n_samp = std::accumulate(task_sizes.begin(), task_sizes.end(), 0); - node_value_arrs::initialize_values_arr(task_sizes, {0, 0}, 3, 2, false); + node_value_arrs::initialize_values_arr(task_sizes, {0, 0}, 4, 2, false); node_value_arrs::initialize_d_matrix_arr(); std::vector<double> value_1(n_samp, 0.0); @@ -61,6 +61,7 @@ namespace FeatureNode feat_1(0, "A", value_1, std::vector<double>(), Unit("m")); FeatureNode feat_2(1, "B", value_2, std::vector<double>(), Unit("m")); FeatureNode feat_3(2, "C", value_3, std::vector<double>(), Unit("s")); + FeatureNode feat_4(3, "D", std::vector<double>(10, 1.0), std::vector<double>(), Unit("s")); std::vector<FeatureNode> phi_0 = {feat_1, feat_2, feat_3}; @@ -232,4 +233,15 @@ namespace boost::filesystem::remove_all("feature_space/"); prop_sorted_d_mat::finalize_sorted_d_matrix_arr(); } + + TEST_F(FeatSpaceTest, CheckFailedSISTest) + { + _inputs.set_calc_type("regression"); + _inputs.set_prop_train(_prop); + _inputs.set_n_sis_select(1000000); + + FeatureSpace feat_space(_inputs); + EXPECT_THROW(feat_space.sis(_prop), std::logic_error); + } + } diff --git a/tests/googletest/feature_creation/parameterization/test_six_pow_node.cc b/tests/googletest/feature_creation/parameterization/test_six_pow_node.cc index ba5766b6e105ee4507b3bee67880bb22d4c4d36b..e00520c47163d6458e5d140f337278ad5e4b997c 100644 --- a/tests/googletest/feature_creation/parameterization/test_six_pow_node.cc +++ b/tests/googletest/feature_creation/parameterization/test_six_pow_node.cc @@ -150,12 +150,12 @@ namespace std::vector<double> expected_val(900, 0.0); allowed_op_funcs::sixth_pow(900, _phi[0]->value_ptr(), copy_test->parameters()[0], copy_test->parameters()[1], expected_val.data()); - EXPECT_LT(std::abs(copy_test->value_ptr()[0] - expected_val[0]), 1e-10); - EXPECT_LT(std::abs(copy_test->value()[0] - expected_val[0]), 1e-10); + EXPECT_LT(std::abs(copy_test->value_ptr()[0] - expected_val[0]), 1e-4); + EXPECT_LT(std::abs(copy_test->value()[0] - expected_val[0]), 1e-4); allowed_op_funcs::sixth_pow(10, _phi[0]->test_value_ptr(), copy_test->parameters()[0], copy_test->parameters()[1], expected_val.data()); - EXPECT_LT(std::abs(copy_test->test_value_ptr()[0] - expected_val[0]), 1e-10); - EXPECT_LT(std::abs(copy_test->test_value()[0] - expected_val[0]), 1e-10); + EXPECT_LT(std::abs(copy_test->test_value_ptr()[0] - expected_val[0]), 1e-4); + EXPECT_LT(std::abs(copy_test->test_value()[0] - expected_val[0]), 1e-4); std::stringstream postfix; postfix << "0|sp: " << std::setprecision(13) << std::scientific <<copy_test->parameters()[0] << ',' << copy_test->parameters()[1]; @@ -169,8 +169,8 @@ namespace double a = copy_test->parameters()[1]; double df_dp = 6.0 * std::pow(alpha * v1 + a, 5.0); - EXPECT_LT(std::abs(_gradient[0] - df_dp * v1), 1e-10); - EXPECT_LT(std::abs(_gradient[_task_sizes_train[0]] - df_dp), 1e-10); + EXPECT_LT(std::abs(_gradient[0] - df_dp * v1), 1e-4); + EXPECT_LT(std::abs(_gradient[_task_sizes_train[0]] - df_dp), 1e-4); } TEST_F(SixPowParamNodeTest, AttributesTest) @@ -183,12 +183,12 @@ namespace std::vector<double> expected_val(900, 0.0); allowed_op_funcs::sixth_pow(900, _phi[0]->value_ptr(), _six_pow_test->parameters()[0], _six_pow_test->parameters()[1], expected_val.data()); - EXPECT_LT(std::abs(_six_pow_test->value_ptr()[0] - expected_val[0]), 1e-10); - EXPECT_LT(std::abs(_six_pow_test->value()[0] - expected_val[0]), 1e-10); + EXPECT_LT(std::abs(_six_pow_test->value_ptr()[0] - expected_val[0]), 1e-4); + EXPECT_LT(std::abs(_six_pow_test->value()[0] - expected_val[0]), 1e-4); allowed_op_funcs::sixth_pow(10, _phi[0]->test_value_ptr(), _six_pow_test->parameters()[0], _six_pow_test->parameters()[1], expected_val.data()); - EXPECT_LT(std::abs(_six_pow_test->test_value_ptr()[0] - expected_val[0]), 1e-10); - EXPECT_LT(std::abs(_six_pow_test->test_value()[0] - expected_val[0]), 1e-10); + EXPECT_LT(std::abs(_six_pow_test->test_value_ptr()[0] - expected_val[0]), 1e-4); + EXPECT_LT(std::abs(_six_pow_test->test_value()[0] - expected_val[0]), 1e-4); std::stringstream postfix; postfix << "0|sp: " << std::setprecision(13) << std::scientific <<_six_pow_test->parameters()[0] << ',' << _six_pow_test->parameters()[1]; diff --git a/tests/pytest/test_feature_creation/test_feature_space/test_feature_space.py b/tests/pytest/test_feature_creation/test_feature_space/test_feature_space.py index 2987cf21c929ebcf6890722874c0cfc9d840003e..33cc40a958a2dd38921e3e41d473f5cf0ab04cb1 100644 --- a/tests/pytest/test_feature_creation/test_feature_space/test_feature_space.py +++ b/tests/pytest/test_feature_creation/test_feature_space/test_feature_space.py @@ -36,7 +36,7 @@ def test_feature_space(): f"feat_{ff}", np.random.random(task_sizes_train[0]) * 1e2 - 50, np.random.random(task_sizes_test[0]) * 1e2 - 50, - Unit(), + Unit("s"), ) for ff in range(10) ] @@ -50,6 +50,42 @@ def test_feature_space(): inputs.max_rung = 2 inputs.n_sis_select = 10 + try: + inputs.max_param_depth = 10 + feat_space = FeatureSpace(inputs) + raise ValueError("FeatureSpace created with invalid parameters") + except RuntimeError: + inputs.max_param_depth = 0 + pass + + try: + inputs.n_rung_generate = 2 + feat_space = FeatureSpace(inputs) + raise ValueError("FeatureSpace created with invalid parameters") + except RuntimeError: + inputs.n_rung_generate = 0 + pass + + try: + inputs.n_rung_generate = 1 + inputs.n_rung_store = 2 + feat_space = FeatureSpace(inputs) + raise ValueError("FeatureSpace created with invalid parameters") + except RuntimeError: + inputs.n_rung_generate = 0 + inputs.n_rung_store = 1 + pass + + try: + inputs.allowed_ops = ["exp"] + feat_space = FeatureSpace(inputs) + raise ValueError( + "FeatureSpace created when there is a rung with no features created" + ) + except RuntimeError: + inputs.allowed_ops = ["add", "sub", "mult", "sq", "cb", "sqrt", "cbrt"] + pass + feat_space = FeatureSpace(inputs) feat_space.sis(inputs.prop_train) @@ -76,6 +112,12 @@ def test_feature_space(): assert feat_space.get_feature(0).expr == "feat_0" assert feat_space.phi_selected[1].d_mat_ind == 1 + try: + feat_space.remove_feature(feat_space.phi_selected[0].feat_ind) + raise ValueError("Removed selected feature.") + except RuntimeError: + pass + test_expr = feat_space.get_feature(len(feat_space.phi) - 2).expr feat_space.remove_feature(len(feat_space.phi) - 2) assert feat_space.get_feature(len(feat_space.phi) - 2).expr != test_expr