Github user R-Rajkumar commented on a diff in the pull request:
https://github.com/apache/stratos/pull/382#discussion_r35234743
--- Diff:
extensions/cep/stratos-cep-extension/src/main/java/org/apache/stratos/cep/extension/CurveFitter.java
---
@@ -0,0 +1,41 @@
+package org.apache.stratos.cep.extension;
+
+
+import org.apache.commons.math3.fitting.PolynomialCurveFitter;
+import org.apache.commons.math3.fitting.WeightedObservedPoints;
+import org.apache.log4j.Logger;
+
+public class CurveFitter {
+ private final Logger log = Logger.getLogger(CurveFitter.class);
+ private double[] timeStampValues;
+ private double[] dataValues;
+
+ public CurveFitter(double[] timeStampValues, double[] dataValues){
+ this.timeStampValues = timeStampValues;
+ this.dataValues = dataValues;
+ }
+
+
+ /**
+ *fit the XValues and dataValues into a second order polynomial
+ * @return the coefficient array of the polynomial
+ */
+ public double[] fit(){
+ WeightedObservedPoints weightedObservedPoints = new
WeightedObservedPoints();
+
+ for(int i = 0 ; i < timeStampValues.length && i <
dataValues.length ; i++){
+ weightedObservedPoints.add(timeStampValues[i], dataValues[i]);
+ }
+
+ /**
+ * create second degree polynomials from the observed points
+ */
+ final PolynomialCurveFitter polynomialCurveFitter =
PolynomialCurveFitter.create(2);
+ final double[] coefficients =
polynomialCurveFitter.fit(weightedObservedPoints.toList());
+
+ log.info("Coefficients a : " + coefficients[0] + " b : " +
coefficients[1] + " c : " + coefficients[2]);
+
+ return coefficients;
+ }
+
+}
--- End diff --
add the licence header to this class
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---