Package org.apache.commons.math.stat.regression

Examples of org.apache.commons.math.stat.regression.SimpleRegression


  }
 
  SimpleRegression make(IList dataValues){
    if(dataValues.length() <= 2)
      throw RuntimeExceptionFactory.illegalArgument(dataValues, null, null, "SimpleRegression data should have more than 2 elements");
    SimpleRegression simple = new SimpleRegression();
    for(IValue v : dataValues){
      ITuple t = (ITuple) v;
      INumber x = (INumber) t.get(0);
      INumber y = (INumber) t.get(1);
      simple.addData(x.toReal().doubleValue(), y.toReal().doubleValue());
    }
    return simple;
  }
View Full Code Here


     * @return Returns Pearson's correlation coefficient for the two arrays
     * @throws  IllegalArgumentException if the arrays lengths do not match or
     * there is insufficient data
     */
    public double correlation(final double[] xArray, final double[] yArray) throws IllegalArgumentException {
        SimpleRegression regression = new SimpleRegression();
        if (xArray.length != yArray.length) {
            throw new DimensionMismatchException(xArray.length, yArray.length);
        } else if (xArray.length < 2) {
            throw MathRuntimeException.createIllegalArgumentException(
                  LocalizedFormats.INSUFFICIENT_DIMENSION, xArray.length, 2);
        } else {
            for(int i=0; i<xArray.length; i++) {
                regression.addData(xArray[i], yArray[i]);
            }
            return regression.getR();
        }
    }
View Full Code Here

      }
    }
   
    System.out.println(bigBag.entropy());
    Map<String,Double> saves = new HashMap<String,Double>();
    SimpleRegression sr = new SimpleRegression();
    for(String s : bigBag.getList()) {
      Bag<String> b = index.get(s);
      //double entropy = b.entropy();
      //double crossEntropy = b.crossEntropy(bigBag);
      //double compressionSaves = (crossEntropy - entropy);
      //System.out.println(s + "\t" + bigBag.getCount(s) + "\t" + entropy + "\t" + compressionSaves);
      //saves.put(s, mutualInformation(bigBag, b));
      //Bag<String> bb = new Bag<String>(b);
      //bb.discardInfrequent(10);
      //if(bb.size() == 0) continue;
      System.out.println(s + "\t" + b.totalCount() + "\t" + b.size());
      sr.addData(Math.log(b.totalCount()), Math.log(b.size()));
    }
    System.out.println(sr.getRSquare());
    double m = sr.getSlope();
    double c = sr.getIntercept();
    for(String s : bigBag.getList()) {
      Bag<String> b = index.get(s);
      saves.put(s, m * Math.log(b.totalCount()) + c - Math.log(b.size()));
    }
   
View Full Code Here

   */
  public static SimpleRegression getRegre(double[] xs, double[] ys){
    if(xs.length != ys.length){
      throw new SSErrorXelException(SSError.NA);
    }else{
      SimpleRegression sr = new SimpleRegression();
      for(int i =0; i < xs.length; i++){
        sr.addData(xs[i], ys[i]);
      }
      return sr;
    }
   
  }
View Full Code Here

      if(evolData == null)
      {
        continue;
      }
     
      SimpleRegression positive = new SimpleRegression();
      SimpleRegression negative = new SimpleRegression();
     
      for(int i=0; i<evolData.m_positiveXPoints.size(); i++)
      {
        positive.addData(evolData.m_positiveXPoints.get(i), evolData.m_positiveYPoints.get(i));
      }
     
      for(int i=0; i<evolData.m_negativeXPoints.size(); i++)
      {
        negative.addData(evolData.m_negativeXPoints.get(i),evolData. m_negativeYPoints.get(i));
      }
     
      logger.debug("Number of negative points: " + evolData.m_negativeXPoints.size());
      logger.debug("Number of positive points: " + evolData.m_positiveXPoints.size());
     
      double nSlope = negative.getSlope();
      double pSlope = positive.getSlope();
     
      if(evolData.m_positiveXPoints.size() < 2 || evolData.m_positiveXPoints.size() < 2)
      {
        //throw new EvaluationException(" Not enough points. Need atleast 2 points to draw a line. ");
        logger.error(" Not enough points. Need atleast 2 points to draw a line. ");
        continue;
      }
         
      if(Math.abs(nSlope) <= Math.abs(pSlope))
      {
        throw new EvaluationException(" Negative regression line slope (" + nSlope
            + ") is less than positive regression line slope (" + pSlope + ").");
      }
         
      logger.debug("Evaluation passed. Negative regression line slope=" + negative.getSlope()
          + ". Positive regression line slope=" + positive.getSlope());

    }
  }
View Full Code Here

     * @return Returns Pearson's correlation coefficient for the two arrays
     * @throws  IllegalArgumentException if the arrays lengths do not match or
     * there is insufficient data
     */
    public double correlation(final double[] xArray, final double[] yArray) throws IllegalArgumentException {
        SimpleRegression regression = new SimpleRegression();
        if(xArray.length == yArray.length && xArray.length > 1) {
            for(int i=0; i<xArray.length; i++) {
                regression.addData(xArray[i], yArray[i]);
            }
            return regression.getR();
        }
        else {
            throw MathRuntimeException.createIllegalArgumentException(
                    "invalid array dimensions. xArray has size {0}; yArray has {1} elements",
                    xArray.length, yArray.length);
View Full Code Here

     * @return Returns Pearson's correlation coefficient for the two arrays
     * @throws  IllegalArgumentException if the arrays lengths do not match or
     * there is insufficient data
     */
    public double correlation(final double[] xArray, final double[] yArray) throws IllegalArgumentException {
        SimpleRegression regression = new SimpleRegression();
        if(xArray.length == yArray.length && xArray.length > 1) {
            for(int i=0; i<xArray.length; i++) {
                regression.addData(xArray[i], yArray[i]);
            }
            return regression.getR();
        }
        else {
            throw MathRuntimeException.createIllegalArgumentException(
                    "invalid array dimensions. xArray has size {0}; yArray has {1} elements",
                    xArray.length, yArray.length);
View Full Code Here

    for (int i = 0; i < list.size() - 1; i++) {
      RTs point1 = list.get(i);
      RTs point2 = list.get(i + 1);
      if (point1.RT < point2.RT - 2) {
        SimpleRegression regression = new SimpleRegression();
        regression.addData(point1.RT, point1.RT2);
        regression.addData(point2.RT, point2.RT2);
        double rt = point1.RT + 1;
        while (rt < point2.RT) {
          RTs newPoint = new RTs(rt, regression.predict(rt));
          list.add(newPoint);
          rt++;
        }

      }
View Full Code Here

    for (int i = 0; i < list.size() - 1; i++) {
      RTs point1 = list.get(i);
      RTs point2 = list.get(i + 1);
      if (point1.RT < point2.RT - 2) {
        SimpleRegression regression = new SimpleRegression();
        regression.addData(point1.RT, point1.RT2);
        regression.addData(point2.RT, point2.RT2);
        double rt = point1.RT + 1;
        while (rt < point2.RT) {
          RTs newPoint = new RTs(rt, regression.predict(rt));
          list.add(newPoint);
          rt++;
        }

      }
View Full Code Here

TOP

Related Classes of org.apache.commons.math.stat.regression.SimpleRegression

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.