Jakarta Commons Cookbook这本书中介绍了一个使用回归分析来估计某个工作需要多长时间的例子。 笔者看过之后感觉有些问题(也可能是笔者数学功底不够)。以下是经过笔者修改后的代码。
import org.apache.commons.lang.math.RandomUtils;
import org.apache.commons.lang.time.StopWatch;
import org.apache.commons.math.stat.regression.SimpleRegression;
public class ProgressEstimator {
//
private StopWatch stopWatch;
private SimpleRegression regression;
/**
*
*/
public ProgressEstimator() {
this.stopWatch = new StopWatch();
this.regression = new SimpleRegression();
}
/**
*
*/
public void start() {
//
regression.clear();
//
stopWatch.reset();
stopWatch.start();
}
public void stop() {
//
stopWatch.stop();
}
/**
*
*/
public void step(int progress) {
regression.addData(progress, stopWatch.getTime());
}
public long getElapsedTime() {
return stopWatch.getTime();
}
public long getRemainingTime(long total) {
long r = (long)(regression.getSlope() * total + regression.getIntercept()) - getElapsedTime();
return r >= 0 ? r : 0;
}
/**
*
*/
public static void main(String args[]) {
//
ProgressEstimator pe = new ProgressEstimator();
pe.start();
//
int count = 1000;
for(int i = 0; i < count; i++) {
//
try {
Thread.sleep(RandomUtils.nextInt(30));
} catch(Exception e) {
break;
}
//
if(i % 10 == 9) {
//
pe.step(i);
//
long elapsed = pe.getElapsedTime();
long estimatedRemaining = pe.getRemainingTime(count);
long estimatedTotal = elapsed + estimatedRemaining;
System.out.println("elapsed time: " + elapsed + ", estimated remaining time: " + estimatedRemaining + ", estimated total: " + estimatedTotal);
}
}
pe.stop();
System.out.println("total elapsed time: " + pe.getElapsedTime());
}
}
分享到:
相关推荐
progress-estimator:记录进度条并估算Promise完成所需的时间。 该库跟踪先前的持续时间,以便随时间提供更准确的估计。
分布式Estimator自定义模型求解;利用tensorflow框架下的tflearn来对iris进行分类代码。
主要记录了一下attitude—estimator——q中的一些内容
绝对值法估算hurst 系数
This is useful toolkit for kernel density estimator implemented in matlab.
PX4位置解算流程图local_position_estimator_main.cpp
position_estimator_inav.cpp思路整理及数据流。给出很多常见问题和解答。
A well-conditioned estimator for large-dimensional covariance matrices.pdfA well-conditioned estimator for large-dimensional covariance matrices.pdf
attitude_estimator_q_main(better).pdf attitude_estimator_q_main(better).pdf attitude_estimator_q_main(better).pdf
OLS estimator is unbiased. Variances-covariance matrix of OLS estimator. GaussMarkov Theorem: OLS estimator is BLUE
PowerPlay Early Power Estimator User Guide For Cyclone II FPGAs
when SNR is high , 1st sample estimator provides good estimate of A. it has no noise effect . so we don’t need averaging effect to reduce noise when SNR is high. However variance is still low in ...
Harvest A high-performance fundamental frequency estimator.pdf Masanori Morise
姿态互补滤波解算
几种经典的估计器程序,相对比较简单,对初学者学习很有帮助
PX4姿态解算流程图attitude_estimator_q_main.cpp
a spectral envelope estimator for high-quality speech synthesis Masanori Morise
The Intrinsic Estimator for Age-PeriodCohort Analysis What It Is and How to.pdf
The score function estimator is widely used for estimating gradients of stochastic objectives in Stochastic Computation Graphs (SCG), e.g., in reinforcement learning and meta-learning. While deriving ...
这是一份有关Altera的FPGA功率预估模型使用的一份手册。