diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 18:24:20 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 18:24:20 +0000 |
commit | 483eb2f56657e8e7f419ab1a4fab8dce9ade8609 (patch) | |
tree | e5d88d25d870d5dedacb6bbdbe2a966086a0a5cf /src/boost/libs/accumulators/example | |
parent | Initial commit. (diff) | |
download | ceph-483eb2f56657e8e7f419ab1a4fab8dce9ade8609.tar.xz ceph-483eb2f56657e8e7f419ab1a4fab8dce9ade8609.zip |
Adding upstream version 14.2.21.upstream/14.2.21upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/boost/libs/accumulators/example')
-rw-r--r-- | src/boost/libs/accumulators/example/Jamfile.v2 | 13 | ||||
-rw-r--r-- | src/boost/libs/accumulators/example/example.vcproj | 396 | ||||
-rw-r--r-- | src/boost/libs/accumulators/example/main.cpp | 262 |
3 files changed, 671 insertions, 0 deletions
diff --git a/src/boost/libs/accumulators/example/Jamfile.v2 b/src/boost/libs/accumulators/example/Jamfile.v2 new file mode 100644 index 00000000..eff105b3 --- /dev/null +++ b/src/boost/libs/accumulators/example/Jamfile.v2 @@ -0,0 +1,13 @@ +# (C) Copyright 2004: Eric Niebler +# Distributed under the Boost Software License, Version 1.0. +# (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +exe example + : + main.cpp + : + <include>../../.. + <include>$(BOOST_ROOT) + <library>/boost/serialization + <cxxflags>"-Wno-deprecated-declarations" + ; diff --git a/src/boost/libs/accumulators/example/example.vcproj b/src/boost/libs/accumulators/example/example.vcproj new file mode 100644 index 00000000..535370e8 --- /dev/null +++ b/src/boost/libs/accumulators/example/example.vcproj @@ -0,0 +1,396 @@ +<?xml version="1.0" encoding="Windows-1252"?> +<VisualStudioProject + ProjectType="Visual C++" + Version="7.10" + Name="example" + ProjectGUID="{57D2AB8B-8CBB-4B28-921E-C6916109B843}" + Keyword="Win32Proj"> + <Platforms> + <Platform + Name="Win32"/> + </Platforms> + <Configurations> + <Configuration + Name="Debug|Win32" + OutputDirectory="Debug" + IntermediateDirectory="Debug" + ConfigurationType="1" + CharacterSet="2"> + <Tool + Name="VCCLCompilerTool" + Optimization="0" + AdditionalIncludeDirectories="..\..\..;$(BOOST_ROOT)" + PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE" + MinimalRebuild="TRUE" + BasicRuntimeChecks="3" + RuntimeLibrary="5" + UsePrecompiledHeader="0" + WarningLevel="3" + Detect64BitPortabilityProblems="TRUE" + DebugInformationFormat="3"/> + <Tool + Name="VCCustomBuildTool"/> + <Tool + Name="VCLinkerTool" + OutputFile="$(OutDir)/example.exe" + LinkIncremental="2" + GenerateDebugInformation="TRUE" + ProgramDatabaseFile="$(OutDir)/example.pdb" + SubSystem="1" + TargetMachine="1"/> + <Tool + Name="VCMIDLTool"/> + <Tool + Name="VCPostBuildEventTool"/> + <Tool + Name="VCPreBuildEventTool"/> + <Tool + Name="VCPreLinkEventTool"/> + <Tool + Name="VCResourceCompilerTool"/> + <Tool + Name="VCWebServiceProxyGeneratorTool"/> + <Tool + Name="VCXMLDataGeneratorTool"/> + <Tool + Name="VCWebDeploymentTool"/> + <Tool + Name="VCManagedWrapperGeneratorTool"/> + <Tool + Name="VCAuxiliaryManagedWrapperGeneratorTool"/> + </Configuration> + <Configuration + Name="Release|Win32" + OutputDirectory="Release" + IntermediateDirectory="Release" + ConfigurationType="1" + CharacterSet="2"> + <Tool + Name="VCCLCompilerTool" + AdditionalIncludeDirectories="..\..\..;$(BOOST_ROOT)" + PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE" + RuntimeLibrary="4" + UsePrecompiledHeader="0" + WarningLevel="3" + Detect64BitPortabilityProblems="TRUE" + DebugInformationFormat="3"/> + <Tool + Name="VCCustomBuildTool"/> + <Tool + Name="VCLinkerTool" + OutputFile="$(OutDir)/example.exe" + LinkIncremental="1" + GenerateDebugInformation="TRUE" + SubSystem="1" + OptimizeReferences="2" + EnableCOMDATFolding="2" + TargetMachine="1"/> + <Tool + Name="VCMIDLTool"/> + <Tool + Name="VCPostBuildEventTool"/> + <Tool + Name="VCPreBuildEventTool"/> + <Tool + Name="VCPreLinkEventTool"/> + <Tool + Name="VCResourceCompilerTool"/> + <Tool + Name="VCWebServiceProxyGeneratorTool"/> + <Tool + Name="VCXMLDataGeneratorTool"/> + <Tool + Name="VCWebDeploymentTool"/> + <Tool + Name="VCManagedWrapperGeneratorTool"/> + <Tool + Name="VCAuxiliaryManagedWrapperGeneratorTool"/> + </Configuration> + </Configurations> + <References> + </References> + <Files> + <Filter + Name="Source Files" + Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx" + UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"> + <File + RelativePath=".\main.cpp"> + </File> + </Filter> + <Filter + Name="Header Files" + Filter="h;hpp;hxx;hm;inl;inc;xsd" + UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"> + <File + RelativePath="..\..\..\boost\accumulators\accumulators.hpp"> + </File> + <File + RelativePath="..\..\..\boost\accumulators\accumulators_fwd.hpp"> + </File> + <File + RelativePath="..\..\..\boost\accumulators\statistics.hpp"> + </File> + <File + RelativePath="..\..\..\boost\accumulators\statistics_fwd.hpp"> + </File> + <Filter + Name="statistics" + Filter=""> + <File + RelativePath="..\..\..\boost\accumulators\statistics\count.hpp"> + </File> + <File + RelativePath="..\..\..\boost\accumulators\statistics\covariance.hpp"> + </File> + <File + RelativePath="..\..\..\boost\accumulators\statistics\density.hpp"> + </File> + <File + RelativePath="..\..\..\boost\accumulators\statistics\error_of.hpp"> + </File> + <File + RelativePath="..\..\..\boost\accumulators\statistics\error_of_mean.hpp"> + </File> + <File + RelativePath="..\..\..\boost\accumulators\statistics\extended_p_square.hpp"> + </File> + <File + RelativePath="..\..\..\boost\accumulators\statistics\extended_p_square_quantile.hpp"> + </File> + <File + RelativePath="..\..\..\boost\accumulators\statistics\kurtosis.hpp"> + </File> + <File + RelativePath="..\..\..\boost\accumulators\statistics\max.hpp"> + </File> + <File + RelativePath="..\..\..\boost\accumulators\statistics\mean.hpp"> + </File> + <File + RelativePath="..\..\..\boost\accumulators\statistics\median.hpp"> + </File> + <File + RelativePath="..\..\..\boost\accumulators\statistics\min.hpp"> + </File> + <File + RelativePath="..\..\..\boost\accumulators\statistics\moment.hpp"> + </File> + <File + RelativePath="..\..\..\boost\accumulators\statistics\p_square_cumulative_distribution.hpp"> + </File> + <File + RelativePath="..\..\..\boost\accumulators\statistics\p_square_quantile.hpp"> + </File> + <File + RelativePath="..\..\..\boost\accumulators\statistics\peaks_over_threshold.hpp"> + </File> + <File + RelativePath="..\..\..\boost\accumulators\statistics\pot_quantile.hpp"> + </File> + <File + RelativePath="..\..\..\boost\accumulators\statistics\pot_tail_mean.hpp"> + </File> + <File + RelativePath="..\..\..\boost\accumulators\statistics\skewness.hpp"> + </File> + <File + RelativePath="..\..\..\boost\accumulators\statistics\stats.hpp"> + </File> + <File + RelativePath="..\..\..\boost\accumulators\statistics\sum.hpp"> + </File> + <File + RelativePath="..\..\..\boost\accumulators\statistics\tail.hpp"> + </File> + <File + RelativePath="..\..\..\boost\accumulators\statistics\tail_mean.hpp"> + </File> + <File + RelativePath="..\..\..\boost\accumulators\statistics\tail_quantile.hpp"> + </File> + <File + RelativePath="..\..\..\boost\accumulators\statistics\tail_variate.hpp"> + </File> + <File + RelativePath="..\..\..\boost\accumulators\statistics\tail_variate_means.hpp"> + </File> + <File + RelativePath="..\..\..\boost\accumulators\statistics\times2_iterator.hpp"> + </File> + <File + RelativePath="..\..\..\boost\accumulators\statistics\variance.hpp"> + </File> + <File + RelativePath="..\..\..\boost\accumulators\statistics\weighted_covariance.hpp"> + </File> + <File + RelativePath="..\..\..\boost\accumulators\statistics\weighted_density.hpp"> + </File> + <File + RelativePath="..\..\..\boost\accumulators\statistics\weighted_extended_p_square.hpp"> + </File> + <File + RelativePath="..\..\..\boost\accumulators\statistics\weighted_kurtosis.hpp"> + </File> + <File + RelativePath="..\..\..\boost\accumulators\statistics\weighted_mean.hpp"> + </File> + <File + RelativePath="..\..\..\boost\accumulators\statistics\weighted_median.hpp"> + </File> + <File + RelativePath="..\..\..\boost\accumulators\statistics\weighted_moment.hpp"> + </File> + <File + RelativePath="..\..\..\boost\accumulators\statistics\weighted_p_square_cumulative_distribution.hpp"> + </File> + <File + RelativePath="..\..\..\boost\accumulators\statistics\weighted_p_square_quantile.hpp"> + </File> + <File + RelativePath="..\..\..\boost\accumulators\statistics\weighted_peaks_over_threshold.hpp"> + </File> + <File + RelativePath="..\..\..\boost\accumulators\statistics\weighted_skewness.hpp"> + </File> + <File + RelativePath="..\..\..\boost\accumulators\statistics\weighted_sum.hpp"> + </File> + <File + RelativePath="..\..\..\boost\accumulators\statistics\weighted_tail_mean.hpp"> + </File> + <File + RelativePath="..\..\..\boost\accumulators\statistics\weighted_tail_quantile.hpp"> + </File> + <File + RelativePath="..\..\..\boost\accumulators\statistics\weighted_tail_variate_means.hpp"> + </File> + <File + RelativePath="..\..\..\boost\accumulators\statistics\weighted_variance.hpp"> + </File> + <File + RelativePath="..\..\..\boost\accumulators\statistics\with_error.hpp"> + </File> + <Filter + Name="variates" + Filter=""> + <File + RelativePath="..\..\..\boost\accumulators\statistics\variates\covariate.hpp"> + </File> + </Filter> + <Filter + Name="parameters" + Filter=""> + <File + RelativePath="..\..\..\boost\accumulators\statistics\parameters\quantile_probability.hpp"> + </File> + </Filter> + </Filter> + <Filter + Name="framework" + Filter=""> + <File + RelativePath="..\..\..\boost\accumulators\framework\accumulator_base.hpp"> + </File> + <File + RelativePath="..\..\..\boost\accumulators\framework\accumulator_concept.hpp"> + </File> + <File + RelativePath="..\..\..\boost\accumulators\framework\accumulator_set.hpp"> + </File> + <File + RelativePath="..\..\..\boost\accumulators\framework\depends_on.hpp"> + </File> + <File + RelativePath="..\..\..\boost\accumulators\framework\external.hpp"> + </File> + <File + RelativePath="..\..\..\boost\accumulators\framework\extractor.hpp"> + </File> + <File + RelativePath="..\..\..\boost\accumulators\framework\features.hpp"> + </File> + <Filter + Name="parameters" + Filter=""> + <File + RelativePath="..\..\..\boost\accumulators\framework\parameters\accumulator.hpp"> + </File> + <File + RelativePath="..\..\..\boost\accumulators\framework\parameters\sample.hpp"> + </File> + <File + RelativePath="..\..\..\boost\accumulators\framework\parameters\weight.hpp"> + </File> + <File + RelativePath="..\..\..\boost\accumulators\framework\parameters\weights.hpp"> + </File> + </Filter> + <Filter + Name="accumulators" + Filter=""> + <File + RelativePath="..\..\..\boost\accumulators\framework\accumulators\droppable_accumulator.hpp"> + </File> + <File + RelativePath="..\..\..\boost\accumulators\framework\accumulators\external_accumulator.hpp"> + </File> + <File + RelativePath="..\..\..\boost\accumulators\framework\accumulators\reference_accumulator.hpp"> + </File> + <File + RelativePath="..\..\..\boost\accumulators\framework\accumulators\value_accumulator.hpp"> + </File> + </Filter> + </Filter> + <Filter + Name="numeric" + Filter=""> + <File + RelativePath="..\..\..\boost\accumulators\numeric\functional.hpp"> + </File> + <File + RelativePath="..\..\..\boost\accumulators\numeric\functional_fwd.hpp"> + </File> + <Filter + Name="functional" + Filter=""> + <File + RelativePath="..\..\..\boost\accumulators\numeric\functional\complex.hpp"> + </File> + <File + RelativePath="..\..\..\boost\accumulators\numeric\functional\valarray.hpp"> + </File> + <File + RelativePath="..\..\..\boost\accumulators\numeric\functional\vector.hpp"> + </File> + </Filter> + <Filter + Name="detail" + Filter=""> + <File + RelativePath="..\..\..\boost\accumulators\numeric\detail\function1.hpp"> + </File> + <File + RelativePath="..\..\..\boost\accumulators\numeric\detail\function2.hpp"> + </File> + <File + RelativePath="..\..\..\boost\accumulators\numeric\detail\function3.hpp"> + </File> + <File + RelativePath="..\..\..\boost\accumulators\numeric\detail\function4.hpp"> + </File> + <File + RelativePath="..\..\..\boost\accumulators\numeric\detail\function_n.hpp"> + </File> + <File + RelativePath="..\..\..\boost\accumulators\numeric\detail\pod_singleton.hpp"> + </File> + </Filter> + </Filter> + </Filter> + </Files> + <Globals> + </Globals> +</VisualStudioProject> diff --git a/src/boost/libs/accumulators/example/main.cpp b/src/boost/libs/accumulators/example/main.cpp new file mode 100644 index 00000000..2c525b21 --- /dev/null +++ b/src/boost/libs/accumulators/example/main.cpp @@ -0,0 +1,262 @@ +/////////////////////////////////////////////////////////////////////////////// +// main.hpp +// +// Copyright 2005 Eric Niebler. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#include <iostream> +#include <fstream> // needed for de/serialization example (4) +#include <algorithm> +#include <boost/ref.hpp> +#include <boost/bind.hpp> +#include <boost/array.hpp> +#include <boost/foreach.hpp> +#include <boost/accumulators/accumulators.hpp> +#include <boost/accumulators/statistics.hpp> +// needed for de/serialization example (4) +#include <boost/archive/text_oarchive.hpp> +#include <boost/archive/text_iarchive.hpp> + +using namespace boost; +using namespace boost::accumulators; + +// Helper that uses BOOST_FOREACH to display a range of doubles +template<typename Range> +void output_range(Range const &rng) +{ + bool first = true; + BOOST_FOREACH(double d, rng) + { + if(!first) std::cout << ", "; + std::cout << d; + first = false; + } + std::cout << '\n'; +} + +/////////////////////////////////////////////////////////////////////////////// +// example1 +// +// Calculate some useful stats using accumulator_set<> and std::for_each() +// +void example1() +{ + accumulator_set< + double + , stats<tag::min, tag::mean(immediate), tag::sum, tag::moment<2> > + > acc; + + boost::array<double, 4> data = {0., 1., -1., 3.14159}; + + // std::for_each pushes each sample into the accumulator one at a + // time, and returns a copy of the accumulator. + acc = std::for_each(data.begin(), data.end(), acc); + + // The following would be equivalent, and could be more efficient + // because it doesn't pass and return the entire accumulator set + // by value. + //std::for_each(data.begin(), data.end(), bind<void>(ref(acc), _1)); + + std::cout << " min""(acc) = " << (min)(acc) << std::endl; // Extra quotes are to prevent complaints from Boost inspect tool + std::cout << " mean(acc) = " << mean(acc) << std::endl; + + // since mean depends on count and sum, we can get their results, too. + std::cout << " count(acc) = " << count(acc) << std::endl; + std::cout << " sum(acc) = " << sum(acc) << std::endl; + std::cout << " moment<2>(acc) = " << accumulators::moment<2>(acc) << std::endl; +} + +/////////////////////////////////////////////////////////////////////////////// +// example2 +// +// Calculate some tail statistics. This demonstrates how to specify +// constructor and accumulator parameters. Note that the tail statistics +// return multiple values, which are returned in an iterator_range. +// +// It pushes data in and displays the intermediate results to demonstrate +// how the tail statistics are updated. +void example2() +{ + // An accumulator which tracks the right tail (largest N items) and + // some data that are covariate with them. N == 4. + accumulator_set< + double + , stats<tag::tail_variate<double, tag::covariate1, right> > + > acc(tag::tail<right>::cache_size = 4); + + acc(2.1, covariate1 = .21); + acc(1.1, covariate1 = .11); + acc(2.1, covariate1 = .21); + acc(1.1, covariate1 = .11); + + std::cout << " tail = "; output_range(tail(acc)); + std::cout << " tail_variate = "; output_range(tail_variate(acc)); + std::cout << std::endl; + + acc(21.1, covariate1 = 2.11); + acc(11.1, covariate1 = 1.11); + acc(21.1, covariate1 = 2.11); + acc(11.1, covariate1 = 1.11); + + std::cout << " tail = "; output_range(tail(acc)); + std::cout << " tail_variate = "; output_range(tail_variate(acc)); + std::cout << std::endl; + + acc(42.1, covariate1 = 4.21); + acc(41.1, covariate1 = 4.11); + acc(42.1, covariate1 = 4.21); + acc(41.1, covariate1 = 4.11); + + std::cout << " tail = "; output_range(tail(acc)); + std::cout << " tail_variate = "; output_range(tail_variate(acc)); + std::cout << std::endl; + + acc(32.1, covariate1 = 3.21); + acc(31.1, covariate1 = 3.11); + acc(32.1, covariate1 = 3.21); + acc(31.1, covariate1 = 3.11); + + std::cout << " tail = "; output_range(tail(acc)); + std::cout << " tail_variate = "; output_range(tail_variate(acc)); +} + +/////////////////////////////////////////////////////////////////////////////// +// example3 +// +// Demonstrate how to calculate weighted statistics. This example demonstrates +// both a simple weighted statistical calculation, and a more complicated +// calculation where the weight statistics are calculated and stored in an +// external weight accumulator. +void example3() +{ + // weight == double + double w = 1.; + + // Simple weighted calculation + { + // stats that depend on the weight are made external + accumulator_set<double, stats<tag::mean>, double> acc; + + acc(0., weight = w); + acc(1., weight = w); + acc(-1., weight = w); + acc(3.14159, weight = w); + + std::cout << " mean(acc) = " << mean(acc) << std::endl; + } + + // Weighted calculation with an external weight accumulator + { + // stats that depend on the weight are made external + accumulator_set<double, stats<tag::mean>, external<double> > acc; + + // Here's an external weight accumulator + accumulator_set<void, stats<tag::sum_of_weights>, double> weight_acc; + + weight_acc(weight = w); acc(0., weight = w); + weight_acc(weight = w); acc(1., weight = w); + weight_acc(weight = w); acc(-1., weight = w); + weight_acc(weight = w); acc(3.14159, weight = w); + + std::cout << " mean(acc) = " << mean(acc, weights = weight_acc) << std::endl; + } +} + +/////////////////////////////////////////////////////////////////////////////// +// example4 +// +// Show how accumulators could be persisted into a file, and then continued +// from where they were left of +// +void example4() +{ + accumulator_set< + double + , stats<tag::min, tag::mean(immediate), tag::sum, tag::moment<2>, tag::p_square_quantile, tag::kurtosis > + > acc(quantile_probability = 0.9); + + { + // accumulate values from array + boost::array<double, 10> data = {-10., -8., -7., -6., -5., -4., -3., -2., -1., 0.}; + + acc = std::for_each(data.begin(), data.end(), acc); + } + + std::cout << " min = " << (min)(acc) << std::endl; + std::cout << " mean = " << mean(acc) << std::endl; + std::cout << " count = " << count(acc) << std::endl; + std::cout << " sum = " << sum(acc) << std::endl; + std::cout << " moment<2> = " << accumulators::moment<2>(acc) << std::endl; + std::cout << " p_square_quantile = " << accumulators::p_square_quantile(acc) << std::endl; + std::cout << " kurtosis = " << accumulators::kurtosis(acc) << std::endl; + + // save accumulator list into a file called "saved-stats" + const unsigned ACC_VER = 0; + const char* file_name = "saved-stats"; + { + std::ofstream ofs(file_name); + boost::archive::text_oarchive oa(ofs); + acc.serialize(oa, ACC_VER); + } + + // create a new accumulator set and initialize from data saved into the file + accumulator_set< + double + , stats<tag::min, tag::mean(immediate), tag::sum, tag::moment<2>, tag::p_square_quantile, tag::kurtosis > + > restored_acc(quantile_probability = 0.9); + + { + std::ifstream ifs(file_name); + boost::archive::text_iarchive ia(ifs); + restored_acc.serialize(ia, ACC_VER); + } + + // continue accumulating into both sets + { + // accumulate values from array + boost::array<double, 10> data = {10., 8., 7., 6., 5., 4., 3., 2., 1., 0.}; + + acc = std::for_each(data.begin(), data.end(), acc); + restored_acc = std::for_each(data.begin(), data.end(), restored_acc); + } + + // validate that both return th same values + std::cout << std::endl << "Values in original set:" << std::endl; + std::cout << " min""(acc) = " << (min)(acc) << std::endl; + std::cout << " mean(acc) = " << mean(acc) << std::endl; + std::cout << " count(acc) = " << count(acc) << std::endl; + std::cout << " sum(acc) = " << sum(acc) << std::endl; + std::cout << " moment<2>(acc) = " << accumulators::moment<2>(acc) << std::endl; + std::cout << " p_square_quantile(acc) = " << accumulators::p_square_quantile(acc) << std::endl; + std::cout << " kurtosis(acc) = " << accumulators::kurtosis(acc) << std::endl; + + std::cout << std::endl << "Values in restored set:" << std::endl; + std::cout << " min""(acc) = " << (min)(restored_acc) << std::endl; + std::cout << " mean(acc) = " << mean(restored_acc) << std::endl; + std::cout << " count(acc) = " << count(restored_acc) << std::endl; + std::cout << " sum(acc) = " << sum(restored_acc) << std::endl; + std::cout << " moment<2>(acc) = " << accumulators::moment<2>(restored_acc) << std::endl; + std::cout << " p_square_quantile(acc) = " << accumulators::p_square_quantile(restored_acc) << std::endl; + std::cout << " kurtosis(acc) = " << accumulators::kurtosis(restored_acc) << std::endl; + +} + +/////////////////////////////////////////////////////////////////////////////// +// main +int main() +{ + std::cout << "Example 1:\n"; + example1(); + + std::cout << "\nExample 2:\n"; + example2(); + + std::cout << "\nExample 3:\n"; + example3(); + + std::cout << "\nExample 4:\n"; + example4(); + + return 0; +} |