]> git.donarmstrong.com Git - mothur.git/blob - npshannon.cpp
changing command name classify.shared to classifyrf.shared
[mothur.git] / npshannon.cpp
1 /*
2  *  npshannon.cpp
3  *  Dotur
4  *
5  *  Created by John Westcott on 1/7/09.
6  *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
7  *
8  */
9
10 #include "npshannon.h"
11
12 /***********************************************************************/
13
14
15 EstOutput NPShannon::getValues(SAbundVector* rank){
16         try {
17                 data.resize(1,0);
18                 float npShannon = 0.0000;
19         
20                 double maxRank = (double)rank->getMaxRank();
21                 double sampled = rank->getNumSeqs();
22         
23                 double Chat = 1.0000 - (double)rank->get(1)/(double)sampled;
24         
25                 if(Chat>0)      {       
26                         for(int i=1;i<=maxRank;i++){
27                                 double pi = ((double) i)/((double)sampled);
28                                 double ChatPi = Chat*pi;
29                                 if(ChatPi>0){
30                                         npShannon += rank->get(i) * ChatPi*log(ChatPi)/(1-pow(1-ChatPi,(double)sampled));
31                                 }
32                         }
33                         npShannon = -npShannon;
34                 }
35                 else{
36                         npShannon = 0.000;
37                 }
38         
39                 data[0] = npShannon;
40                 
41                 if (isnan(data[0]) || isinf(data[0])) { data[0] = 0; }
42                 
43                 return data;
44         }
45         catch(exception& e) {
46                 m->errorOut(e, "NPShannon", "getValues");
47                 exit(1);
48         }
49 }
50
51 /***********************************************************************/