]> git.donarmstrong.com Git - ape.git/blobdiff - src/mvr.c
bunch of fixes for ape 3.0-2
[ape.git] / src / mvr.c
index 5f9fc0cd7e5b795758e2344a7b9b846275dea5fa..f27298265a706dbbbf09ad7c2728f4b78fc6e527 100644 (file)
--- a/src/mvr.c
+++ b/src/mvr.c
@@ -1,6 +1,6 @@
-/* mvr.c    2011-10-11 */
+/* mvr.c    2012-04-02 */
 
-/* Copyright 2011 Andrei-Alin Popescu */
+/* Copyright 2011-2012 Andrei-Alin Popescu */
 
 /* This file is part of the R-package `ape'. */
 /* See the file ../COPYING for licensing issues. */
@@ -74,9 +74,9 @@ void mvr(double *D, double* v,int *N, int *edge1, int *edge2, double *edge_lengt
                        }
                }
 
-                /*Rprintf("agglomerating %i and %i, Q=%f \n",OTU1,OTU2,smallest_S);
+                //Rprintf("agglomerating %i and %i, Q=%f \n",OTU1,OTU2,smallest_S);
 
-                for(i=1;i<n;i++)
+                /*for(i=1;i<n;i++)
                   {
                     for(j=i+1;j<=n;j++)
                       {
@@ -125,15 +125,15 @@ void mvr(double *D, double* v,int *N, int *edge1, int *edge2, double *edge_lengt
                 edge_length[k]=D[give_index(OTU1,OTU2,n)]/2 + eLenSum;
 
                 eLenSum=0;
-                for(i=1;i<=n;i++)
+                /*for(i=1;i<=n;i++)
                  {
                    if(i == OTU1 || i==OTU2)continue;
 
                    double wi=miu/(v[give_index(i,OTU1,n)]+v[give_index(i,OTU2,n)]);
                    eLenSum+=wi*(D[give_index(i,OTU2,n)]-D[give_index(i,OTU1,n)]);
-                 }
+                }*/
 
-                edge_length[k+1]=D[give_index(OTU1,OTU2,n)]/2 + eLenSum;
+                edge_length[k+1]=D[give_index(OTU1,OTU2,n)]/2 - edge_length[k];
 
                A = D[smallest];
                ij = 0;
@@ -142,7 +142,7 @@ void mvr(double *D, double* v,int *N, int *edge1, int *edge2, double *edge_lengt
                        double xi = D[give_index(i, OTU1, n)]; /* dist between OTU1 and i */
                        double yi = D[give_index(i, OTU2, n)]; /* dist between OTU2 and i */
                         double lamb=v[give_index(i,OTU2,n)]/(v[give_index(i,OTU2,n)]+v[give_index(i,OTU1,n)]);
-                       new_dist[ij] = lamb*(xi-edge_length[k])+(1-lamb)*(yi-edge_length[k]);
+                       new_dist[ij] = lamb*(xi-edge_length[k])+(1-lamb)*(yi-edge_length[k+1]);
                         new_v[ij]=(v[give_index(i,OTU2,n)]*v[give_index(i,OTU1,n)])/(v[give_index(i,OTU2,n)]+v[give_index(i,OTU1,n)]);
                        ij++;
                }
@@ -186,4 +186,3 @@ void mvr(double *D, double* v,int *N, int *edge1, int *edge2, double *edge_lengt
        edge_length[*N*2 - 5] = (D[0] + D[2] - D[1])/2;
        edge_length[*N*2 - 6] = (D[2] + D[1] - D[0])/2;
 }
-