EDIT: The more I play around with jak, the more I discover the cool things it can do. It might be a good idea to keep it after all.
Monday, June 28, 2010
Jak working
I finally got Jak working (mostly, it compiles with errors, but if you ignore them the sample file will work and you get a very basic kml file, but it's kml non the less). To get it to work, JAXB2.xxx must be installed following the instructions here. This is not an ideal situation for my library as I would like it to be self contained and I don't want to make the user install other libraries in addition to phyloGeoRef. This may mean I'll have to find another KML writing library or write my own. Considering the time frame I think it is still early enough that I would be willing to give writing my own KML writers a shot. This would cut into time I would have otherwise spent writing more parsers to support more filetypes. This doesn't mean more filetypes won't be supported it just makes for more work. At the moment I feel motivated to add this extra bit of work and I think I can still work in additional parser writing. I'll work on it this week in addition to my planned work on the tree location algorithms and see how it goes.
Wednesday, June 23, 2010
Mean Position Algorithm Breakdown
I'm between World Cup matches so I'll take some time to explain how the mean node position function works. Here's the important part of the function:
if ( !node.isExternal() ) {
node.getNodeData().setDistribution(new Distribution(""));
Distribution dist = data.getDistribution();
for (int i=0; i node.getNumberOfDescendants(); i++){ //do mean calcs
PhylogenyNode childNode = node.getChildNode(i);
NodeData childData = childNode.getNodeData();
Distribution childDist = childData.getDistribution();
BigDecimal childLat = childDist.getLatitude();
BigDecimal childLong = childDist.getLongitude();
childCoordsLat.add(childLat);
childCoordsLong.add(childLong);
latSum = latSum.add(childLat);
longSum = longSum.add(childLong);
c++;
}
BigDecimal count = new BigDecimal(c);
BigDecimal meanLat = latSum.divide(count,BigDecimal.ROUND_CEILING);
BigDecimal meanLong = longSum.divide(count,BigDecimal.ROUND_CEILING);
dist.setLatitude(meanLat);
dist.setLongitude(meanLong);
Now to break it down.
if ( !node.isExternal() ) {node.getNodeData().setDistribution(new Distribution(""));Distribution dist = data.getDistribution();
We're only assigning non external nodes for this function, so first we check to make sure the node is internal. Next, since this node doesn't have a distribution yet we need to give it an empty one. Then we can get at the distribution of the node, here called dist.
Next we iterate through all the descendants of the node collecting the lat and long of each descendent:
for (int i=0; i node.getNumberOfDescendants(); i++){PhylogenyNode childNode = node.getChildNode(i);NodeData childData = childNode.getNodeData();Distribution childDist = childData.getDistribution();BigDecimal childLat = childDist.getLatitude();BigDecimal childLong = childDist.getLongitude();childCoordsLat.add(childLat);childCoordsLong.add(childLong);
Now we need to get the sum of all the children, we simply add:
latSum = latSum.add(childLat);longSum = longSum.add(childLong);
and keep track of how many descendants we've seen: c++;
This last bit is just a convoluted way of getting the mean:
BigDecimal count = new BigDecimal(c);BigDecimal meanLat = latSum.divide(count,BigDecimal.ROUND_CEILING);BigDecimal meanLong = longSum.divide(count,BigDecimal.ROUND_CEILING);dist.setLatitude(meanLat);dist.setLongitude(meanLong);
It's convoluted because we're dealing with BigDecimal objects so we have to do a bunch of stuff to keep the data types happy.
Sunday, June 20, 2010
Saturday, June 19, 2010
Mean Position Algorithm
I've implemented the mean position algorithm for assigning coordinates to the nodes. Basically, the function looks at all the children of the node and takes the mean of the latitude and longitude of the children and assigns it to the node.
Friday, June 18, 2010
Binary Tree Algorithm
Here's a brief outline of the binary tree algorithm:
For trees that are completely binary (each node has exactly two children) the leafs are assigned latitude and longitude from the coordinate file. The other nodes are assigned their latitude and longitude based on the midpoint of the two children. The altitudes of all nodes are assigned based on the height of the tree.
EDIT: I'm playing around with this function a lot so check github to make sure you have the latest version.
Thursday, June 17, 2010
testMain
I've added a main class for testing library functions and some test files, they're up on github. It's been really helpful for tracking down bugs. I'll keep adding features to this class as the project progresses. It's really basic at the moment, I'll post detailed instructions once everything is looking nice later today. If you're feeling adventurous go ahead and try it out now!
Wednesday, June 9, 2010
lat/long/alt
I've implemented a function to assign lat/long/alt coordinates to nodes of binary trees. These are trees where each node has exactly two children. This same function can be used for 'lazy' node coordinate assignment. The basic idea is given the height of the tree, altitudes are assigned to each node using altitude = a + ((n-1)*b) from from Janies et al. 2007. Check out the paper or the project site for more info on that algorithm. To assign latitude and longitude the function simply takes the midpoint of the two children. This is exactly how the 'lazy' node assigning function works. Neither of these functions take branch length into consideration.
EDIT: these functions have been pushed to GitHub
Subscribe to:
Posts (Atom)
