Home
Install
Use
Develop
Support
News
Credits
hosted by
|
11#ifndef __EstimateStats_h
12#define __EstimateStats_h
19template < typename T, typename U>
28 return diff * diff / var;
31template < typename T, typename U>
34 return chisq (a.get_Estimate(), b.get_Estimate());
37template < typename T, typename U>
40 return 0.5 * ( chisq(a.get_cos(), b.get_cos()) +
41 chisq(a.get_sin(), b.get_sin()) );
44template < typename T, typename U>
48 for ( auto element: vals)
50 return mean.get_Estimate();
53template < typename T, typename U>
54void weighted_quartiles ( const std::vector< Estimate<T,U> >& vals,
59 unsigned nval = vals.size();
62 throw Error (InvalidState, "weighted_quartiles", "ndat=%u < 3", nval);
65 std::vector< Estimate<T,U> > cleaned ( nval );
67 for ( unsigned ival=0; ival < nval; ival++)
68 if (vals[ival].var > 0)
70 cleaned[iclean] = vals[ival];
75 std::cerr << "weighted_quartiles: nval=" << nval << " nclean=" << iclean << std::endl;
80 cleaned.resize (nval);
83 for ( auto element: cleaned)
84 total_weight += 1.0 / element.var;
86 std::sort (cleaned.begin(), cleaned.end());
89 for ( unsigned i=0; i<3; i++)
90 quartile_weight[i] = 0.25 * (i+1) * total_weight;
92 unsigned quartile_index[3] = { 0, 0, 0 };
96 for ( unsigned ival=0; ival < nval; ival++)
98 weight += 1.0 / cleaned[ival].var;
100 for ( unsigned i=0; i<3; i++)
101 if (weight < quartile_weight[i])
102 quartile_index[i] = ival;
106 std::cerr << "weighted_quartile indeces: ";
107 for ( unsigned i=0; i<3; i++)
108 std::cerr << " Q" << i+1 << "=" << quartile_index[i];
109 std::cerr << std::endl;
112 Q1 = Estimate<T,U> (cleaned[quartile_index[0]].val, 1.0/total_weight);
113 Q2 = Estimate<T,U> (cleaned[quartile_index[1]].val, 1.0/total_weight);
114 Q3 = Estimate<T,U> (cleaned[quartile_index[2]].val, 1.0/total_weight);
117template < typename T, typename U>
121 weighted_quartiles (vals, Q1, Q2, Q3);
A convenient exception handling class. Definition Error.h:54
Generated using doxygen 1.14.0
|