草庐IT

accumulate

全部标签

c++ - 使用 boost::accumulators 对值之间的增量进行采样

我有一个包含N个样本(比如13、16、17、20)的数据集,其中每个下一个样本都递增某个值(在本例中为3、1、3),我想找到关于该样本的各种统计数据第二个序列。样本是增量收集的时间戳(即并非所有样本都一次可用),因此我想使用boost::accumulators::accumulator_set看起来它符合要求.我希望能够做这样的事情:accumulator_set>acc;...acc(13);acc(16);acc(17);acc(20);...但是对差异而不是实际值进行采样。如何在不手动跟踪最后一个值的情况下使用accumulator_set做到这一点?

php - 将带有 std::accumulate 的 C++ 映射移植到 PHP

我不太精通PHP中的数组操作,所以我有一个简单的移植问题。在C++中,我有一张mapstd::map,其中键的隐式排序是结构的关键部分。我想要做的是汇总初始键范围的所有值,我这样做是这样的://accumulatehelper,since"value_type"is"pair"intpair_adder(intn,conststd::map::value_type&p){returnn+p.second;}//ToaddupvaluesforkeysuptoN:inttotal_value_up_to_time_N(intN){returnstd::accumulate(mymap.b

c++ - 编译时等效于 std::accumulate()

我试着编写一个基本的编译时版本的std::accumulate()通过定义一个类模板,该模板将递归迭代给定范围并在每次迭代时添加元素。在Ubuntu14.04上使用gcc4.8.4编译测试程序时,出现以下错误:compile-time-accumulate.cpp:Infunction‘intmain()’:compile-time-accumulate.cpp:44:40:error:calltonon-constexprfunction‘std::vector::const_iteratorstd::vector::cbegin()const[with_Tp=int;_Alloc=

c++ - std::accumulate 的第三个参数的充分理由?

我刚刚写了一个小的辅助函数作为std::accumulate的包装:templateinlineautoaccumulate(FwdIterbegin,FwdIterend)->std::iterator_traits::value_type{returnstd::accumulate(begin,end,std::iterator_traits::value_type());}我可能忽略了这里的一些东西。为什么这不是std::accumulate的现有重载?功能如此明显,不容忽视;有人有充分的理由强制要求第三个参数。(另见Understandingstd::accumulate-我明

c++ - 使用 std::accumulate 计算均值失败

我正在尝试使用以下代码(使用g++mean.cc-std=c++0x编译)计算doublevector的平均值://mean.cc#include#include#includestructMean{unsignedintn;Mean(unsignedintn):n(n){}doubleoperator()(doublesum,doublex){returnsum+x/n;}};intmain(){std::vectorv={1,2,3,4,5,6};Meanmean(v.size());std::cout平均值应该是3.5,我想。然而,该程序打印出mean:1。如果我在我的opera

c++ - 为什么 C++ 中的 accumulate 定义了两个模板

为什么C++中的accumulate定义了两个模板,而工作只能用一个模板完成(带有binaryOperation且默认值为sum的模板)?我指的是来自http://www.cplusplus.com/reference/numeric/accumulate/的累积声明 最佳答案 因为标准就是这样指定的。使用重载还是默认参数通常是个人喜好问题。在这种情况下,选择了过载(由委员会、AlexanderStepanov或碰巧负责选择的人)。默认值比重载更受限制。例如,你可以有一个函数指针T(*)(InputIterator,InputIte

c++ - 使用 std::accumulate

需要以下示例的更漂亮的解决方案,但需要使用std::accumulate。#include#include#includeclassObject{public:Object(doublea,doubleb):a_(a),b_(b){}doubleGetA()const{returna_;}doubleGetB()const{returnb_;}//othermethodsprivate:doublea_;doubleb_;};classCalculator{public:Calculator(double&result):result_(result){}voidoperator()(

c++ - 为什么 std::accumulate 生成 705032704 作为输出而不是 vector 中元素的总和?

输出是705032704而不是5000000000。这是为什么?我认为std::accumulate会计算vector中元素的总和。#include#include#include#include#include#include#include#include#includetypedeflonglongll;intmain(){std::vectornums={1000000000,1000000000,1000000000,1000000000,1000000000};std::cout 最佳答案 整数溢出。std::accum

c++ - 使用 accumulate 计算数组 double[] 平均值的函数

想必是最常见的功能吧,大家在某处都有一段代码,但我其实在SO以及其他C++网站上找了不下1.5小时,都没有找到解决办法。我想使用函数计算双数组[]的平均值。我想将数组作为引用传递给函数。有数百万个示例在main()循环中计算平均值,但我正在寻找的是一个函数,我可以将其放入外部文件并在以后随时使用它。到目前为止,这是我的最新版本,是什么导致了编译错误:doublemean_array(doublearray[]){intcount=sizeof(array)/sizeof(array[0]);doublesum=accumulate(array,array+count,0);return

c++ - 使用 boost::accumulators,如何重置滚动窗口大小,它是否保留额外的历史记录?

我正在查看boost::accumulator框架,特别是一些rolling_window计算。#include#include#includeaccumulator_set>acc(tag::rolling_window::window_size=3);正如您在此处看到的,我已将window_size设置为3,以便它仅保持最后三个样本的平均值。我能否在运行时修改该大小,也许是基于用户设置?如果是这样,并且我增加了window_size,如果累加器已经看到超过我的新window_size,它是否有额外的内部状态,或者我是否必须等待额外的值? 最佳答案