6 #ifndef OPENMPCD_IMPLEMENTATIONDETAILS_ONTHEFLYSTATISTICSDDDA_HPP
7 #define OPENMPCD_IMPLEMENTATIONDETAILS_ONTHEFLYSTATISTICSDDDA_HPP
38 return blocks[0].getSampleSize();
44 if(getSampleSize() == 0)
48 "Tried to get mean without having supplied data.");
51 return blocks[0].getSampleMean();
57 if(getSampleSize() == 0)
61 "Tried to get mean without having supplied data.");
64 return std::size_t(1) << getMaximumBlockID();
72 return blocks.size() - 1;
77 const std::size_t blockID)
const
80 blockID <= getMaximumBlockID(),
83 return blocks[blockID].getSampleSize() >= 2;
88 const std::size_t blockID)
const
91 blockID <= getMaximumBlockID(),
94 if(!hasBlockVariance(blockID))
97 return blocks[blockID].getSampleVariance();
102 const std::size_t blockID)
const
104 return sqrt(getBlockVariance(blockID));
110 return getBlockStandardDeviation(0);
115 const std::size_t blockID)
const
118 blockID <= getMaximumBlockID(),
121 if(!hasBlockVariance(blockID))
124 return blocks[blockID].getStandardErrorOfTheMean();
130 const std::size_t blockID)
const
133 blockID <= getMaximumBlockID(),
136 if(!hasBlockVariance(blockID))
139 const T se = getBlockStandardErrorOfTheMean(blockID);
140 const std::size_t reducedSampleSize = blocks[blockID].getSampleSize();
142 return se /
sqrt(2 * reducedSampleSize);
149 if(getSampleSize() < 2)
152 const T rawStandardError = blocks[0].getStandardErrorOfTheMean();
154 if(rawStandardError == 0)
157 std::size_t optimalBlockID = getMaximumBlockID();
159 for(std::size_t blockID = getMaximumBlockID(); ; --blockID)
161 if(!hasBlockVariance(blockID))
169 const std::size_t blockSize = std::size_t(1) << blockID;
170 const T blockedStandardError =
171 blocks[blockID].getStandardErrorOfTheMean();
172 const T quotient = blockedStandardError / rawStandardError;
173 const T quotientPower2 = quotient * quotient;
174 const T quotientPower4 = quotientPower2 * quotientPower2;
176 const T threshold = 2 * getSampleSize() * quotientPower4;
177 if(blockSize * blockSize * blockSize > threshold)
178 optimalBlockID = blockID;
184 return optimalBlockID;
192 const std::size_t blockID = getOptimalBlockIDForStandardErrorOfTheMean();
193 const std::size_t blockSize = std::size_t(1) << blockID;
195 return 50 * blockSize < getSampleSize();
201 const std::size_t blockID = getOptimalBlockIDForStandardErrorOfTheMean();
203 return getBlockStandardErrorOfTheMean(blockID);
213 blocks[blockID].addDatum(datum);
217 const T mean = (datum + *waiting[blockID]) / 2.0;
219 waiting[blockID] = boost::none;
220 if(blockID + 1 == blocks.size())
223 waiting.push_back(boost::none);
226 addDatum(mean, blockID + 1);
230 waiting[blockID] = datum;
237 BOOST_STATIC_ASSERT(boost::is_arithmetic<T>::value);
239 std::stringstream ss;
241 ss.precision(std::numeric_limits<T>::digits10 + 2);
245 for(std::size_t i = 0; i < blocks.size(); ++i)
246 ss <<
"|" << blocks[i].serializeToString();
249 for(std::size_t i = 0; i < blocks.size(); ++i)
262 BOOST_STATIC_ASSERT(boost::is_arithmetic<T>::value);
264 std::vector<std::string> parts;
265 boost::algorithm::split(parts, state, boost::algorithm::is_any_of(
"|"));
269 if(parts[0][0] ==
'-')
271 const unsigned int version =
272 boost::lexical_cast<unsigned int>(parts[0]);
277 if(parts[1][0] ==
'-')
279 const std::size_t blockCount =
280 boost::lexical_cast<unsigned int>(parts[1]);
282 if(parts.size() != 2 + 2 * blockCount)
285 std::vector<OnTheFlyStatistics<T> > _blocks;
286 for(std::size_t i = 0; i < blockCount; ++i)
290 _blocks.push_back(block);
293 std::vector<boost::optional<T> > _waiting;
294 for(std::size_t i = 0; i < blockCount; ++i)
296 boost::optional<T> w;
297 const std::string& part = parts[2 + blockCount + i];
299 w = boost::lexical_cast<T>(part);
300 _waiting.push_back(w);
312 catch(
const boost::bad_lexical_cast&)
320 #endif //OPENMPCD_IMPLEMENTATIONDETAILS_ONTHEFLYSTATISTICSDDDA_HPP