5 * Created by John Westcott on 1/7/09.
6 * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
10 #include "npshannon.h"
12 /***********************************************************************/
15 EstOutput NPShannon::getValues(SAbundVector* rank){
18 float npShannon = 0.0000;
20 double maxRank = (double)rank->getMaxRank();
21 int sampled = rank->getNumSeqs();
23 double Chat = 1.0000 - (double)rank->get(1)/(double)sampled;
26 for(int i=1;i<=maxRank;i++){
27 double pi = ((double) i)/((double)sampled);
28 double ChatPi = Chat*pi;
30 npShannon += rank->get(i) * ChatPi*log(ChatPi)/(1-pow(1-ChatPi,(double)sampled));
33 npShannon = -npShannon;
41 if (isnan(data[0]) || isinf(data[0])) { data[0] = 0; }
46 errorOut(e, "NPShannon", "getValues");
51 /***********************************************************************/