backward costs tree performs the backward pass of the Fitch algorithm on a given tree.
The arguments costs and tree are the values returned by the forward function.
It returns a tree where each branch is annotated with a pair consisting of the original branch data and an integer representing the chosen category index.
Example:
let input_tree = Tree.(node (1, [|List1.[1; 2]|]) [branch (1, [|List1.[1]|]) (leaf ("A", 1)); branch (2, [|List1.[2]|]) (leaf ("B", 2))])
let costs = [| [|0.; 2.|]; [|2.; 0.|] |]
let optimal_routing = backward costs input_tree
(* Accessing the routing *)
let node_data, children = optimal_routing.data
let child_1, child_2 = children.(1), children.(2) (* Children of the root node *)
let category_1, path_1 = child_1.tip.data (* Category and path of child 1 *)
let category_2, path_2 = child_2.tip.data (* Category and path of child 2 *)
This example showcases the usage of the backward function to compute the optimal routing of a tree. We provide a costs array representing the costs between different categories. The input_tree represents a pre-defined tree structure. By calling backward with the appropriate arguments, we obtain the optimal_routing tree, which contains the computed optimal routing information. We can access the routing information by traversing the optimal_routing tree structure and retrieving the category and path for each child node.