Changeset 4236


Ignore:
Timestamp:
07/23/08 12:34:14 (12 years ago)
Author:
nor
Message:

updated (hopefully) for first and last indices

File:
1 edited

Legend:

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

    r4235 r4236  
    6565 
    6666  public GACurveFitter() { 
     67    initialize(); 
     68  } 
     69 
     70  public void initialize() { 
    6771    curveData = null; 
    6872    numExponentials = 1; 
     
    7579  } 
    7680 
     81   
    7782  // -- CurveFitter API methods -- 
    7883 
     
    196201    double total = 0.0d; 
    197202    double[] expected = getEstimates(curveData, curveEstimate); 
    198     for (int i = 0; i < curveData.length; i++) { 
     203    for (int i = firstindex; i < curveData.length && i <= lastindex; i++) { 
    199204      if (expected[i] > 0) { 
    200205        double observed = (double) curveData[i]; 
     
    227232  public void setData(int[] data) { 
    228233    curveData = data; 
     234    firstindex = 0; 
     235    lastindex = data.length - 1; 
    229236  } 
    230237 
     
    251258 
    252259  // Initializes the curve fitter with a starting curve estimate. 
    253   // 7/21 EK - Changed to use 1d data rows. 
    254260  public void estimate() { 
    255261    if (numExponentials >= 1) { 
     
    257263 
    258264      double guessC = Double.MAX_VALUE; 
    259       for (int i = 0; i < curveData.length; i++) { 
     265      for (int i = firstindex; i < curveData.length && i < lastindex; i++) { 
    260266        if (curveData[i] < guessC) guessC = curveData[i]; 
    261267      } 
     
    268274      double num = 0.0; 
    269275      double den = 0.0; 
    270       for (int i = 1; i < curveData.length; i++) { 
     276      //for (int i = 1; i < curveData.length; i++) { 
     277      for (int i = firstindex + 1; i < curveData.length && i < lastindex; i++) { 
    271278        if (curveData[i] > guessC && curveData[i-1] > guessC) { 
    272279          //double time = curveData[i][0] - curveData[i-1][0]; 
     
    288295      // do it for the first 5, which have the most data. 
    289296      //for (int i = 0; i < curveData.length; i++) 
    290       for(int i = 0; i < 5; i++) { 
     297      for(int i = firstindex; i < 5 + firstindex && i < curveData.length; i++) { 
    291298        if (curveData[i] > guessC) { 
    292299          // calculate e^-bt based on our exponent estimate 
     
    310317    if (numExponentials == 2) { 
    311318      double guessC = Double.MAX_VALUE; 
    312       for(int i = 0; i < curveData.length; i++) { 
     319      //for(int i = 0; i < curveData.length; i++) { 
     320      for (int i = firstindex; i < curveData.length && i < lastindex; i++) { 
    313321        if(curveData[i] < guessC) guessC = curveData[i]; 
    314322      } 
     
    320328      double high = 0.0d; 
    321329      double low = Double.MAX_VALUE; 
    322       for (int i = 3; i < curveData.length; i++) { 
     330      for (int i = firstindex + 3; i < lastindex && i < curveData.length; i++) { 
    323331        if (curveData[i] > guessC && curveData[i-3] > guessC + 10) { 
    324332          //double time = curveData[i][0] - curveData[i-3][0]; 
     
    340348      double highA = 0.0d; 
    341349      double lowA = Double.MAX_VALUE; 
    342       //for (int i = 0; i < curveData.length; i++) 
    343       for(int i = 0; i < 5; i++) { 
     350      for(int i = firstindex; i < 5 + firstindex && i < curveData.length; i++) { 
    344351        if (curveData[i] > guessC + 10) { 
    345352          // calculate e^-bt based on our exponent estimate 
     
    365372      lowEst[0][1] = curveEstimate[1][1]; 
    366373      lowEst[0][2] = curveEstimate[1][2]; 
    367       double[] lowData = getEstimates(curveData, lowEst); 
    368       double[][] lowValues = new double[curveData.length][2]; 
     374      int[] cdata = new int[lastindex - firstindex + 1]; 
     375      System.arraycopy(curveData, firstindex, cdata, 0, cdata.length); 
     376      double[] lowData = getEstimates(cdata, lowEst); 
     377      double[][] lowValues = new double[cdata.length][2]; 
    369378      for (int i = 0; i < lowValues.length; i++) { 
    370379        lowValues[i][0] = i; 
    371         lowValues[i][1] = curveData[i] - lowData[i]; 
     380        lowValues[i][1] = cdata[i] - lowData[i]; 
    372381      } 
    373382 
     
    450459  // -- Helper methods -- 
    451460 
     461  // TODO: Do I actually need the data anymore? 
    452462  private double[] getEstimates(int[] data, double[][] estimate) { 
    453463    double[] toreturn = new double[data.length]; 
     
    474484  } 
    475485 
     486  // Split this stuff out into a CurveUtils class 
    476487  private double getChiSquaredError(double[][] estCurve) { 
    477488    double total = 0.0d; 
    478489    double[] expected = getEstimates(curveData, estCurve); 
    479     for (int i = 0; i < curveData.length; i++) { 
     490    for (int i = firstindex; i < curveData.length && i <= lastindex; i++) { 
    480491      if (expected[i] > 0) { 
    481492        double observed = curveData[i]; 
Note: See TracChangeset for help on using the changeset viewer.