Changeset 4233


Ignore:
Timestamp:
07/23/08 11:13:38 (12 years ago)
Author:
nor
Message:

Modified CurveFitters to have first and last indices
Moved constants out of the iterate method of GACurveFitter

Location:
trunk/loci/slim
Files:
3 edited

Legend:

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

    r4216 r4233  
    9696  void setCurve(double[][] curve); 
    9797 
     98  void setFirst(int firstindex); 
     99 
     100  void setLast(int lastindex); 
    98101} 
  • trunk/loci/slim/GACurveFitter.java

    r4225 r4233  
    4747  protected double currentRCSE; 
    4848  protected int stallGenerations; 
     49  protected int firstindex; 
     50  protected int lastindex; 
     51  private double mutationFactor; 
    4952 
    5053  private static final boolean DEBUG = false; 
     54   
     55  private static final int STALL_GENERATIONS = 5; 
     56  private static final double STALLED_FACTOR = 2.0d; 
     57  private static final double MUTATION_CHANCE = .25d; 
     58  private static final int SPECIMENS = 25; 
     59  // Must be 0 < x < 1 
     60  private static final double INITIAL_MUTATION_FACTOR = .5;  
     61  // Must be 0 < x < 1 
     62  private static final double MUTATION_FACTOR_REDUCTION = .9; 
    5163   
    5264  // -- Constructor -- 
     
    6072    currentRCSE = Double.MAX_VALUE; 
    6173    stallGenerations = 0; 
     74    mutationFactor = INITIAL_MUTATION_FACTOR; 
    6275  } 
    6376 
     
    7891 
    7992    // TODO: Move these out, reuse them. Synchronized? 
    80     double[][][] newGeneration = new double[25][degrees][3]; 
     93    double[][][] newGeneration = new double[SPECIMENS][degrees][3]; 
    8194    Random r = new Random(); 
    8295 
     
    8699    // Additionally, if we haven't improved for a number of generations, 
    87100    // shake things up. 
    88     if (geneticData == null || fitness == null || stallGenerations > 10) { 
     101    if (geneticData == null || fitness == null || stallGenerations > STALL_GENERATIONS) { 
    89102      stallGenerations = 0; 
     103      mutationFactor *= MUTATION_FACTOR_REDUCTION; 
    90104      for (int i = 1; i < newGeneration.length; i++) { 
    91105        for (int j = 0; j < degrees; j++) { 
    92106          for (int k = 0; k < 3; k++) { 
    93             double factor = r.nextDouble() * 2.0d; 
     107            double factor = r.nextDouble() * STALLED_FACTOR; 
    94108            newGeneration[i][j][k] = curveEstimate[j][k] * factor; 
    95109          } 
     
    137151          for (int k = 0; k < 3; k++) { 
    138152            // mutate, if necessary 
    139             if (r.nextDouble() < .25) { 
    140               newGeneration[i][j][k] *= (.9 + r.nextDouble() * .2); 
     153            if (r.nextDouble() < MUTATION_CHANCE) { 
     154              newGeneration[i][j][k] *=  
     155                ((1.0 - mutationFactor) + r.nextDouble() * (2.0 * mutationFactor)); 
    141156            } 
    142157          } 
     
    488503  } 
    489504 
     505  public void setFirst(int index) { 
     506    firstindex = index; 
     507  } 
     508 
     509  public void setLast(int index) { 
     510    lastindex = index; 
     511  } 
     512 
    490513} 
  • trunk/loci/slim/LMCurveFitter.java

    r4222 r4233  
    205205  } 
    206206 
    207  
     207  // TODO: Dummy methods to implement CurveFitter 
     208  public void setFirst(int index) {} 
     209 
     210  public void setLast(int index) {} 
     211   
    208212} 
Note: See TracChangeset for help on using the changeset viewer.