Changeset 4338


Ignore:
Timestamp:
08/30/08 01:40:04 (12 years ago)
Author:
nor
Message:

Documentation improvements

Location:
trunk/loci/slim
Files:
4 edited

Legend:

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

    r4323 r4338  
    3030 
    3131/** 
    32  * TODO 
    3332 * 
    3433 * <dl><dt><b>Source code:</b></dt> 
     
    7675  } 
    7776 
     77  /** Set the number of exponentials to fit */ 
    7878  public void setComponentCount(int numExp) { 
    7979    numExponentials = numExp; 
     
    8282  } 
    8383 
     84  /** Repeatedly update the image for this renderer, updating based on 
     85   *  improvements from the curve fitters 
     86   */ 
    8487  public void run() { 
    8588    alive = true; 
    8689    // initial pass - estimates 
     90    // First, go through on all the subsample levels and do an estimate 
     91    // for each curve in each subsample level. 
     92    // If stop is called, alive will be set to false, and we'll drop out. 
     93     
    8794    while(subsampleLevel >= 0 && alive && !estimated) { 
    8895      currentCurves = curveData.getCurves(subsampleLevel); 
    8996      while(currentY < currentDim && alive) { 
    9097        while(currentX < currentDim && alive) { 
    91           //System.out.println("ssl: " + subsampleLevel + " x: " + currentX + " y: " + currentY); 
    9298          // HACKY CRAP: GET RID OF THIS IN FINAL VERSION OR SUFFER 
    9399          int[] cdata = currentCurves[currentY][currentX].getData(); 
     
    101107          } 
    102108          currentCurves[currentY][currentX].setFirst(maxIndex); 
    103           //System.out.println("Set first to " + maxIndex); 
    104109          // END HACKY CRAP 
    105110          currentCurves[currentY][currentX].estimate(); 
    106111          //currentCurves[currentY][currentX].iterate(); 
    107112          // This only really matters for the last subsampleLevel 
     113          // We want to initialize a cache of the RCSEs, so we can quickly 
     114          // find the worst one without a lot of function calls. 
    108115          if(subsampleLevel == 0) { 
    109116            double newRCSE = currentCurves[currentY][currentX].getReducedChiSquaredError(); 
    110117            rcsecache[currentY][currentX] = newRCSE; 
    111118          } 
     119          // Order the exponentials. 
    112120          double[][] curve = currentCurves[currentY][currentX].getCurve(); 
    113121          double[] exponentials = new double[numExponentials]; 
    114122          for(int i = 0; i < numExponentials; i++) { 
    115123            exponentials[i] = curve[i][1]; 
    116             //System.out.println("b" + i + ": " + exponentials[i]); 
    117124          } 
    118125          Arrays.sort(exponentials); 
    119            
     126          // Update the image  
    120127          int pixelsize = maxDim / currentDim; 
    121128          for(int x = 0; x < pixelsize; x++) { 
     
    125132                int indexb = ((currentY * pixelsize + y) * maxDim) + (currentX * pixelsize + x); 
    126133                image[indexa][indexb] = exponentials[c]; 
    127                 //System.out.println("Setting image[" + indexa + "][" + indexb + "] to " + exponentials[c]); 
    128                 //image[numExponentials-c-1][((currentY * pixelsize + y) * maxDim) + 
    129                 //                           (currentX * pixelsize + x)] = exponentials[c]; 
    130134              } 
    131135            } 
     
    149153    } 
    150154    // initial pass - iterations 
     155    // Pass through the image a given number of times, calling iterate() 
    151156    maxIterations = 1; // TEMP? 
    152157    while(alive && !improving) { 
     
    163168          currProgress = (currentX * maxDim) + currentY; 
    164169          while(currentIterations < maxIterations) { 
    165             //System.out.println("x: " + currentX + " y: " + currentY + " iter: " + currentIterations); 
    166170            currentIterations++; 
    167171            double currRCSE = currentCurves[currentY][currentX].getReducedChiSquaredError(); 
     
    192196    } 
    193197    // continuing improvement 
    194     //System.out.println("Got to continuing"); 
     198    // Find the worst RCSE, and iterate. Repeat. 
    195199    while(alive) { 
    196200      improving = true; 
     
    224228        for(int c = 0; c < numExponentials; c++) { 
    225229          image[numExponentials-c-1][currentY * maxDim + currentX] = exponentials[c]; 
    226           //image[numExponentials-c-1][currentY * maxDim + currentX] = 1; 
    227         } 
    228       } 
    229       //System.out.println("x: " + currentX + "  y: " + currentY + "   RCSE: " + currentCurves[currentY][currentX].getReducedChiSquaredError()); 
    230     } 
    231   } 
    232  
     230        } 
     231      } 
     232    } 
     233  } 
     234 
     235  /** Return the current image */ 
    233236  public double[][] getImage() { 
    234237    return image; 
    235238  } 
    236239 
     240  /** Return the current X being worked on */ 
    237241  public int getImageX() { 
    238242    return (currentX * (maxDim/currentDim)) + ((maxDim/currentDim) / 2); 
    239243  } 
    240244 
     245  /** Return the current Y being worked on */ 
    241246  public int getImageY() { 
    242247    return (currentY * (maxDim/currentDim)) + ((maxDim/currentDim) / 2); 
    243248  } 
    244249 
     250  /** Get the current worst RCSE */ 
    245251  public double getWorstRCSE() { 
    246252    return worstRCSE; 
  • trunk/loci/slim/CurveFitter.java

    r4239 r4338  
    4444   * iterate() runs through one iteration of whatever curve fitting 
    4545   * technique this curve fitter uses. This will generally update the 
    46    * information returned by getCurve and getChiSquaredError. 
     46   * information returned by getCurve and getChiSquaredError.  
     47   * Specifically, it will usually update curveEstimate. 
    4748   */ 
    4849  public abstract void iterate(); 
     
    6667  }  
    6768 
     69  /** Returns the Chi Squared Error of a given curve estimate */ 
    6870  public double getChiSquaredError(double[][] estCurve) { 
    6971    double total = 0.0d; 
     
    99101  }  
    100102   
     103  /** Returns the Reduced Chi Squared Error of a given curve estimate 
     104   *  See getReducedChiSquaredError() for details. 
     105   */ 
    101106  public double getReducedChiSquaredError(double[][] estCurve) { 
    102107    int df = 1 + (estCurve.length * 2); 
     
    108113  } 
    109114 
     115  /** Returns expected values for a given curve estimate. */ 
    110116  public double[] getEstimates(int[] data, double[][] estimate) { 
    111117    double[] toreturn = new double[data.length]; 
     
    155161   * For each exponential of the form ae^-bt+c, 
    156162   * [][0] is a, [1] is b, [2] is c. 
    157    * TODO: Make multiple exponentials a class, to remove multi-c stupidity 
    158163   */ 
    159164  public abstract double[][] getCurve(); 
     
    166171  public abstract void setCurve(double[][] curve); 
    167172 
     173  /** Set the first index of the data that is the actual curve */ 
    168174  public abstract void setFirst(int firstindex); 
    169175 
     176  /** Set the last index of the data that is the actual curve */ 
    170177  public abstract void setLast(int lastindex); 
    171178} 
  • trunk/loci/slim/GACurveFitter.java

    r4323 r4338  
    7777  // -- CurveFitter API methods -- 
    7878 
    79   // TODO: The set methods do not create internal copies of the passed 
    80   //       arrays. Should they? 
    81  
    8279  /** 
    8380   * iterate() runs through one iteration of whatever curve fitting 
     
    8885    if (currentRCSE == Double.MAX_VALUE) estimate(); 
    8986 
    90     // TODO: Move these out, reuse them. Synchronized? 
    9187    double[][][] newGeneration = new double[SPECIMENS][components][3]; 
    9288    Random r = new Random(); 
     
    137133        } 
    138134        double minfluence = r.nextDouble(); 
     135        // Combine the mother and father in random percentages 
    139136        for (int j = 0; j < components; j++) { 
    140137          for (int k = 0; k < 3; k++) { 
     
    184181      } 
    185182    } 
    186     /* 
    187     System.out.println("RCSE: " + currentRCSE); 
    188     for(int j = 0; j < components; j++) { 
    189       System.out.println("a: " + curveEstimate[j][0] + " b: " + curveEstimate[j][1] + " c: " + curveEstimate[j][2]); 
    190     } 
    191     */ 
    192183  } 
    193184 
     
    226217  // Initializes the curve fitter with a starting curve estimate. 
    227218  public void estimate() { 
    228     /* 
    229     System.out.println("****** DATA ******"); 
    230     for(int i = 0; i < curveData.length; i++) { 
    231       System.out.println("i: " + i + "  data: " + curveData[i]); 
    232     } 
    233     */ 
    234     //try { Thread.sleep(1000); } catch(Exception e) {} 
     219    // For single component, we're just going to take guesses along the 
     220    // curve as to what the exponent is, and use that for our estimate. 
    235221    if (components >= 1) { 
    236       // TODO: Estimate c, factor it in below. 
    237  
     222      // Guess that c is the minimum data value. 
    238223      double guessC = Double.MAX_VALUE; 
    239224      for (int i = firstindex; i < curveData.length && i < lastindex; i++) { 
    240225        if (curveData[i] < guessC) guessC = curveData[i]; 
    241226      } 
    242  
    243       //double guessC = 0.0d; 
    244227 
    245228      // First, get a guess for the exponent. 
     
    248231      double num = 0.0; 
    249232      double den = 0.0; 
    250       //for (int i = 1; i < curveData.length; i++) { 
    251233      for (int i = firstindex + 1; i < curveData.length && i < lastindex; i++) { 
    252234        if (curveData[i] > guessC && curveData[i-1] > guessC) { 
    253           //double time = curveData[i][0] - curveData[i-1][0]; 
    254235          double time = 1.0d; 
    255236          double factor = 
     
    287268     
    288269    if (components == 2) { 
     270      // For 2 components, we're going to guess what the first exponent is 
     271      // based on the front end of the curve, which is usually the higher 
     272      // exponential. Then, we'll subtract that out, and get a guess for 
     273      // the second. 
    289274      double guessC = Double.MAX_VALUE; 
    290       //for(int i = 0; i < curveData.length; i++) { 
    291275      for (int i = firstindex; i < curveData.length && i < lastindex; i++) { 
    292276        if(curveData[i] < guessC) guessC = curveData[i]; 
     
    301285      for (int i = firstindex + 3; i < lastindex && i < curveData.length; i++) { 
    302286        if (curveData[i] > guessC && curveData[i-3] > guessC + 10) { 
    303           //double time = curveData[i][0] - curveData[i-3][0]; 
    304287          double time = 3.0d; 
    305288          double factor = 
     
    325308        } 
    326309      } 
    327       /* 
    328       if (10.0 > lowA) lowA = 10.0; 
    329       if (20.0 > highA) highA = 20.0; 
    330       */ 
    331310      curveEstimate[0][0] = highA - lowA; 
    332311      curveEstimate[1][0] = lowA; 
     
    393372      if(curveEstimate[i][1] < 0) { 
    394373        doNegativeEstimation = true; 
    395         //System.out.println("Negative factor " + curveEstimate[i][1] + " found."); 
    396374      } 
    397375    } 
     
    414392        } 
    415393      } 
    416       //System.out.println("maxIndex: " + maxIndex + "  minIndex: " + minIndex); 
    417394      // If we have valid min and max data, perform the "estimate" 
    418395      double expguess = -1; 
     
    444421        expguess = 1; 
    445422      } 
    446       //System.out.println("Estimating: " + expguess); 
    447       //System.out.println("maxData: " + maxData + "  firstindex: " + firstindex + "  data: " + curveData[firstindex]); 
    448423      if(components == 1) { 
    449424        curveEstimate[0][0] = maxData - minData; 
     
    503478  } 
    504479 
     480  // Set the beginning of the curve 
    505481  public void setFirst(int index) { 
    506482    firstindex = index; 
    507483  } 
    508484 
     485  // Set the end of the curve 
    509486  public void setLast(int index) { 
    510487    lastindex = index; 
  • trunk/loci/slim/Renderer.java

    r4302 r4338  
    2626 
    2727/** 
    28  * TODO 
    29  * 
    3028 * <dl><dt><b>Source code:</b></dt> 
    3129 * <dd><a href="https://skyking.microscopy.wisc.edu/trac/java/browser/trunk/loci/slim/Renderer.java">Trac</a>, 
     
    4947  protected int numExponentials; 
    5048 
     49  /** 
     50   * The renderer's run method should use the curve collection and somehow 
     51   * continually update the image array returned by getImage() 
     52   * The method for this is left to the sub class. The idea is that the 
     53   * image should get better the longer it is run, so some sort of iterative 
     54   * approach is best. 
     55   * The run method should set alive to true at the beginning, and run until 
     56   * stop is called (and alive is set to false) 
     57   **/ 
    5158  public abstract void run(); 
    5259 
     60  /** Called to stop the run() method. */ 
    5361  public void stop() { 
    5462    alive = false; 
    5563  } 
    5664 
     65  /** Constructor. Get the curve collection to generate the image from */ 
    5766  public Renderer(CurveCollection cc) { 
    5867    curveData = cc; 
    5968  } 
    6069 
     70  // Accessor methods 
     71   
    6172  public int getCurrentIterations() { 
    6273    return currentIterations; 
     
    103114  } 
    104115 
     116  /** Return the current rendered image */ 
    105117  public abstract double[][] getImage(); 
    106118 
     
    109121  } 
    110122 
     123  /** Get the X coordinate currently being improved */ 
    111124  public abstract int getImageX(); 
    112125 
     126  /** Get the Y coordinate currently being improved */ 
    113127  public abstract int getImageY(); 
    114128 
     129  /** Get the current worst RCSE for any curve in the collection */ 
    115130  public abstract double getWorstRCSE(); 
    116131} 
Note: See TracChangeset for help on using the changeset viewer.