Commit 568a6538 authored by Thomas Purcell's avatar Thomas Purcell
Browse files

Bug Fix

Postfix was done correctly, issue was sorting of the phi_temp from the file
parent 240f5b81
......@@ -244,9 +244,11 @@ FeatureSpace::FeatureSpace(
_n_feat = phi_temp.size();
_phi.resize(_n_feat);
std::vector<int> rungs(_n_feat, 0);
std::vector<unsigned int> sort_scores(_n_feat, 0);
for(int ff = 0; ff < _n_feat; ++ff)
{
rungs[ff] = phi_temp[ff]->rung();
sort_scores[ff] = phi_temp[ff]->rung() * _n_feat + phi_temp[ff]->arr_ind();
if(phi_temp[ff]->type() == NODE_TYPE::FEAT)
{
continue;
......@@ -289,7 +291,6 @@ FeatureSpace::FeatureSpace(
}
}
std::vector<int> rung_inds = util_funcs::argsort<int>(rungs);
_max_rung = *std::max_element(rungs.begin(), rungs.end());
#ifdef PARAMETERIZE
node_value_arrs::set_max_rung(_max_rung, _allowed_param_ops.size() > 0);
......@@ -297,6 +298,7 @@ FeatureSpace::FeatureSpace(
node_value_arrs::set_max_rung(_max_rung);
#endif
std::vector<int> rung_inds = util_funcs::argsort<unsigned int>(sort_scores);
_phi[0] = phi_temp[rung_inds[0]];
for(int ff = 1; ff < _n_feat; ++ff)
{
......
......@@ -74,16 +74,16 @@ node_ptr str2node::postfix2node(const std::string postfix_expr, const std::vecto
if(op_terms[0] == "add")
{
#ifndef PARAMETERIZE
stack[stack.size() - 2] = std::make_shared<AddNode>(stack[stack.size() - 1], stack[stack.size() - 2], feat_ind);
stack[stack.size() - 2] = std::make_shared<AddNode>(stack[stack.size() - 2], stack[stack.size() - 1], feat_ind);
#else
if(op_terms.size() > 1)
{
stack[stack.size() - 2] = std::make_shared<AddParamNode>(stack[stack.size() - 1], stack[stack.size() - 2], feat_ind);
stack[stack.size() - 2] = std::make_shared<AddParamNode>(stack[stack.size() - 2], stack[stack.size() - 1], feat_ind);
set_parameters(stack[stack.size() - 2], op_terms);
}
else
{
stack[stack.size() - 2] = std::make_shared<AddNode>(stack[stack.size() - 1], stack[stack.size() - 2], feat_ind);
stack[stack.size() - 2] = std::make_shared<AddNode>(stack[stack.size() - 2], stack[stack.size() - 1], feat_ind);
}
#endif
stack.pop_back();
......@@ -91,16 +91,16 @@ node_ptr str2node::postfix2node(const std::string postfix_expr, const std::vecto
else if(op_terms[0] == "sub")
{
#ifndef PARAMETERIZE
stack[stack.size() - 2] = std::make_shared<SubNode>(stack[stack.size() - 1], stack[stack.size() - 2], feat_ind);
stack[stack.size() - 2] = std::make_shared<SubNode>(stack[stack.size() - 2], stack[stack.size() - 1], feat_ind);
#else
if(op_terms.size() > 1)
{
stack[stack.size() - 2] = std::make_shared<SubParamNode>(stack[stack.size() - 1], stack[stack.size() - 2], feat_ind);
stack[stack.size() - 2] = std::make_shared<SubParamNode>(stack[stack.size() - 2], stack[stack.size() - 1], feat_ind);
set_parameters(stack[stack.size() - 2], op_terms);
}
else
{
stack[stack.size() - 2] = std::make_shared<SubNode>(stack[stack.size() - 1], stack[stack.size() - 2], feat_ind);
stack[stack.size() - 2] = std::make_shared<SubNode>(stack[stack.size() - 2], stack[stack.size() - 1], feat_ind);
}
#endif
stack.pop_back();
......@@ -108,16 +108,16 @@ node_ptr str2node::postfix2node(const std::string postfix_expr, const std::vecto
else if(op_terms[0] == "abd")
{
#ifndef PARAMETERIZE
stack[stack.size() - 2] = std::make_shared<AbsDiffNode>(stack[stack.size() - 1], stack[stack.size() - 2], feat_ind);
stack[stack.size() - 2] = std::make_shared<AbsDiffNode>(stack[stack.size() - 2], stack[stack.size() - 1], feat_ind);
#else
if(op_terms.size() > 1)
{
stack[stack.size() - 2] = std::make_shared<AbsDiffParamNode>(stack[stack.size() - 1], stack[stack.size() - 2], feat_ind);
stack[stack.size() - 2] = std::make_shared<AbsDiffParamNode>(stack[stack.size() - 2], stack[stack.size() - 1], feat_ind);
set_parameters(stack[stack.size() - 2], op_terms);
}
else
{
stack[stack.size() - 2] = std::make_shared<AbsDiffNode>(stack[stack.size() - 1], stack[stack.size() - 2], feat_ind);
stack[stack.size() - 2] = std::make_shared<AbsDiffNode>(stack[stack.size() - 2], stack[stack.size() - 1], feat_ind);
}
#endif
stack.pop_back();
......@@ -125,16 +125,16 @@ node_ptr str2node::postfix2node(const std::string postfix_expr, const std::vecto
else if(op_terms[0] == "mult")
{
#ifndef PARAMETERIZE
stack[stack.size() - 2] = std::make_shared<MultNode>(stack[stack.size() - 1], stack[stack.size() - 2], feat_ind);
stack[stack.size() - 2] = std::make_shared<MultNode>(stack[stack.size() - 2], stack[stack.size() - 1], feat_ind);
#else
if(op_terms.size() > 1)
{
stack[stack.size() - 2] = std::make_shared<MultParamNode>(stack[stack.size() - 1], stack[stack.size() - 2], feat_ind);
stack[stack.size() - 2] = std::make_shared<MultParamNode>(stack[stack.size() - 2], stack[stack.size() - 1], feat_ind);
set_parameters(stack[stack.size() - 2], op_terms);
}
else
{
stack[stack.size() - 2] = std::make_shared<MultNode>(stack[stack.size() - 1], stack[stack.size() - 2], feat_ind);
stack[stack.size() - 2] = std::make_shared<MultNode>(stack[stack.size() - 2], stack[stack.size() - 1], feat_ind);
}
#endif
stack.pop_back();
......@@ -142,16 +142,16 @@ node_ptr str2node::postfix2node(const std::string postfix_expr, const std::vecto
else if(op_terms[0] == "div")
{
#ifndef PARAMETERIZE
stack[stack.size() - 2] = std::make_shared<DivNode>(stack[stack.size() - 1], stack[stack.size() - 2], feat_ind);
stack[stack.size() - 2] = std::make_shared<DivNode>(stack[stack.size() - 2], stack[stack.size() - 1], feat_ind);
#else
if(op_terms.size() > 1)
{
stack[stack.size() - 2] = std::make_shared<DivParamNode>(stack[stack.size() - 1], stack[stack.size() - 2], feat_ind);
stack[stack.size() - 2] = std::make_shared<DivParamNode>(stack[stack.size() - 2], stack[stack.size() - 1], feat_ind);
set_parameters(stack[stack.size() - 2], op_terms);
}
else
{
stack[stack.size() - 2] = std::make_shared<DivNode>(stack[stack.size() - 1], stack[stack.size() - 2], feat_ind);
stack[stack.size() - 2] = std::make_shared<DivNode>(stack[stack.size() - 2], stack[stack.size() - 1], feat_ind);
}
#endif
stack.pop_back();
......
......@@ -139,14 +139,12 @@ def test_feature_space():
inputs.cross_cor_max,
)
# shutil.rmtree("feature_space/")
assert feat_space.n_feat == feat_space_2.n_feat
feat_space_2.sis(inputs.prop_train)
assert (
feat_space.phi_selected[0].postfix_expr
== feat_space_2.phi_selected[0].postfix_expr
)
assert feat_space.phi_selected[0].expr == feat_space_2.phi_selected[0].expr
shutil.rmtree("feature_space/")
if __name__ == "__main__":
......
......@@ -48,13 +48,13 @@ def test_gen_feature_space_from_file():
f"{parent}/phi.txt", phi_0, prop, task_sizes_train, "regression", 1, 1.0, []
)
feat_space.sis(prop)
assert feat_space.phi_selected[0].postfix_expr == "0|1|add|sq"
assert feat_space.phi_selected[0].postfix_expr == "1|0|add|sq"
feat_space = FeatureSpace(
f"{parent}/phi.txt", phi_0, list(prop), task_sizes_train, "regression", 1, 1.0
)
feat_space.sis(prop)
assert feat_space.phi_selected[0].postfix_expr == "0|1|add|sq"
assert feat_space.phi_selected[0].postfix_expr == "1|0|add|sq"
if __name__ == "__main__":
......
......@@ -28,8 +28,8 @@ def test_gen_feature_space_from_file():
str(parent / "selected_features.txt"), inputs.phi_0, []
)
assert phi_sel[0].postfix_expr == "3|abs|2|3|add|add"
assert phi_sel[1].postfix_expr == "0|0|1|div|div"
assert phi_sel[0].postfix_expr == "3|2|add|3|abs|add"
assert phi_sel[1].postfix_expr == "1|0|div|0|div"
if __name__ == "__main__":
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment