From: cmzmasek@gmail.com Date: Tue, 18 Mar 2014 00:38:14 +0000 (+0000) Subject: inprogress X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=dd04eb6f09074d32b99879cbe5f6bb5aa7db0ce6;p=jalview.git inprogress --- diff --git a/forester/java/src/org/forester/evoinference/TestPhylogenyReconstruction.java b/forester/java/src/org/forester/evoinference/TestPhylogenyReconstruction.java index c545f59..a27d9f6 100644 --- a/forester/java/src/org/forester/evoinference/TestPhylogenyReconstruction.java +++ b/forester/java/src/org/forester/evoinference/TestPhylogenyReconstruction.java @@ -33,8 +33,8 @@ import java.io.StringWriter; import java.util.Date; import java.util.List; import java.util.Set; -import java.util.SortedSet; +import org.forester.archaeopteryx.Archaeopteryx; import org.forester.evoinference.distance.NeighborJoining; import org.forester.evoinference.distance.NeighborJoiningF; import org.forester.evoinference.distance.NeighborJoiningR; @@ -91,7 +91,7 @@ public class TestPhylogenyReconstruction { else { System.out.println( " failed." ); } - timeNeighborJoining(); + // timeNeighborJoining(); } public static boolean test( final File test_dir ) { @@ -2074,7 +2074,7 @@ public class TestPhylogenyReconstruction { //NeighborJoiningR njr = NeighborJoiningR.createInstance( true, 6 ); nj = NeighborJoining.createInstance( true, 6 ); final Phylogeny p2 = nj.execute( m ); - // Archaeopteryx.createApplication( p2 ); + Archaeopteryx.createApplication( p2 ); p2.reRoot( p2.getNode( "Bovine" ) ); if ( isUnequal( p2.getNode( "Chimp" ).getDistanceToParent(), 0.151675 ) ) { return false; @@ -2480,8 +2480,10 @@ public class TestPhylogenyReconstruction { m2.setRow( "1.59050 1.46290 0.55830 0.47100 0.30830 0.26920 0.00000", 6 ); final NeighborJoiningR nj2 = NeighborJoiningR.createInstance( true, 6 ); final Phylogeny p2 = nj2.execute( m2 ); + Archaeopteryx.createApplication( p2 ); p2.reRoot( p2.getNode( "Bovine" ) ); if ( isUnequal( p2.getNode( "Chimp" ).getDistanceToParent(), 0.151675 ) ) { + System.out.println( p2.getNode( "Chimp" ).getDistanceToParent() ); return false; } if ( isUnequal( p2.getNode( "Human" ).getDistanceToParent(), 0.117525 ) ) { @@ -2523,7 +2525,7 @@ public class TestPhylogenyReconstruction { return false; } // - System.exit(1); + // System.exit( 1 ); final BasicSymmetricalDistanceMatrix m3 = new BasicSymmetricalDistanceMatrix( 20 ); m3.setIdentifier( 0, "F_MOUSE" ); m3.setIdentifier( 1, "11_RAT" ); @@ -2589,7 +2591,7 @@ public class TestPhylogenyReconstruction { final Phylogeny p3 = nj3.execute( m3 ); //Archaeopteryx.createApplication( p3 ); //// - final int size = 100; + final int size = 10; for( int n = 0; n <= 100; ++n ) { final NeighborJoiningR njn = NeighborJoiningR.createInstance( false, 6 ); final BasicSymmetricalDistanceMatrix mt = new BasicSymmetricalDistanceMatrix( size ); diff --git a/forester/java/src/org/forester/evoinference/distance/NeighborJoiningR.java b/forester/java/src/org/forester/evoinference/distance/NeighborJoiningR.java index 2149f8a..c92fd54 100644 --- a/forester/java/src/org/forester/evoinference/distance/NeighborJoiningR.java +++ b/forester/java/src/org/forester/evoinference/distance/NeighborJoiningR.java @@ -52,7 +52,8 @@ public final class NeighborJoiningR { private S _s; private double _d_min; //TODO remove me private int[] _rev_mappings; - private double _umax; + private double _umax; + private double _rmax; private NeighborJoiningR() { _verbose = false; @@ -80,15 +81,15 @@ public final class NeighborJoiningR { } // Calculates the minimal distance. // If more than one minimal distances, always the first found is used - final double m = updateM(); + updateM(); final int otu1 = _min_i; final int otu2 = _min_j; - if ( _verbose ) { - 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 otu 2 " + _mappings[ otu2 ] ); - } + //if ( _verbose ) { + // 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 otu 2 " + _mappings[ otu2 ] ); + // } final PhylogenyNode node = new PhylogenyNode(); //final double d = getDvalueUnmapped( otu1, _mappings[ otu2 ] ); final double d = _d_values[ otu1 ][ _mappings[ otu2 ] ]; @@ -170,7 +171,7 @@ public final class NeighborJoiningR { // final double new_d = ( getDvalueUnmapped( otu1, _mappings[ j ] ) + getDvalue( j, otu2 ) - d ) / 2; // System.out.println( "\nnew d value: " + DF.format( new_d ) ); if ( otu1 < mj ) { - _s.removePairing( _d_values[ otu1][ mj ] , otu1, mj ); + _s.removePairing( _d_values[ otu1 ][ mj ], otu1, mj ); } else { _s.removePairing( _d_values[ mj ][ otu1 ], mj, otu1 ); @@ -202,14 +203,13 @@ public final class NeighborJoiningR { } private final void calculateNetDivergences() { - _umax = -1000; + _rmax = -Double.MAX_VALUE; for( int i = 0; i < _n; ++i ) { _r[ i ] = calculateNetDivergence( i ); - if ( _r[ i ] > _umax ) { - _umax = _r[i ]; + if ( _r[ i ] > _rmax ) { + _rmax = _r[ i ]; } } - // System.out.println( "umax=" + _umax ); } private double calculateNetDivergence( final int i ) { @@ -320,7 +320,7 @@ public final class NeighborJoiningR { } } - private final double updateM() { + private final void updateM() { calculateNetDivergences(); Double min_m = Double.MAX_VALUE; _min_i = -1; @@ -329,32 +329,41 @@ public final class NeighborJoiningR { if ( _verbose ) { printM(); } - J: for( int j = 1; j < _n; ++j ) { + // + X: for( int j = 1; j < _n; ++j ) { final double r_j = _r[ j ]; final int m_j = _mappings[ j ]; - if ( _verbose ) { - System.out.print( "j=" + j + " mj=" + m_j + ": " ); - } for( final Entry> entry : _s.getSentrySet( m_j ) ) { for( final int sorted_i : entry.getValue() ) { final double m = _d_values[ sorted_i ][ m_j ] - ( ( _r[ _rev_mappings[ sorted_i ] ] + r_j ) / n_minus_2 ); - //final double m = getDvalueUnmapped( sorted_i, m_j ) - // - ( ( _r[ _rev_mappings[ sorted_i ] ] + r_j ) / n_minus_2 ); - - System.out.println( "m=" + m ); - System.out.println( "r_j=" + r_j ); - System.out.println( "umax=" + _umax ); - System.out.println( " =" + ( m - r_j - _umax ) ); - System.out.println( " min_m=" + min_m ); - if ( ( m - r_j - _umax ) > min_m ) { - System.out.println(">>>>>>>>>>>>>>>>>>>>>>" + m ); + if ( ( m < min_m ) ) { + min_m = m; + _min_i = sorted_i; + _min_j = j; + } + } + continue X; + } + } + // + J: for( int j = 1; j < _n; ++j ) { + //System.out.println( "~~~~~~~~~~~~~ min_m=" + min_m ); + final double r_j = _r[ j ]; + final int m_j = _mappings[ j ]; + boolean first = true; + for( final Entry> entry : _s.getSentrySet( m_j ) ) { + if ( first ) { + first = false; + continue; + } + for( final int sorted_i : entry.getValue() ) { + final double d = _d_values[ sorted_i ][ m_j ]; + if ( ( d - ( ( _umax + r_j ) / n_minus_2 ) ) > min_m ) { continue J; } - - + final double m = d - ( ( _r[ _rev_mappings[ sorted_i ] ] + r_j ) / n_minus_2 ); if ( ( m < min_m ) ) { - // _d_min = getDvalueUnmapped( sorted_i, m_j ); min_m = m; _min_i = sorted_i; _min_j = j; @@ -377,7 +386,6 @@ public final class NeighborJoiningR { if ( _verbose ) { System.out.println(); } - return min_m; } // otu2 will, in effect, be "deleted" from the matrix. diff --git a/forester/java/src/org/forester/evoinference/distance/S.java b/forester/java/src/org/forester/evoinference/distance/S.java index 2c3de8c..fa05363 100644 --- a/forester/java/src/org/forester/evoinference/distance/S.java +++ b/forester/java/src/org/forester/evoinference/distance/S.java @@ -8,15 +8,14 @@ import java.util.List; import java.util.Map.Entry; import java.util.Set; import java.util.SortedMap; -import java.util.SortedSet; import java.util.TreeMap; import org.forester.evoinference.matrix.distance.BasicSymmetricalDistanceMatrix; public final class S { - public final static int FACTOR = 1000000; - private final static boolean DEBUG = true; + public final static int FACTOR = 1000000; + private final static boolean DEBUG = true; private final List>> _data; public S() {