Antonie
|
00001 #pragma once 00002 #include <stdio.h> 00003 #include <string> 00004 #include <stdint.h> 00005 00006 void chomp(char* line); 00007 char* sfgets(char* p, int num, FILE* fp); 00008 void reverseNucleotides(std::string* nucleotides); 00009 uint64_t filesize(const char* name); 00010 bool stringfgets(FILE* fp, std::string* line); 00011 00015 class VarMeanEstimator 00016 { 00017 public: 00018 VarMeanEstimator() : N(0), xTot(0), x2Tot(0) {} 00019 void operator()(double val) 00020 { 00021 ++N; 00022 xTot += val; 00023 x2Tot += val*val; 00024 } 00025 friend double mean(const VarMeanEstimator& vme); 00026 friend double variance(const VarMeanEstimator& vme); 00027 private: 00028 uint64_t N; 00029 double xTot; 00030 double x2Tot; 00031 }; 00032 00034 inline double mean(const VarMeanEstimator& vme) 00035 { 00036 return vme.xTot/vme.N; 00037 } 00038 00040 inline double variance(const VarMeanEstimator& vme) 00041 { 00042 return (vme.x2Tot - vme.xTot*vme.xTot/vme.N)/vme.N; 00043 }