Changeset 10579 for branches/DataAnalysis.IslandAlgorithms/HeuristicLab.Algorithms.DataAnalysis.Symbolic
- Timestamp:
- 03/12/14 15:23:47 (11 years ago)
- Location:
- branches/DataAnalysis.IslandAlgorithms/HeuristicLab.Algorithms.DataAnalysis.Symbolic/3.3
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/DataAnalysis.IslandAlgorithms/HeuristicLab.Algorithms.DataAnalysis.Symbolic/3.3/ConsecutiveSamplesEvaluator.cs
r10421 r10579 20 20 #endregion 21 21 22 using System; 22 23 using System.Collections.Generic; 23 24 using System.Linq; … … 131 132 var generation = generationValue == null ? 0 : generationValue.Value; 132 133 133 //calculat new rows for evaluation 134 if (dataMigrationInterval != 0 && 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 consecutiveSamples = (int)(ConsecutiveSamples * samples.Size); 142 var overlap = (int)Overlap * consecutiveSamples; 143 var consecutiveRows = GenerateRows(samples, fixedSamples, consecutiveSamples, overlap, iteration); 144 rows = rows.Concat(consecutiveRows); 145 } 146 //filter out test rows 147 rows = rows.Where(r => r < problemData.TestPartition.Start || r > problemData.TestPartition.End); 134 if (ConsecutiveSamples > 0 && dataMigrationInterval == 0) 135 throw new ArgumentException("The data migration interval must not be 0 if consecutive samples are used."); 148 136 149 //TODO change to lookup parameter 150 ExecutionContext.Scope.Variables.Remove("Rows"); 151 ExecutionContext.Scope.Variables.Add(new HeuristicLab.Core.Variable("Rows", new EnumerableItem<int>(rows))); 137 //create fixed rows enumerable 138 var rows = Enumerable.Range(fixedSamples.Start, fixedSamples.Size); 139 //create consecutive rows enumerable 140 if (ConsecutiveSamples > 0) { 141 var islandIndex = IslandIndexParameter.ActualValue.Value; 142 var iteration = islandIndex + (generation / dataMigrationInterval); 143 var consecutiveSamples = (int)(ConsecutiveSamples * samples.Size); 144 var overlap = (int)Overlap * consecutiveSamples; 145 var consecutiveRows = GenerateRows(samples, fixedSamples, consecutiveSamples, overlap, iteration); 146 rows = rows.Concat(consecutiveRows); 152 147 } 148 //filter out test rows 149 rows = rows.Where(r => r < problemData.TestPartition.Start || r > problemData.TestPartition.End); 150 151 //TODO change to lookup parameter 152 ExecutionContext.Scope.Variables.Remove("Rows"); 153 ExecutionContext.Scope.Variables.Add(new HeuristicLab.Core.Variable("Rows", new EnumerableItem<int>(rows))); 153 154 154 155 var executionContext = new ExecutionContext(ExecutionContext, evaluator, ExecutionContext.Scope); -
branches/DataAnalysis.IslandAlgorithms/HeuristicLab.Algorithms.DataAnalysis.Symbolic/3.3/RandomSamplesEvaluator .cs
r10421 r10579 20 20 #endregion 21 21 22 using System; 22 23 using System.Linq; 23 24 using HeuristicLab.Common; … … 25 26 using HeuristicLab.Data; 26 27 using HeuristicLab.Operators; 27 using HeuristicLab.Optimization;28 28 using HeuristicLab.Parameters; 29 29 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; … … 34 34 namespace HeuristicLab.Algorithms.DataAnalysis.Symbolic { 35 35 [StorableClass] 36 public sealed class RandomSamplesEvaluator : SingleSuccessorOperator, IStochasticOperator, ISymbolicDataAnalysisIslandGeneticAlgorithmEvaluator { 37 private const string RandomParameterName = "Random"; 36 public sealed class RandomSamplesEvaluator : SingleSuccessorOperator, ISymbolicDataAnalysisIslandGeneticAlgorithmEvaluator { 38 37 private const string ProblemDataParameterName = "ProblemData"; 39 38 private const string EvaluatorParameterName = "ProblemEvaluator"; … … 43 42 private const string DataMigrationIntervalParameterName = "DataMigrationInterval"; 44 43 private const string RandomSamplesParameterName = "RandomSamples"; 44 private const string IslandIndexParameterName = "IslandIndex"; 45 45 private const string IterationsParameterName = "Iterations"; 46 46 private const string MaximumIterationsParameterName = "Maximum Iterations"; 47 47 48 48 #region parameter properties 49 public ILookupParameter<IRandom> RandomParameter {50 get { return (ILookupParameter<IRandom>)Parameters[RandomParameterName]; }51 }52 49 public ILookupParameter<IDataAnalysisProblemData> ProblemDataParameter { 53 50 get { return (ILookupParameter<IDataAnalysisProblemData>)Parameters[ProblemDataParameterName]; } … … 70 67 public IFixedValueParameter<PercentValue> RandomSamplesParameter { 71 68 get { return (IFixedValueParameter<PercentValue>)Parameters[RandomSamplesParameterName]; } 69 } 70 public ILookupParameter<IntValue> IslandIndexParameter { 71 get { return (ILookupParameter<IntValue>)Parameters[IslandIndexParameterName]; } 72 72 } 73 73 public ILookupParameter<IntValue> IterationsParameter { … … 98 98 public RandomSamplesEvaluator() 99 99 : base() { 100 Parameters.Add(new LookupParameter<IRandom>(RandomParameterName, "The random generator to use."));101 100 Parameters.Add(new LookupParameter<IDataAnalysisProblemData>(ProblemDataParameterName, "The problem data on which the symbolic data analysis solution should be evaluated.")); 102 101 Parameters.Add(new LookupParameter<IOperator>(EvaluatorParameterName, "The evaluator provided by the symbolic data analysis problem.")); … … 106 105 Parameters.Add(new FixedValueParameter<PercentValue>(RandomSamplesParameterName, "The number of random samples used for fitness calculation in each island.", new PercentValue())); 107 106 Parameters.Add(new ValueLookupParameter<IntValue>(DataMigrationIntervalParameterName, "The number of generations that should pass between data migration phases.")); 107 Parameters.Add(new LookupParameter<IntValue>(IslandIndexParameterName, "The index of the current island.")); 108 108 Parameters.Add(new LookupParameter<IntValue>(IterationsParameterName, "The number of performed iterations.")); 109 109 Parameters.Add(new ValueLookupParameter<IntValue>(MaximumIterationsParameterName, "The maximum number of performed iterations.") { Hidden = true }); … … 122 122 var generation = generationValue == null ? 0 : generationValue.Value; 123 123 124 //calculat new rows for evaluation125 if (dataMigrationInterval != 0 && generation % dataMigrationInterval == 0) {126 //create fixed rows enumerable127 var rows = Enumerable.Range(fixedSamples.Start, fixedSamples.Size);128 //create randomly chosen rows enumerable129 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 124 137 rows = rows.Concat(randomRows); 125 if (randomSamples > 0 && dataMigrationInterval == 0) 126 throw new ArgumentException("The data migration interval must not be 0 if random samples are used."); 127 128 //create fixed rows enumerable 129 var rows = Enumerable.Range(fixedSamples.Start, fixedSamples.Size); 130 //create randomly chosen rows enumerable 131 if (randomSamples > 0) { 132 var islandIndex = IslandIndexParameter.ActualValue.Value; 133 var random = new FastRandom(islandIndex + (generation / dataMigrationInterval)); 134 135 if (randomSamples > samples.Size - fixedSamples.Size) { 136 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); 137 throw new OperatorExecutionException(this, error); 138 138 } 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))); 139 var randomRows = Enumerable.Range(samples.Start, samples.Size).Where(r => r < fixedSamples.Start || r >= fixedSamples.End); 140 randomRows = randomRows.SampleRandomWithoutRepetition(random, randomSamples, samples.Size - fixedSamples.Size); 141 rows = rows.Concat(randomRows); 143 142 } 143 144 //filter out test rows 145 rows = rows.Where(r => r < problemData.TestPartition.Start || r > problemData.TestPartition.End); 146 //TODO change to lookup parameter 147 ExecutionContext.Scope.Variables.Remove("Rows"); 148 ExecutionContext.Scope.Variables.Add(new HeuristicLab.Core.Variable("Rows", new EnumerableItem<int>(rows))); 144 149 145 150 var executionContext = new ExecutionContext(ExecutionContext, evaluator, ExecutionContext.Scope);
Note: See TracChangeset
for help on using the changeset viewer.