使用ojalgo计算滚动平均值
使用ojalgo计算滚动平均值的最佳方法是什么 第一个示例集是将每个数字添加到windows大小的倍 其次,代码意图不明显 我有:使用ojalgo计算滚动平均值,ojalgo,Ojalgo,使用ojalgo计算滚动平均值的最佳方法是什么 第一个示例集是将每个数字添加到windows大小的倍 其次,代码意图不明显 我有: final Array1D<Double> doubles = Array1D.factory(Primitive32Array.FACTORY).makeFilled(10, new Uniform()); System.out.println(doubles.toString()); final Array1D<Dou
final Array1D<Double> doubles = Array1D.factory(Primitive32Array.FACTORY).makeFilled(10, new Uniform());
System.out.println(doubles.toString());
final Array1D<Double> rollingMedian = Array1D.PRIMITIVE32.makeZero(doubles.size());
rollingMedian.set(0, doubles.get(0));
System.out.printf("%1$s -> %1$s\n", doubles.get(0));
final Array1D<Double> someSamples2 = doubles.subList(0, 2);
final double mean2 = SampleSet.wrap(someSamples2).getMean();
rollingMedian.set(1, mean2);
System.out.printf("%s -> %s\n", someSamples2.toString(), mean2);
for (int i = 2; i < doubles.length; i++) {
final Array1D<Double> someSamples = doubles.subList(i - 2, i + 1);
final double mean = SampleSet.wrap(someSamples).getMean();
rollingMedian.set(i, mean);
System.out.printf("%s -> %s\n", someSamples.toString(), mean2);
}
System.out.println(rollingMedian.toString());
final Array1D doubles=Array1D.factory(Primitive32Array.factory).makeFilled(10,new Uniform());
System.out.println(doubles.toString());
final Array1D rollingMedian=Array1D.PRIMITIVE32.makeZero(doubles.size());
滚动中值集(0,doubles.get(0));
System.out.printf(“%1$s->%1$s\n”,doubles.get(0));
最终数组1d someSamples2=双倍子列表(0,2);
final double means2=SampleSet.wrap(someSamples2.getMeans();
滚动中值集(1,平均值2);
System.out.printf(“%s->%s\n”,someSamples2.toString(),意思是2);
对于(int i=2;i%s\n”,someSamples.toString(),表示2);
}
System.out.println(rollingmedia.toString());
哪一种不是最好的…不确定哪一种是最好的方式,但这里有一种选择:
for (int i = 0; i < doubles.length; i++) {
int first = Math.max(0, i - 2);
int limit = i + 1;
double mean = doubles.aggregateRange(first, limit, Aggregator.AVERAGE);
rollingMedian.set(i, mean);
}
for(int i=0;i
我没有看到Aggregator.AVERAGE和Array1D没有实现Access1D.Aggregatable如果你没有看到Aggregator.AVERAGE,你没有使用最新版本-它只是在v45.1中添加的。你想怎么做?我可以创建pull请求,将rollaply函数添加到Array1D或相应的接口中。