Changeset 10974
- Timestamp:
- 06/11/14 12:07:15 (10 years ago)
- Location:
- branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution/ArtificialAnt/GEArtificialAntEvaluator.cs
r10968 r10974 35 35 36 36 namespace HeuristicLab.Problems.GrammaticalEvolution { 37 [Item("GEArtificialAntEvaluator", "Evaluates an artificial ant solution , implemented in Grammatical Evolution.")]37 [Item("GEArtificialAntEvaluator", "Evaluates an artificial ant solution for grammatical evolution.")] 38 38 [StorableClass] 39 39 public class GEArtificialAntEvaluator : SingleSuccessorOperator, -
branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution/ArtificialAnt/GEArtificialAntProblem.cs
r10968 r10974 128 128 #endregion 129 129 130 // BackwardsCompatibility3.3131 #region Backwards compatible code, remove with 3.4132 [Obsolete]133 [Storable(Name = "operators")]134 private IEnumerable<IOperator> oldOperators {135 get { return null; }136 set {137 if (value != null && value.Any())138 Operators.AddRange(value);139 }140 }141 #endregion142 143 130 [StorableConstructor] 144 131 private GEArtificialAntProblem(bool deserializing) : base(deserializing) { } -
branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution/Mappers/GenotypeToPhenotypeMapper.cs
r10968 r10974 34 34 namespace HeuristicLab.Problems.GrammaticalEvolution { 35 35 /// <summary> 36 /// GenotypeToPhenotypeMapper36 /// Abstract base class for GenotypeToPhenotypeMappers 37 37 /// </summary> 38 38 public abstract class GenotypeToPhenotypeMapper : IntegerVectorOperator, IGenotypeToPhenotypeMapper { … … 66 66 67 67 // no terminal node exists for the given parent node 68 if ( possibleSymbolsList.Count() < 1) return null;68 if (!possibleSymbolsList.Any()) return null; 69 69 70 70 var newNode = possibleSymbolsList.SelectRandom(random).CreateTreeNode(); -
branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution/Mappers/PIGEMapper.cs
r10968 r10974 71 71 public class PIGEMapper : GenotypeToPhenotypeMapper { 72 72 73 private object nontVectorLocker = new object(); 73 74 private IntegerVector nontVector; 74 75 … … 78 79 } 79 80 80 private IntegerVector GetNontVector(IRandom random, IntMatrix bounds, int length) {81 private static IntegerVector GetNontVector(IRandom random, IntMatrix bounds, int length) { 81 82 IntegerVector v = new IntegerVector(length); 82 83 v.Randomize(random, bounds); … … 114 115 tree.Root = rootNode; 115 116 116 if (NontVector == null) { 117 NontVector = GetNontVector(random, bounds, length); 117 // Map can be called simultaniously on multiple threads 118 lock (nontVectorLocker) { 119 if (NontVector == null) { 120 NontVector = GetNontVector(random, bounds, length); 121 } 118 122 } 119 123 -
branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution/Symbolic/GESymbolicDataAnalysisEvaluator.cs
r10968 r10974 129 129 [StorableHook(HookType.AfterDeserialization)] 130 130 private void AfterDeserialization() { 131 if (Parameters.ContainsKey(ApplyLinearScalingParameterName) && !(Parameters[ApplyLinearScalingParameterName] is LookupParameter<BoolValue>))132 Parameters.Remove(ApplyLinearScalingParameterName);133 if (!Parameters.ContainsKey(ApplyLinearScalingParameterName))134 Parameters.Add(new LookupParameter<BoolValue>(ApplyLinearScalingParameterName, "Flag that indicates if the individual should be linearly scaled before evaluating."));135 if (!Parameters.ContainsKey(ValidRowIndicatorParameterName))136 Parameters.Add(new ValueLookupParameter<StringValue>(ValidRowIndicatorParameterName, "An indicator variable in the data set that specifies which rows should be evaluated (those for which the indicator <> 0) (optional)."));137 }138 139 protected IEnumerable<int> GenerateRowsToEvaluate() {140 return GenerateRowsToEvaluate(RelativeNumberOfEvaluatedSamplesParameter.ActualValue.Value);141 }142 143 protected IEnumerable<int> GenerateRowsToEvaluate(double percentageOfRows) {144 IEnumerable<int> rows;145 int samplesStart = EvaluationPartitionParameter.ActualValue.Start;146 int samplesEnd = EvaluationPartitionParameter.ActualValue.End;147 int testPartitionStart = ProblemDataParameter.ActualValue.TestPartition.Start;148 int testPartitionEnd = ProblemDataParameter.ActualValue.TestPartition.End;149 if (samplesEnd < samplesStart) throw new ArgumentException("Start value is larger than end value.");150 151 if (percentageOfRows.IsAlmost(1.0))152 rows = Enumerable.Range(samplesStart, samplesEnd - samplesStart);153 else {154 int seed = RandomParameter.ActualValue.Next();155 int count = (int)((samplesEnd - samplesStart) * percentageOfRows);156 if (count == 0) count = 1;157 rows = RandomEnumerable.SampleRandomNumbers(seed, samplesStart, samplesEnd, count);158 }159 160 rows = rows.Where(i => i < testPartitionStart || testPartitionEnd <= i);161 if (ValidRowIndicatorParameter.ActualValue != null) {162 string indicatorVar = ValidRowIndicatorParameter.ActualValue.Value;163 var problemData = ProblemDataParameter.ActualValue;164 var indicatorRow = problemData.Dataset.GetReadOnlyDoubleValues(indicatorVar);165 rows = rows.Where(r => !indicatorRow[r].IsAlmost(0.0));166 }167 return rows;168 }169 170 [ThreadStatic]171 private static double[] cache;172 protected static void CalculateWithScaling(IEnumerable<double> targetValues, IEnumerable<double> estimatedValues,173 double lowerEstimationLimit, double upperEstimationLimit,174 IOnlineCalculator calculator, int maxRows) {175 if (cache == null || cache.Length < maxRows) {176 cache = new double[maxRows];177 }178 179 // calculate linear scaling180 int i = 0;181 var linearScalingCalculator = new OnlineLinearScalingParameterCalculator();182 var targetValuesEnumerator = targetValues.GetEnumerator();183 var estimatedValuesEnumerator = estimatedValues.GetEnumerator();184 while (targetValuesEnumerator.MoveNext() & estimatedValuesEnumerator.MoveNext()) {185 double target = targetValuesEnumerator.Current;186 double estimated = estimatedValuesEnumerator.Current;187 cache[i] = estimated;188 if (!double.IsNaN(estimated) && !double.IsInfinity(estimated))189 linearScalingCalculator.Add(estimated, target);190 i++;191 }192 if (linearScalingCalculator.ErrorState == OnlineCalculatorError.None && (targetValuesEnumerator.MoveNext() || estimatedValuesEnumerator.MoveNext()))193 throw new ArgumentException("Number of elements in target and estimated values enumeration do not match.");194 195 double alpha = linearScalingCalculator.Alpha;196 double beta = linearScalingCalculator.Beta;197 if (linearScalingCalculator.ErrorState != OnlineCalculatorError.None) {198 alpha = 0.0;199 beta = 1.0;200 }201 202 //calculate the quality by using the passed online calculator203 targetValuesEnumerator = targetValues.GetEnumerator();204 var scaledBoundedEstimatedValuesEnumerator = Enumerable.Range(0, i).Select(x => cache[x] * beta + alpha)205 .LimitToRange(lowerEstimationLimit, upperEstimationLimit).GetEnumerator();206 207 while (targetValuesEnumerator.MoveNext() & scaledBoundedEstimatedValuesEnumerator.MoveNext()) {208 calculator.Add(targetValuesEnumerator.Current, scaledBoundedEstimatedValuesEnumerator.Current);209 }210 131 } 211 132 } -
branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution/Symbolic/GESymbolicDataAnalysisProblem.cs
r10968 r10974 61 61 private const string BoundsParameterName = "Bounds"; 62 62 private const string GenotypeToPhenotypeMapperParameterName = "GenotypeToPhenotypeMapper"; 63 64 63 private const string ProblemDataParameterDescription = ""; 65 64 private const string SymbolicExpressionTreeGrammarParameterDescription = "The grammar that should be used for symbolic expression tree."; 66 private const string SymoblicExpressionTreeInterpreterParameterDescription = "The interpreter that should be used to evaluate the symbolic expression tree."; 67 private const string MaximumSymbolicExpressionTreeDepthParameterDescription = "Maximal depth of the symbolic expression. The minimum depth needed for the algorithm is 3 because two levels are reserved for the ProgramRoot and the Start symbol."; 65 private const string SymbolicExpressionTreeInterpreterParameterDescription = "The interpreter that should be used to evaluate the symbolic expression tree."; 68 66 private const string MaximumSymbolicExpressionTreeLengthParameterDescription = "Maximal length of the symbolic expression."; 69 private const string MaximumFunctionDefinitionsParameterDescription = "Maximal number of automatically defined functions";70 private const string MaximumFunctionArgumentsParameterDescription = "Maximal number of arguments of automatically defined functions.";71 67 private const string RelativeNumberOfEvaluatedSamplesParameterDescription = "The relative number of samples of the dataset partition, which should be randomly chosen for evaluation."; 72 68 private const string FitnessCalculationPartitionParameterDescription = "The partition of the problem data training partition, that should be used to calculate the fitness of an individual."; … … 84 80 get { return (IValueParameter<T>)Parameters[ProblemDataParameterName]; } 85 81 } 86 public IValueParameter< GESymbolicExpressionGrammar> SymbolicExpressionTreeGrammarParameter {87 get { return (IValueParameter< GESymbolicExpressionGrammar>)Parameters[SymbolicExpressionTreeGrammarParameterName]; }82 public IValueParameter<ISymbolicDataAnalysisGrammar> SymbolicExpressionTreeGrammarParameter { 83 get { return (IValueParameter<ISymbolicDataAnalysisGrammar>)Parameters[SymbolicExpressionTreeGrammarParameterName]; } 88 84 } 89 85 public IValueParameter<ISymbolicDataAnalysisExpressionTreeInterpreter> SymbolicExpressionTreeInterpreterParameter { … … 125 121 } 126 122 127 public GESymbolicExpressionGrammar SymbolicExpressionTreeGrammar {123 public ISymbolicDataAnalysisGrammar SymbolicExpressionTreeGrammar { 128 124 get { return SymbolicExpressionTreeGrammarParameter.Value; } 129 125 set { SymbolicExpressionTreeGrammarParameter.Value = value; } … … 167 163 : base(evaluator, solutionCreator) { 168 164 Parameters.Add(new ValueParameter<T>(ProblemDataParameterName, ProblemDataParameterDescription, problemData)); 169 Parameters.Add(new ValueParameter< GESymbolicExpressionGrammar>(SymbolicExpressionTreeGrammarParameterName, SymbolicExpressionTreeGrammarParameterDescription));170 Parameters.Add(new ValueParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>(SymbolicExpressionTreeInterpreterParameterName, Sym oblicExpressionTreeInterpreterParameterDescription));165 Parameters.Add(new ValueParameter<ISymbolicDataAnalysisGrammar>(SymbolicExpressionTreeGrammarParameterName, SymbolicExpressionTreeGrammarParameterDescription)); 166 Parameters.Add(new ValueParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>(SymbolicExpressionTreeInterpreterParameterName, SymbolicExpressionTreeInterpreterParameterDescription)); 171 167 Parameters.Add(new FixedValueParameter<IntValue>(MaximumSymbolicExpressionTreeLengthParameterName, MaximumSymbolicExpressionTreeLengthParameterDescription)); 172 168 Parameters.Add(new FixedValueParameter<IntRange>(FitnessCalculationPartitionParameterName, FitnessCalculationPartitionParameterDescription)); … … 200 196 } 201 197 202 pr otected virtualvoid UpdateGrammar() {198 private void UpdateGrammar() { 203 199 DeregisterGrammarHandler(); 204 200 // create a new grammar instance with the correct allowed input variables … … 209 205 210 206 private void InitializeOperators() { 211 Operators.AddRange(ApplicationManager.Manager.GetInstances<IIntegerVectorOperator>() .OfType<IOperator>());207 Operators.AddRange(ApplicationManager.Manager.GetInstances<IIntegerVectorOperator>()); 212 208 Operators.Add(new SymbolicExpressionSymbolFrequencyAnalyzer()); 213 209 Operators.Add(new SymbolicDataAnalysisVariableFrequencyAnalyzer()); -
branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution/Symbolic/GESymbolicRegressionSingleObjectiveEvaluator.cs
r10968 r10974 44 44 get { return (IValueParameter<ISymbolicRegressionSingleObjectiveEvaluator>)Parameters[EvaluatorParameterName]; } 45 45 } 46 public ILookupParameter<IRandom> RandomParameter {47 get { return (ILookupParameter<IRandom>)Parameters[RandomParameterName]; }48 }49 46 public ILookupParameter<IntMatrix> BoundsParameter { 50 47 get { return (ILookupParameter<IntMatrix>)Parameters[BoundsParameterName]; } … … 54 51 } 55 52 56 p rivateISymbolicRegressionSingleObjectiveEvaluator Evaluator {53 public ISymbolicRegressionSingleObjectiveEvaluator Evaluator { 57 54 get { return EvaluatorParameter.Value; } 58 55 } -
branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution/Symbolic/GESymbolicRegressionSingleObjectiveProblem.cs
r10968 r10974 35 35 namespace HeuristicLab.Problems.GrammaticalEvolution { 36 36 [Item("Grammatical Evolution Symbolic Regression Problem (single objective)", 37 "Represents a single objective symbolic regression problem, implemented in Grammatical Evolution.")]37 "Represents grammatical evolution for single objective symbolic regression problems.")] 38 38 [StorableClass] 39 39 [Creatable("Problems")] … … 72 72 73 73 ApplyLinearScalingParameter.Value.Value = true; 74 Maximization.Value = true;74 Maximization.Value = Evaluator.Maximization; 75 75 MaximumSymbolicExpressionTreeLength.Value = InitialMaximumTreeLength; 76 76 … … 86 86 87 87 private void RegisterEventHandlers() { 88 // nothing to do 88 // when the ge evaluator itself changes 89 EvaluatorParameter.ValueChanged += (sender, args) => { 90 // register a new hander for the symbreg evaluator in the ge evaluator 91 // hacky because we the evaluator does not have an event for changes of the maximization property 92 EvaluatorParameter.Value.EvaluatorParameter.ValueChanged += 93 (_, __) => Maximization.Value = Evaluator.Maximization; 94 }; 95 EvaluatorParameter.Value.EvaluatorParameter.ValueChanged += 96 (sender, args) => Maximization.Value = Evaluator.Maximization; 89 97 } 90 98 -
branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution/Symbolic/IGESymbolicDataAnalysisProblem.cs
r10968 r10974 32 32 public interface IGESymbolicDataAnalysisProblem : IDataAnalysisProblem, IHeuristicOptimizationProblem { 33 33 34 IValueParameter< GESymbolicExpressionGrammar> SymbolicExpressionTreeGrammarParameter { get; }34 IValueParameter<ISymbolicDataAnalysisGrammar> SymbolicExpressionTreeGrammarParameter { get; } 35 35 IValueParameter<ISymbolicDataAnalysisExpressionTreeInterpreter> SymbolicExpressionTreeInterpreterParameter { get; } 36 36 IFixedValueParameter<IntValue> MaximumSymbolicExpressionTreeLengthParameter { get; } … … 39 39 IFixedValueParameter<IntRange> ValidationPartitionParameter { get; } 40 40 41 GESymbolicExpressionGrammar SymbolicExpressionTreeGrammar { get; set; }41 ISymbolicDataAnalysisGrammar SymbolicExpressionTreeGrammar { get; set; } 42 42 ISymbolicDataAnalysisExpressionTreeInterpreter SymbolicExpressionTreeInterpreter { get; set; } 43 43 IntValue MaximumSymbolicExpressionTreeLength { get; } … … 48 48 49 49 public interface IGESymbolicDataAnalysisSingleObjectiveProblem : IGESymbolicDataAnalysisProblem, ISingleObjectiveHeuristicOptimizationProblem { } 50 public interface IGESymbolicDataAnalysisMultiObjectiveProblem : IGESymbolicDataAnalysisProblem, IMultiObjectiveHeuristicOptimizationProblem { }51 50 } -
branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution/Symbolic/IGESymbolicRegressionSingleObjectiveEvaluator.cs
r10968 r10974 23 23 #endregion 24 24 25 using HeuristicLab.Core; 25 26 using HeuristicLab.Problems.DataAnalysis; 27 using HeuristicLab.Problems.DataAnalysis.Symbolic.Regression; 26 28 27 29 namespace HeuristicLab.Problems.GrammaticalEvolution { 28 30 public interface IGESymbolicRegressionSingleObjectiveEvaluator : IGESymbolicRegressionEvaluator, 29 31 IGESymbolicDataAnalysisSingleObjectiveEvaluator<IRegressionProblemData> { 32 IValueParameter<ISymbolicRegressionSingleObjectiveEvaluator> EvaluatorParameter { get; } 30 33 } 31 34 }
Note: See TracChangeset
for help on using the changeset viewer.