Changeset 10230 for branches/DataAnalysis.IslandAlgorithms/HeuristicLab.Algorithms.DataAnalysis.Symbolic
- Timestamp:
- 12/16/13 16:11:31 (11 years ago)
- Location:
- branches/DataAnalysis.IslandAlgorithms/HeuristicLab.Algorithms.DataAnalysis.Symbolic/3.3
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/DataAnalysis.IslandAlgorithms/HeuristicLab.Algorithms.DataAnalysis.Symbolic/3.3/ConsecutiveSamplesEvaluator.cs
r10178 r10230 47 47 private const string MaximumIterationsParameterName = "Maximum Iterations"; 48 48 49 50 49 #region parameter properties 51 50 public ILookupParameter<IDataAnalysisProblemData> ProblemDataParameter { … … 59 58 } 60 59 public ILookupParameter<IntRange> FitnessCalculationPartitionParameter { 61 get { return (I ValueLookupParameter<IntRange>)Parameters[FitnessCalculationPartitionParameterName]; }60 get { return (ILookupParameter<IntRange>)Parameters[FitnessCalculationPartitionParameterName]; } 62 61 } 63 62 public ILookupParameter<IntRange> FixedSamplesPartitionParameter { … … 128 127 var fixedSamples = FixedSamplesPartitionParameter.ActualValue; 129 128 130 //create fixed rows enumerable 131 var rows = Enumerable.Range(fixedSamples.Start, fixedSamples.Size); 132 //create consecutive rows enumerable 133 if (ConsecutiveSamples > 0) { 134 var dataMigrationInterval = DataMigrationIntervalParameter.ActualValue.Value; 135 var islandIndex = IslandIndexParameter.ActualValue.Value; 136 var generation = IterationsParameter.ActualValue.Value; 137 var iteration = islandIndex + (generation / dataMigrationInterval); 138 var consecutiveRows = GenerateRows(samples, fixedSamples, ConsecutiveSamples, Overlap, iteration); 139 rows = rows.Concat(consecutiveRows); 129 var dataMigrationInterval = DataMigrationIntervalParameter.ActualValue.Value; 130 var generationValue = IterationsParameter.ActualValue; 131 var generation = generationValue == null ? 0 : generationValue.Value; 132 133 //calculat new rows for evaluation 134 if (generation % dataMigrationInterval == 0) { 135 //create fixed rows enumerable 136 var rows = Enumerable.Range(fixedSamples.Start, fixedSamples.Size); 137 //create consecutive rows enumerable 138 if (ConsecutiveSamples > 0) { 139 var islandIndex = IslandIndexParameter.ActualValue.Value; 140 var iteration = islandIndex + (generation / dataMigrationInterval); 141 var consecutiveRows = GenerateRows(samples, fixedSamples, ConsecutiveSamples, Overlap, iteration); 142 rows = rows.Concat(consecutiveRows); 143 } 144 //filter out test rows 145 rows = rows.Where(r => r < problemData.TestPartition.Start || r > problemData.TestPartition.End); 146 147 //TODO change to lookup parameter 148 ExecutionContext.Scope.Variables.Remove("Rows"); 149 ExecutionContext.Scope.Variables.Add(new HeuristicLab.Core.Variable("Rows", new EnumerableItem<int>(rows))); 140 150 } 141 //filter out test rows142 rows = rows.Where(r => r < problemData.TestPartition.Start || r > problemData.TestPartition.End);143 151 144 //execution context is created manually to be able to clear the rows parameter easily145 152 var executionContext = new ExecutionContext(ExecutionContext, evaluator, ExecutionContext.Scope); 146 147 //TODO change to lookup parameter148 executionContext.Scope.Variables.Remove("Rows");149 executionContext.Scope.Variables.Add(new HeuristicLab.Core.Variable("Rows", new EnumerableItem<int>(rows)));150 153 var successor = evaluator.Execute(executionContext, this.CancellationToken); 151 154 return new OperationCollection(successor, base.Apply()); -
branches/DataAnalysis.IslandAlgorithms/HeuristicLab.Algorithms.DataAnalysis.Symbolic/3.3/ISymbolicDataAnalysisIslandAlgorithmEvaluator .cs
r10177 r10230 20 20 #endregion 21 21 22 using HeuristicLab.Core; 23 using HeuristicLab.Data; 22 24 using HeuristicLab.Optimization; 23 25 24 26 namespace HeuristicLab.Algorithms.DataAnalysis.Symbolic { 25 public interface ISymbolicDataAnalysisIslandGeneticAlgorithmEvaluator : ISingleObjectiveEvaluator { 27 public interface ISymbolicDataAnalysisIslandGeneticAlgorithmEvaluator : ISingleObjectiveEvaluator, IIterationBasedOperator { 28 IValueLookupParameter<IntValue> DataMigrationIntervalParameter { get; } 26 29 } 27 30 } -
branches/DataAnalysis.IslandAlgorithms/HeuristicLab.Algorithms.DataAnalysis.Symbolic/3.3/RandomSamplesEvaluator .cs
r10177 r10230 41 41 private const string FitnessCalculationPartitionParameterName = "FitnessCalculationPartition"; 42 42 private const string FixedSamplesPartitionParameterName = "FixedSamplesPartition"; 43 private const string DataMigrationIntervalParameterName = "DataMigrationInterval"; 43 44 private const string RandomSamplesParameterName = "RandomSamples"; 45 private const string IterationsParameterName = "Iterations"; 46 private const string MaximumIterationsParameterName = "Maximum Iterations"; 44 47 45 48 #region parameter properties … … 62 65 get { return (ILookupParameter<IntRange>)Parameters[FixedSamplesPartitionParameterName]; } 63 66 } 67 public IValueLookupParameter<IntValue> DataMigrationIntervalParameter { 68 get { return (IValueLookupParameter<IntValue>)Parameters[DataMigrationIntervalParameterName]; } 69 } 64 70 public IFixedValueParameter<IntValue> RandomSamplesParameter { 65 71 get { return (IFixedValueParameter<IntValue>)Parameters[RandomSamplesParameterName]; } 72 } 73 public ILookupParameter<IntValue> IterationsParameter { 74 get { return (ILookupParameter<IntValue>)Parameters[IterationsParameterName]; } 75 } 76 public IValueLookupParameter<IntValue> MaximumIterationsParameter { 77 get { return (IValueLookupParameter<IntValue>)Parameters[MaximumIterationsParameterName]; } 66 78 } 67 79 #endregion … … 93 105 Parameters.Add(new LookupParameter<IntRange>(FixedSamplesPartitionParameterName, "The data partition which is used to calculate the fitness on the fixed samples.")); 94 106 Parameters.Add(new FixedValueParameter<IntValue>(RandomSamplesParameterName, "The number of random samples used for fitness calculation in each island.", new IntValue())); 107 Parameters.Add(new ValueLookupParameter<IntValue>(DataMigrationIntervalParameterName, "The number of generations that should pass between data migration phases.")); 108 Parameters.Add(new LookupParameter<IntValue>(IterationsParameterName, "The number of performed iterations.")); 109 Parameters.Add(new ValueLookupParameter<IntValue>(MaximumIterationsParameterName, "The maximum number of performed iterations.") { Hidden = true }); 95 110 } 96 111 … … 103 118 var randomSamples = RandomSamples; 104 119 105 //create fixed rows enumerable 106 var rows = Enumerable.Range(fixedSamples.Start, fixedSamples.Size); 107 //create randomly chosen rows enumerable 108 if (randomSamples > 0) { 109 if (randomSamples > samples.Size - fixedSamples.Size) { 110 var error = string.Format("Could not select {0} random samples, because there are {1} total samples present from which {2} where used in the fixed partition. Please lower the number of random samples in the algorithm configuration.", randomSamples, samples.Size, fixedSamples.Size); 111 throw new OperatorExecutionException(this, error); 120 var dataMigrationInterval = DataMigrationIntervalParameter.ActualValue.Value; 121 var generationValue = IterationsParameter.ActualValue; 122 var generation = generationValue == null ? 0 : generationValue.Value; 123 124 //calculat new rows for evaluation 125 if (generation % dataMigrationInterval == 0) { 126 //create fixed rows enumerable 127 var rows = Enumerable.Range(fixedSamples.Start, fixedSamples.Size); 128 //create randomly chosen rows enumerable 129 if (randomSamples > 0) { 130 if (randomSamples > samples.Size - fixedSamples.Size) { 131 var error = string.Format("Could not select {0} random samples, because there are {1} total samples present from which {2} where used in the fixed partition. Please lower the number of random samples in the algorithm configuration.", randomSamples, samples.Size, fixedSamples.Size); 132 throw new OperatorExecutionException(this, error); 133 } 134 var randomRows = Enumerable.Range(samples.Start, samples.Size).Where(r => r < fixedSamples.Start || r >= fixedSamples.End); 135 randomRows = randomRows.SampleRandomWithoutRepetition(RandomParameter.ActualValue, randomSamples, samples.Size - fixedSamples.Size); 136 137 rows = rows.Concat(randomRows); 112 138 } 113 var randomRows = Enumerable.Range(samples.Start, samples.Size).Where(r => r < fixedSamples.Start || r >= fixedSamples.End); 114 randomRows = randomRows.SampleRandomWithoutRepetition(RandomParameter.ActualValue, randomSamples, samples.Size - fixedSamples.Size); 139 //filter out test rows 140 rows = rows.Where(r => r < problemData.TestPartition.Start || r > problemData.TestPartition.End); 141 ExecutionContext.Scope.Variables.Remove("Rows"); 142 ExecutionContext.Scope.Variables.Add(new HeuristicLab.Core.Variable("Rows", new EnumerableItem<int>(rows))); 143 } 115 144 116 rows = rows.Concat(randomRows);117 }118 //filter out test rows119 rows = rows.Where(r => r < problemData.TestPartition.Start || r > problemData.TestPartition.End);120 121 //execution context is created manually to be able to clear the rows parameter easily122 145 var executionContext = new ExecutionContext(ExecutionContext, evaluator, ExecutionContext.Scope); 123 124 //TODO change to lookup parameter125 executionContext.Scope.Variables.Remove("Rows");126 executionContext.Scope.Variables.Add(new HeuristicLab.Core.Variable("Rows", new EnumerableItem<int>(rows)));127 146 var successor = evaluator.Execute(executionContext, this.CancellationToken); 128 147 return new OperationCollection(successor, base.Apply()); -
branches/DataAnalysis.IslandAlgorithms/HeuristicLab.Algorithms.DataAnalysis.Symbolic/3.3/SymbolicDataAnalysisIslandGeneticAlgorithm.cs
r10177 r10230 132 132 FixedSamplesParameter.Value.ValueChanged += (o, e) => { 133 133 RecalculateFixedSamplesPartitions(); 134 ReevaluateImmigrants = FixedSamples >=Problem.FitnessCalculationPartition.Size;134 ReevaluateImmigrants = FixedSamples < Problem.FitnessCalculationPartition.Size; 135 135 }; 136 136 Analyzer.Operators.PropertyChanged += (o, e) => ParameterizeAnalyzers(); … … 162 162 private void ParameterizeEvaluator() { 163 163 var evaluator = EvaluatorParameter.Value; 164 165 var randomEvaluator = evaluator as RandomSamplesEvaluator; 166 if (randomEvaluator != null) { 167 ReevaluteElites = randomEvaluator.RandomSamples != 0; 168 } 169 170 var consecutiveEvaluator = evaluator as ConsecutiveSamplesEvaluator; 171 if (consecutiveEvaluator != null) { 172 consecutiveEvaluator.DataMigrationIntervalParameter.ActualName = MigrationIntervalParameter.Name; 173 } 164 evaluator.IterationsParameter.ActualName = "Generations"; 165 evaluator.MaximumIterationsParameter.ActualName = MaximumGenerationsParameter.Name; 166 evaluator.DataMigrationIntervalParameter.ActualName = MigrationIntervalParameter.Name; 167 168 ParameterizeStochasticOperatorForIsland(evaluator); 174 169 } 175 170 -
branches/DataAnalysis.IslandAlgorithms/HeuristicLab.Algorithms.DataAnalysis.Symbolic/3.3/SymbolicDataAnalysisIslandOffspringSelectionGeneticAlgorithm.cs
r10177 r10230 128 128 FixedSamplesParameter.Value.ValueChanged += (o, e) => { 129 129 RecalculateFixedSamplesPartitions(); 130 ReevaluateImmigrants = FixedSamples >=Problem.FitnessCalculationPartition.Size;130 ReevaluateImmigrants = FixedSamples < Problem.FitnessCalculationPartition.Size; 131 131 }; 132 132 Analyzer.Operators.PropertyChanged += (o, e) => ParameterizeAnalyzers(); … … 158 158 private void ParameterizeEvaluator() { 159 159 var evaluator = EvaluatorParameter.Value; 160 161 var randomEvaluator = evaluator as RandomSamplesEvaluator; 162 if (randomEvaluator != null) { 163 ReevaluteElites = randomEvaluator.RandomSamples != 0; 164 } 165 166 var consecutiveEvaluator = evaluator as ConsecutiveSamplesEvaluator; 167 if (consecutiveEvaluator != null) { 168 consecutiveEvaluator.DataMigrationIntervalParameter.ActualName = MigrationIntervalParameter.Name; 169 } 160 evaluator.IterationsParameter.ActualName = "Generations"; 161 evaluator.MaximumIterationsParameter.ActualName = MaximumGenerationsParameter.Name; 162 evaluator.DataMigrationIntervalParameter.ActualName = MigrationIntervalParameter.Name; 163 164 ParameterizeStochasticOperator(evaluator); 170 165 } 171 166
Note: See TracChangeset
for help on using the changeset viewer.