- Timestamp:
- 01/23/13 10:18:22 (12 years ago)
- Location:
- branches/DataAnalysis.IslandAlgorithms/HeuristicLab.Algorithms.DataAnalysis.Symbolic/3.3
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/DataAnalysis.IslandAlgorithms/HeuristicLab.Algorithms.DataAnalysis.Symbolic/3.3/HeuristicLab.Algorithms.DataAnalysis.Symbolic.csproj
r9077 r9182 99 99 <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Random-3.3.dll</HintPath> 100 100 </Reference> 101 <Reference Include="HeuristicLab.Selection-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 102 <SpecificVersion>False</SpecificVersion> 103 <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Selection-3.3.dll</HintPath> 104 </Reference> 101 105 <Reference Include="System" /> 102 106 <Reference Include="System.Core" /> -
branches/DataAnalysis.IslandAlgorithms/HeuristicLab.Algorithms.DataAnalysis.Symbolic/3.3/SymbolicDataAnalysisIslandGAEvaluator.cs
r9077 r9182 44 44 private const string FitnessCalculationPartitionParameterName = "FitnessCalculationPartition"; 45 45 private const string FixedSamplesPartitionParameterName = "FixedSamplesPartition"; 46 private const string FixedSamplesParameterName = "FixedSamples";47 private const string FixedSamplesFitnessWeightParameterName = "FixedSamplesFitnessWeight";48 46 private const string RandomSamplesParameterName = "RandomSamples"; 49 private const string RandomSamplesFitnessWeightParameterName = "RandomSamplesFitnessWeight";50 47 51 48 #region parameter properties … … 71 68 get { return (ILookupParameter<IntRange>)Parameters[FixedSamplesPartitionParameterName]; } 72 69 } 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 }79 70 public ILookupParameter<IntValue> RandomSamplesParameter { 80 71 get { return (ILookupParameter<IntValue>)Parameters[RandomSamplesParameterName]; } 81 72 } 82 public IFixedValueParameter<DoubleValue> RandomSamplesFitnessWeightParameter {83 get { return (IFixedValueParameter<DoubleValue>)Parameters[RandomSamplesFitnessWeightParameterName]; }84 }85 73 #endregion 86 74 87 #region properties88 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 #endregion97 75 98 76 [StorableConstructor] … … 114 92 Parameters.Add(new ValueLookupParameter<IntRange>(FitnessCalculationPartitionParameterName, "The data partition used to calculate the fitness")); 115 93 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)));118 94 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)));120 95 121 96 EvaluatorParameter.Hidden = true; … … 124 99 public override IOperation Apply() { 125 100 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 132 104 var samplesStart = FitnessCalculationPartitionParameter.ActualValue.Start; 133 105 var samplesEnd = FitnessCalculationPartitionParameter.ActualValue.End; … … 137 109 var maxRandomSamples = samplesEnd - samplesStart - fixedSamplesEnd + fixedSamplesStart; 138 110 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); 145 116 146 117 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); 149 120 return base.Apply(); 150 121 } -
branches/DataAnalysis.IslandAlgorithms/HeuristicLab.Algorithms.DataAnalysis.Symbolic/3.3/SymbolicDataAnalysisIslandGeneticAlgorithm.cs
r9172 r9182 27 27 using HeuristicLab.Core; 28 28 using HeuristicLab.Data; 29 using HeuristicLab.Operators; 29 30 using HeuristicLab.Optimization; 30 31 using HeuristicLab.Parameters; … … 33 34 using HeuristicLab.Problems.DataAnalysis.Symbolic; 34 35 using HeuristicLab.Random; 36 using HeuristicLab.Selection; 35 37 36 38 namespace HeuristicLab.Algorithms.DataAnalysis.Symbolic { 37 39 [Item("Symbolic DataAnalysis Island Genetic Algorithm", "A symbolic data analysis island genetic algorithm.")] 38 [Creatable(" Algorithms")]40 [Creatable("Data Analysis")] 39 41 [StorableClass] 40 42 public sealed class SymbolicDataAnalysisIslandGeneticAlgorithm : IslandGeneticAlgorithm { … … 122 124 insertionPoint.Successor = fixedSamplesPartitionCreator; 123 125 126 //necessary to reevaluate elites 127 var evaluatorPlaceHolder = new Placeholder(); 128 evaluatorPlaceHolder.OperatorParameter.ActualName = "Evaluator"; 129 130 UniformSubScopesProcessor subScopesProcessor = new UniformSubScopesProcessor(); 131 subScopesProcessor.Name = "Reevaluate elites"; 132 subScopesProcessor.Parallel.Value = true; 133 subScopesProcessor.Operator = evaluatorPlaceHolder; 134 OperatorGraph.Iterate().OfType<RightReducer>().First().Successor = subScopesProcessor; 135 124 136 RegisterParameterEvents(); 125 137 RecalculateFixedSamplesPartitions(); … … 161 173 } 162 174 163 175 164 176 private void ParameterizeAnalyzers() { 165 177 foreach (var analyzer in Analyzer.Operators.OfType<ISymbolicDataAnalysisAnalyzer>()) { … … 192 204 if (Problem is IRegressionProblem) { 193 205 var evaluator = new SymbolicDataAnalysisIslandGAEvaluator<IRegressionProblemData>(); 194 evaluator.FixedSamplesParameter.ActualName = FixedSamplesParameterName;195 206 evaluator.RandomSamplesParameter.ActualName = RandomSamplesParameterName; 196 207 EvaluatorParameter.Value = evaluator; 197 208 } else if (Problem is IClassificationProblem) { 198 209 var evaluator = new SymbolicDataAnalysisIslandGAEvaluator<IClassificationProblemData>(); 199 evaluator.FixedSamplesParameter.ActualName = FixedSamplesParameterName;200 210 evaluator.RandomSamplesParameter.ActualName = RandomSamplesParameterName; 201 211 EvaluatorParameter.Value = evaluator;
Note: See TracChangeset
for help on using the changeset viewer.