I am new to Tree structures. I am trying to develop an algorithm that takes a predefined tree as input. Then it should plant the root of the tree with an object of my own design (I don’t think it is related to the design of the algorithm, but the object is an ArrayList) and uses the “change operator” to modify the object along each tree branch. The number of passes of the change statement depends on the length of the branch. An object must be evaluated in each node of the tree, and this node value is then used to evaluate the values of its child nodes. Therefore, I can’t just evaluate the value at each tip using the total length from root to tip, since the change statement that I use is stochastic, not deterministic. Therefore, the value of each child element node depends on the value of its parent node.
I tried to do it myself. I started by creating an array of times when one branch split into its children.
int[] times = new int[branchnumber]; times[0] = 1; times[1] = 5;
Then I created a method that took up the fork time (which I interpreted as the branch length), an ArrayList object, the current time, and the total number of branches.
public static void Brancher(int[] times, List<double[][]> sequences, int t){ boolean checker = false; for (int i = 0; i < times.length; i++) { if (times[i] == t) { checker = true; } } if (checker == true) { double[][] seq = sequences.get(sequences.size() - 1); sequences.add(seq); } }
The Brancher method is implemented as follows:
for (int j = 0; j <= loopnumber; j++) { MathsOperators.Brancher(times, sequences, t); for (int i = 0; i < sequences.size(); i++) { double[][] sequenceholder = sequences.get(i); MathsOperators.PrintOutput(sequenceholder, t); ComplexInput.evolvesequence(sequenceholder, frequencies, transitionrate, transversionrate, random); sequences.set(i, sequenceholder); } t = t + dt; }
So, I save the current state of all objects in the tree, since arrays are stored in ArrayList sequences. Then the evolve method acts on these objects, and updated objects replace the originals in the ArrayList. When you need to add a branch, the Brancher method takes the last Array object in the ArrayList, copies it, and adds the copy to the list. This actually simulated splitting the last object into two objects. The copy is then updated and developed in the next iteration of the simulation cycle.
This way of doing things, though not very, leads to trees that look like this: http://content.science20.com/files/Tree3A.jpg . This is a relatively simple structure.
However, it is not possible to create a tree of this form: http://content.science20.com/files/Tree4.jpg . This tree has several sections in the far right corner. I do not know the exact terminology to describe the differences between the trees here, but its is reasonably obvious.
I think I'm confused here. Any advice on how to think about this issue would be greatly appreciated.
(If this helps with context, the input object is a genetic sequence (ACGT). The idea is to develop a sequence along each tree branch, with each tip representing a descendant of the original (input) sequence)
EDIT
The input object is an ArrayList containing several (nx 2) double arrays. The first column of each array contains n integers from the set {1,2,3,4} that I control. However, the order of these characters in the column is random. Each integer represents one of the characters A, C, G, T in the DNA sequence. The second column contains a double indicator of the rate of evolution for each DNA site, therefore one record of speed for each whole record. The initial array is generated using the function I call DNASEQ, it is very long and does not matter for this question.
To get started, I create one of these arrays and add it to sequences called ArrayList. Using the simulation loop shown above, I then apply the evolvesequence method to each array in the ArrayList.
When Brancher detects that the time that is updated after each cycle in steps of 1 is equal to one of the indicated branches, then it takes the last array in ArrayList and adds a copy of the array to ArrayList. If the simulation stops there, the array will be identical to the one with which it was copied. However, now that it is in an ArrayList, it is subject to the evolvesequence method. Since evolvesequence is a stochastic / probabilistic method, no two outputs are guaranteed to be the same for a given input. So, after several iterations of the simulation cycle, the copied array will be very different from the original.
