private static boolean testNeighborJoiningR() {
try {
- final NeighborJoiningR nj = NeighborJoiningR.createInstance();
+ // final NeighborJoiningR nj0 = NeighborJoiningR.createInstance();
// final BasicSymmetricalDistanceMatrix m0 = new BasicSymmetricalDistanceMatrix( 4 );
// m0.setIdentifier( 0, "A" );
// m0.setIdentifier( 1, "B" );
// m0.setRow( "5 ", 1 );
// m0.setRow( "3 6 ", 2 );
// m0.setRow( "7.5 10.5 5.5", 3 );
- // final Phylogeny p0 = nj.execute( m0 );
+ // final Phylogeny p0 = nj0.execute( m0 );
// p0.reRoot( p0.getNode( "D" ) );
// // Archaeopteryx.createApplication( p0 );
// if ( isUnequal( p0.getNode( "A" ).getDistanceToParent(), 1 ) ) {
// m.setIdentifier( 3, "D" );
// m.setIdentifier( 4, "E" );
// m.setIdentifier( 5, "F" );
- // nj = NeighborJoiningR.createInstance();
- // final Phylogeny p1 = nj.execute( m );
+ // final NeighborJoiningR nj1 = NeighborJoiningR.createInstance();
+ // final Phylogeny p1 = nj1.execute( m );
// p1.reRoot( p1.getNode( "F" ) );
// Archaeopteryx.createApplication( p1 );
// if ( isUnequal( p1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
m.setRow( "1.52430 1.44650 0.59580 0.46310 0.00000 0.34840 0.30830", 4 );
m.setRow( "1.60430 1.43890 0.61790 0.50610 0.34840 0.00000 0.26920", 5 );
m.setRow( "1.59050 1.46290 0.55830 0.47100 0.30830 0.26920 0.00000", 6 );
- final NeighborJoiningR njr = NeighborJoiningR.createInstance( true, 6 );
+ final NeighborJoiningR nj2 = NeighborJoiningR.createInstance( true, 6 );
//nj = NeighborJoining.createInstance( true, 6 );
- final Phylogeny p2 = njr.execute( m );
+ final Phylogeny p2 = nj2.execute( m );
// Archaeopteryx.createApplication( p2 );
p2.reRoot( p2.getNode( "Bovine" ) );
if ( isUnequal( p2.getNode( "Chimp" ).getDistanceToParent(), 0.151675 ) ) {
package org.forester.evoinference.distance;
+import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Map.Entry;
_data = new ArrayList<SortedMap<Double, SortedSet<Integer>>>();
}
+ @Override
+ public String toString() {
+ final DecimalFormat df = new DecimalFormat( "0.00" );
+ final StringBuilder sb = new StringBuilder();
+ for( int j = 1; j < size(); ++j ) {
+ for( final Entry<Double, SortedSet<Integer>> entry : getSentrySet( j ) ) {
+ final double key = entry.getKey();
+ final SortedSet<Integer> values = entry.getValue();
+ sb.append( df.format( key ) + "->" );
+ boolean first = true;
+ for( final Integer v : values ) {
+ if ( !first ) {
+ sb.append( "," );
+ }
+ first = false;
+ sb.append( v );
+ }
+ sb.append( " " );
+ }
+ sb.append( "\n" );
+ }
+ return sb.toString();
+ }
+
void addPairing( final double key, final int value, final int j ) {
- final SortedMap<Double, SortedSet<Integer>> m = _data.get( j );
+ final SortedMap<Double, SortedSet<Integer>> m = getS( j );
addPairing( key, value, m );
}
}
Set<Entry<Double, SortedSet<Integer>>> getSentrySet( final int j ) {
- return _data.get( j ).entrySet();
+ return getS( j ).entrySet();
}
void initialize( final BasicSymmetricalDistanceMatrix d ) {
addPairing( d.getValues()[ i ][ j ], i, map );
}
}
+ System.out.println( toString() );
}
void removePairing( final double key, final int value, final int j ) {
if ( x.size() == 1 ) {
if ( !x.contains( value ) ) {
//TODO remove me later
- throw new IllegalStateException( "!x.contains( value )" );
+ throw new IllegalStateException( "pairing " + key + " -> " + value + " does not exist" );
}
m.remove( key );
}
final boolean removed = x.remove( value );
if ( !removed ) {
//TODO remove me later
- throw new IllegalStateException( value + " not found" );
+ throw new IllegalStateException( "pairing " + key + " -> " + value + " does not exist/was not removed" );
}
}
else {
}
}
+ int size() {
+ return _data.size();
+ }
+
private static void addPairing( final double key, final int value, final SortedMap<Double, SortedSet<Integer>> m ) {
if ( !m.containsKey( key ) ) {
final TreeSet<Integer> x = new TreeSet<Integer>();