Changeset 4219


Ignore:
Timestamp:
07/22/08 12:01:02 (12 years ago)
Author:
nor
Message:

Fixes to curve fitting:

  • Work around for negative tau issue
  • Fixed incorrect constant estimate on 2 component curves
  • Fixed a value estimate by using only early curve values
  • Other suck-reducing fixes
File:
1 edited

Legend:

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

    r4214 r4219  
     1// TODO: Tau cannot be negative. >_< 
    12// 
    23// GACurveFitter.java 
     
    169170      } 
    170171    } 
     172    for(int q = 0; q < curveEstimate.length; q++) { 
     173      System.out.println("c" + q + ": " + curveEstimate[q][2]); 
     174    } 
    171175  } 
    172176 
    173177  // Returns the Chi Squared Error of the current curve estimate 
    174178  public double getChiSquaredError() { 
     179    System.out.println("**********"); 
    175180    double total = 0.0d; 
    176181    double[] expected = getEstimates(curveData, curveEstimate); 
     
    183188        // (o-e)^2 / e 
    184189        term /= expected[i]; 
    185         //System.out.println("Obs: " + observed + 
    186         //  " Expect: " + expected[i] + " Term: " + term); 
     190        System.out.println("Obs: " + observed + 
     191          " Expect: " + expected[i] + " Term: " + term); 
    187192        total += term; 
    188193      } 
     
    235240    if (degrees >= 1) { 
    236241      // TODO: Estimate c, factor it in below. 
    237       /* 
     242       
    238243      double guessC = Double.MAX_VALUE; 
    239244      for (int i = 0; i < curveData.length; i++) { 
    240         if (curveData[i][1] < guessC) guessC = curveData[i][1]; 
    241       } 
    242       */ 
    243  
    244       double guessC = 0.0d; 
     245        if (curveData[i] < guessC) guessC = curveData[i]; 
     246      } 
     247       
     248 
     249      //double guessC = 0.0d; 
    245250 
    246251      // First, get a guess for the exponent. 
     
    256261            (curveData[i] - guessC) / (curveData[i-1] - guessC); 
    257262          double guess = 1.0 * -Math.log(factor); 
     263          System.out.println("Guess: " + guess + "   Factor: " + factor); 
    258264          num += (guess * (curveData[i] - guessC)); 
    259265          den += curveData[i] - guessC; 
     
    261267      } 
    262268      double exp = num/den; 
     269      System.out.println("Final exp guess: " + exp); 
    263270      num = 0.0; 
    264271      den = 0.0; 
    265       for (int i = 0; i < curveData.length; i++) { 
     272      // Hacky... we would like to do this over the entire curve length, 
     273      // but the actual data is far too noisy to do this. Instead, we'll just 
     274      // do it for the first 5, which have the most data. 
     275      //for (int i = 0; i < curveData.length; i++) { 
     276      for(int i = 0; i < 5; i++) { 
    266277        if (curveData[i] > guessC) { 
    267278          // calculate e^-bt based on our exponent estimate 
    268279          double value = Math.pow(Math.E, -i * exp); 
    269280          // estimate a 
    270           double guessA = curveData[i] / value; 
     281          double guessA = (curveData[i] - guessC) / value; 
    271282          num += guessA * (curveData[i] - guessC); 
    272283          den += curveData[i] - guessC; 
     284          System.out.println("Data: " + curveData[i] + " Value: " + value + " guessA: " + guessA); 
    273285        } 
    274286      } 
     
    279291    } 
    280292    if (degrees == 2) { 
    281       double guessC = 0.0d; 
     293      double guessC = Double.MAX_VALUE; 
     294      for(int i = 0; i < curveData.length; i++) { 
     295        if(curveData[i] < guessC) guessC = curveData[i]; 
     296      } 
    282297      curveEstimate[0][2] = guessC; 
    283       curveEstimate[1][2] = guessC; 
     298      curveEstimate[1][2] = 0; 
    284299 
    285300      // First, get a guess for the exponents. 
     
    307322      double highA = 0.0d; 
    308323      double lowA = Double.MAX_VALUE; 
    309       for (int i = 0; i < curveData.length; i++) { 
     324      //for (int i = 0; i < curveData.length; i++) { 
     325      for(int i = 0; i < 5; i++) { 
    310326        if (curveData[i] > guessC + 10) { 
    311327          // calculate e^-bt based on our exponent estimate 
     
    354370      num = 0.0; 
    355371      den = 0.0; 
    356       for (int i = 0; i < lowValues.length; i++) { 
     372      //for (int i = 0; i < lowValues.length; i++) { 
     373      for(int i = 0; i < 5; i++) { 
    357374        if (lowValues[i][1] > guessC) { 
    358375          // calculate e^-bt based on our exponent estimate 
     
    375392      // For now, however, this produces reasonably good estimates, good 
    376393      // enough to start the GA process. 
     394 
     395      // Fix bug where the estimate occasionally produces negative 
     396      // tau values. If this happens, we'll sort it out in iteration. 
     397      if(curveEstimate[0][1] <= 0) curveEstimate[0][1] = 2000; 
     398      if(curveEstimate[1][1] <= 0) curveEstimate[1][1] = 800; 
     399       
    377400 
    378401    } 
Note: See TracChangeset for help on using the changeset viewer.