From ff8e93a90cb6d3e91d2761ef4990a6ccbdd967da Mon Sep 17 00:00:00 2001 From: cmzmasek Date: Mon, 17 Mar 2014 03:25:55 +0000 Subject: [PATCH] in progress --- .../evoinference/TestPhylogenyReconstruction.java | 4 ++- .../evoinference/distance/NeighborJoiningR.java | 23 ++++++++------ .../src/org/forester/evoinference/distance/S.java | 32 ++++++++++---------- 3 files changed, 33 insertions(+), 26 deletions(-) diff --git a/forester/java/src/org/forester/evoinference/TestPhylogenyReconstruction.java b/forester/java/src/org/forester/evoinference/TestPhylogenyReconstruction.java index 6db6453..c545f59 100644 --- a/forester/java/src/org/forester/evoinference/TestPhylogenyReconstruction.java +++ b/forester/java/src/org/forester/evoinference/TestPhylogenyReconstruction.java @@ -32,6 +32,7 @@ import java.io.FileInputStream; import java.io.StringWriter; import java.util.Date; import java.util.List; +import java.util.Set; import java.util.SortedSet; import org.forester.evoinference.distance.NeighborJoining; @@ -2350,7 +2351,7 @@ public class TestPhylogenyReconstruction { } s0.addPairing( 2, 33, 0 ); s0.addPairing( 2, 333, 0 ); - final SortedSet[] a = s0.toArray( 0 ); + final Set[] a = s0.toArray( 0 ); if ( !a[ 0 ].contains( 1 ) ) { return false; } @@ -2522,6 +2523,7 @@ public class TestPhylogenyReconstruction { return false; } // + System.exit(1); final BasicSymmetricalDistanceMatrix m3 = new BasicSymmetricalDistanceMatrix( 20 ); m3.setIdentifier( 0, "F_MOUSE" ); m3.setIdentifier( 1, "11_RAT" ); diff --git a/forester/java/src/org/forester/evoinference/distance/NeighborJoiningR.java b/forester/java/src/org/forester/evoinference/distance/NeighborJoiningR.java index ef7e49b..2149f8a 100644 --- a/forester/java/src/org/forester/evoinference/distance/NeighborJoiningR.java +++ b/forester/java/src/org/forester/evoinference/distance/NeighborJoiningR.java @@ -29,7 +29,7 @@ import java.text.DecimalFormat; import java.util.ArrayList; import java.util.List; import java.util.Map.Entry; -import java.util.SortedSet; +import java.util.Set; import org.forester.evoinference.matrix.distance.BasicSymmetricalDistanceMatrix; import org.forester.phylogeny.Phylogeny; @@ -205,7 +205,7 @@ public final class NeighborJoiningR { _umax = -1000; for( int i = 0; i < _n; ++i ) { _r[ i ] = calculateNetDivergence( i ); - if ( _r[i ] > _umax ) { + if ( _r[ i ] > _umax ) { _umax = _r[i ]; } } @@ -304,7 +304,7 @@ public final class NeighborJoiningR { System.out.print( " " ); } System.out.print( "\t\t" ); - for( final Entry> entry : _s.getSentrySet( _mappings[ j ] ) ) { + for( final Entry> entry : _s.getSentrySet( _mappings[ j ] ) ) { System.out.print( DF.format( ( double ) entry.getKey() / S.FACTOR ) + "=" ); boolean first = true; for( final int v : entry.getValue() ) { @@ -329,22 +329,27 @@ public final class NeighborJoiningR { if ( _verbose ) { printM(); } - for( int j = 1; j < _n; ++j ) { + J: 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 + ": " ); } - X: for( final Entry> entry : _s.getSentrySet( 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 ); - if ( m - r_j - _umax > min_m ) { - System.out.println( m ); - continue X; + 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 ); + continue J; } @@ -358,7 +363,7 @@ public final class NeighborJoiningR { } if ( _verbose ) { System.out.println(); - for( final Entry> entry : _s.getSentrySet( m_j ) ) { + for( final Entry> entry : _s.getSentrySet( m_j ) ) { for( final int sorted_i : entry.getValue() ) { System.out.print( sorted_i ); System.out.print( "->" ); diff --git a/forester/java/src/org/forester/evoinference/distance/S.java b/forester/java/src/org/forester/evoinference/distance/S.java index b510a61..2c3de8c 100644 --- a/forester/java/src/org/forester/evoinference/distance/S.java +++ b/forester/java/src/org/forester/evoinference/distance/S.java @@ -3,13 +3,13 @@ package org.forester.evoinference.distance; import java.text.DecimalFormat; import java.util.ArrayList; +import java.util.HashSet; 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 java.util.TreeSet; import org.forester.evoinference.matrix.distance.BasicSymmetricalDistanceMatrix; @@ -17,10 +17,10 @@ public final class S { public final static int FACTOR = 1000000; private final static boolean DEBUG = true; - private final List>> _data; + private final List>> _data; public S() { - _data = new ArrayList>>(); + _data = new ArrayList>>(); } final public void addPairing( final double key, final int value, final int j ) { @@ -31,17 +31,17 @@ public final class S { addPairing( key, value, getS( j ) ); } - final public SortedMap> getS( final int j ) { + final public SortedMap> getS( final int j ) { return _data.get( j ); } - final public SortedSet getValues( final int key, final int j ) { + final public Set getValues( final int key, final int j ) { return getS( j ).get( key ); } final public void initialize( final BasicSymmetricalDistanceMatrix d ) { for( int j = 0; j < d.getSize(); ++j ) { - final TreeMap> map = new TreeMap>(); + final TreeMap> map = new TreeMap>(); _data.add( map ); for( int i = 0; i < j; ++i ) { addPairing( ( int ) ( FACTOR * d.getValues()[ i ][ j ] ), i, map ); @@ -52,7 +52,7 @@ public final class S { final public void initialize( final int size ) { for( int j = 0; j < size; ++j ) { - final TreeMap> map = new TreeMap>(); + final TreeMap> map = new TreeMap>(); _data.add( map ); } } @@ -62,8 +62,8 @@ public final class S { } final public void removePairing( final int key, final int value, final int j ) { - final SortedMap> m = _data.get( j ); - final SortedSet x = m.get( key ); + final SortedMap> m = _data.get( j ); + final Set x = m.get( key ); if ( DEBUG ) { if ( x == null ) { System.out.println(); @@ -108,8 +108,8 @@ public final class S { // Slow, only for testing @SuppressWarnings( "unchecked") - final public SortedSet[] toArray( final int j ) { - return _data.get( j ).values().toArray( new SortedSet[ _data.get( j ).size() ] ); + final public Set[] toArray( final int j ) { + return _data.get( j ).values().toArray( new Set[ _data.get( j ).size() ] ); } @Override @@ -119,9 +119,9 @@ public final class S { for( int j = 0; j < size(); ++j ) { sb.append( j ); sb.append( ": " ); - for( final Entry> entry : getSentrySet( j ) ) { + for( final Entry> entry : getSentrySet( j ) ) { final double key = entry.getKey(); - final SortedSet values = entry.getValue(); + final Set values = entry.getValue(); sb.append( df.format( key / FACTOR ) + "->" ); boolean first = true; for( final int v : values ) { @@ -138,13 +138,13 @@ public final class S { return sb.toString(); } - final Set>> getSentrySet( final int j ) { + final Set>> getSentrySet( final int j ) { return getS( j ).entrySet(); } - final private static void addPairing( final int key, final int value, final SortedMap> m ) { + final private static void addPairing( final int key, final int value, final SortedMap> m ) { if ( !m.containsKey( key ) ) { - final TreeSet x = new TreeSet(); + final HashSet x = new HashSet(); x.add( value ); m.put( key, x ); } -- 1.7.10.2