Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/23/13 10:18:22 (12 years ago)
Author:
mkommend
Message:

#1997: Added reevaluation of elits to symbolic data analysis island ga and changed evaluator to combine the fixed and random samples.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/DataAnalysis.IslandAlgorithms/HeuristicLab.Algorithms.DataAnalysis.Symbolic/3.3/SymbolicDataAnalysisIslandGAEvaluator.cs

    r9077 r9182  
    4444    private const string FitnessCalculationPartitionParameterName = "FitnessCalculationPartition";
    4545    private const string FixedSamplesPartitionParameterName = "FixedSamplesPartition";
    46     private const string FixedSamplesParameterName = "FixedSamples";
    47     private const string FixedSamplesFitnessWeightParameterName = "FixedSamplesFitnessWeight";
    4846    private const string RandomSamplesParameterName = "RandomSamples";
    49     private const string RandomSamplesFitnessWeightParameterName = "RandomSamplesFitnessWeight";
    5047
    5148    #region parameter properties
     
    7168      get { return (ILookupParameter<IntRange>)Parameters[FixedSamplesPartitionParameterName]; }
    7269    }
    73     public ILookupParameter<IntValue> FixedSamplesParameter {
    74       get { return (ILookupParameter<IntValue>)Parameters[FixedSamplesParameterName]; }
    75     }
    76     public IFixedValueParameter<DoubleValue> FixedSamplesFitnessWeightParameter {
    77       get { return (IFixedValueParameter<DoubleValue>)Parameters[FixedSamplesFitnessWeightParameterName]; }
    78     }
    7970    public ILookupParameter<IntValue> RandomSamplesParameter {
    8071      get { return (ILookupParameter<IntValue>)Parameters[RandomSamplesParameterName]; }
    8172    }
    82     public IFixedValueParameter<DoubleValue> RandomSamplesFitnessWeightParameter {
    83       get { return (IFixedValueParameter<DoubleValue>)Parameters[RandomSamplesFitnessWeightParameterName]; }
    84     }
    8573    #endregion
    8674
    87     #region properties
    88     public double FixedSamplesFitnessWeight {
    89       get { return FixedSamplesFitnessWeightParameter.Value.Value; }
    90       set { FixedSamplesFitnessWeightParameter.Value.Value = value; }
    91     }
    92     public double RandomSamplesFitnessWeight {
    93       get { return RandomSamplesFitnessWeightParameter.Value.Value; }
    94       set { RandomSamplesFitnessWeightParameter.Value.Value = value; }
    95     }
    96     #endregion
    9775
    9876    [StorableConstructor]
     
    11492      Parameters.Add(new ValueLookupParameter<IntRange>(FitnessCalculationPartitionParameterName, "The data partition used to calculate the fitness"));
    11593      Parameters.Add(new LookupParameter<IntRange>(FixedSamplesPartitionParameterName, "The data partition which is used to calculate the fitness on the fixed samples."));
    116       Parameters.Add(new LookupParameter<IntValue>(FixedSamplesParameterName, "The number of fixed samples used for fitness calculation in each island."));
    117       Parameters.Add(new FixedValueParameter<DoubleValue>(FixedSamplesFitnessWeightParameterName, "The weight of the fitness obtained on the fixed samples.", new DoubleValue(1)));
    11894      Parameters.Add(new LookupParameter<IntValue>(RandomSamplesParameterName, "The number of random samples used for fitness calculation in each island."));
    119       Parameters.Add(new FixedValueParameter<DoubleValue>(RandomSamplesFitnessWeightParameterName, "The weight of the fitness obtained on the random samples.", new DoubleValue(1)));
    12095
    12196      EvaluatorParameter.Hidden = true;
     
    12499    public override IOperation Apply() {
    125100      var evaluator = EvaluatorParameter.ActualValue;
    126       //calculate fitness on fixed samples
    127       if (QualityParameter.ActualValue == null) {
    128         var operation = ExecutionContext.CreateOperation(evaluator, ExecutionContext.Scope);
    129         return new OperationCollection() { operation, ExecutionContext.CreateOperation(this) };
    130       }
    131       //calculate fitness on random samples;
     101      var tree = SymbolicExpressionTreeParameter.ActualValue;
     102      var problemData = ProblemDataParameter.ActualValue;
     103
    132104      var samplesStart = FitnessCalculationPartitionParameter.ActualValue.Start;
    133105      var samplesEnd = FitnessCalculationPartitionParameter.ActualValue.End;
     
    137109      var maxRandomSamples = samplesEnd - samplesStart - fixedSamplesEnd + fixedSamplesStart;
    138110
    139       var rows = Enumerable.Range(samplesStart, samplesEnd - samplesStart).Where(r => r < fixedSamplesStart || r >= fixedSamplesEnd);
    140       rows = rows.SampleRandomWithoutRepetition(RandomParameter.ActualValue, randomSamples, maxRandomSamples);
    141 
    142       var fixedSamplesFitness = QualityParameter.ActualValue.Value;
    143       var tree = SymbolicExpressionTreeParameter.ActualValue;
    144       var problemData = ProblemDataParameter.ActualValue;
     111      //create rows for evaluation
     112      var fixedRows = Enumerable.Range(fixedSamplesStart, fixedSamplesEnd - fixedSamplesStart);
     113      var randomRows = Enumerable.Range(samplesStart, samplesEnd - samplesStart).Where(r => r < fixedSamplesStart || r >= fixedSamplesEnd);
     114      randomRows = randomRows.SampleRandomWithoutRepetition(RandomParameter.ActualValue, randomSamples, maxRandomSamples);
     115      var rows = fixedRows.Concat(randomRows);
    145116
    146117      var executionContext = new ExecutionContext(ExecutionContext, evaluator, ExecutionContext.Scope);
    147       var randomSamplesFitness = evaluator.Evaluate(executionContext, tree, problemData, rows);
    148       QualityParameter.ActualValue.Value = fixedSamplesFitness * FixedSamplesFitnessWeight + randomSamplesFitness * RandomSamplesFitnessWeight;
     118      var fitness = evaluator.Evaluate(executionContext, tree, problemData, rows);
     119      QualityParameter.ActualValue = new DoubleValue(fitness);
    149120      return base.Apply();
    150121    }
Note: See TracChangeset for help on using the changeset viewer.