betoesquivel

p3 DataSet

Mar 3rd, 2015
508
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.53 KB | None | 0 0
  1. package mx.itesm.a01139626.p3.src;
  2.  
  3. public class DataSet {
  4.     private double dXK;
  5.     private double dSumX;
  6.     private double dSumY;
  7.     private double dSumXY;
  8.     private double dSumX2;
  9.     private double dSumY2;
  10.     private int iN;
  11.     private double dXAvg;
  12.     private double dYAvg;
  13.     private double dR;
  14.     private double dR2;
  15.     private double dB0;
  16.     private double dB1;
  17.     private double dYK;
  18.    
  19.     /**
  20.      *  DataSet constructor to initialize all DataSet
  21.      *  values with the default 0 value.
  22.      */
  23.     public DataSet() {
  24.         this.dXK = 0;
  25.         this.dSumX = 0;
  26.         this.dSumY = 0;
  27.         this.dSumXY = 0;
  28.         this.dSumX2 = 0;
  29.         this.dSumY2 = 0;
  30.         this.iN = 0;
  31.         this.dXAvg = 0;
  32.         this.dYAvg = 0;
  33.         this.dR = 0;
  34.         this.dR2 = 0;
  35.         this.dB0 = 0;
  36.         this.dB1 = 0;
  37.         this.dYK = 0;
  38.     }
  39.    
  40.     /**
  41.      * addPair
  42.      *
  43.      * This method adds a pair to the data set, modifying all
  44.      * accumulators in the class, in order to calculate the correlation
  45.      * and the betas.
  46.      *
  47.      * @param dX
  48.      * @param dY
  49.      */
  50.     public void addPair(double dX, double dY) {
  51.         dSumX += dX;
  52.         dSumY += dY;
  53.         dSumXY += dX * dY;
  54.         dSumX2 += Math.pow(dX, 2);
  55.         dSumY2 += Math.pow(dY, 2);
  56.         iN += 1;
  57.     }
  58.    
  59.     public boolean calculate() {
  60.         if ( iN > 1 ) {
  61.             // calculate dAvgX
  62.             dXAvg = dSumX / iN;
  63.            
  64.             // calculate dAvgY
  65.             dYAvg = dSumY / iN;
  66.            
  67.             // calculate dB1
  68.             dB1 = ( dSumXY - iN * dXAvg * dYAvg ) / ( dSumX2 - iN * Math.pow(dXAvg, 2) );
  69.            
  70.             // calculate dB0
  71.             dB0 = dYAvg - dB1 * dXAvg;
  72.            
  73.             // calculate dR
  74.             dR = ( iN * dSumXY - dSumX * dSumY ) / Math.sqrt ( ( iN * dSumX2 - Math.pow(dSumX, 2) ) * ( iN * dSumY2 - Math.pow(dSumY, 2) ) );              
  75.            
  76.             // calculate dR2
  77.             dR2 = Math.pow(dR, 2);
  78.            
  79.             // calculate dYK
  80.             dYK = dB0 + dB1 * dXK;
  81.            
  82.             return true;
  83.         } else {
  84.            
  85.             return false;
  86.         }
  87.     }
  88.    
  89.     /**
  90.      * @return the dXK
  91.      */
  92.     public double getdXK() {
  93.         return dXK;
  94.     }
  95.  
  96.     /**
  97.      * @param dXK the dXK to set
  98.      */
  99.     public void setdXK(double dXK) {
  100.         this.dXK = dXK;
  101.     }
  102.  
  103.     /**
  104.      * @return the dSumX
  105.      */
  106.     public double getdSumX() {
  107.         return dSumX;
  108.     }
  109.  
  110.     /**
  111.      * @param dSumX the dSumX to set
  112.      */
  113.     public void setdSumX(double dSumX) {
  114.         this.dSumX = dSumX;
  115.     }
  116.  
  117.     /**
  118.      * @return the dSumY
  119.      */
  120.     public double getdSumY() {
  121.         return dSumY;
  122.     }
  123.  
  124.     /**
  125.      * @param dSumY the dSumY to set
  126.      */
  127.     public void setdSumY(double dSumY) {
  128.         this.dSumY = dSumY;
  129.     }
  130.  
  131.     /**
  132.      * @return the dSumXY
  133.      */
  134.     public double getdSumXY() {
  135.         return dSumXY;
  136.     }
  137.  
  138.     /**
  139.      * @param dSumXY the dSumXY to set
  140.      */
  141.     public void setdSumXY(double dSumXY) {
  142.         this.dSumXY = dSumXY;
  143.     }
  144.  
  145.     /**
  146.      * @return the dSumX2
  147.      */
  148.     public double getdSumX2() {
  149.         return dSumX2;
  150.     }
  151.  
  152.     /**
  153.      * @param dSumX2 the dSumX2 to set
  154.      */
  155.     public void setdSumX2(double dSumX2) {
  156.         this.dSumX2 = dSumX2;
  157.     }
  158.  
  159.     /**
  160.      * @return the dSumY2
  161.      */
  162.     public double getdSumY2() {
  163.         return dSumY2;
  164.     }
  165.  
  166.     /**
  167.      * @param dSumY2 the dSumY2 to set
  168.      */
  169.     public void setdSumY2(double dSumY2) {
  170.         this.dSumY2 = dSumY2;
  171.     }
  172.  
  173.     /**
  174.      * @return the iN
  175.      */
  176.     public int getiN() {
  177.         return iN;
  178.     }
  179.  
  180.     /**
  181.      * @param iN the iN to set
  182.      */
  183.     public void setiN(int iN) {
  184.         this.iN = iN;
  185.     }
  186.  
  187.     /**
  188.      * @return the dXAvg
  189.      */
  190.     public double getdXAvg() {
  191.         return dXAvg;
  192.     }
  193.  
  194.     /**
  195.      * @param dXAvg the dXAvg to set
  196.      */
  197.     public void setdXAvg(double dXAvg) {
  198.         this.dXAvg = dXAvg;
  199.     }
  200.  
  201.     /**
  202.      * @return the dYAvg
  203.      */
  204.     public double getdYAvg() {
  205.         return dYAvg;
  206.     }
  207.  
  208.     /**
  209.      * @param dYAvg the dYAvg to set
  210.      */
  211.     public void setdYAvg(double dYAvg) {
  212.         this.dYAvg = dYAvg;
  213.     }
  214.  
  215.     /**
  216.      * @return the dR
  217.      */
  218.     public double getdR() {
  219.         return dR;
  220.     }
  221.  
  222.     /**
  223.      * @param dR the dR to set
  224.      */
  225.     public void setdR(double dR) {
  226.         this.dR = dR;
  227.     }
  228.  
  229.     /**
  230.      * @return the dR2
  231.      */
  232.     public double getdR2() {
  233.         return dR2;
  234.     }
  235.  
  236.     /**
  237.      * @param dR2 the dR2 to set
  238.      */
  239.     public void setdR2(double dR2) {
  240.         this.dR2 = dR2;
  241.     }
  242.  
  243.     /**
  244.      * @return the dB0
  245.      */
  246.     public double getdB0() {
  247.         return dB0;
  248.     }
  249.  
  250.     /**
  251.      * @param dB0 the dB0 to set
  252.      */
  253.     public void setdB0(double dB0) {
  254.         this.dB0 = dB0;
  255.     }
  256.  
  257.     /**
  258.      * @return the dB1
  259.      */
  260.     public double getdB1() {
  261.         return dB1;
  262.     }
  263.  
  264.     /**
  265.      * @param dB1 the dB1 to set
  266.      */
  267.     public void setdB1(double dB1) {
  268.         this.dB1 = dB1;
  269.     }
  270.  
  271.     /**
  272.      * @return the dYK
  273.      */
  274.     public double getdYK() {
  275.         return dYK;
  276.     }
  277.  
  278.     /**
  279.      * @param dYK the dYK to set
  280.      */
  281.     public void setdYK(double dYK) {
  282.         this.dYK = dYK;
  283.     }
  284.  
  285.     public String toString() {
  286.         String sFormat = "";
  287.         return String.format(sFormat);
  288.     }
  289.    
  290.    
  291. }
Advertisement
Add Comment
Please, Sign In to add comment