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 NeighborJoining nj = NeighborJoining.createInstance( true, 6 );
+ //nj = NeighborJoining.createInstance( true, 6 );
+ final Phylogeny pnj = nj.execute( m );
+ //
+ m = new BasicSymmetricalDistanceMatrix( 7 );
+ m.setIdentifier( 0, "Bovine" );
+ m.setIdentifier( 1, "Mouse" );
+ m.setIdentifier( 2, "Gibbon" );
+ m.setIdentifier( 3, "Orang" );
+ m.setIdentifier( 4, "Gorilla" );
+ m.setIdentifier( 5, "Chimp" );
+ m.setIdentifier( 6, "Human" );
+ m.setRow( "0.00000 1.68660 1.71980 1.66060 1.52430 1.60430 1.59050", 0 );
+ m.setRow( "1.68660 0.00000 1.52320 1.48410 1.44650 1.43890 1.46290", 1 );
+ m.setRow( "1.71980 1.52320 0.00000 0.71150 0.59580 0.61790 0.55830", 2 );
+ m.setRow( "1.66060 1.48410 0.71150 0.00000 0.46310 0.50610 0.47100", 3 );
+ 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 nj2 = NeighborJoiningR.createInstance( true, 6 );
//nj = NeighborJoining.createInstance( true, 6 );
final Phylogeny p2 = nj2.execute( m );
}
private static void timeNeighborJoining() {
+ final NeighborJoiningR njr = NeighborJoiningR.createInstance();
+ for( int n = 3; n <= 9; ++n ) {
+ final int x = ( int ) Math.pow( 2, n );
+ final BasicSymmetricalDistanceMatrix mt = new BasicSymmetricalDistanceMatrix( x );
+ mt.randomize( new Date().getTime() );
+ final long start_time = new Date().getTime();
+ njr.execute( mt );
+ System.out.println( "Size: " + x + " -> " + ( new Date().getTime() - start_time ) + "ms" );
+ }
final NeighborJoiningF njf = NeighborJoiningF.createInstance();
for( int n = 3; n <= 9; ++n ) {
final int x = ( int ) Math.pow( 2, n );
public final class NeighborJoining {
+ private final static DecimalFormat DF = new DecimalFormat( "0.00000" );
private BasicSymmetricalDistanceMatrix _d;
private double[][] _d_values;
private final DecimalFormat _df;
}
}
}
+ for( int j = 1; j < _n; ++j ) {
+ final double r_j = _r[ j ];
+ final int m_j = _mappings[ j ];
+ for( int i = 0; i < j; ++i ) {
+ System.out.print( i );
+ System.out.print( "->" );
+ System.out.print( DF.format( _r[ i ] ) );
+ System.out.print( " " );
+ }
+ System.out.println();
+ }
}
// otu2 will, in effect, be "deleted" from the matrix.
private final void updateMappings( final int otu2 ) {
for( int i = otu2; i < ( _mappings.length - 1 ); ++i ) {
+ System.out.print( _mappings[ i ] );
_mappings[ i ] = _mappings[ i + 1 ];
+ System.out.println( "----->" + _mappings[ i ] );
+ }
+ for( int i = 0; i < _mappings.length; ++i ) {
+ System.out.println( i + "-->" + _mappings[ i ] );
}
}
final int otu2 = _min_j;
System.out.println( _min_i + " " + _min_j + " => " + DF.format( m ) + " (" + DF.format( _d_min ) + ")" );
// It is a condition that otu1 < otu2.
- System.out.println( "mapped 1 " + _mappings[ otu1 ] );
- System.out.println( "mapped 2 " + _mappings[ otu2 ] );
+ //System.out.println( "mapped 1 " + _mappings[ otu1 ] );
+ System.out.println( "mapped otu 2 " + _mappings[ otu2 ] );
final PhylogenyNode node = new PhylogenyNode();
- final double d = getDvalueUnmapped( otu1, _mappings[ otu2 ] );
+ //final double d = getDvalueUnmapped( otu1, _mappings[ otu2 ] );
+ final double d = _d_values[ otu1 ][ _mappings[ otu2 ] ];
final double d1 = ( d / 2 ) + ( ( _r[ otu1 ] - _r[ otu2 ] ) / ( 2 * ( _n - 2 ) ) );
final double d2 = d - d1;
if ( _df == null ) {
System.out.println( "otu1=" + otu1 );
System.out.println( "otu2=" + otu2 );
calculateDistancesFromNewNode( otu1, otu2, d );
- _external_nodes[ _mappings[ otu1 ] ] = node;
+ // _external_nodes[ _mappings[ otu1 ] ] = node;
+ _external_nodes[ otu1 ] = node;
updateMappings( otu2 );
--_n;
System.out.println( "" );
System.out.print( sorted_i + " " );
System.out.print( "(" + DF.format( getDvalueUnmapped( sorted_i, m_j ) ) + ") " );
final double m = getDvalueUnmapped( sorted_i, m_j ) - ( ( _r[ sorted_i ] + r_j ) / n_minus_2 );
- if ( ( m < min_m ) && ( sorted_i != j ) ) {
+ if ( ( m < min_m ) ) {
_d_min = getDvalueUnmapped( sorted_i, m_j );
min_m = m;
_min_i = sorted_i;
}
}
System.out.println();
+ for( final Entry<Integer, SortedSet<Integer>> entry : _s.getSentrySet( m_j ) ) {
+ for( final int sorted_i : entry.getValue() ) {
+ System.out.print( sorted_i );
+ System.out.print( "->" );
+ System.out.print( DF.format( _r[ sorted_i ] ) );
+ System.out.print( " " );
+ }
+ }
+ System.out.println();
/*
for( int i = 0; i < j; ++i ) {
final double m = getDvalue( i, j ) - ( ( _r[ i ] + r_j ) / n_minus_2 );
throw new IllegalArgumentException( "key " + key + " (->" + value + ") does not exist for row " + j );
}
}
- // if ( x.size() == 1 ) {
- // if ( DEBUG ) {
- // if ( !x.contains( value ) ) {
- // System.out.println();
- // System.out
- // .println( "________________________________________________________________________________________" );
- // System.out.println( toString() );
- // throw new IllegalArgumentException( "pairing " + key + "->" + value + " does not exist for row "
- // + j );
- // }
- // }
- // m.remove( key );
- // }
- else if ( x.size() >= 1 ) {
+ if ( x.size() == 1 ) {
+ if ( DEBUG ) {
+ if ( !x.contains( value ) ) {
+ System.out.println();
+ System.out
+ .println( "________________________________________________________________________________________" );
+ System.out.println( toString() );
+ throw new IllegalArgumentException( "pairing " + key + "->" + value + " does not exist for row "
+ + j );
+ }
+ }
+ m.remove( key );
+ }
+ else if ( x.size() > 1 ) {
if ( DEBUG ) {
if ( !x.remove( value ) ) {
throw new IllegalArgumentException( "pairing " + key + "->" + value