[Avida-SVN] r2233 - / development/source/analyze
kaben at myxo.css.msu.edu
kaben at myxo.css.msu.edu
Wed Dec 19 12:29:22 PST 2007
Author: kaben
Date: 2007-12-19 15:29:22 -0500 (Wed, 19 Dec 2007)
New Revision: 2233
Modified:
/
development/source/analyze/cAnalyzeTreeStats_Gamma.cc
development/source/analyze/cAnalyzeTreeStats_Gamma.h
Log:
r2271 at vallista: kaben | 2007-12-19 12:21:47 -0800
Added incomplete support for calculating gamma statistic using update-born instead of phylogenetic depth.
Property changes on:
___________________________________________________________________
Name: svk:merge
- 079b078a-dbed-46b9-b3da-37668d4295ca:/avida/xcode-test:1653
c457ea80-0a68-11dc-9323-a45eea2efad5:/private:2270
+ 079b078a-dbed-46b9-b3da-37668d4295ca:/avida/xcode-test:1653
c457ea80-0a68-11dc-9323-a45eea2efad5:/private:2271
Modified: development/source/analyze/cAnalyzeTreeStats_Gamma.cc
===================================================================
--- development/source/analyze/cAnalyzeTreeStats_Gamma.cc 2007-12-19 20:29:20 UTC (rev 2232)
+++ development/source/analyze/cAnalyzeTreeStats_Gamma.cc 2007-12-19 20:29:22 UTC (rev 2233)
@@ -29,7 +29,11 @@
#include "cWorld.h"
#include <math.h>
+#include <iostream>
+using namespace std;
+
+
cAnalyzeTreeStats_Gamma::cAnalyzeTreeStats_Gamma(cWorld* world)
: m_world(world)
, m_gen_array(0)
@@ -81,14 +85,19 @@
/* if we fell off the end of a redundant subsequence, restore the saved redundant g. */
if(in_redundant_subsequence) {
m_g[m_gen_array.GetSize()] = saved_g;
- // saved_g = -1;
- // in_redundant_subsequence = false;
}
}
void cAnalyzeTreeStats_Gamma::CalculateGamma(void){
// n: number of leaves, constant for a given tree.
int n = m_gen_array.GetSize();
+ if(n <= 2){
+ if(m_world->GetVerbosity() >= VERBOSE_ON) {
+ cerr << "Error: not enough genotypes in batch to calculate gamma - " << endl;
+ }
+ return;
+ }
+
int T = 0;
for(int j = 2; j <= n; j++) { T += j*m_g[j]; }
@@ -116,7 +125,7 @@
-// Comparison function for heapsort.
+// Comparison functions for heapsort.
int CompareAGPhyloDepth(const void * _a, const void * _b){
cAnalyzeGenotype a(**((cAnalyzeGenotype**)_a));
cAnalyzeGenotype b(**((cAnalyzeGenotype**)_b));
@@ -124,14 +133,52 @@
if(a.GetDepth() < b.GetDepth()){ return -1; }
return 0;
}
+int CompareAGUpdateBorn(const void * _a, const void * _b){
+ cAnalyzeGenotype a(**((cAnalyzeGenotype**)_a));
+ cAnalyzeGenotype b(**((cAnalyzeGenotype**)_b));
+ if(a.GetUpdateBorn() > b.GetUpdateBorn()){ return 1; }
+ if(a.GetUpdateBorn() < b.GetUpdateBorn()){ return -1; }
+ return 0;
+}
+
+// Heapsort functions.
int HeapSortAGPhyloDepth(tArray<cAnalyzeGenotype *> &gen_array){
const int size = gen_array.GetSize();
cAnalyzeGenotype *c_gen_array[size];
+
/* Copy unsorted array from gen_array into c_gen_array. */
- for(int i = 0; i < size; i++){ c_gen_array[i] = (gen_array[i]); }
+ for(int i = 0; i < size; i++){
+ c_gen_array[i] = (gen_array[i]);
+ }
+
/* Heapsort c_gen_array. */
int result = heapsort(c_gen_array, size, sizeof(cAnalyzeGenotype*), CompareAGPhyloDepth);
+
/* If heapsort returned successfully, copy sorted array from c_gen_array into gen_array. */
- if(result == 0){ for(int i = 0; i < size; i++){ gen_array[i] = (c_gen_array[i]); } }
+ if(result == 0){
+ for(int i = 0; i < size; i++){
+ gen_array[i] = (c_gen_array[i]);
+ }
+ }
return result;
}
+int HeapSortAGUpdateBorn(tArray<cAnalyzeGenotype *> &gen_array){
+ const int size = gen_array.GetSize();
+ cAnalyzeGenotype *c_gen_array[size];
+
+ /* Copy unsorted array from gen_array into c_gen_array. */
+ for(int i = 0; i < size; i++){
+ c_gen_array[i] = (gen_array[i]);
+ }
+
+ /* Heapsort c_gen_array. */
+ int result = heapsort(c_gen_array, size, sizeof(cAnalyzeGenotype*), CompareAGUpdateBorn);
+
+ /* If heapsort returned successfully, copy sorted array from c_gen_array into gen_array. */
+ if(result == 0){
+ for(int i = 0; i < size; i++){
+ gen_array[i] = (c_gen_array[i]);
+ }
+ }
+ return result;
+}
Modified: development/source/analyze/cAnalyzeTreeStats_Gamma.h
===================================================================
--- development/source/analyze/cAnalyzeTreeStats_Gamma.h 2007-12-19 20:29:20 UTC (rev 2232)
+++ development/source/analyze/cAnalyzeTreeStats_Gamma.h 2007-12-19 20:29:22 UTC (rev 2233)
@@ -55,8 +55,11 @@
void AnalyzeBatch(tList<cAnalyzeGenotype> &genotype_list);
};
-// Comparison function for heapsort.
+// Comparison functions for heapsort.
int CompareAGPhyloDepth(const void * _a, const void * _b);
+int CompareAGUpdateBorn(const void * _a, const void * _b);
+// Heapsort functions.
int HeapSortAGPhyloDepth(tArray<cAnalyzeGenotype *> &gen_array);
+int HeapSortAGUpdateBorn(tArray<cAnalyzeGenotype *> &gen_array);
#endif
More information about the Avida-cvs
mailing list