From a7372ecbb1d6deb19c6be8a810a08fa7494562bd Mon Sep 17 00:00:00 2001 From: "cmzmasek@gmail.com" Date: Fri, 14 Mar 2014 21:33:38 +0000 Subject: [PATCH] inprogress --- .../evoinference/TestPhylogenyReconstruction.java | 25 +- .../distance/CopyOfNeighborJoiningR.java | 353 -------------------- .../evoinference/distance/NeighborJoiningR.java | 78 +++-- .../src/org/forester/evoinference/distance/S.java | 4 +- 4 files changed, 61 insertions(+), 399 deletions(-) delete mode 100644 forester/java/src/org/forester/evoinference/distance/CopyOfNeighborJoiningR.java diff --git a/forester/java/src/org/forester/evoinference/TestPhylogenyReconstruction.java b/forester/java/src/org/forester/evoinference/TestPhylogenyReconstruction.java index 3b4ac8d..fd5ca08 100644 --- a/forester/java/src/org/forester/evoinference/TestPhylogenyReconstruction.java +++ b/forester/java/src/org/forester/evoinference/TestPhylogenyReconstruction.java @@ -91,7 +91,7 @@ public class TestPhylogenyReconstruction { else { System.out.println( " failed." ); } - // timeNeighborJoining(); + //timeNeighborJoining(); } public static boolean test( final File test_dir ) { @@ -2484,6 +2484,7 @@ public class TestPhylogenyReconstruction { final NeighborJoining nj = NeighborJoining.createInstance( true, 6 ); //nj = NeighborJoining.createInstance( true, 6 ); final Phylogeny pnj = nj.execute( m ); + pnj.reRoot( pnj.getNode( "Bovine" ) ); Archaeopteryx.createApplication( pnj ); // m = new BasicSymmetricalDistanceMatrix( 7 ); @@ -2504,21 +2505,21 @@ public class TestPhylogenyReconstruction { final NeighborJoiningR nj2 = NeighborJoiningR.createInstance( true, 6 ); //nj = NeighborJoining.createInstance( true, 6 ); final Phylogeny p2 = nj2.execute( m ); - Archaeopteryx.createApplication( p2 ); p2.reRoot( p2.getNode( "Bovine" ) ); - if ( isUnequal( p2.getNode( "Chimp" ).getDistanceToParent(), 0.151675 ) ) { + Archaeopteryx.createApplication( p2 ); + if ( isUnequal( p2.getNode( "Chimp" ).getDistanceToParent(), 0.15168 ) ) { return false; } - if ( isUnequal( p2.getNode( "Human" ).getDistanceToParent(), 0.117525 ) ) { + if ( isUnequal( p2.getNode( "Human" ).getDistanceToParent(), 0.11752 ) ) { return false; } - if ( isUnequal( p2.getNode( "Gorilla" ).getDistanceToParent(), 0.153932 ) ) { + if ( isUnequal( p2.getNode( "Gorilla" ).getDistanceToParent(), 0.15393 ) ) { return false; } - if ( isUnequal( p2.getNode( "Orang" ).getDistanceToParent(), 0.284694 ) ) { + if ( isUnequal( p2.getNode( "Orang" ).getDistanceToParent(), 0.28469 ) ) { return false; } - if ( isUnequal( p2.getNode( "Gibbon" ).getDistanceToParent(), 0.357931 ) ) { + if ( isUnequal( p2.getNode( "Gibbon" ).getDistanceToParent(), 0.35793 ) ) { return false; } if ( isUnequal( p2.getNode( "Mouse" ).getDistanceToParent(), 0.76891 ) ) { @@ -2527,20 +2528,20 @@ public class TestPhylogenyReconstruction { if ( isUnequal( p2.getNode( "Bovine" ).getDistanceToParent(), 0.458845 ) ) { return false; } - if ( isUnequal( p2.getNode( "Chimp" ).getParent().getDistanceToParent(), 0.039819 ) ) { + if ( isUnequal( p2.getNode( "Chimp" ).getParent().getDistanceToParent(), 0.03982 ) ) { return false; } - if ( isUnequal( p2.getNode( "Human" ).getParent().getDistanceToParent(), 0.039819 ) ) { + if ( isUnequal( p2.getNode( "Human" ).getParent().getDistanceToParent(), 0.03982 ) ) { return false; } - if ( isUnequal( p2.getNode( "Chimp" ).getParent().getParent().getDistanceToParent(), 0.026956 ) ) { + if ( isUnequal( p2.getNode( "Chimp" ).getParent().getParent().getDistanceToParent(), 0.02696 ) ) { return false; } - if ( isUnequal( p2.getNode( "Chimp" ).getParent().getParent().getParent().getDistanceToParent(), 0.046481 ) ) { + if ( isUnequal( p2.getNode( "Chimp" ).getParent().getParent().getParent().getDistanceToParent(), 0.04648 ) ) { return false; } if ( isUnequal( p2.getNode( "Chimp" ).getParent().getParent().getParent().getParent().getDistanceToParent(), - 0.420269 ) ) { + 0.42027 ) ) { return false; } if ( isUnequal( p2.getNode( "Chimp" ).getParent().getParent().getParent().getParent().getParent() diff --git a/forester/java/src/org/forester/evoinference/distance/CopyOfNeighborJoiningR.java b/forester/java/src/org/forester/evoinference/distance/CopyOfNeighborJoiningR.java deleted file mode 100644 index 2a0e6ee..0000000 --- a/forester/java/src/org/forester/evoinference/distance/CopyOfNeighborJoiningR.java +++ /dev/null @@ -1,353 +0,0 @@ -// $Id: -// FORESTER -- software libraries and applications -// for evolutionary biology research and applications. -// -// Copyright (C) 2014 Christian M. Zmasek -// All rights reserved -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA -// -// Contact: phylosoft @ gmail . com -// WWW: https://sites.google.com/site/cmzmasek/home/software/forester - -package org.forester.evoinference.distance; - -import java.math.RoundingMode; -import java.text.DecimalFormat; -import java.util.ArrayList; -import java.util.List; -import java.util.Map.Entry; -import java.util.SortedSet; - -import org.forester.evoinference.matrix.distance.BasicSymmetricalDistanceMatrix; -import org.forester.phylogeny.Phylogeny; -import org.forester.phylogeny.PhylogenyNode; -import org.forester.util.ForesterUtil; - -public final class CopyOfNeighborJoiningR { - - private final static DecimalFormat DF = new DecimalFormat( "0.00000" ); - private BasicSymmetricalDistanceMatrix _d; - private double[][] _d_values; - private final DecimalFormat _df; - private PhylogenyNode[] _external_nodes; - private int[] _mappings; - private int _n; - private double[] _r; - private final boolean _verbose; - private int _min_i; - private int _min_j; - private S _s; - private double _d_min; //TODO remove me - - private CopyOfNeighborJoiningR() { - _verbose = false; - _df = null; - } - - private CopyOfNeighborJoiningR( final boolean verbose, final int maximum_fraction_digits_for_distances ) { - if ( ( maximum_fraction_digits_for_distances < 1 ) || ( maximum_fraction_digits_for_distances > 9 ) ) { - throw new IllegalArgumentException( "maximum fraction digits for distances is out of range: " - + maximum_fraction_digits_for_distances ); - } - _verbose = verbose; - _df = new DecimalFormat(); - _df.setMaximumFractionDigits( maximum_fraction_digits_for_distances ); - _df.setRoundingMode( RoundingMode.HALF_UP ); - } - - public final Phylogeny execute( final BasicSymmetricalDistanceMatrix distance ) { - reset( distance ); - final Phylogeny phylogeny = new Phylogeny(); - while ( _n > 2 ) { - System.out.println( "N=" + _n ); - System.out.println(); - // Calculates the minimal distance. - // If more than one minimal distances, always the first found is used - final double m = updateM(); - final int otu1 = _min_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 ] ); - final PhylogenyNode node = new PhylogenyNode(); - final double d = getDvalue( otu1, otu2 ); - final double d1 = ( d / 2 ) + ( ( _r[ otu1 ] - _r[ otu2 ] ) / ( 2 * ( _n - 2 ) ) ); - final double d2 = d - d1; - if ( _df == null ) { - getExternalPhylogenyNode( otu1 ).setDistanceToParent( d1 ); - getExternalPhylogenyNode( otu2 ).setDistanceToParent( d2 ); - } - else { - // yes, yes, slow but only grows with n (and not n^2 or worse)... - getExternalPhylogenyNode( otu1 ).setDistanceToParent( Double.parseDouble( _df.format( d1 ) ) ); - getExternalPhylogenyNode( otu2 ).setDistanceToParent( Double.parseDouble( _df.format( d2 ) ) ); - } - node.addAsChild( getExternalPhylogenyNode( otu1 ) ); - node.addAsChild( getExternalPhylogenyNode( otu2 ) ); - if ( _verbose ) { - printProgress( otu1, otu2, node ); - printProgress( _mappings[ otu1 ], _mappings[ otu2 ], node ); - } - System.out.println( "otu1=" + otu1 ); - System.out.println( "otu2=" + otu2 ); - calculateDistancesFromNewNode( otu1, otu2, d ); - _external_nodes[ _mappings[ otu1 ] ] = node; - updateMappings( otu2 ); - --_n; - System.out.println( "" ); - System.out.println( "----------------------------------------------------------------------------------" ); - System.out.println( "" ); - } - final double d = getDvalue( 0, 1 ) / 2; - if ( _df == null ) { - getExternalPhylogenyNode( 0 ).setDistanceToParent( d ); - getExternalPhylogenyNode( 1 ).setDistanceToParent( d ); - } - else { - final double dd = Double.parseDouble( _df.format( d ) ); - getExternalPhylogenyNode( 0 ).setDistanceToParent( dd ); - getExternalPhylogenyNode( 1 ).setDistanceToParent( dd ); - } - final PhylogenyNode root = new PhylogenyNode(); - root.addAsChild( getExternalPhylogenyNode( 0 ) ); - root.addAsChild( getExternalPhylogenyNode( 1 ) ); - if ( _verbose ) { - printProgress( 0, 1, root ); - } - phylogeny.setRoot( root ); - phylogeny.setRooted( false ); - return phylogeny; - } - - public final List execute( final List distances_list ) { - final List pl = new ArrayList(); - for( final BasicSymmetricalDistanceMatrix distances : distances_list ) { - pl.add( execute( distances ) ); - } - return pl; - } - - private final void calculateDistancesFromNewNode( final int otu1, final int otu2, final double d ) { - System.out.print( "new D values: " ); - for( int j = 0; j < _n; ++j ) { - if ( ( j == otu1 ) || ( j == otu2 ) ) { - continue; - } - updateDvalue( otu1, otu2, j, d ); - } - System.out.println(); - } - - private final void updateDvalue( final int otu1, final int otu2, final int j, final double d ) { - final double new_d = ( getDvalue( otu1, j ) + getDvalue( j, otu2 ) - d ) / 2; - System.out.print( DF.format( new_d ) + " " ); - System.out.println( "going to remove: " + getDvalue( otu1, j ) + ", " + _mappings[ otu1 ] + ", " - + _mappings[ j ] ); - _s.removePairing( getDvalue( otu1, j ), _mappings[ otu1 ], _mappings[ j ] ); - System.out.println( "going to remove: " + getDvalue( j, otu2 ) + ", " + _mappings[ otu2 ] + ", " - + _mappings[ j ] ); - _s.removePairing( getDvalue( j, otu2 ), _mappings[ otu2 ], _mappings[ j ] ); - _s.addPairing( new_d, otu1, _mappings[ j ] ); - setDvalue( otu1, j, new_d ); - } - - private void setDvalue( final int i, final int j, final double d ) { - if ( i < j ) { - _d_values[ _mappings[ i ] ][ _mappings[ j ] ] = d; - } - _d_values[ _mappings[ j ] ][ _mappings[ i ] ] = d; - } - - private double getDvalue( final int i, final int j ) { - if ( i < j ) { - return _d_values[ _mappings[ i ] ][ _mappings[ j ] ]; - } - return _d_values[ _mappings[ j ] ][ _mappings[ i ] ]; - } - - private double getDvalueUnmapped( final int i, final int j ) { - if ( i < j ) { - return _d_values[ i ][ j ]; - } - return _d_values[ j ][ i ]; - } - - private final void calculateNetDivergences() { - for( int i = 0; i < _n; ++i ) { - _r[ i ] = calculateNetDivergence( i ); - } - } - - private double calculateNetDivergence( final int i ) { - double d = 0; - for( int n = 0; n < _n; ++n ) { - if ( i != n ) { - d += getDvalue( n, i ); - } - } - return d; - } - - private final PhylogenyNode getExternalPhylogenyNode( final int i ) { - return _external_nodes[ _mappings[ i ] ]; - } - - private final void initExternalNodes() { - _external_nodes = new PhylogenyNode[ _n ]; - String id; - for( int i = 0; i < _n; ++i ) { - _external_nodes[ i ] = new PhylogenyNode(); - id = _d.getIdentifier( i ); - if ( id != null ) { - _external_nodes[ i ].setName( id ); - } - else { - _external_nodes[ i ].setName( Integer.toString( i ) ); - } - _mappings[ i ] = i; - } - } - - private final void printProgress( final int otu1, final int otu2, final PhylogenyNode node ) { - System.out.println( "Node " + printProgressNodeToString( getExternalPhylogenyNode( otu1 ) ) + " joins " - + ( printProgressNodeToString( getExternalPhylogenyNode( otu2 ) ) ) + " [resulting in node " - + ( printProgressNodeToString( node ) ) + "]" ); - } - - private final String printProgressNodeToString( final PhylogenyNode n ) { - if ( n.isExternal() ) { - if ( ForesterUtil.isEmpty( n.getName() ) ) { - return Long.toString( n.getId() ); - } - return n.getName(); - } - return n.getId() - + " (" - + ( ForesterUtil.isEmpty( n.getChildNode1().getName() ) ? n.getChildNode1().getId() : n.getChildNode1() - .getName() ) - + "+" - + ( ForesterUtil.isEmpty( n.getChildNode2().getName() ) ? n.getChildNode2().getId() : n.getChildNode2() - .getName() ) + ")"; - } - - // only the values in the lower triangle are used. - // !matrix values will be changed! - private final void reset( final BasicSymmetricalDistanceMatrix distances ) { - _n = distances.getSize(); - _d = distances; - _r = new double[ _n ]; - _mappings = new int[ _n ]; - _d_values = _d.getValues(); - _s = new S(); - _s.initialize( distances ); - initExternalNodes(); - System.out.println(); - printM(); - System.out.println( "----------------------------------------------------------------------------------" ); - System.out.println(); - System.out.println(); - } - - final private void printM() { - for( int j = 0; j < _d_values.length; ++j ) { - System.out.print( _external_nodes[ j ] ); - System.out.print( "\t\t" ); - for( int i = 0; i < _d_values[ j ].length; ++i ) { - System.out.print( DF.format( _d_values[ i ][ j ] ) ); - System.out.print( " " ); - } - System.out.println(); - } - for( int j = 0; j < _n; ++j ) { - System.out.print( getExternalPhylogenyNode( j ) ); - System.out.print( "\t\t" ); - for( int i = 0; i < _n; ++i ) { - System.out.print( DF.format( _d_values[ _mappings[ i ] ][ _mappings[ j ] ] ) ); - System.out.print( " " ); - } - System.out.print( "\t\t" ); - 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() ) { - if ( !first ) { - System.out.print( "," ); - } - first = false; - System.out.print( v ); - } - System.out.print( " " ); - } - System.out.println(); - } - } - - private final double updateM() { - calculateNetDivergences(); - Double min = Double.MAX_VALUE; - _min_i = -1; - _min_j = -1; - final int n_minus_2 = _n - 2; - printM(); - for( int j = 1; j < _n; ++j ) { - final double r_j = _r[ j ]; - final int m_j = _mappings[ j ]; - for( final Entry> entry : _s.getSentrySet( m_j ) ) { - for( final int sorted_i : entry.getValue() ) { - System.out.print( sorted_i + " " ); - System.out.print( "(" + DF.format( getDvalueUnmapped( sorted_i, m_j ) ) + ") " ); - final double m = getDvalue( sorted_i, j ) - ( ( _r[ sorted_i ] + r_j ) / n_minus_2 ); - if ( ( m < min ) && ( sorted_i != j ) ) { - _d_min = getDvalueUnmapped( sorted_i, m_j ); - min = m; - _min_i = sorted_i; - _min_j = j; - } - } - } - System.out.println(); - /* - for( int i = 0; i < j; ++i ) { - final double m = getDvalue( i, j ) - ( ( _r[ i ] + r_j ) / n_minus_2 ); - if ( m < min ) { - min = m; - _d_min = getDvalue( i, j ); - _min_i = i; - _min_j = j; - } - }*/ - } - System.out.println(); - return min; - } - - // 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 ) { - _mappings[ i ] = _mappings[ i + 1 ]; - } - } - - public final static CopyOfNeighborJoiningR createInstance() { - return new CopyOfNeighborJoiningR(); - } - - public final static CopyOfNeighborJoiningR createInstance( final boolean verbose, - final int maximum_fraction_digits_for_distances ) { - return new CopyOfNeighborJoiningR( verbose, maximum_fraction_digits_for_distances ); - } -} diff --git a/forester/java/src/org/forester/evoinference/distance/NeighborJoiningR.java b/forester/java/src/org/forester/evoinference/distance/NeighborJoiningR.java index 52b6fba..bf2a59f 100644 --- a/forester/java/src/org/forester/evoinference/distance/NeighborJoiningR.java +++ b/forester/java/src/org/forester/evoinference/distance/NeighborJoiningR.java @@ -40,17 +40,17 @@ public final class NeighborJoiningR { private final static DecimalFormat DF = new DecimalFormat( "0.00000" ); private BasicSymmetricalDistanceMatrix _d; - private double[][] _d_values; + private float[][] _d_values; private final DecimalFormat _df; private PhylogenyNode[] _external_nodes; private int[] _mappings; private int _n; - private double[] _r; + private float[] _r; private final boolean _verbose; private int _min_i; private int _min_j; private S _s; - private double _d_min; //TODO remove me + private float _d_min; //TODO remove me private int[] _rev_mappings; private NeighborJoiningR() { @@ -86,9 +86,9 @@ public final class NeighborJoiningR { 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 ] ]; - final double d1 = ( d / 2 ) + ( ( _r[ _rev_mappings[ otu1 ] ] - _r[ otu2 ] ) / ( 2 * ( _n - 2 ) ) ); - final double d2 = d - d1; + final float d = _d_values[ otu1 ][ _mappings[ otu2 ] ]; + final float d1 = ( d / 2 ) + ( ( _r[ _rev_mappings[ otu1 ] ] - _r[ otu2 ] ) / ( 2 * ( _n - 2 ) ) ); + final float d2 = d - d1; if ( _df == null ) { _external_nodes[ otu1 ].setDistanceToParent( d1 ); getExternalPhylogenyNode( otu2 ).setDistanceToParent( d2 ); @@ -114,13 +114,13 @@ public final class NeighborJoiningR { System.out.println( "----------------------------------------------------------------------------------" ); System.out.println( "" ); } - final double d = getDvalue( 0, 1 ) / 2; + final float d = getDvalue( 0, 1 ) / 2; if ( _df == null ) { getExternalPhylogenyNode( 0 ).setDistanceToParent( d ); getExternalPhylogenyNode( 1 ).setDistanceToParent( d ); } else { - final double dd = Double.parseDouble( _df.format( d ) ); + final float dd = Float.parseFloat( _df.format( d ) ); getExternalPhylogenyNode( 0 ).setDistanceToParent( dd ); getExternalPhylogenyNode( 1 ).setDistanceToParent( dd ); } @@ -143,60 +143,69 @@ public final class NeighborJoiningR { return pl; } - private final void calculateDistancesFromNewNode( final int otu1, final int otu2, final double d ) { - System.out.print( "new D values: " ); + private final void calculateDistancesFromNewNode( final int otu1, final int otu2, final float d ) { for( int j = 0; j < _n; ++j ) { - if ( j == otu2 ) { + if ( ( j == otu2 ) || ( j == _rev_mappings[ otu1 ] ) ) { continue; } - if ( otu1 < _mappings[ j ] ) { - updateDvalue( otu1, otu2, j, d ); - } - // else if ( otu1 > _mappings[ j ] ) { - // updateDvalue( otu2, otu1, j, d ); - // } + updateDvalue( otu1, otu2, j, d ); } System.out.println(); } - private final void updateDvalue( final int otu1, final int otu2, final int j, final double d ) { - final double new_d = ( getDvalueUnmapped( otu1, _mappings[ j ] ) + getDvalue( j, otu2 ) - d ) / 2; - System.out.print( DF.format( new_d ) + " " ); - // System.out.println( "going to remove: " + getDvalueUnmapped( otu1, _mappings[ j ] ) + ", " + otu1 + ", " - // + _mappings[ j ] ); + private final void updateDvalue( final int otu1, final int otu2, final int j, final float d ) { + final float new_d = ( getDvalueUnmapped( otu1, _mappings[ j ] ) + getDvalue( j, otu2 ) - d ) / 2; + System.out.println( "\nnew d value: " + DF.format( new_d ) ); if ( otu1 < _mappings[ j ] ) { + System.out.println( " otu1=" + otu1 ); + System.out.println( " otu2=" + otu2 ); + System.out.println( "motu1=" + _mappings[ otu1 ] ); + System.out.println( "motu2=" + _mappings[ otu2 ] ); + System.out.println( " j=" + j ); + System.out.println( "mj=" + _mappings[ j ] ); + System.out.println( "d=" + DF.format( getDvalueUnmapped( otu1, _mappings[ j ] ) ) ); _s.removePairing( getDvalueUnmapped( otu1, _mappings[ j ] ), otu1, _mappings[ j ] ); } else { + System.out.println( " otu1=" + otu1 ); + System.out.println( " otu2=" + otu2 ); + System.out.println( "motu1=" + _mappings[ otu1 ] ); + System.out.println( "motu2=" + _mappings[ otu2 ] ); + System.out.println( " j=" + j ); + System.out.println( "mj=" + _mappings[ j ] ); + System.out.println( "d=" + DF.format( getDvalueUnmapped( otu1, _mappings[ j ] ) ) ); _s.removePairing( getDvalueUnmapped( otu1, _mappings[ j ] ), _mappings[ j ], otu1 ); } - // System.out.println( "going to remove: " + getDvalue( j, otu2 ) + ", " +_mappings[ otu2 ] + ", " - // + _mappings[ j ] ); if ( _mappings[ otu2 ] < _mappings[ j ] ) { _s.removePairing( getDvalue( j, otu2 ), _mappings[ otu2 ], _mappings[ j ] ); } else { _s.removePairing( getDvalue( j, otu2 ), _mappings[ j ], _mappings[ otu2 ] ); } - _s.addPairing( new_d, otu1, _mappings[ j ] ); + if ( otu1 < _mappings[ j ] ) { + _s.addPairing( new_d, otu1, _mappings[ j ] ); + } + else { + _s.addPairing( new_d, _mappings[ j ], otu1 ); + } setDvalueU( otu1, j, new_d ); } - private void setDvalueU( final int i, final int j, final double d ) { + private void setDvalueU( final int i, final int j, final float d ) { if ( i < _mappings[ j ] ) { _d_values[ i ][ _mappings[ j ] ] = d; } _d_values[ _mappings[ j ] ][ i ] = d; } - private double getDvalue( final int i, final int j ) { + private float getDvalue( final int i, final int j ) { if ( i < j ) { return _d_values[ _mappings[ i ] ][ _mappings[ j ] ]; } return _d_values[ _mappings[ j ] ][ _mappings[ i ] ]; } - private double getDvalueUnmapped( final int i, final int j ) { + private float getDvalueUnmapped( final int i, final int j ) { if ( i < j ) { return _d_values[ i ][ j ]; } @@ -209,8 +218,8 @@ public final class NeighborJoiningR { } } - private double calculateNetDivergence( final int i ) { - double d = 0; + private float calculateNetDivergence( final int i ) { + float d = 0; for( int n = 0; n < _n; ++n ) { if ( i != n ) { d += getDvalue( n, i ); @@ -267,10 +276,15 @@ public final class NeighborJoiningR { private final void reset( final BasicSymmetricalDistanceMatrix distances ) { _n = distances.getSize(); _d = distances; - _r = new double[ _n ]; + _r = new float[ _n ]; _mappings = new int[ _n ]; _rev_mappings = new int[ _n ]; - _d_values = _d.getValues(); + _d_values = new float[ distances.getSize() ][ distances.getSize() ]; + for( int i = 0; i < distances.getSize(); ++i ) { + for( int j = 0; j < distances.getSize(); ++j ) { + _d_values[ i ][ j ] = ( float ) distances.getValue( i, j ); + } + } _s = new S(); _s.initialize( distances ); initExternalNodes(); diff --git a/forester/java/src/org/forester/evoinference/distance/S.java b/forester/java/src/org/forester/evoinference/distance/S.java index fe70cd6..ef32273 100644 --- a/forester/java/src/org/forester/evoinference/distance/S.java +++ b/forester/java/src/org/forester/evoinference/distance/S.java @@ -23,7 +23,7 @@ public final class S { _data = new ArrayList>>(); } - final public void addPairing( final double key, final int value, final int j ) { + final public void addPairing( final float key, final int value, final int j ) { addPairing( ( int ) ( FACTOR * key ), value, getS( j ) ); } @@ -57,7 +57,7 @@ public final class S { } } - final public void removePairing( final double key, final int value, final int j ) { + final public void removePairing( final float key, final int value, final int j ) { removePairing( ( int ) ( key * FACTOR ), value, j ); } -- 1.7.10.2