COOPY » Guide
version 0.6.5
|
00001 #ifndef COOPY_MEASUREPASS 00002 #define COOPY_MEASUREPASS 00003 00004 #include <coopy/DataSheet.h> 00005 #include <coopy/OrderResult.h> 00006 #include <coopy/Dbg.h> 00007 #include <coopy/SparseSheet.h> 00008 #include <coopy/SheetView.h> 00009 00010 #include <math.h> 00011 00012 namespace coopy { 00013 namespace cmp { 00014 class MeasurePass; 00015 } 00016 } 00017 00018 class coopy::cmp::MeasurePass { 00019 public: 00020 coopy::store::SheetView& va; 00021 coopy::store::SheetView& vb; 00022 coopy::store::DataSheet& a; 00023 coopy::store::DataSheet& b; 00024 coopy::store::IntSheet asel, bsel; 00025 coopy::store::SparseFloatSheet match; 00026 int bound; 00027 00028 MeasurePass(coopy::store::SheetView& va, 00029 coopy::store::SheetView& vb) : va(va), vb(vb), 00030 a(va.sheet), b(vb.sheet) { 00031 bound = -1; 00032 } 00033 00034 void setSize(int alen, int blen) { 00035 asel.resize(1,alen,-1); 00036 bsel.resize(1,blen,-1); 00037 match.resize(alen,blen,0); 00038 } 00039 00040 void setBound(int bound) { 00041 this->bound = bound; 00042 } 00043 00044 int getBound() { 00045 return bound; 00046 } 00047 00048 void clearMatch() { 00049 match.resize(match.width(),match.height(),0); 00050 } 00051 00052 coopy::store::Stat flatten() { 00053 int w = match.width(); 00054 int h = match.height(); 00055 double mean = 0; 00056 double var = 0; 00057 int ct = 0; 00058 for (int y=0; y<h; y++) { 00059 if (y<w) { 00060 float tmp = match.cell_const(y,y); 00061 float tmp2 = match.cell_const(0,y); 00062 if (tmp2>=-0.0001) { 00063 match.cell(y,y) = tmp2; 00064 match.cell(0,y) = tmp; 00065 if (asel.cell(0,y)==-1) { 00066 //printf(" [%d:%g] ", ct, tmp); 00067 mean += tmp; 00068 var += tmp*tmp; 00069 ct++; 00070 } 00071 } 00072 } 00073 } 00074 if (ct>0) { 00075 mean /= ct; 00076 var /= ct; 00077 } 00078 coopy::store::Stat s; 00079 s.mean = mean; 00080 s.stddev = sqrt(var); 00081 s.valid = (ct>=10); 00082 dbg_printf("Mean is %g (count %d)\n", s.mean, ct); 00083 return s; 00084 } 00085 00086 OrderResult getOrder() { 00087 OrderResult order; 00088 order.setup(asel,bsel); 00089 return order; 00090 } 00091 }; 00092 00093 #endif 00094