Original address:
Http://blog.csdn.net/qustmeng/article/details/52186378?locationNum=4&fps=1
Import java.util.LinkedList;
Import java.util.List;
public class Demo {
/**
* Two times exponential smoothing method for predicting values
* @param list Base data collection
* @param year of the next few installments
* @param modulus Smoothing coefficient
* @return Predictive value
*/
/**
The original code setting, when the number of input data (list length) is less than 10, no calculation
*/
private static Double Getexpect (list<double> List, int year, double modulus) {
if (List.size () < | | modulus <= 0 | | modulus >= 1) {
return null;
}
Double modulusleft = 1-modulus;
Double lastIndex = list.get (0);
Double lastsecindex = list.get (0);
for (Double data:list) {
LastIndex = modulus * data + modulusleft * LASTINDEX;
Lastsecindex = modulus * lastIndex + modulusleft * LASTSECINDEX;
}
Double A = 2 * LASTINDEX-LASTSECINDEX;
Double B = (modulus/modulusleft) * (Lastindex-lastsecindex);
return a + b * year;
}
public static void Main (string[] args) {
list<double> list = new linkedlist<double> ();
List.add (30.177);
List.add (30.1762);
List.add (30.1761);
List.add (30.1763);
List.add (30.1774);
List.add (30.1766);
List.add (30.1767);
List.add (30.177);
List.add (30.179);
List.add (30.1799);
List.add (30.1813);
List.add (30.1813);
List.add (30.1816);
List.add (30.1839);
List.add (30.1847);
List.add (30.1841);
List.add (30.1824);
List.add (30.1806);
List.add (30.1802);
List.add (30.179);
List.add (30.1773);
List.add (30.1769);
List.add (30.1783);
List.add (30.1822);
List.add (30.1852);
Double value = Getexpect (list, 1, 0.6);
System.out.println (value);
}
}
:
Reprint: Two times the Java code of the exponential smoothing method for predicting the value