|
ʻOhana
Population structure, admixture history, and selection using learning methods.
|
7 #ifndef JADE_TREE_CONTROLLER_HPP__
8 #define JADE_TREE_CONTROLLER_HPP__
10 #include "jade.controller.hpp"
11 #include "jade.rerooted_tree.hpp"
19 template <
typename TValue>
64 , _settings (settings)
66 , _unrooted_tree_ptr ()
69 const auto rk = this->
get_rk();
74 _unrooted_tree_ptr.reset(
81 _rerooted_tree.
reset(*_unrooted_tree_ptr);
88 for (
size_t r = 0; r < rk; r++)
89 for (
size_t c = 0; c <= r; c++)
90 _table.emplace_back(_rerooted_tree, r, c);
113 const auto root_id = _unrooted_tree_ptr->get_id();
116 _unrooted_tree_ptr->for_each([&](
node_type *
const target) ->
void
118 const auto id = target->
get_id();
119 const auto source = source_root->find_id(
id);
120 if (source->has_length())
128 const auto & tout = opts.
get_tout();
129 std::cout <<
"Writing tree to " << tout << std::endl;
130 _unrooted_tree_ptr->write(tout);
134 std::cout <<
"\n[Tree]\n" << *_unrooted_tree_ptr << std::endl;
142 _copy_tree_to_container(container, _rerooted_tree.
get_tree());
162 auto iterator = src.begin();
163 _copy_container_to_tree(_rerooted_tree.
get_tree(), iterator);
170 for (
const auto & entry : _table)
193 : i (row * rerooted_tree.
get_rk() + column)
194 , p (rerooted_tree.get_overlap(row, column))
203 typedef std::vector<table_entry> table_type;
204 typedef basic_newick_node<value_type> node_type;
214 void _copy_container_to_tree(
215 const node_type & parent,
216 typename container_type::const_iterator & iterator)
219 for (
auto child : parent.get_children())
221 child->set_length(*iterator++);
222 _copy_container_to_tree(*child, iterator);
234 void _copy_tree_to_container(
236 const node_type & parent)
239 for (
auto child : parent.get_children())
241 container.push_back(child->get_length());
242 _copy_tree_to_container(container, *child);
253 #endif // JADE_TREE_CONTROLLER_HPP__
A template for a class that performs the Nelder-Mead optimization. This class implements shared featu...
const options_type & get_options() const
simplex_type::container_type container_type
The container type for the simplex.
pointer_type reroot() const
Creates a new tree based on the tree associated with this node; in the tree returned,...
size_t get_length() const
void erase_length()
Erases the length.
basic_rerooted_tree< value_type > rerooted_tree_type
The rerooted tree type.
basic_options< value_type > options_type
The options type.
void reset(const node_type &node)
Resets the tree maintained by this instance.
simplex_type::exit_condition_type exit_condition_type
The exit condition type for the simplex.
virtual bool _decode_lower(matrix_type &dst, const container_type &src) override
Decodes the specified Nelder-Mead container and stores the result into the lower triangle,...
A template class representing a node from a Newick tree.
A template for a class that implements the Nelder-Mead Simplex Method, which attempts to minimize an ...
const std::string & get_tout() const
basic_tree_controller(const settings_type &settings)
Initializes a new instance of the class based on the specified program settings.
void set_length(const value_type length)
Assigns the length.
std::vector< value_type > container_type
The container type.
basic_tree_path< value_type > path_type
The path type.
simplex_type::container_type container_type
The container type for the simplex.
bool is_tout_specified() const
virtual void emit_results(const options_type &opts, const simplex_type &simplex, const exit_condition_type &)
Writes results to standard output and files.
const std::string & get_tin() const
A template for a class encapsulating the settings provided to the optimizer.
const_pointer_type find_id(const int id) const
virtual container_type init_parameters() override
Creates and returns the initial set of parameters for the Nelder- Mead algorithm.
basic_matrix< value_type > matrix_type
The matrix type.
A template for a class that encodes and decodes parameters for the Nelder-Mead algorithm....
virtual void emit_results(const options_type &opts, const simplex_type &simplex, const exit_condition_type &condition) override
Writes results to standard output and files.
TValue value_type
The value type.
static pointer_type from_file(char const *const path)
basic_simplex< value_type > simplex_type
The simplex type.
basic_settings< value_type > settings_type
The settings type.
basic_newick_node< value_type > unrooted_tree_type
The unrooted tree type.
std::unique_ptr< unrooted_tree_type > unrooted_tree_ptr_type
The pointer to an unrooted tree type.