EMlab-generation Documentation  1.0
Documentation of the EMLab-Generation model.
TrendEstimator.java
1 /*******************************************************************************
2  * Copyright 2012 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  ******************************************************************************/
16 package emlab.gen.util;
17 
18 
19 import org.apache.commons.math.stat.regression.SimpleRegression;
20 
21 public class TrendEstimator {
22 
23 
24  public static double[] estimateLinearTrend(double[][] input, double[] predictionYears){
25  ;
26  //Get logarithm of second trend
27  SimpleRegression sr = new SimpleRegression();
28  sr.addData(input);
29  double result[] = new double[predictionYears.length];
30  for(int i = 0 ; i<result.length; i++){
31  result[i]=sr.predict(predictionYears[i]);
32  }
33  return result;
34 
35  }
36 
37 
38  public static double[] estimateGeometricTrend(double[][] input, double[] predictionYears){
39  //Get logarithm of second trend
40  for(int i=0;i<input.length;i++){
41  input[i][1]=Math.log(input[i][1]);
42  }
43  //input[1]=log;
44  SimpleRegression sr = new SimpleRegression();
45  sr.addData(input);
46  double result[] = new double[predictionYears.length];
47  for(int i = 0 ; i<result.length; i++){
48  result[i]=Math.exp(sr.predict(predictionYears[i]));
49  }
50  return result;
51 
52  }
53 
54 }