final S s0 = new S();
s0.initialize( 1 );
s0.addPairing( 0, 1, 0 );
- s0.addPairing( 7.0000001, 8, 0 );
- s0.addPairing( 7.00000011, 9, 0 );
- s0.addPairing( 7.000000111, 10, 0 );
- s0.addPairing( 7.000000111, 101, 0 );
+ s0.addPairing( 7, 8, 0 );
s0.addPairing( 4, 55, 0 );
s0.addPairing( 2, 3, 0 );
s0.addPairing( 4, 5, 0 );
if ( s0.size() != 1 ) {
return false;
}
- if ( s0.getS( 0 ).size() != 10 ) {
+ if ( s0.getS( 0 ).size() != 8 ) {
return false;
}
if ( s0.getValues( 0, 0 ).size() != 1 ) {
if ( s0.getValues( 6, 0 ).size() != 1 ) {
return false;
}
- if ( s0.getValues( 7.0000001, 0 ).size() != 1 ) {
- return false;
- }
- if ( s0.getValues( 7.00000011, 0 ).size() != 1 ) {
- return false;
- }
- if ( s0.getValues( 7.000000111, 0 ).size() != 2 ) {
+ if ( s0.getValues( 7, 0 ).size() != 1 ) {
return false;
}
if ( !s0.getValues( 0, 0 ).contains( 1 ) ) {
if ( s0.getValues( 5, 0 ).size() != 1 ) {
return false;
}
- if ( s0.getS( 0 ).size() != 10 ) {
+ if ( s0.getS( 0 ).size() != 8 ) {
return false;
}
s0.removePairing( 5, 6, 0 );
- if ( s0.getS( 0 ).size() != 9 ) {
+ if ( s0.getS( 0 ).size() != 7 ) {
return false;
}
s0.addPairing( 5, 6, 0 );
- if ( s0.getS( 0 ).size() != 10 ) {
+ if ( s0.getS( 0 ).size() != 8 ) {
return false;
}
if ( s0.getValues( 5, 0 ).size() != 1 ) {
if ( !s0.getValues( 5, 0 ).contains( 403 ) ) {
return false;
}
- s0.addPairing( 693.539324, 100, 0 );
- s0.addPairing( 693.539324, 101, 0 );
- if ( s0.getValues( 693.539324, 0 ).size() != 2 ) {
+ s0.addPairing( 693, 100, 0 );
+ s0.addPairing( 693, 101, 0 );
+ if ( s0.getValues( 693, 0 ).size() != 2 ) {
return false;
}
s0.addPairing( 2, 33, 0 );
if ( !a[ 2 ].contains( 333 ) ) {
return false;
}
- if ( a[ 2 ].size() != 3 ) {
- return false;
- }
- if ( a[ 8 ].size() != 1 ) {
- return false;
- }
- if ( !a[ 8 ].contains( 9 ) ) {
- return false;
- }
- if ( a[ 9 ].size() != 2 ) {
- return false;
- }
- if ( !a[ 9 ].contains( 10 ) ) {
- return false;
- }
- if ( !a[ 9 ].contains( 101 ) ) {
- return false;
- }
- if ( !a[ 10 ].contains( 100 ) ) {
- return false;
- }
- if ( !a[ 10 ].contains( 101 ) ) {
- return false;
- }
- if ( a[ 4 ].size() != 2 ) {
- return false;
- }
- if ( !a[ 4 ].contains( 5 ) ) {
- return false;
- }
- if ( !a[ 4 ].contains( 55 ) ) {
- return false;
- }
}
catch ( final Exception e ) {
e.printStackTrace( System.out );
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.
+ //for( int j = 0; j < _s.size(); ++j ) {
+ _s.removePairing( _d_min, _min_i, 1 );
+ // }
final PhylogenyNode node = new PhylogenyNode();
final double d = getDvalue( otu1, otu2 );
final double d1 = ( d / 2 ) + ( ( _r[ otu1 ] - _r[ otu2 ] ) / ( 2 * ( _n - 2 ) ) );
}
private final void updateDvalue( final int otu1, final int otu2, final int i, final double d ) {
- setDvalue( otu1, i, ( getDvalue( otu1, i ) + getDvalue( i, otu2 ) - d ) / 2 );
+ final double new_d = ( getDvalue( otu1, i ) + getDvalue( i, otu2 ) - d ) / 2;
+ _s.addPairing( new_d, otu1, i );
+ setDvalue( otu1, i, new_d );
}
private void setDvalue( final int i, final int j, final double d ) {
System.out.print( " " );
}
System.out.print( " " );
- for( final Entry<Double, SortedSet<Integer>> entry : _s.getSentrySet( _mappings[ j ] ) ) {
+ for( final Entry<Integer, SortedSet<Integer>> entry : _s.getSentrySet( _mappings[ j ] ) ) {
final double key = entry.getKey();
final SortedSet<Integer> value = entry.getValue();
- System.out.print( DF.format( key ) + "=" );
+ System.out.print( DF.format( key / S.FACTOR ) + "=" );
boolean first = true;
for( final Integer v : value ) {
if ( !first ) {
final int m_j = _mappings[ j ];
int counter = 0;
int counter_all = 0;
- X: for( final Entry<Double, SortedSet<Integer>> entry : _s.getSentrySet( m_j ) ) {
+ for( final Entry<Integer, SortedSet<Integer>> entry : _s.getSentrySet( m_j ) ) {
for( final int sorted_i : entry.getValue() ) {
//if ( counter_all >= j ) {
// break X;
//}
if ( _mappings[ counter ] == counter_all ) {
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 ) {
- _d_min = getDvalueUnmapped( sorted_i, m_j );
+ System.out.print( "(" + DF.format( getDvalue( sorted_i, j ) ) + ") " );
+ final double m = getDvalue( sorted_i, j ) - ( ( _r[ sorted_i ] + r_j ) / n_minus_2 );
+ if ( ( m < min ) && ( sorted_i != j ) ) {
+ _d_min = getDvalue( sorted_i, j );
min = m;
_min_i = sorted_i;
_min_j = j;
public final class S {
- private final static boolean DEBUG = true;
- private final List<SortedMap<Double, SortedSet<Integer>>> _data;
+ public final static int FACTOR = 1000000;
+ private final static boolean DEBUG = true;
+ private final List<SortedMap<Integer, SortedSet<Integer>>> _data;
public S() {
- _data = new ArrayList<SortedMap<Double, SortedSet<Integer>>>();
+ _data = new ArrayList<SortedMap<Integer, SortedSet<Integer>>>();
}
final public void addPairing( final double key, final int value, final int j ) {
+ addPairing( ( int ) ( FACTOR * key ), value, getS( j ) );
+ }
+
+ final public void addPairing( final int key, final int value, final int j ) {
addPairing( key, value, getS( j ) );
}
- final public SortedMap<Double, SortedSet<Integer>> getS( final int j ) {
+ final public SortedMap<Integer, SortedSet<Integer>> getS( final int j ) {
return _data.get( j );
}
- final public SortedSet<Integer> getValues( final double key, final int j ) {
+ final public SortedSet<Integer> 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<Double, SortedSet<Integer>> map = new TreeMap<Double, SortedSet<Integer>>();
+ final TreeMap<Integer, SortedSet<Integer>> map = new TreeMap<Integer, SortedSet<Integer>>();
_data.add( map );
for( int i = 0; i < j; ++i ) {
- addPairing( d.getValues()[ i ][ j ], i, map );
+ addPairing( ( int ) ( FACTOR * d.getValues()[ i ][ j ] ), i, map );
}
}
System.out.println( toString() );
final public void initialize( final int size ) {
for( int j = 0; j < size; ++j ) {
- final TreeMap<Double, SortedSet<Integer>> map = new TreeMap<Double, SortedSet<Integer>>();
+ final TreeMap<Integer, SortedSet<Integer>> map = new TreeMap<Integer, SortedSet<Integer>>();
_data.add( map );
}
}
final public void removePairing( final double key, final int value, final int j ) {
- final SortedMap<Double, SortedSet<Integer>> m = _data.get( j );
+ removePairing( ( int ) ( key * FACTOR ), value, j );
+ }
+
+ final public void removePairing( final int key, final int value, final int j ) {
+ final SortedMap<Integer, SortedSet<Integer>> m = _data.get( j );
final SortedSet<Integer> x = m.get( key );
+ if ( DEBUG ) {
+ if ( x == null ) {
+ System.out.println( toString() );
+ throw new IllegalArgumentException( "key " + key + " (->" + value + ") does not exist for row " + j );
+ }
+ }
if ( x.size() == 1 ) {
if ( DEBUG ) {
if ( !x.contains( value ) ) {
- throw new IllegalArgumentException( "pairing " + key + " -> " + value + " does not exist for row "
+ throw new IllegalArgumentException( "pairing " + key + "->" + value + " does not exist for row "
+ j );
}
}
else if ( x.size() > 1 ) {
if ( DEBUG ) {
if ( !x.remove( value ) ) {
- throw new IllegalArgumentException( "pairing " + key + " -> " + value
+ throw new IllegalArgumentException( "pairing " + key + "->" + value
+ " does not exist (could not be removed) for row " + j );
}
}
final DecimalFormat df = new DecimalFormat( "0.00" );
final StringBuilder sb = new StringBuilder();
for( int j = 0; j < size(); ++j ) {
- for( final Entry<Double, SortedSet<Integer>> entry : getSentrySet( j ) ) {
+ for( final Entry<Integer, SortedSet<Integer>> entry : getSentrySet( j ) ) {
final double key = entry.getKey();
final SortedSet<Integer> values = entry.getValue();
- sb.append( df.format( key ) + "->" );
+ sb.append( df.format( key / FACTOR ) + "->" );
boolean first = true;
- for( final Integer v : values ) {
+ for( final int v : values ) {
if ( !first ) {
sb.append( "," );
}
return sb.toString();
}
- final Set<Entry<Double, SortedSet<Integer>>> getSentrySet( final int j ) {
+ final Set<Entry<Integer, SortedSet<Integer>>> getSentrySet( final int j ) {
return getS( j ).entrySet();
}
- final private static void addPairing( final double key,
- final int value,
- final SortedMap<Double, SortedSet<Integer>> m ) {
+ final private static void addPairing( final int key, final int value, final SortedMap<Integer, SortedSet<Integer>> m ) {
if ( !m.containsKey( key ) ) {
final TreeSet<Integer> x = new TreeSet<Integer>();
x.add( value );
else {
if ( DEBUG ) {
if ( m.get( key ).contains( value ) ) {
- throw new IllegalArgumentException( "pairing " + key + " -> " + value + " already exists" );
+ throw new IllegalArgumentException( "pairing " + key + "->" + value + " already exists" );
}
}
m.get( key ).add( value );