Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions vowpalwabbit/cats_tree.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "explore_internal.h"
#include "hash.h"
#include "guard.h"
#include "label_parser.h"

using namespace VW::config;
using namespace VW::LEARNER;
Expand Down Expand Up @@ -360,16 +361,18 @@ base_learner* setup(options_i& options, vw& all)
options.replace("link", "glf1");
}

auto tree = scoped_calloc_or_throw<cats_tree>();
auto tree = VW::make_unique<cats_tree>();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like _cost_star, _a, _b are unitialized after this call.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just recommitted. Let me know if manually initializing _a and _b is preferred to creating a constructor in node_cost.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having the node_cost initialization done internally is good as it affects any other usage too. So this approach is better

tree->init(num_actions, bandwidth);
tree->set_trace_message(all.trace_message.get(), all.logger.quiet);

base_learner* base = setup_base(options, all);

learner<cats_tree, example>& l = init_learner(tree, as_singleline(base), learn, predict, tree->learner_count(),
prediction_type_t::multiclass, all.get_setupfn_name(setup));

return make_base(l);
int32_t params_per_weight = tree->learner_count();
auto* l = make_reduction_learner(std::move(tree), as_singleline(base), learn, predict, all.get_setupfn_name(setup))
.set_params_per_weight(params_per_weight)
.set_prediction_type(prediction_type_t::multiclass)
.set_label_type(label_type_t::cb)
.build();
return make_base(*l);
}

} // namespace cats_tree
Expand Down
4 changes: 3 additions & 1 deletion vowpalwabbit/cats_tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ struct node_cost
{
uint32_t node_id;
float cost;
node_cost() : node_id(0), cost(0.f) {}
node_cost(uint32_t node_id, float cost) : node_id(node_id), cost(cost) {}
};

struct cats_tree
Expand All @@ -72,7 +74,7 @@ struct cats_tree
uint64_t app_seed = uniform_hash("vw", 2, 0);
std::string tree_stats_to_string();
min_depth_binary_tree _binary_tree;
float _cost_star;
float _cost_star = 0.f;
node_cost _a;
node_cost _b;
std::ostream* _trace_stream = nullptr;
Expand Down