/********************************************************************* * * 文 件: NormalDistribution.cpp * * 版权所有: Shanghai Baosight Software Co., Ltd. * zoufuzhou *********************************************************************/ #include #include #include #include #include #include #include #include #include #include using namespace std; using namespace boost::accumulators; extern iDA::Connection cn; using namespace log4cplus; NormalDistribution::NormalDistribution(void) { m_avg = 0; m_stddev = 0; } NormalDistribution::NormalDistribution(const vector vdat) { this->ReSet(vdat); } void NormalDistribution::ReSet(const vector vdat) { // accumulator_set > > acc; accumulator_set > acc; for(int i=0; i(acc); } //int NormalDistribution::ReadDBSample(const string& where) //{ // LOG d("NormalDistribution::ReadDBSample"); // if( where.length() == 0) return -1; // accumulator_set > > acc; // // string sql = "select data,datajson from T_RULE_SAMPLE WHERE "+where; // // iDA::Command cmd; // cmd.SetConnection( &cn); // cmd.SetCommandText( sql); // try{ // cmd.Execute(); // }catch( iDA::Exception &e) // { // d.Error()<(acc); // return 0; //} int NormalDistribution::Analysis(double probability,ConfidenceInterval* cfdi) { LOG d("NormalDistribution::Analysis",AUTO_CATCH_PID); d.Debug() << "m_avg:" << m_avg <<" m_stddev:" << m_stddev << std::endl; if(probability < 0 || probability > 1 || m_stddev == 0) { return -1; } boost::math::normal_distibution<> normal(m_avg, m_stddev); d.Debug() << "Prob" << probability << std::endl; // cfdi->up = boost::math::quantile(normal,probability) + m_stddev*1.0; // add 0.2 avg to up in order to increase mistake alarm // cfdi->low = 2.0*m_avg - cfdi->up - m_stddev*1.0;// sub 0.2 avg to up in order to increase mistake alarm cfdi->up = boost::math::quantile(normal,probability); cfdi->low = 2.0*m_avg - cfdi->up; double diff = fabs(cfdi->up-cfdi->low); cfdi->up += diff*0.1; cfdi->low -= diff*0.1; cfdi->probability = probability; cfdi->avg = m_avg; cfdi->std_dev = m_stddev; return 0; }