Changeset 4235


Ignore:
Timestamp:
07/23/08 11:48:23 (12 years ago)
Author:
curtis
Message:

Normalize exponential component count methods in various places.

Location:
trunk/loci/slim
Files:
8 edited

Legend:

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

    r4225 r4235  
    3030 
    3131/** 
     32 * TODO 
    3233 * 
    3334 * <dl><dt><b>Source code:</b></dt> 
     
    4243  protected int currentDim; 
    4344  protected double[][] image; 
    44   protected int maxdim; 
     45  protected int maxDim; 
    4546  private boolean estimated; 
    4647  private boolean improving; 
     
    5455    currentIterations = 0; 
    5556    currProgress = 0; 
    56     //maxdim = Math.pow(2, subsampleLevel); 
    57     maxdim = 1 << subsampleLevel; 
    58     maxProgress = 2 * maxdim * maxdim - 1; 
    59     image = new double[1][maxdim*maxdim]; 
     57    maxDim = 1 << subsampleLevel; // 2^subsampleLevel 
     58    maxProgress = 2 * maxDim * maxDim - 1; 
     59    image = new double[1][maxDim*maxDim]; 
    6060    alive = false; 
    61     ready = true; 
    6261    maxIterations = Integer.MAX_VALUE; 
    6362    maxRCSE = 1.0d; 
     
    6867  } 
    6968 
    70   public void setComponentCount(int degrees) { 
    71     image = new double[degrees][maxdim*maxdim]; 
     69  public void setComponentCount(int numExp) { 
     70    numExponentials = numExp; 
     71    image = new double[numExponentials][maxDim*maxDim]; 
     72    curveData.setComponentCount(numExponentials); 
    7273  } 
    7374 
     
    7879      while(currentY < currentDim && alive) { 
    7980        while(currentX < currentDim && alive) { 
    80           currentCurves[currentY][currentX].setDegrees(numExponentials); 
    8181          currentCurves[currentY][currentX].estimate(); 
    8282          double[][] curve = currentCurves[currentY][currentX].getCurve(); 
     
    8686          } 
    8787          Arrays.sort(exponentials); 
    88           int pixelsize = maxdim / currentDim; 
     88          int pixelsize = maxDim / currentDim; 
    8989          for(int x = 0; x < pixelsize; x++) { 
    9090            for(int y = 0; y < pixelsize; y++) { 
    9191              for(int c = 0; c < numExponentials; c++) { 
    92                 image[numExponentials-c-1][((currentY * pixelsize + y) * maxdim) + 
     92                image[numExponentials-c-1][((currentY * pixelsize + y) * maxDim) + 
    9393                                           (currentX * pixelsize + x)] = exponentials[c]; 
    9494              } 
     
    131131            } 
    132132            Arrays.sort(exponentials); 
    133             int pixelsize = maxdim / currentDim; 
     133            int pixelsize = maxDim / currentDim; 
    134134            for(int x = 0; x < pixelsize; x++) { 
    135135              for(int y = 0; y < pixelsize; y++) { 
    136136                for(int c = 0; c < numExponentials; c++) { 
    137                   image[numExponentials-c-1][((currentY * pixelsize + y) * maxdim) + 
     137                  image[numExponentials-c-1][((currentY * pixelsize + y) * maxDim) + 
    138138                    (currentX * pixelsize + x)] = exponentials[c]; 
    139139                } 
     
    152152      int worsty = -1; 
    153153      double worstval = 0; 
    154       for(int x = 0; x < maxdim; x++) { 
    155         for(int y = 0; y < maxdim; y++) { 
     154      for(int x = 0; x < maxDim; x++) { 
     155        for(int y = 0; y < maxDim; y++) { 
    156156          if(currentCurves[y][x].getReducedChiSquaredError() > worstval) { 
    157157            worstval = currentCurves[y][x].getReducedChiSquaredError(); 
     
    172172 
    173173  public int getImageX() { 
    174     return (currentX * (maxdim/currentDim)) + ((maxdim/currentDim) / 2); 
     174    return (currentX * (maxDim/currentDim)) + ((maxDim/currentDim) / 2); 
    175175  } 
    176176 
    177177  public int getImageY() { 
    178     return (currentY * (maxdim/currentDim)) + ((maxdim/currentDim) / 2); 
     178    return (currentY * (maxDim/currentDim)) + ((maxDim/currentDim) / 2); 
    179179  } 
    180180 
  • trunk/loci/slim/CurveCollection.java

    r4231 r4235  
    4949  protected CurveFitter[][][] curves; 
    5050 
    51   // -- Constructor -- 
     51  // -- Constructors -- 
    5252 
    5353  /** 
     
    142142  public int getSubsamplingDepth() { return curves.length - 1; } 
    143143 
     144  /** 
     145   * Sets how many exponentials are expected to be fitted. 
     146   * Currently, more than 2 is not supported. 
     147   */ 
     148  public void setComponentCount(int numExp) { 
     149    int depth = curves.length; 
     150    int numRows = curves[0].length; 
     151    int numCols = curves[0][0].length; 
     152    for (int d=0; d<depth; d++) { 
     153      for (int y=0; y<numRows; y++) { 
     154        for (int x=0; x<numCols; x++) { 
     155          curves[d][y][x].setComponentCount(numExp); 
     156        } 
     157      } 
     158    } 
     159  } 
     160 
    144161  // -- Utility methods -- 
    145162 
     
    149166  { 
    150167    int numRows = data.length; 
    151     int numCols = data.length; 
    152     int timeBins = data.length; 
     168    int numCols = data[0].length; 
     169    int timeBins = data[0][0].length; 
    153170 
    154171    if (binRadius > 0) { 
     
    157174      for (int y=0; y<numRows; y++) { 
    158175        for (int x=0; x<numCols; x++) { 
    159           for (int b=0; b<timeBins; b++) { 
     176          for (int t=0; t<timeBins; t++) { 
    160177            int sum = 0; 
    161178            for (int dy=y-binRadius; dy<=y+binRadius; dy++) { 
     
    165182                if (dx < 0) continue; 
    166183                if (dx >= numCols) break; 
    167                 sum += data[dy][dx][b]; 
     184                sum += data[dy][dx][t]; 
    168185              } 
    169186            } 
    170             binnedData[y][x][b] = sum; 
     187            binnedData[y][x][t] = sum; 
    171188          } 
    172189        } 
  • trunk/loci/slim/CurveFitter.java

    r4233 r4235  
    3939   * iterate() runs through one iteration of whatever curve fitting 
    4040   * technique this curve fitter uses. This will generally update the 
    41    * information returned by getCurve and getChiSquaredError 
    42    **/ 
     41   * information returned by getCurve and getChiSquaredError. 
     42   */ 
    4343  void iterate(); 
    4444 
    45   // Returns the Chi Squared Error of the current curve estimate 
     45  /** Returns the Chi Squared Error of the current curve estimate. */ 
    4646  double getChiSquaredError(); 
    4747 
    48   // Returns the Reduced Chi Squared Error of the current curve estimate 
    49   // This is based on the number of datapoints in data and the number 
    50   // of exponentials in setDegrees 
     48  /** 
     49   * Returns the Reduced Chi Squared Error of the current curve estimate 
     50   * This is based on the number of datapoints in data and the number 
     51   * of exponentials in setComponentCount. 
     52   */ 
    5153  double getReducedChiSquaredError(); 
    5254 
     
    5557   * Single dimension of data... time values are index, since 
    5658   * we can assume that the datapoints are evenly spaced. 
    57    **/ 
     59   */ 
    5860  void setData(int[] data); 
    5961 
     
    6264   * Single dimension of data... time values are index, since 
    6365   * we can assume that the datapoints are evenly spaced. 
    64    **/ 
     66   */ 
    6567  int[] getData(); 
    66    
    67   // TODO: Set time domain? 
    6868 
    69   /** 
    70    * Sets how many exponentials are expected to be fitted. 
    71    * Currently, more than 2 is not supported. 
    72    * TODO: Change Degrees to exponentials or whatever 
    73    **/ 
    74   void setDegrees(int degrees); 
     69  /** Sets how many exponentials are expected to be fitted. */ 
     70  void setComponentCount(int numExp); 
    7571 
    76   // Returns the number of exponentials to be fitted. 
    77   int getDegrees(); 
     72  /** Returns the number of exponentials to be fitted. */ 
     73  int getComponentCount(); 
    7874 
    79   // Initializes the curve fitter with a starting curve estimate. 
     75  /** Initializes the curve fitter with a starting curve estimate. */ 
    8076  void estimate(); 
    8177 
     
    8682   * [][0] is a, [1] is b, [2] is c. 
    8783   * TODO: Make multiple exponentials a class, to remove multi-c stupidity 
    88    **/ 
     84   */ 
    8985  double[][] getCurve(); 
    9086 
     
    9389   * curve is already known. 
    9490   * See getCurve for information about the array to pass. 
    95    **/ 
     91   */ 
    9692  void setCurve(double[][] curve); 
    9793 
  • trunk/loci/slim/CurveFitterTester.java

    r4212 r4235  
    7575  public static void main(String[] args) throws Exception { 
    7676    BufferedReader in = new BufferedReader(new FileReader(args[0])); 
    77     int degrees = Integer.parseInt(args[1]); 
     77    int numExp = Integer.parseInt(args[1]); 
    7878 
    7979    int[] data = curveData(in); 
     
    8181    CurveFitter cf = new GACurveFitter(); 
    8282    // TODO: Change this to test all of the test data. 
    83     cf.setDegrees(degrees); 
     83    cf.setComponentCount(numExp); 
    8484    cf.setData(data); 
    8585    cf.estimate(); 
  • trunk/loci/slim/GACurveFitter.java

    r4233 r4235  
    4242  protected int[] curveData; 
    4343  protected double[][] curveEstimate; 
    44   protected int degrees; 
     44  protected int numExponentials; 
    4545  protected double[][][] geneticData; 
    4646  protected double[] fitness; 
     
    6666  public GACurveFitter() { 
    6767    curveData = null; 
    68     degrees = 1; 
    69     curveEstimate = new double[degrees][3]; 
     68    numExponentials = 1; 
     69    curveEstimate = new double[numExponentials][3]; 
    7070    geneticData = null; 
    7171    fitness = null; 
     
    9191 
    9292    // TODO: Move these out, reuse them. Synchronized? 
    93     double[][][] newGeneration = new double[SPECIMENS][degrees][3]; 
     93    double[][][] newGeneration = new double[SPECIMENS][numExponentials][3]; 
    9494    Random r = new Random(); 
    9595 
     
    103103      mutationFactor *= MUTATION_FACTOR_REDUCTION; 
    104104      for (int i = 1; i < newGeneration.length; i++) { 
    105         for (int j = 0; j < degrees; j++) { 
     105        for (int j = 0; j < numExponentials; j++) { 
    106106          for (int k = 0; k < 3; k++) { 
    107107            double factor = r.nextDouble() * STALLED_FACTOR; 
     
    110110        } 
    111111      } 
    112       for (int j = 0; j < degrees; j++) { 
     112      for (int j = 0; j < numExponentials; j++) { 
    113113        for (int k = 0; k < 3; k++) { 
    114114          newGeneration[0][j][k] = curveEstimate[j][k]; 
     
    139139        } 
    140140        double minfluence = r.nextDouble(); 
    141         for (int j = 0; j < degrees; j++) { 
     141        for (int j = 0; j < numExponentials; j++) { 
    142142          for (int k = 0; k < 3; k++) { 
    143143            newGeneration[q][j][k] = 
     
    148148      } 
    149149      for (int i = 0; i < newGeneration.length; i++) { 
    150         for (int j = 0; j < degrees; j++) { 
     150        for (int j = 0; j < numExponentials; j++) { 
    151151          for (int k = 0; k < 3; k++) { 
    152152            // mutate, if necessary 
     
    180180      stallGenerations = 0; 
    181181      currentRCSE = best; 
    182       for (int j = 0; j < degrees; j++) { 
     182      for (int j = 0; j < numExponentials; j++) { 
    183183        for (int k = 0; k < 3; k++) { 
    184184          curveEstimate[j][k] = geneticData[bestindex][j][k]; 
     
    213213 
    214214  public double getReducedChiSquaredError() { 
    215     int df = 1 + (degrees * 2); 
     215    int df = 1 + (numExponentials * 2); 
    216216    int datapoints = curveData.length; 
    217217    if (datapoints - df > 0) { 
     
    241241   * Currently, more than 2 is not supported. 
    242242   **/ 
    243   public void setDegrees(int deg) { 
    244     degrees = deg; 
    245     curveEstimate = new double[deg][3]; 
    246   } 
    247  
    248   // Returns the number of exponentials to be fitted. 
    249   public int getDegrees() { 
    250     return degrees; 
     243  public void setComponentCount(int numExp) { 
     244    numExponentials = numExp; 
     245    curveEstimate = new double[numExponentials][3]; 
     246  } 
     247 
     248  public int getComponentCount() { 
     249    return numExponentials; 
    251250  } 
    252251 
     
    254253  // 7/21 EK - Changed to use 1d data rows. 
    255254  public void estimate() { 
    256     if (degrees >= 1) { 
     255    if (numExponentials >= 1) { 
    257256      // TODO: Estimate c, factor it in below. 
    258257 
     
    309308      if (curveEstimate[0][1] <= 0) curveEstimate[0][1] = 1000; 
    310309    } 
    311     if (degrees == 2) { 
     310    if (numExponentials == 2) { 
    312311      double guessC = Double.MAX_VALUE; 
    313312      for(int i = 0; i < curveData.length; i++) { 
     
    438437   **/ 
    439438  public void setCurve(double[][] curve) { 
    440     if (curve.length != degrees) { 
    441       throw new IllegalArgumentException("Incorrect number of degrees."); 
     439    if (curve.length != numExponentials) { 
     440      throw new IllegalArgumentException("Incorrect number of exponentials."); 
    442441    } 
    443442    if (curve[0].length != 3) { 
     
    495494 
    496495  private double getReducedChiSquaredError(double[][] estCurve) { 
    497     int df = 1 + (degrees * 2); 
     496    int df = 1 + (numExponentials * 2); 
    498497    int datapoints = curveData.length; 
    499498    if (datapoints - df > 0) { 
  • trunk/loci/slim/LMCurveFitter.java

    r4233 r4235  
    4545 
    4646  protected ExpFunction func; 
    47   protected int numExp = 1; 
     47  protected int numExponentials = 1; 
    4848  protected double[][] curve; 
    4949  protected double chi2; 
     
    5656  // -- Constructor -- 
    5757 
    58   public LMCurveFitter() { setDegrees(1); } 
     58  public LMCurveFitter() { setComponentCount(1); } 
    5959 
    6060  // -- LMCurveFitter API methods -- 
     
    7474  /** Gets chi squared error scaled by degrees of freedom. */ 
    7575  public double getReducedChiSquaredError() { 
    76     return chi2 / (data.length - 2 * numExp - 1); 
     76    return chi2 / (data.length - 2 * numExponentials - 1); 
    7777  } 
    7878 
     
    9595 
    9696  /** Sets the number of components in the fit. Must be 1 or 2. */ 
    97   public void setDegrees(int deg) { 
    98     if (deg < 1 || deg > 2) { 
     97  public void setComponentCount(int numExp) { 
     98    if (numExp < 1 || numExp > 2) { 
    9999      throw new IllegalArgumentException("Number of degrees must be 1 or 2"); 
    100100    } 
    101     numExp = deg; 
    102     func = new ExpFunction(numExp); 
     101    numExponentials = numExp; 
     102    func = new ExpFunction(numExponentials); 
    103103  } 
    104104 
    105105  /** Gets the number of components in the fit. */ 
    106   public int getDegrees() { return numExp; } 
     106  public int getComponentCount() { return numExponentials; } 
    107107 
    108108  /** HACK - performs the actual fit. */ 
     
    110110    int num = data.length; 
    111111    final float[] guess = {num / 10, num / 5}; 
    112     float[] params = new float[2 * numExp + 1]; 
    113     for (int i=0; i<numExp; i++) { 
     112    float[] params = new float[2 * numExponentials + 1]; 
     113    for (int i=0; i<numExponentials; i++) { 
    114114      int e = 2 * i; 
    115       params[e] = maxVal / numExp; 
     115      params[e] = maxVal / numExponentials; 
    116116      params[e + 1] = guess[i]; // ? 
    117117    } 
     
    126126 
    127127    // store parameters into curve array 
    128     curve = new double[numExp][3]; 
    129     for (int i=0; i<numExp; i++) { 
     128    curve = new double[numExponentials][3]; 
     129    for (int i=0; i<numExponentials; i++) { 
    130130      int e = 2 * i; 
    131131      curve[i][0] = lma.parameters[e]; // a 
    132132      curve[i][1] = lma.parameters[e + 1]; // b 
    133133    } 
    134     curve[0][2] = lma.parameters[2 * numExp]; // c 
     134    curve[0][2] = lma.parameters[2 * numExponentials]; // c 
    135135  } 
    136136 
  • trunk/loci/slim/Renderer.java

    r4225 r4235  
    3737 
    3838  protected boolean alive; 
    39   protected boolean ready; 
    4039  protected int maxIterations; 
    4140  protected double maxRCSE; 
     
    106105  public abstract double[][] getImage(); 
    107106 
    108   public void setComponentCount(int degrees) { 
    109     numExponentials = degrees; 
     107  public void setComponentCount(int numExp) { 
     108    numExponentials = numExp; 
    110109  } 
    111110 
  • trunk/loci/slim/SlimPlotter.java

    r4229 r4235  
    11651165            data[i] = (int) samps[timeBins * cc + maxPeak + i]; 
    11661166          } 
    1167           fitter.setDegrees(numExp); 
     1167          fitter.setComponentCount(numExp); 
    11681168          fitter.setData(data); 
    11691169          fitter.estimate(); 
Note: See TracChangeset for help on using the changeset viewer.