1 /*
2  *  hellinger.cpp
3  *  Mothur
4  *
5  *  Created by westcott on 12/15/10.
6  *  Copyright 2010 Schloss Lab. All rights reserved.
7  *
8  */
9 
10 #include "hellinger.h"
11 
12 /***********************************************************************/
getValues(vector<SharedRAbundVector * > shared)13 EstOutput Hellinger::getValues(vector<SharedRAbundVector*> shared) {
14 	try {
15 		data.resize(1,0);
16 
17 		double sumA = 0.0;
18 		double sumB = 0.0;
19 
20 		//calc the 2 denominators
21 		for (int i = 0; i < shared[0]->getNumBins(); i++) {
22 			sumA += shared[0]->get(i);
23 			sumB += shared[1]->get(i);
24 		}
25 
26 
27 		//calc sum
28 		double sum = 0.0;
29 		for (int i = 0; i < shared[0]->getNumBins(); i++) {
30 
31 			int Aij = shared[0]->get(i);
32 			int Bij = shared[1]->get(i);
33 
34 			double term1 = sqrt((Aij / sumA));
35 			double term2 = sqrt((Bij / sumB));
36 
37 			sum += ((term1 - term2) * (term1 - term2));
38 		}
39 
40 		data[0] = sqrt(sum);
41 
42 		if (isnan(data[0]) || isinf(data[0])) { data[0] = 0; }
43 
44 		return data;
45 	}
46 	catch(exception& e) {
47 		m->errorOut(e, "Hellinger", "getValues");
48 		exit(1);
49 	}
50 }
51 /***********************************************************************/
52 
53 
54