Changeset 4212


Ignore:
Timestamp:
07/21/08 11:15:30 (12 years ago)
Author:
nor
Message:

Modified data to be passed from double[][] to int[]

Location:
trunk/loci/slim
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/loci/slim/CurveCollection.java

    r4211 r4212  
    8181        for (int x=0; x<res; x++) { 
    8282          CurveFitter cf = new GACurveFitter(); 
    83           /* 
    8483          int[] data0 = curves[d-1][2*y][2*x].getData(); 
    8584          int[] data1 = curves[d-1][2*y][2*x+1].getData(); 
     
    9190          } 
    9291          cf.setData(data); 
    93           */ 
    9492          curves[d][y][x] = cf; 
    9593        } 
  • trunk/loci/slim/CurveFitter.java

    r4048 r4212  
    5353  /** 
    5454   * Sets the data to be used to generate curve estimates. 
    55    * The array is expected to be of size [datapoints][2]. 
    56    * [][0] contains a time value, [][1] contains the data value. 
    57    * TODO: Do I actually need the time values, or can I hardcode? 
     55   * Single dimension of data... time values are index, since 
     56   * we can assume that the datapoints are evenly spaced. 
    5857   **/ 
    59   void setData(double[][] data); 
     58  void setData(int[] data); 
    6059 
     60  /** 
     61   * Sets the data to be used to generate curve estimates. 
     62   * Single dimension of data... time values are index, since 
     63   * we can assume that the datapoints are evenly spaced. 
     64   **/ 
     65  int[] getData(); 
     66   
    6167  // TODO: Set time domain? 
    6268 
  • trunk/loci/slim/CurveFitterTester.java

    r4048 r4212  
    4040 
    4141  // Read a test file 
    42   public static double[][] curveData(BufferedReader in) throws IOException { 
     42  public static int[] curveData(BufferedReader in) throws IOException { 
    4343    in.readLine(); 
    4444    in.readLine(); 
     
    6262    } 
    6363    in.readLine(); 
    64     double[][] data = new double[datapoints][2]; 
     64    int[] data = new int[datapoints]; 
    6565    for(int i = 0; i < datapoints; i++) { 
    6666      st = new StringTokenizer(in.readLine()); 
    6767      st.nextToken(); 
    68       data[i][1] = Integer.parseInt(st.nextToken()); 
    69       data[i][0] = timeinc * (i + 1); 
     68      data[i] = Integer.parseInt(st.nextToken()); 
     69      //data[i][0] = timeinc * (i + 1); 
    7070      //System.out.println(i + ": " + data[i][1]); 
    7171    } 
     
    7777    int degrees = Integer.parseInt(args[1]); 
    7878 
    79     double[][] data = curveData(in); 
     79    int[] data = curveData(in); 
    8080    long start = System.currentTimeMillis(); 
    8181    CurveFitter cf = new GACurveFitter(); 
  • trunk/loci/slim/GACurveFitter.java

    r4048 r4212  
    4040  // -- Fields -- 
    4141 
    42   protected double[][] curveData; 
     42  protected int[] curveData; 
    4343  protected double[][] curveEstimate; 
    4444  protected int degrees; 
     
    177177    for (int i = 0; i < curveData.length; i++) { 
    178178      if (expected[i] > 0) { 
    179         double observed = curveData[i][1]; 
     179        double observed = (double) curveData[i]; 
    180180        double term = (observed - expected[i]); 
    181181        // (o-e)^2 
     
    202202  /** 
    203203   * Sets the data to be used to generate curve estimates. 
    204    * The array is expected to be of size [datapoints][2]. 
    205    * [][0] contains a time value, [][1] contains the data value. 
     204   * The array is expected to be of size datapoints 
    206205   **/ 
    207   public void setData(double[][] data) throws IllegalArgumentException { 
    208     if (data[0].length != 2) { 
    209       throw new IllegalArgumentException( 
    210           "Wrong number of elements per datapoint."); 
    211     } 
     206  public void setData(int[] data) throws IllegalArgumentException { 
    212207    curveData = data; 
     208  } 
     209 
     210  /** 
     211   * Returns a reference to the data array 
     212   * Does not create a copy. 
     213   **/  
     214  public int[] getData() { 
     215    return curveData; 
    213216  } 
    214217 
     
    228231 
    229232  // Initializes the curve fitter with a starting curve estimate. 
     233  // 7/21 EK - Changed to use 1d data rows. 
    230234  public void estimate() { 
    231235    if (degrees >= 1) { 
     
    246250      double den = 0.0; 
    247251      for (int i = 1; i < curveData.length; i++) { 
    248         if (curveData[i][1] > guessC && curveData[i-1][1] > guessC) { 
    249           double time = curveData[i][0] - curveData[i-1][0]; 
     252        if (curveData[i] > guessC && curveData[i-1] > guessC) { 
     253          //double time = curveData[i][0] - curveData[i-1][0]; 
     254          double time = 1.0d; 
    250255          double factor = 
    251             (curveData[i][1] - guessC) / (curveData[i-1][1] - guessC); 
    252           double guess = (1.0 / time) * -Math.log(factor); 
    253           num += (guess * (curveData[i][1] - guessC)); 
    254           den += curveData[i][1] - guessC; 
     256            (curveData[i] - guessC) / (curveData[i-1] - guessC); 
     257          double guess = 1.0 * -Math.log(factor); 
     258          num += (guess * (curveData[i] - guessC)); 
     259          den += curveData[i] - guessC; 
    255260        } 
    256261      } 
     
    259264      den = 0.0; 
    260265      for (int i = 0; i < curveData.length; i++) { 
    261         if (curveData[i][1] > guessC) { 
     266        if (curveData[i] > guessC) { 
    262267          // calculate e^-bt based on our exponent estimate 
    263           double value = Math.pow(Math.E, -curveData[i][0] * exp); 
     268          double value = Math.pow(Math.E, -i * exp); 
    264269          // estimate a 
    265           double guessA = curveData[i][1] / value; 
    266           num += guessA * (curveData[i][1] - guessC); 
    267           den += curveData[i][1] - guessC; 
     270          double guessA = curveData[i] / value; 
     271          num += guessA * (curveData[i] - guessC); 
     272          den += curveData[i] - guessC; 
    268273        } 
    269274      } 
     
    283288      double low = Double.MAX_VALUE; 
    284289      for (int i = 3; i < curveData.length; i++) { 
    285         if (curveData[i][1] > guessC && curveData[i-3][1] > guessC + 10) { 
    286           double time = curveData[i][0] - curveData[i-3][0]; 
     290        if (curveData[i] > guessC && curveData[i-3] > guessC + 10) { 
     291          //double time = curveData[i][0] - curveData[i-3][0]; 
     292          double time = 3.0d; 
    287293          double factor = 
    288             (curveData[i][1] - guessC) / (curveData[i-3][1] - guessC); 
    289           double guess = (1.0 / time) * -Math.log(factor); 
     294            (curveData[i] - guessC) / (curveData[i-3] - guessC); 
     295          double guess = (1.0 / 3.0) * -Math.log(factor); 
    290296          if (guess > high) high = guess; 
    291297          if (guess < low) low = guess; 
    292298        } 
    293299      } 
     300      /* 
    294301      if (10.0 > low) low = 10.0; 
    295302      if (20.0 > high) high = 20.0; 
     303      */ 
    296304      curveEstimate[0][1] = high; 
    297305      curveEstimate[1][1] = low; 
     
    300308      double lowA = Double.MAX_VALUE; 
    301309      for (int i = 0; i < curveData.length; i++) { 
    302         if (curveData[i][1] > guessC + 10) { 
     310        if (curveData[i] > guessC + 10) { 
    303311          // calculate e^-bt based on our exponent estimate 
    304           double value = Math.pow(Math.E, -curveData[i][0] * low); 
     312          double value = Math.pow(Math.E, -i * low); 
    305313          // estimate a 
    306           double guessA = curveData[i][1] / value; 
     314          double guessA = curveData[i] / value; 
    307315          if (guessA > highA) highA = guessA; 
    308316          if (guessA < lowA) lowA = guessA; 
    309317        } 
    310318      } 
     319      /* 
    311320      if (10.0 > lowA) lowA = 10.0; 
    312321      if (20.0 > highA) highA = 20.0; 
     322      */ 
    313323      curveEstimate[0][0] = highA - lowA; 
    314324      curveEstimate[1][0] = lowA; 
     
    324334      double[][] lowValues = new double[curveData.length][2]; 
    325335      for (int i = 0; i < lowValues.length; i++) { 
    326         lowValues[i][0] = curveData[i][0]; 
    327         lowValues[i][1] = curveData[i][1] - lowData[i]; 
     336        lowValues[i][0] = i; 
     337        lowValues[i][1] = curveData[i] - lowData[i]; 
    328338      } 
    329339 
     
    401411  // -- Helper methods -- 
    402412 
    403   private double[] getEstimates(double[][] data, double[][] estimate) { 
     413  private double[] getEstimates(int[] data, double[][] estimate) { 
    404414    double[] toreturn = new double[data.length]; 
    405415    for (int i = 0; i < toreturn.length; i++) { 
     
    407417      for (int j = 0; j < estimate.length; j++) { 
    408418        // e^-bt 
    409         double term = Math.pow(Math.E, -estimate[j][1] * data[i][0]); 
     419        double term = Math.pow(Math.E, -estimate[j][1] * i); 
    410420        // ae^-bt 
    411421        term *= estimate[j][0]; 
     
    430440    for (int i = 0; i < curveData.length; i++) { 
    431441      if (expected[i] > 0) { 
    432         double observed = curveData[i][1]; 
     442        double observed = curveData[i]; 
    433443        double term = (observed - expected[i]); 
    434444        // (o-e)^2 
Note: See TracChangeset for help on using the changeset viewer.