Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/EmptyTag/149.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 使用增压蓄能器库的正确选项是什么?_C++ - Fatal编程技术网

C++ 使用增压蓄能器库的正确选项是什么?

C++ 使用增压蓄能器库的正确选项是什么?,c++,C++,我正在试着编译 但这一个头球是不够的,我已经花了半个小时来试图击倒所有的错误。为什么不指定所需的包含项 我这样做: #include <boost/accumulators/statistics/weighted_p_square_cumulative_distribution.hpp> #include <vector> #include <boost/accumulators/accumulators.hpp> #include <boost/te

我正在试着编译

但这一个头球是不够的,我已经花了半个小时来试图击倒所有的错误。为什么不指定所需的包含项

我这样做:

#include <boost/accumulators/statistics/weighted_p_square_cumulative_distribution.hpp>
#include <vector>
#include <boost/accumulators/accumulators.hpp> 
#include <boost/test/test_tools.hpp>
#include <boost/random/lagged_fibonacci.hpp>
#include <boost/random/normal_distribution.hpp>
#include <boost/random/variate_generator.hpp>
#include <boost/range/iterator_range.hpp>
#include <boost/fusion/support/void.hpp>
#include <boost/accumulators/framework/depends_on.hpp>

using namespace boost::accumulators;
using namespace boost;

int main() {
    // tolerance in %
    double epsilon = 4;

    typedef accumulator_set<double, stats<tag::weighted_p_square_cumulative_distribution>, double > accumulator_t;

    accumulator_t acc_upper(tag::weighted_p_square_cumulative_distribution::num_cells = 100);
    accumulator_t acc_lower(tag::weighted_p_square_cumulative_distribution::num_cells = 100);

    // two random number generators
    double mu_upper = 1.0;
    double mu_lower = -1.0;
    boost::lagged_fibonacci607 rng;
    boost::normal_distribution<> mean_sigma_upper(mu_upper,1);
    boost::normal_distribution<> mean_sigma_lower(mu_lower,1);
    boost::variate_generator<boost::lagged_fibonacci607&, boost::normal_distribution<> > normal_upper(rng, mean_sigma_upper);
    boost::variate_generator<boost::lagged_fibonacci607&, boost::normal_distribution<> > normal_lower(rng, mean_sigma_lower);

    for (std::size_t i=0; i<100000; ++i)
    {
        double sample = normal_upper();
        acc_upper(sample, weight = std::exp(-mu_upper * (sample - 0.5 * mu_upper)));
    }

    for (std::size_t i=0; i<100000; ++i)
    {
        double sample = normal_lower();
        acc_lower(sample, weight = std::exp(-mu_lower * (sample - 0.5 * mu_lower)));
    }

    typedef iterator_range<std::vector<std::pair<double, double> >::iterator > histogram_type;
    histogram_type histogram_upper = weighted_p_square_cumulative_distribution(acc_upper);
    histogram_type histogram_lower = weighted_p_square_cumulative_distribution(acc_lower);

    // Note that applaying importance sampling results in a region of the distribution 
    // to be estimated more accurately and another region to be estimated less accurately
    // than without importance sampling, i.e., with unweighted samples

    for (std::size_t i = 0; i < histogram_upper.size(); ++i)
    {
        // problem with small results: epsilon is relative (in percent), not absolute!

        // check upper region of distribution
        if ( histogram_upper[i].second > 0.1 )    
            BOOST_CHECK_CLOSE( 0.5 * (1.0 + erf( histogram_upper[i].first / sqrt(2.0) )), histogram_upper[i].second, epsilon );
        // check lower region of distribution
        if ( histogram_lower[i].second < -0.1 )    
            BOOST_CHECK_CLOSE( 0.5 * (1.0 + erf( histogram_lower[i].first / sqrt(2.0) )), histogram_lower[i].second, epsilon );
    }
}
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
使用名称空间boost::累加器;
使用名称空间boost;
int main(){
//公差,单位为%
双ε=4;
typedef蓄能器\u set蓄能器\u t;
累加器上(标签:加权平方分布:单元格数=100);
累加器acc较低(标签::加权p平方分布::累积单元格数=100);
//两个随机数发生器
双μu上限=1.0;
双μu下限=-1.0;
boost::滞后光纤ACI607 rng;
boost::正态分布平均值σ上限(μ上限,1);
boost::正态分布平均值σ较低(μ较低,1);
boost::变量发生器正常上限(rng,平均值σ上限);
boost::变量发生器正常值较低(rng,平均值较低);

对于(std::size\u t i=0;i很遗憾,您没有显示您得到的编译错误,因此我将尝试在黑暗中拍摄:

你用过吗

using namespace boost::accumulators;
在您的代码中?为了简洁起见,大多数示例都需要这样做

编辑:
既然你发布了你的代码(我也检查了链接中的代码示例),在我看来,这个示例是错误的。关键错误似乎是:

错误:“struct boost::fusion::void\u”中没有名为“result\u type”的类型

但是,由于我没有使用boost::累加器的经验,我不得不在这里放弃:-(

也许你可以联系boost::累加器的作者,让他知道这个例子不是开箱即用的。他应该能够修复这个例子。你甚至可能因为发现了这个问题而获得荣誉:-)

很抱歉,我无法提供一个清晰的解决方案,但我希望我能帮助您找出问题所在。Boost fusion使您能够构建结构等效对象,在这些对象中可以使用模板参数访问字段。我为什么要告诉您这些?因为您遇到的错误通常是您在尝试访问不存在的字段时遇到的错误融合结构中的st

这些错误由以下行生成:

accumulator_t acc_upper(tag::weighted_p_square_cumulative_distribution::num_cells = 100);
accumulator_t acc_lower(tag::weighted_p_square_cumulative_distribution::num_cells = 100);
我敢肯定,如果删除构造函数的参数,错误就会消失

accumulator_t acc_upper;
accumulator_t acc_lower;

我对boost累加器了解不多,但错误可能来自两个原因:要么是您对累加器集合的定义不正确(您使用的“stats”和boost累加器文档中建议的“features”之间有区别吗?),要么是您对构造函数中使用的参数的定义不正确(不正确)。找出可能解决编译错误的方法。

使用boost创建依赖项列表,然后可以确保包含所有依赖项。

文档中显示的示例是从库的单元测试中提取的。请查看
libs/累加器/test/weighted\u p\u square\u cum\u dist.cpp

@Neil然后你需要告诉我们你得到的错误,否则我们帮不了你。(我的理论是,我所包含的fusion::void_u可能是真正fusion::void_u的特化,它存在于其他地方,需要被包含……)不确定这是否有意义。模板是一场噩梦。你发布了所有的代码吗?目前它只包含include和using指令(编译时没有错误)。其余的代码与链接上的一样,但我也会包含。接下来……我如何在mac上安装它?“哪个增强?”没有发现任何东西。该命令实际上是bcp,而不是boost-我应该更清楚一点。你必须自己构建它,这有点痛苦。谢谢,将stats更改为features,会出现以下错误:/opt/local/include/boost/contractors/statistics/weighted_p_square_累计分布。hpp:177:错误:调用o重载的“abs(double&)”是不明确的/usr/include/stdlib.h:145:注意:候选项是:int abs(int)/opt/local/include/gcc44/c++/cstdlib:144:注意:long int std::abs(long int)/opt/local/include/gcc44/c++/cstdlib:175:注意:long long-long int_ugnu cxx::abs(long-long-long-long-int),这不是解决方案,但为了找到“real”错误,请定义一个双abs(double)函数。是否尝试删除构造函数的参数?
accumulator_t acc_upper(tag::weighted_p_square_cumulative_distribution::num_cells = 100);
accumulator_t acc_lower(tag::weighted_p_square_cumulative_distribution::num_cells = 100);
accumulator_t acc_upper;
accumulator_t acc_lower;