- Timestamp:
- 07/26/17 19:34:13 (7 years ago)
- Location:
- branches/PushGP/HeuristicLab.PushGP
- Files:
-
- 12 added
- 8 deleted
- 34 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/PushGP/HeuristicLab.PushGP
-
Property
svn:ignore
set to
*.user
-
Property
svn:ignore
set to
-
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Analyzer/IndividualZeroErrorAnalyzer.cs
r15275 r15289 19 19 private const string RESULTS_PARAMETER_NAME = "Results"; 20 20 private const string INDIVIDUAL_ZERO_ERROR_PARAMETER_NAME = "ZeroErrorIndividualsPerCase"; 21 private const string INDIVIDUAL_ZERO_ERROR_HISTORY_PARAMETER_NAME = INDIVIDUAL_ZERO_ERROR_PARAMETER_NAME + "History"; 21 22 22 23 private const string RESULT_PARAMETER_NAME = "Zero Error Individuals Per Case"; 23 24 private const string RESULT_PARAMETER_DESCRIPTION = "Relative frequency of instructions aggregated over the whole population."; 24 25 private const string Y_AXIS_TITLE = "Count of zero error individuals"; 25 private const string X_AXIS_TITLE = "Case Index";26 private const string X_AXIS_TITLE = "Case Nr"; 26 27 private const string ROW_NAME = "Cases"; 28 private const string HISTORY_TABLE_NAME = "Individual Zero Error history"; 27 29 28 30 public IndividualZeroErrorAnalyzer() { … … 31 33 "The data table to store the count of individuals with zero error.")); 32 34 35 Parameters.Add(new ValueLookupParameter<DataTableHistory>( 36 INDIVIDUAL_ZERO_ERROR_HISTORY_PARAMETER_NAME, 37 "The data table to store the history.")); 38 33 39 Parameters.Add(new LookupParameter<ResultCollection>( 34 40 RESULTS_PARAMETER_NAME, … … 38 44 IntegerVectorPushProblem.CaseQualitiesScopeParameterName, 39 45 "The quality of every single training case for each individual.")); 46 47 Parameters.Add(new ValueParameter<BoolValue>( 48 "StoreHistory", 49 "True if the history of the analysis should be stored.", 50 new BoolValue(false))); 51 52 Parameters.Add(new ValueParameter<IntValue>( 53 "UpdateInterval", 54 "The interval in which the analysis should be applied.", 55 new IntValue(1))); 56 57 Parameters.Add(new ValueParameter<IntValue>( 58 "UpdateCounter", 59 "The value which counts how many times the operator was called since the last update.", 60 new IntValue(0))); 61 62 IndividualZeroErrorParameter.Hidden = true; 63 IndividualZeroErrorHistoryParameter.Hidden = true; 64 ResultsParameter.Hidden = true; 65 UpdateCounterParameter.Hidden = true; 40 66 } 41 67 … … 51 77 public bool EnabledByDefault { get { return true; } } 52 78 79 public ValueParameter<BoolValue> StoreHistoryParameter 80 { 81 get { return (ValueParameter<BoolValue>)Parameters["StoreHistory"]; } 82 } 83 public ValueParameter<IntValue> UpdateIntervalParameter 84 { 85 get { return (ValueParameter<IntValue>)Parameters["UpdateInterval"]; } 86 } 87 public ValueParameter<IntValue> UpdateCounterParameter 88 { 89 get { return (ValueParameter<IntValue>)Parameters["UpdateCounter"]; } 90 } 91 53 92 public ILookupParameter<DataTable> IndividualZeroErrorParameter 54 93 { … … 56 95 } 57 96 97 public ValueLookupParameter<DataTableHistory> IndividualZeroErrorHistoryParameter 98 { 99 get { return (ValueLookupParameter<DataTableHistory>)Parameters[INDIVIDUAL_ZERO_ERROR_HISTORY_PARAMETER_NAME]; } 100 } 101 58 102 public ILookupParameter<ResultCollection> ResultsParameter 59 103 { … … 67 111 68 112 public override IOperation Apply() { 113 UpdateCounterParameter.Value.Value++; 114 // the analyzer runs periodically, every 'updateInterval' times 115 if (UpdateCounterParameter.Value.Value != UpdateIntervalParameter.Value.Value) 116 return base.Apply(); 117 118 UpdateCounterParameter.Value.Value = 0; // reset counter 119 69 120 var caseQualitiesPerIndividual = CaseQualitiesParameter.ActualValue; 70 121 var caseCount = caseQualitiesPerIndividual[0].Length; … … 80 131 YAxisTitle = Y_AXIS_TITLE, 81 132 XAxisTitle = X_AXIS_TITLE, 82 XAxisMinimumFixedValue = 0, 133 YAxisMinimumFixedValue = 0, 134 YAxisMaximumFixedValue = 1, 135 YAxisMinimumAuto = false, 136 SecondYAxisMaximumAuto = false, 137 XAxisMinimumFixedValue = 1, 83 138 XAxisMaximumFixedValue = caseCount, 84 139 XAxisMaximumAuto = false, … … 100 155 StartIndexZero = true, 101 156 IsVisibleInLegend = false, 102 ChartType = DataRowVisualProperties.DataRowChartType. Bars,157 ChartType = DataRowVisualProperties.DataRowChartType.Columns, 103 158 } 104 159 }; … … 107 162 } 108 163 109 var caseCountChanged = row.Values.Count != caseCount; 110 111 if (caseCountChanged) { 112 individualZeroErrorCounts.VisualProperties.XAxisMaximumFixedValue = caseCount; 113 row.Values.Clear(); 114 } 164 row.Values.Clear(); 115 165 116 166 for (var i = 0; i < caseCount; i++) { … … 124 174 } 125 175 126 if (caseCountChanged) 127 row.Values.Add(count); 128 else 129 row.Values[i] = count; 176 var relativeCount = count / (double)caseQualitiesPerIndividual.Length; 177 178 row.Values.Add(relativeCount); 179 } 180 181 var storeHistory = StoreHistoryParameter.Value.Value; 182 183 if (storeHistory) { 184 var history = IndividualZeroErrorHistoryParameter.ActualValue; 185 186 if (history == null) { 187 history = new DataTableHistory(); 188 IndividualZeroErrorHistoryParameter.ActualValue = history; 189 } 190 191 history.Add((DataTable)individualZeroErrorCounts.Clone()); 192 193 if (!results.ContainsKey(HISTORY_TABLE_NAME)) { 194 results.Add(new Result(HISTORY_TABLE_NAME, history)); 195 } else { 196 results[HISTORY_TABLE_NAME].Value = history; 197 } 130 198 } 131 199 -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Analyzer/IndividualZeroErrorDistributionAnalyzer.cs
r15275 r15289 20 20 private const string RESULTS_PARAMETER_NAME = "Results"; 21 21 private const string INDIVIDUAL_ZERO_ERROR_PARAMETER_NAME = "ZeroErrorIndividualsPerCaseDistribution"; 22 private const string INDIVIDUAL_ZERO_ERROR_HISTORY_PARAMETER_NAME = "ZeroErrorIndividualsPerCaseDistributionHistory"; 22 23 24 private const string HISTORY_TABLE_NAME = "Individual Zero Error Distribution History"; 23 25 private const string RESULT_PARAMETER_NAME = "Zero Error Individual Per Case Distribution"; 24 26 private const string RESULT_PARAMETER_DESCRIPTION = "Relative frequency of instructions aggregated over the whole population."; 25 27 private const string Y_AXIS_TITLE = "Number of zero error cases"; 26 private const string X_AXIS_TITLE = " Number of individuals";28 private const string X_AXIS_TITLE = "Individuals Nr"; 27 29 private const string ROW_NAME = "Cases"; 28 30 … … 31 33 INDIVIDUAL_ZERO_ERROR_PARAMETER_NAME, 32 34 "The data table to store the count of individuals with zero error.")); 35 36 Parameters.Add(new ValueLookupParameter<DataTableHistory>( 37 INDIVIDUAL_ZERO_ERROR_HISTORY_PARAMETER_NAME, 38 "The data table to store the history.")); 33 39 34 40 Parameters.Add(new LookupParameter<ResultCollection>( … … 39 45 IntegerVectorPushProblem.CaseQualitiesScopeParameterName, 40 46 "The quality of every single training case for each individual.")); 47 48 Parameters.Add(new ValueParameter<BoolValue>( 49 "StoreHistory", 50 "True if the history of the analysis should be stored.", 51 new BoolValue(false))); 52 53 Parameters.Add(new ValueParameter<IntValue>( 54 "UpdateInterval", 55 "The interval in which the analysis should be applied.", 56 new IntValue(1))); 57 58 Parameters.Add(new ValueParameter<IntValue>( 59 "UpdateCounter", 60 "The value which counts how many times the operator was called since the last update.", 61 new IntValue(0))); 62 63 IndividualZeroErrorDistributionParameter.Hidden = true; 64 IndividualZeroErrorDistributionHistoryParameter.Hidden = true; 65 ResultsParameter.Hidden = true; 66 UpdateCounterParameter.Hidden = true; 41 67 } 42 68 43 [StorableConstructor Attribute]69 [StorableConstructor] 44 70 public IndividualZeroErrorDistributionAnalyzer(bool deserializing) : base(deserializing) { } 45 71 … … 52 78 public bool EnabledByDefault { get { return true; } } 53 79 80 public ValueParameter<BoolValue> StoreHistoryParameter 81 { 82 get { return (ValueParameter<BoolValue>)Parameters["StoreHistory"]; } 83 } 84 public ValueParameter<IntValue> UpdateIntervalParameter 85 { 86 get { return (ValueParameter<IntValue>)Parameters["UpdateInterval"]; } 87 } 88 public ValueParameter<IntValue> UpdateCounterParameter 89 { 90 get { return (ValueParameter<IntValue>)Parameters["UpdateCounter"]; } 91 } 92 54 93 public ILookupParameter<DataTable> IndividualZeroErrorDistributionParameter 55 94 { 56 95 get { return (ILookupParameter<DataTable>)Parameters[INDIVIDUAL_ZERO_ERROR_PARAMETER_NAME]; } 96 } 97 98 public ValueLookupParameter<DataTableHistory> IndividualZeroErrorDistributionHistoryParameter 99 { 100 get { return (ValueLookupParameter<DataTableHistory>)Parameters[INDIVIDUAL_ZERO_ERROR_HISTORY_PARAMETER_NAME]; } 57 101 } 58 102 … … 68 112 69 113 public override IOperation Apply() { 114 UpdateCounterParameter.Value.Value++; 115 // the analyzer runs periodically, every 'updateInterval' times 116 if (UpdateCounterParameter.Value.Value != UpdateIntervalParameter.Value.Value) 117 return base.Apply(); 118 119 UpdateCounterParameter.Value.Value = 0; // reset counter 120 70 121 var caseQualitiesPerIndividual = CaseQualitiesParameter.ActualValue; 71 122 var individualCount = caseQualitiesPerIndividual.Length; … … 82 133 YAxisTitle = Y_AXIS_TITLE, 83 134 XAxisTitle = X_AXIS_TITLE, 84 XAxisMinimumFixedValue = 0, 85 XAxisMaximumAuto = true, 135 YAxisMaximumFixedValue = 1, 136 YAxisMinimumFixedValue = 0, 137 YAxisMaximumAuto = false, 138 YAxisMinimumAuto = false, 139 XAxisMinimumFixedValue = 1, 140 XAxisMaximumFixedValue = individualCount, 141 XAxisMaximumAuto = false, 86 142 XAxisMinimumAuto = false, 87 143 } … … 101 157 StartIndexZero = true, 102 158 IsVisibleInLegend = false, 103 ChartType = DataRowVisualProperties.DataRowChartType. Histogram,159 ChartType = DataRowVisualProperties.DataRowChartType.Columns, 104 160 } 105 161 }; … … 108 164 } 109 165 110 var caseCountChanged = row.Values.Count != caseCount;166 row.Values.Clear(); 111 167 112 if (caseCountChanged) { 113 row.Values.Clear(); 168 for (var i = 0; i < caseQualitiesPerIndividual.Length; i++) { 169 var count = caseQualitiesPerIndividual[i].Count(q => q == 0.0); 170 var ratio = count / (double)caseCount; 171 172 row.Values.Add(ratio); 114 173 } 115 174 116 // key represents the number of cases with zero error 117 // value represents the number of individuals with key cases with zero error 118 var distribution = caseQualitiesPerIndividual 119 .Select(individual => individual.Count(x => x == 0.0)) 120 .GroupBy(x => x) 121 .ToDictionary(x => x.Key, x => x.Count()); 175 var storeHistory = StoreHistoryParameter.Value.Value; 122 176 123 for (var i = 0; i < caseCount; i++) { 124 int count; 125 distribution.TryGetValue(i, out count); 126 var x = count / (double)individualCount; 177 if (storeHistory) { 178 var history = IndividualZeroErrorDistributionHistoryParameter.ActualValue; 127 179 128 if (caseCountChanged) 129 row.Values.Add(x); 130 else 131 row.Values[i] = x; 180 if (history == null) { 181 history = new DataTableHistory(); 182 IndividualZeroErrorDistributionHistoryParameter.ActualValue = history; 183 } 184 185 history.Add((DataTable)individualZeroErrorDistribution.Clone()); 186 187 if (!results.ContainsKey(HISTORY_TABLE_NAME)) { 188 results.Add(new Result(HISTORY_TABLE_NAME, history)); 189 } else { 190 results[HISTORY_TABLE_NAME].Value = history; 191 } 132 192 } 133 193 -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Analyzer/PushExpressionFrequencyAnalyzer.cs
r15273 r15289 1 1 namespace HeuristicLab.Problems.ProgramSynthesis.Push.Analyzer { 2 2 using System; 3 using System.Collections.Generic; 3 4 using System.Linq; 4 5 … … 14 15 using HeuristicLab.Problems.ProgramSynthesis.Push.Attributes; 15 16 using HeuristicLab.Problems.ProgramSynthesis.Push.Configuration; 17 using HeuristicLab.Problems.ProgramSynthesis.Push.Encoding; 16 18 using HeuristicLab.Problems.ProgramSynthesis.Push.Expressions; 17 19 using HeuristicLab.Problems.ProgramSynthesis.Push.Individual; 18 using HeuristicLab.Problems.ProgramSynthesis.Push.ObjectPools.Random;19 20 20 21 /// <summary> … … 24 25 [StorableClass] 25 26 public class PushExpressionFrequencyAnalyzer : SingleSuccessorOperator, IPushExpressionAnalyzer { 26 private readonly SeededRandomPool randomPool = new SeededRandomPool();27 27 28 28 private const string PUSH_CONFIGURATION_PARAMETER_NAME = "PushConfiguration"; … … 40 40 Parameters.Add(new LookupParameter<IReadOnlyPushConfiguration>(PUSH_CONFIGURATION_PARAMETER_NAME, "The current specified push configuration.")); 41 41 Parameters.Add(new ScopeTreeLookupParameter<IntegerVector>(INTEGER_VECTOR_PARAMETER_NAME, "The integer vectors to analyze.")); 42 Parameters.Add(new ScopeTreeLookupParameter<PlushVector>("Plush", "The plush vectors to analyze.")); 42 43 Parameters.Add(new LookupParameter<DataTable>(EXPRESSION_FREQUENCIES_PARAMETER_NAME, "The data table to store the instruction frequencies.")); 43 44 Parameters.Add(new LookupParameter<ResultCollection>(RESULTS_PARAMETER_NAME, "The result collection where the symbol frequencies should be stored.")); … … 60 61 { 61 62 get { return (ILookupParameter<IReadOnlyPushConfiguration>)Parameters[PUSH_CONFIGURATION_PARAMETER_NAME]; } 63 } 64 65 public IScopeTreeLookupParameter<PlushVector> PlushVectorParameter 66 { 67 get { return (IScopeTreeLookupParameter<PlushVector>)Parameters["Plush"]; } 62 68 } 63 69 … … 95 101 public override IOperation Apply() { 96 102 var config = PushConfigurationParameter.ActualValue; 97 var integerVectors = IntegerVectorParameter.ActualValue;98 103 99 randomPool.Seed = config.Seed;104 IReadOnlyList<PushProgram> pushPrograms = null; 100 105 101 var pushPrograms = integerVectors.Select(iv => { 102 var random = randomPool.ResetAndAllocate(); 103 var program = iv.ToPushProgram(config, random); 104 randomPool.Free(random); 105 106 return program; 107 }); 106 if (IntegerVectorParameter.ActualValue.Length > 0) { 107 pushPrograms = IntegerVectorParameter.ActualValue.Select(iv => iv.ToPushProgram(config)).ToList(); 108 } else if (PlushVectorParameter.ActualValue.Length > 0) { 109 pushPrograms = PlushVectorParameter.ActualValue.Select(pv => pv.PushProgram).ToList(); 110 } else { 111 // nothing to do 112 return base.Apply(); 113 } 108 114 109 115 var results = ResultsParameter.ActualValue; … … 136 142 group => group.Count()); 137 143 138 var totalNumber ofExpressions = Math.Max(1.0, expressionFrequencies.Values.Sum());144 var totalNumberOfExpressions = Math.Max(1.0, expressionFrequencies.Values.Sum()); 139 145 140 146 // all rows must have the same number of values so we can just take the first … … 152 158 } 153 159 154 frequencies.Rows[pair.Key].Values.Add(Math.Round(pair.Value / totalNumber ofExpressions, 3));160 frequencies.Rows[pair.Key].Values.Add(Math.Round(pair.Value / totalNumberOfExpressions, 3)); 155 161 } 156 162 -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Attributes/PushStackAttribute.cs
r14834 r15289 7 7 public class PushStackAttribute : Attribute { 8 8 public readonly StackTypes StackType; 9 9 10 public PushStackAttribute(StackTypes stackType) { 10 11 StackType = stackType; -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Configuration/IEnabledExpressionsConfiguration.cs
r15273 r15289 20 20 int InExpressionCount { get; } 21 21 22 22 23 IReadOnlyList<string> EnabledExpressions { get; } 23 24 IReadOnlyDictionary<StackTypes, int> ExpressionsPerStackCount { get; } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Configuration/IReadonlyPushConfiguration.cs
r15273 r15289 1 1 namespace HeuristicLab.Problems.ProgramSynthesis.Push.Configuration { 2 using System.Collections.Generic;3 2 using Base.Erc; 4 3 … … 6 5 7 6 public interface IReadOnlyPushConfiguration : IReadOnlyExpressionsConfiguration { 8 int Seed { get; }9 7 int EvalPushLimit { get; } 10 8 int MaxDepth { get; } … … 18 16 double ParenthesesCloseBiasLevel { get; } 19 17 IReadOnlyErcOptions ErcOptions { get; } 20 IReadOnlyList<string> EnabledExpressions { get; }21 18 string FloatStringFormat { get; } 22 19 -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Configuration/PushConfiguration.cs
r15032 r15289 52 52 53 53 54 IReadOnlyList<string> IReadOnly PushConfiguration.EnabledExpressions { get { return enabledExpressions; } }54 IReadOnlyList<string> IReadOnlyExpressionsConfiguration.EnabledExpressions { get { return enabledExpressions; } } 55 55 56 56 [Storable] -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Configuration/PushConfigurationParameterCollection.cs
r15273 r15289 154 154 } 155 155 156 IReadOnlyList<string> IReadOnly PushConfiguration.EnabledExpressions156 IReadOnlyList<string> IReadOnlyExpressionsConfiguration.EnabledExpressions 157 157 { 158 158 get -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Constants/PushEnvironment.cs
r15189 r15289 17 17 public const string CharSymbolStr = "'"; 18 18 public const string StringSymbolStr = "\""; 19 public const string NewLine = "\n"; 19 public const char NewLine = '\n'; 20 public const string NewLineStr = "\n"; 20 21 } 21 22 } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Crossover/AlternationCrossover.cs
r15275 r15289 10 10 using HeuristicLab.Parameters; 11 11 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 12 using HeuristicLab.Problems.ProgramSynthesis.Base.Extensions; 12 13 using HeuristicLab.Problems.ProgramSynthesis.Push.Encoding; 13 14 using HeuristicLab.Random; … … 23 24 public AlternationCrossover() { 24 25 Parameters.Add(new LookupParameter<IRandom>("Random", "The pseudo random number generator which should be used for stochastic crossover operators.")); 26 25 27 Parameters.Add(new ScopeTreeLookupParameter<PlushVector>("Parents", "The parent vectors which should be crossed.")); 26 28 ParentsParameter.ActualName = "PlushVector"; 29 27 30 Parameters.Add(new LookupParameter<PlushVector>("Child", "The child vector resulting from the crossover.")); 28 31 ChildParameter.ActualName = "PlushVector"; 32 29 33 Parameters.Add(new FixedValueParameter<PercentValue>("AlternationRate", "Specifies the probability of switching to another parent.", new PercentValue(0.5))); 30 34 Parameters.Add(new FixedValueParameter<DoubleValue>("AlignmentDeviation", "When alternating between parents, the index at which to continue copying may be offset backward or forward some amount based on a random sample from a normal distribution with mean 0 and standard deviation set by the alignment deviation parameter", new DoubleValue(1.0))); … … 90 94 91 95 public sealed override IOperation InstrumentedApply() { 92 ChildParameter.ActualValue = Cross(RandomParameter.ActualValue, ParentsParameter.ActualValue); 96 ChildParameter.ActualValue = Cross( 97 RandomParameter.ActualValue, 98 ParentsParameter.ActualValue, 99 AlternationRate, 100 MaxLength, 101 AlignmentDeviation); 93 102 return base.InstrumentedApply(); 94 103 } 95 104 96 private PlushVector Cross(IRandom random, ItemArray<PlushVector> parents) { 97 var normalDistributedRandom = new NormalDistributedRandom(random, Mean, AlignmentDeviation); 105 private static PlushVector Cross( 106 IRandom random, 107 ItemArray<PlushVector> parents, 108 double alternationRate, 109 int maxChildLength, 110 double alignmentDeviation) { 111 var normalDistributedRandom = new NormalDistributedRandom(random, Mean, alignmentDeviation); 98 112 var maxLength = parents.Max(p => p.Entries.Count); 99 113 var parentIndex = random.Next(0, 2); 100 114 var parent = parents[parentIndex]; 101 115 var child = new PlushVector(maxLength); 102 var maxChildLength = MaxLength;103 116 104 117 for (var i = 0; i < maxLength && child.Entries.Count <= maxChildLength; i++) { … … 109 122 110 123 // switch parent? 111 if (random.NextDouble() < AlternationRate) {124 if (random.NextDouble() < alternationRate) { 112 125 parentIndex = parentIndex == 0 ? 1 : 0; 113 126 parent = parents[parentIndex]; 114 i += normalDistributedRandom.Next ();127 i += normalDistributedRandom.NextRounded(); 115 128 i = Math.Max(i, 0); 116 129 } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Encoding/PlushEncoding.cs
r15275 r15289 34 34 inInstructionProbabilityParameter = new FixedValueParameter<PercentValue>(Name + ".InInstructionProbability"); 35 35 36 Parameters.Add(minLengthParameter); 37 Parameters.Add(maxLengthParameter); 38 Parameters.Add(minCloseParameter); 39 Parameters.Add(maxCloseParameter); 40 Parameters.Add(closeBiasLevelParameter); 36 41 Parameters.Add(instructionsParameter); 37 42 Parameters.Add(ercOptionsParameter); … … 371 376 creator.MinCloseParameter.ActualName = MinCloseParameter.Name; 372 377 creator.MaxCloseParameter.ActualName = MinCloseParameter.Name; 378 creator.CloseBiasLevelParameter.ActualName = CloseBiasLevelParameter.Name; 373 379 creator.ErcOptionsParameter.ActualName = ErcOptionsParameter.Name; 374 380 creator.InstructionsParameter.ActualName = InstructionsParameter.Name; -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Encoding/PlushVector.cs
r15275 r15289 26 26 27 27 public PlushVector(PlushVector origin, Cloner cloner) : base(origin, cloner) { 28 entries = new List<PlushEntry>(origin.entries); 29 pushProgram = origin.pushProgram; 28 30 } 29 31 -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/PrintExpressions.cs
r15189 r15289 72 72 73 73 public override void Eval(IInternalPushInterpreter interpreter) { 74 Eval(interpreter, interpreter.BooleanStack); 74 var value = interpreter.BooleanStack.Pop(); 75 interpreter.PrintStack.Push(value); 75 76 } 76 77 } … … 92 93 93 94 public override void Eval(IInternalPushInterpreter interpreter) { 94 Eval(interpreter, interpreter.CharStack); 95 var value = interpreter.CharStack.Pop(); 96 interpreter.PrintStack.Push(value); 95 97 } 96 98 } … … 113 115 114 116 public override void Eval(IInternalPushInterpreter interpreter) { 115 Eval(interpreter, interpreter.ExecStack); 117 var value = interpreter.ExecStack.Pop(); 118 interpreter.PrintStack.Push(value); 116 119 } 117 120 } … … 136 139 var str = value.ToString(interpreter.Configuration.FloatStringFormat, CultureInfo.InvariantCulture); 137 140 138 if (interpreter.PrintStack.IsEmpty) 139 interpreter.PrintStack.Push(str); 140 else 141 interpreter.PrintStack.Top += str; 141 interpreter.PrintStack.Push(str); 142 142 } 143 143 } … … 180 180 181 181 public override void Eval(IInternalPushInterpreter interpreter) { 182 Eval(interpreter, interpreter.StringStack); 182 var value = interpreter.StringStack.Pop(); 183 interpreter.PrintStack.Push(value); 183 184 } 184 185 } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Generators/CodeGenerator/CodeGeneratorUtils.cs
r15275 r15289 28 28 ? customExpressions.Values.ElementAt(index - enabledExpressionCount) 29 29 : MapToExpression(index, random, ercOptions, config); 30 } 31 32 internal static Expression MapToExpression( 33 int index, 34 IReadOnlyExpressionsConfiguration config) { 35 36 switch (index) { 37 case PushSolutionEncoding.Noop: 38 return Noop; 39 } 40 41 var name = config.EnabledExpressions[index]; 42 return ExpressionTable.GetExpression(name); 30 43 } 31 44 … … 76 89 instructions.InExpressionCount > 0) { 77 90 78 var nr = random.Next(0, instructions.InExpressionCount) + 1;79 expression = ExpressionTable.InExpressionTable[ nr];91 var index = random.Next(0, instructions.InExpressionCount); 92 expression = ExpressionTable.InExpressionTable[index]; 80 93 } else { 81 94 expression = GetRandomExpression(random, instructions); -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Individual/IndividualExtensions.cs
r15273 r15289 1 1 namespace HeuristicLab.Problems.ProgramSynthesis.Push.Individual { 2 2 using System.Collections.Generic; 3 4 using HeuristicLab.Core;5 3 using HeuristicLab.Encodings.IntegerVectorEncoding; 6 4 using HeuristicLab.Optimization; 7 5 using HeuristicLab.Problems.ProgramSynthesis.Push.Configuration; 8 6 using HeuristicLab.Problems.ProgramSynthesis.Push.Expressions; 9 using HeuristicLab.Problems.ProgramSynthesis.Push.Generators.CodeGenerator;10 7 using HeuristicLab.Problems.ProgramSynthesis.Push.SolutionCreator; 11 8 12 9 public static class IndividualExtensions { 13 10 14 public static PushProgram ToPushProgram(this Individual individual, IReadOnlyPushConfiguration config , IRandom random) {15 return individual.IntegerVector().ToPushProgram(config , random);11 public static PushProgram ToPushProgram(this Individual individual, IReadOnlyPushConfiguration config) { 12 return individual.IntegerVector().ToPushProgram(config); 16 13 } 17 14 18 public static PushProgram ToPushProgram(this IntegerVector vector, IReadOnlyPushConfiguration config , IRandom random) {15 public static PushProgram ToPushProgram(this IntegerVector vector, IReadOnlyPushConfiguration config) { 19 16 //var currentIndex = 0; 20 17 //var close = 0; … … 24 21 var index = vector[i]; 25 22 26 if (index == PushSolutionEncoding.End) 27 break;23 if (index == PushSolutionEncoding.End) break; 24 if (index == PushSolutionEncoding.Noop) continue; 28 25 29 // skip noops 30 if (index == PushSolutionEncoding.Noop) 31 continue; 26 var name = config.EnabledExpressions[index]; 27 var expression = ExpressionTable.GetExpression(name); 32 28 33 var expression = CodeGeneratorUtils.MapToExpression(34 index,35 random,36 config.ErcOptions,37 config);29 //var expression = CodeGeneratorUtils.MapToExpression( 30 // index, 31 // random, 32 // config.ErcOptions, 33 // config); 38 34 39 35 expressions.Add(expression); -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Interpreter/Extensions.cs
r15273 r15289 5 5 using System; 6 6 using System.Collections; 7 using System.Globalization; 7 8 using System.Reflection; 8 9 … … 26 27 } 27 28 28 public static Type GetStackEntryType(this StackTypes stackType) { 29 if (StackProperties.ContainsKey(stackType) && 30 StackProperties[stackType].PropertyType.IsGenericType) { 31 var genericTypeDef = StackProperties[stackType].PropertyType.GetGenericTypeDefinition(); 32 if (genericTypeDef == typeof(IPushStack<>)) 33 return genericTypeDef.GetGenericArguments()[0]; 29 public static string StringifyResult(this IPushInterpreter interpreter, ExampleArgumentType type, int offset) { 30 var emptyString = string.Empty; 31 32 switch (type) { 33 case ExampleArgumentType.Integer: 34 return GetEntryAsString(offset, interpreter.IntegerStack); 35 36 case ExampleArgumentType.IntegerVector: 37 return GetVectorEntryAsString(offset, interpreter.IntegerVectorStack); 38 39 case ExampleArgumentType.Float: 40 return interpreter.FloatStack.Count > offset 41 ? interpreter.FloatStack[offset].ToString(CultureInfo.CurrentUICulture) 42 : emptyString; 43 44 case ExampleArgumentType.FloatVector: 45 return GetVectorEntryAsString(offset, interpreter.FloatVectorStack); 46 47 case ExampleArgumentType.Boolean: 48 return GetEntryAsString(offset, interpreter.BooleanStack); 49 50 case ExampleArgumentType.Char: 51 return GetEntryAsString(offset, interpreter.CharStack); 52 53 case ExampleArgumentType.Print: 54 return interpreter.PrintStack.ToString(); 55 56 case ExampleArgumentType.String: 57 return GetEntryAsString(offset, interpreter.StringStack); 58 59 case ExampleArgumentType.StringVector: 60 return GetVectorEntryAsString(offset, interpreter.StringVectorStack); 61 62 default: return string.Empty; 34 63 } 64 } 35 65 36 return StackProperties.ContainsKey(stackType) 37 ? StackProperties[stackType] 38 .PropertyType 39 .GetInterfaces() 40 .First(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IPushStack<>)) 41 .GetGenericArguments() 42 .First() 43 : null; 66 private static string GetEntryAsString<T>(int offset, IPushStack<T> stack) { 67 return stack.Count > offset 68 ? stack[offset].ToString() 69 : string.Empty; 70 } 71 72 private static string GetVectorEntryAsString<T>(int offset, IPushStack<IReadOnlyList<T>> vectorStack) { 73 return vectorStack.Count > offset 74 ? "[" + string.Join(",", vectorStack[offset]) + "]" 75 : string.Empty; 44 76 } 45 77 -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Manipulator/UniformMutation.cs
r15275 r15289 1 1 namespace HeuristicLab.Problems.ProgramSynthesis.Push.Manipulator { 2 2 3 using HeuristicLab.Common; 3 4 using HeuristicLab.Core; … … 11 12 using HeuristicLab.Problems.ProgramSynthesis.Push.Encoding; 12 13 using HeuristicLab.Problems.ProgramSynthesis.Push.Generators.CodeGenerator; 13 using HeuristicLab.Random;14 14 15 15 /// <summary> … … 23 23 Parameters.Add(new LookupParameter<IRandom>("Random", "The pseudo random number generator which should be used for stochastic manipulation operators.")); 24 24 Parameters.Add(new LookupParameter<PlushVector>("PlushVector", "The vector which should be manipulated.")); 25 Parameters.Add(new ValueLookupParameter<IntValue>("MinLength", "The min length of the vector."));26 Parameters.Add(new ValueLookupParameter<IntValue>("MaxLength", "The max length of the vector."));27 25 Parameters.Add(new ValueLookupParameter<IReadOnlyExpressionsConfiguration>("Instructions", "The enabled instructions")); 28 26 Parameters.Add(new ValueLookupParameter<IReadOnlyErcOptions>("ErcOptions", "ERC options")); 29 27 Parameters.Add(new ValueLookupParameter<PercentValue>("InInstructionProbability", "The probability of IN Instructions")); 30 28 31 Parameters.Add(new FixedValueParameter<PercentValue>("InstructionMutationProbability", "The probability a value gets mutated", new PercentValue(0.02))); 32 Parameters.Add(new FixedValueParameter<DoubleValue>("CloseMutationDeviation", "When mutating individual, the amount of which the close marker is incremented or decrement is based on a random sample from a normal distribution with mean 0 and standard deviation set by the close mutation deviation parameter", new DoubleValue(1.0))); 29 Parameters.Add(new FixedValueParameter<PercentValue>("InstructionMutationProbability", "The probability an instruction gets mutated", new PercentValue(0.02))); 30 Parameters.Add(new FixedValueParameter<PercentValue>("CloseMutationProbability", "The probability close gets mutated", new PercentValue(0.02))); 31 Parameters.Add(new FixedValueParameter<PercentValue>("CloseIncrementRate", "When mutating individual, the increment rate specifies if close should be increased or decreased by 1.", new PercentValue(0.5))); 33 32 } 34 33 … … 50 49 } 51 50 52 public IValueParameter<PercentValue> CloseMutation DeviationParameter51 public IValueParameter<PercentValue> CloseMutationProbabilityParameter 53 52 { 54 get { return (IValueParameter<PercentValue>)Parameters["CloseMutation Deviation"]; }53 get { return (IValueParameter<PercentValue>)Parameters["CloseMutationProbability"]; } 55 54 } 56 55 57 public double CloseMutation Deviation56 public double CloseMutationProbability 58 57 { 59 get { return CloseMutationDeviationParameter.Value.Value; } 60 set { CloseMutationDeviationParameter.Value.Value = value; } 58 get { return CloseMutationProbabilityParameter.Value.Value; } 59 set { CloseMutationProbabilityParameter.Value.Value = value; } 60 } 61 62 public IValueParameter<PercentValue> CloseIncrementRateParameter 63 { 64 get { return (IValueParameter<PercentValue>)Parameters["CloseIncrementRate"]; } 65 } 66 67 public double CloseIncrementRate 68 { 69 get { return CloseIncrementRateParameter.Value.Value; } 70 set { CloseIncrementRateParameter.Value.Value = value; } 61 71 } 62 72 … … 72 82 { 73 83 get { return (ILookupParameter<PlushVector>)Parameters["PlushVector"]; } 74 }75 public IValueLookupParameter<IntValue> MinLengthParameter76 {77 get { return (IValueLookupParameter<IntValue>)Parameters["MinLength"]; }78 }79 public IValueLookupParameter<IntValue> MaxLengthParameter80 {81 get { return (IValueLookupParameter<IntValue>)Parameters["MaxLength"]; }82 84 } 83 85 public IValueLookupParameter<IReadOnlyExpressionsConfiguration> InstructionsParameter … … 99 101 100 102 public sealed override IOperation InstrumentedApply() { 101 Manipulate(RandomParameter.ActualValue, PlushVectorParameter.ActualValue); 103 Manipulate( 104 RandomParameter.ActualValue, 105 PlushVectorParameter.ActualValue, 106 CloseIncrementRate, 107 ErcOptionsParameter.ActualValue, 108 InstructionsParameter.ActualValue, 109 InInstructionProbabilityParameter.ActualValue.Value, 110 CloseMutationProbability, 111 InstructionMutationProbability); 102 112 return base.InstrumentedApply(); 103 113 } 104 114 105 private void Manipulate(IRandom random, PlushVector plushVector) { 106 var normalDistributedRandom = new NormalDistributedRandom(random, 0, CloseMutationDeviation); 107 var ercOptions = ErcOptionsParameter.ActualValue; 108 var instructions = InstructionsParameter.ActualValue; 109 var inInstructionProbability = InInstructionProbabilityParameter.ActualValue.Value; 110 var instructionMutationProbability = InstructionMutationProbability; 115 private static void Manipulate( 116 IRandom random, 117 PlushVector plushVector, 118 double closeIncrementRate, 119 IReadOnlyErcOptions ercOptions, 120 IReadOnlyExpressionsConfiguration instructions, 121 double inInstructionProbability, 122 double closeMutationProbability, 123 double instructionMutationProbability 124 ) { 111 125 112 126 for (var i = 0; i < plushVector.Entries.Count; i++) { … … 123 137 } 124 138 125 entry.Close += normalDistributedRandom.Next(); 139 x = random.NextDouble(); 140 141 if (x < closeMutationProbability) { 142 x = random.NextDouble(); 143 entry.Close += x < closeIncrementRate ? 1 : -1; 144 145 if (entry.Close < 0) 146 entry.Close = 0; 147 } 126 148 } 127 149 -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/ObjectPools/Random/SeededRandomPool.cs
r15273 r15289 12 12 public SeededRandomPool() : this(new Random().Next()) { } 13 13 14 public SeededRandomPool(int seed) : this(seed, () => new MersenneTwister()) { }14 public SeededRandomPool(int seed) : this(seed, () => new FastRandom()) { } 15 15 16 16 public SeededRandomPool(int seed, Func<IRandom> randomCreator) { -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Problem/BenchmarkSuite/IntegerVectorPushBenchmarkSuiteProblem.cs
r15275 r15289 7 7 using HeuristicLab.BenchmarkSuite; 8 8 using HeuristicLab.BenchmarkSuite.Problems; 9 using HeuristicLab.Problems.ProgramSynthesis.Push.Evaluator; 9 10 using HeuristicLab.Problems.ProgramSynthesis.Push.Expressions; 11 using HeuristicLab.Problems.ProgramSynthesis.Push.Solution; 12 using HeuristicLab.Problems.ProgramSynthesis.Push.Solution.BenchmarkSuite; 10 13 11 14 using Instances; -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Problem/BenchmarkSuite/PlushPushBenchmarkSuiteProblem.cs
r15275 r15289 7 7 using HeuristicLab.Problems.Instances; 8 8 using HeuristicLab.Problems.ProgramSynthesis.Push.Configuration; 9 using HeuristicLab.Problems.ProgramSynthesis.Push.Evaluator; 9 10 using HeuristicLab.Problems.ProgramSynthesis.Push.Expressions; 11 using HeuristicLab.Problems.ProgramSynthesis.Push.Solution; 12 using HeuristicLab.Problems.ProgramSynthesis.Push.Solution.BenchmarkSuite; 10 13 using HeuristicLab.Problems.ProgramSynthesis.Push.Stack; 11 14 -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Problem/IntegerVectorPushProblem.cs
r15275 r15289 4 4 using Common; 5 5 using Configuration; 6 using Core;7 using HeuristicLab.Data;8 6 using HeuristicLab.Encodings.IntegerVectorEncoding; 9 7 using HeuristicLab.Problems.ProgramSynthesis.Push.Analyzer; 8 using HeuristicLab.Problems.ProgramSynthesis.Push.Evaluator; 10 9 using HeuristicLab.Problems.ProgramSynthesis.Push.Expressions; 11 10 using HeuristicLab.Problems.ProgramSynthesis.Push.Individual; 12 11 using HeuristicLab.Problems.ProgramSynthesis.Push.SolutionCreator; 12 13 13 using Optimization; 14 14 using Persistence.Default.CompositeSerializers.Storable; … … 54 54 // IndividualMapper.Clear(); 55 55 // RandomPool.Clear(); 56 // Config.Seed = 0;57 56 //} 58 57 … … 81 80 } 82 81 83 protected override PushProgram MapIndividual(Individual individual , IRandom random) {84 var program = individual.ToPushProgram(Config , random);82 protected override PushProgram MapIndividual(Individual individual) { 83 var program = individual.ToPushProgram(Config); 85 84 86 85 return program; 87 86 } 88 87 89 public override double Evaluate(Individual individual, IRandom random) { 90 // init seed of random pool 91 //Interlocked.CompareExchange(ref RandomPool.Seed, random.Next(), 0); 92 //Config.Seed = RandomPool.Seed; 88 //public override double Evaluate(Individual individual, IRandom random) { 89 // var seed = random.Next(); 93 90 94 //var rand = RandomPool.ResetAndAllocate(); 95 var program = MapIndividual(individual, random); 96 //RandomPool.Free(rand); 91 // var program = individual.ToPushProgram(Config); 97 92 98 //rand = RandomPool.ResetAndAllocate(); 99 var result = PushEvaluator.EvaluateTraining(Pool, program, random); 100 //RandomPool.Free(rand); 93 // var rand = new FastRandom(seed); 94 // var result = PushEvaluator.EvaluateTraining(Pool, program, rand); 101 95 102 individual[CaseQualitiesScopeParameterName] = new DoubleArray(result.ExampleQualities); 96 // individual[CaseQualitiesScopeParameterName] = new DoubleArray(result.ExampleQualities); 97 // individual[SeedScopeParameterName] = new IntValue(seed); 103 98 104 return result.AvgQuality;105 }99 // return result.AvgQuality; 100 //} 106 101 } 107 102 } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Problem/PlushPushProblem.cs
r15275 r15289 9 9 using HeuristicLab.Problems.ProgramSynthesis.Push.Analyzer; 10 10 using HeuristicLab.Problems.ProgramSynthesis.Push.Encoding; 11 using HeuristicLab.Problems.ProgramSynthesis.Push.Evaluator; 11 12 using HeuristicLab.Problems.ProgramSynthesis.Push.Expressions; 12 13 … … 43 44 } 44 45 45 protected override PushProgram MapIndividual(Individual individual , IRandom random) {46 protected override PushProgram MapIndividual(Individual individual) { 46 47 var plushVector = individual.PlushVector(); 47 48 var program = plushVector.PushProgram; … … 49 50 return program; 50 51 } 51 52 public override double Evaluate(Individual individual, IRandom random) {53 var program = MapIndividual(individual, random);54 var result = PushEvaluator.EvaluateTraining(Pool, program, random);55 56 individual[CaseQualitiesScopeParameterName] = new DoubleArray(result.ExampleQualities);57 58 return result.AvgQuality;59 }60 52 } 61 53 } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Problem/PushProblemBase.cs
r15275 r15289 10 10 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 11 11 using HeuristicLab.Problems.ProgramSynthesis.Push.Configuration; 12 using HeuristicLab.Problems.ProgramSynthesis.Push.Evaluator; 12 13 using HeuristicLab.Problems.ProgramSynthesis.Push.Expressions; 13 14 using HeuristicLab.Problems.ProgramSynthesis.Push.Interpreter; 14 15 using HeuristicLab.Problems.ProgramSynthesis.Push.ObjectPools.Random; 16 using HeuristicLab.Problems.ProgramSynthesis.Push.Solution; 17 using HeuristicLab.Random; 15 18 16 19 [StorableClass] … … 31 34 public const string CasesScopeParameterName = "CaseQualities"; 32 35 public const string CaseQualitiesScopeParameterName = "CaseQualities"; 36 public const string SeedScopeParameterName = "Seed"; 33 37 34 38 protected PushProblemBase(IPushEvaluator evaluator) { … … 88 92 var bestQuality = Maximization ? qualities.Max() : qualities.Min(); 89 93 var bestIdx = Array.IndexOf(qualities, bestQuality); 90 var program = MapIndividual(individuals[bestIdx], random); 94 var bestIndividual = individuals[bestIdx]; 95 var seed = (IntValue)bestIndividual[SeedScopeParameterName]; 96 var program = MapIndividual(bestIndividual); 91 97 92 var isIndividualBetter = AnalyzeBestTrainingSolution(program, bestQuality, results, random); 98 var rand = new FastRandom(seed.Value); 99 var isIndividualBetter = AnalyzeBestTrainingSolution(program, bestQuality, results, rand); 93 100 94 101 if (isIndividualBetter) { 95 AnalyzeBestTestSolution(program, results, random); 102 rand.Reset(seed.Value); 103 AnalyzeBestTestSolution(program, results, rand); 96 104 } 97 105 } 98 106 99 107 protected void AnalyzeBestTestSolution(PushProgram program, ResultCollection results, IRandom random) { 100 var testResult = PushEvaluator.EvaluateT raining(Pool, program, random);108 var testResult = PushEvaluator.EvaluateTest(Pool, program, random); 101 109 102 110 if (!results.ContainsKey(TEST_QUALITY_RESULT_NAME)) { … … 108 116 109 117 protected bool AnalyzeBestTrainingSolution(PushProgram program, double bestQuality, ResultCollection results, IRandom random) { 110 if (!results.ContainsKey(BEST_TRAINING_SOLUTION_RESULT_NAME)) { 111 var solution = CreatePushSolution( 118 var solution = CreatePushSolution( 112 119 program, 113 120 bestQuality, 114 (IRandom)random.Clone(),121 random, // is already cloned 115 122 (IReadOnlyPushConfiguration)Config.Clone()); 116 123 124 if (!results.ContainsKey(BEST_TRAINING_SOLUTION_RESULT_NAME)) { 117 125 results.Add(new Result(BEST_TRAINING_SOLUTION_RESULT_NAME, solution)); 118 126 return true; … … 123 131 if ((!Maximization && currentBestQuality > bestQuality) || 124 132 (Maximization && currentBestQuality < bestQuality)) { 125 results[BEST_TRAINING_SOLUTION_RESULT_NAME].Value = CreatePushSolution( 126 program, 127 bestQuality, 128 random, 129 Config); 133 results[BEST_TRAINING_SOLUTION_RESULT_NAME].Value = solution; 130 134 return true; 131 135 } … … 135 139 136 140 public override double Evaluate(Individual individual, IRandom random) { 137 var program = MapIndividual(individual, random); 138 var result = PushEvaluator.EvaluateTraining(Pool, program, random); 141 var program = MapIndividual(individual); 142 var seed = random.Next(); 143 var rand = new FastRandom(seed); 144 var result = PushEvaluator.EvaluateTraining(Pool, program, rand); 139 145 140 146 individual[CaseQualitiesScopeParameterName] = new DoubleArray(result.ExampleQualities); 147 individual[SeedScopeParameterName] = new IntValue(seed); 141 148 142 149 return result.AvgQuality; 143 150 } 144 151 145 protected abstract PushProgram MapIndividual(Individual individual , IRandom random);152 protected abstract PushProgram MapIndividual(Individual individual); 146 153 147 154 protected abstract PushSolution CreatePushSolution( -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Selector/LexicaseSelector.cs
r15275 r15289 60 60 61 61 protected override IScope[] Select(List<IScope> population) { 62 var count = NumberOfSelectedSubScopesParameter.ActualValue.Value; 63 var copy = CopySelectedParameter.Value.Value; 64 var maximization = MaximizationParameter.ActualValue.Value; 65 var random = RandomParameter.ActualValue; 62 var selected = Apply( 63 population, 64 NumberOfSelectedSubScopesParameter.ActualValue.Value, 65 CopySelectedParameter.Value.Value, 66 MaximizationParameter.ActualValue.Value, 67 RandomParameter.ActualValue, 68 CaseQualitiesParameter.ActualValue); 69 70 return selected; 71 } 72 73 public static IScope[] Apply( 74 List<IScope> population, 75 int count, 76 bool copy, 77 bool maximization, 78 IRandom random, 79 ItemArray<DoubleArray> caseQualities) { 66 80 var selected = new IScope[count]; 67 var caseQualities = CaseQualitiesParameter.ActualValue;68 81 var repeats = (int)Math.Ceiling(count / (double)population.Count); 69 82 var caseCount = caseQualities[0].Length; -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/SolutionCreator/IPlushCreator.cs
r15275 r15289 12 12 IValueLookupParameter<IntValue> MinCloseParameter { get; } 13 13 IValueLookupParameter<IntValue> MaxCloseParameter { get; } 14 IValueLookupParameter<DoubleValue> CloseBiasLevelParameter { get; } 14 15 IValueLookupParameter<PercentValue> InInstructionProbabilityParameter { get; } 15 16 IValueLookupParameter<IReadOnlyErcOptions> ErcOptionsParameter { get; } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/SolutionCreator/PlushCreator.cs
r15275 r15289 77 77 get { return (IValueLookupParameter<IntValue>)Parameters["MaxClose"]; } 78 78 } 79 public IValueLookupParameter<DoubleValue> CloseBiasLevel 79 public IValueLookupParameter<DoubleValue> CloseBiasLevelParameter 80 80 { 81 81 get { return (IValueLookupParameter<DoubleValue>)Parameters["CloseBiasLevel"]; } … … 99 99 var minClose = MinCloseParameter.ActualValue.Value; 100 100 var maxClose = MaxCloseParameter.ActualValue.Value; 101 var biasLevel = CloseBiasLevel .ActualValue.Value;101 var biasLevel = CloseBiasLevelParameter.ActualValue.Value; 102 102 103 103 if (minLength > maxLength) … … 111 111 112 112 for (var i = 0; i < length; i++) { 113 var expression = CodeGeneratorUtils.GetRandomExpression(random, ercOptions, instructions, inInstructionProbability); 113 var expression = CodeGeneratorUtils.GetRandomExpression( 114 random, 115 ercOptions, 116 instructions, 117 inInstructionProbability); 118 114 119 var close = random.NextBiased(minClose, maxClose, biasLevel); 115 120 -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/SolutionCreator/PushSolutionCreator.cs
r15273 r15289 1 1 namespace HeuristicLab.Problems.ProgramSynthesis.Push.SolutionCreator { 2 using System;3 2 4 3 using HeuristicLab.Common; … … 9 8 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 10 9 using HeuristicLab.Problems.ProgramSynthesis.Base.Erc; 10 using HeuristicLab.Problems.ProgramSynthesis.Push.Configuration; 11 11 12 12 /// <summary> … … 34 34 if (!Parameters.ContainsKey(IN_INSTRUCTION_PROBABILITY)) 35 35 Parameters.Add(new FixedValueParameter<PercentValue>(IN_INSTRUCTION_PROBABILITY, new PercentValue(0.05))); 36 37 Parameters.Add(new ValueLookupParameter<IReadOnlyExpressionsConfiguration>("Instructions", "The enabled instructions")); 36 38 } 37 39 … … 68 70 } 69 71 72 public IValueLookupParameter<IReadOnlyExpressionsConfiguration> InstructionsParameter 73 { 74 get { return (IValueLookupParameter<IReadOnlyExpressionsConfiguration>)Parameters["Instructions"]; } 75 } 76 70 77 //public IValueParameter<IntValue> MaxLengthParameter 71 78 //{ … … 94 101 var result = new IntegerVector(len); 95 102 96 var variableLength = random.Next(MinLength, len); 97 var contentLength = Math.Min(variableLength, len); 103 var contentLength = random.Next(MinLength, len); 98 104 var lowerBound = bounds[0, 0]; 99 105 var upperBound = bounds[0, 1]; 100 var inInstructionRelativeProbability = ErcOptions.ErcProbability + InInstructionProbability; 106 //var inInstructionRelativeProbability = ErcOptions.ErcProbability + InInstructionProbability; 107 //var instructions = InstructionsParameter.ActualValue; 101 108 102 109 for (var i = 0; i < contentLength; i++) { 103 var x = random.NextDouble();110 //var x = random.NextDouble(); 104 111 105 if (ErcOptions.ErcProbability > 0 && 106 x <= ErcOptions.ErcProbability) 107 result[i] = PushSolutionEncoding.Erc; 108 else if (InInstructionProbability > 0 && 109 x <= inInstructionRelativeProbability) 110 result[i] = PushSolutionEncoding.In; 111 else 112 result[i] = random.Next(lowerBound, upperBound); 112 //if (ErcOptions.ErcProbability > 0 && x <= ErcOptions.ErcProbability) { 113 // result[i] = PushSolutionEncoding.Erc; 114 //} else if (InInstructionProbability > 0 && x <= inInstructionRelativeProbability && instructions.InExpressionCount > 0) { 115 // var index = random.Next(0, instructions.InExpressionCount); 116 // var expression = ExpressionTable.InExpressionTable[index]; 117 118 // instructions.EnabledExpressions 119 // //result[i] = PushSolutionEncoding.In; 120 //} else { 121 result[i] = random.Next(lowerBound, upperBound); 122 //} 113 123 } 114 124 -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Stack/IPrintStack.cs
r15189 r15289 1 1 namespace HeuristicLab.Problems.ProgramSynthesis.Push.Stack { 2 public interface IPrintStack : IPushStack <string>{2 public interface IPrintStack : IPushStack { 3 3 void NewLine(); 4 4 void Push<T>(T item); -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Stack/IPushStack.cs
r15189 r15289 16 16 void Push(IReadOnlyList<T> items); 17 17 void Push(IEnumerable<T> items); 18 void Swap(int count); 19 void Yank(int index); 20 void RemoveTop(); 21 void Remove(int count); 22 void RemoveAt(int index); 23 void RemoveAt(int index, int count); 18 24 new void Clear(); 19 25 IReadOnlyList<T> Peek(int count); -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Stack/IPushStackBase.cs
r15032 r15289 9 9 10 10 void Clear(); 11 void Swap(int count); 12 void Yank(int index); 13 void RemoveTop(); 14 void Remove(int count); 15 void RemoveAt(int index); 16 void RemoveAt(int index, int count); 11 17 12 IEnumerable<string> AsStrings(); 18 13 IEnumerable<object> AsObjects(); -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Stack/InterpreterStackStringifier.cs
r15189 r15289 44 44 } 45 45 46 private static IEnumerable<string> StringifyLiteralStack <T>(IPushStack<T>stack, string prefix = "", string postfix = "", bool reverse = true) {46 private static IEnumerable<string> StringifyLiteralStack(IPushStack stack, string prefix = "", string postfix = "", bool reverse = true) { 47 47 var result = stack.AsStrings(); 48 48 -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Stack/PrintStack.cs
r15189 r15289 6 6 using System.Collections.Generic; 7 7 8 using HeuristicLab.Problems.ProgramSynthesis.Push.Constants; 8 9 using HeuristicLab.Problems.ProgramSynthesis.Push.Extensions; 9 10 … … 12 13 /// </summary> 13 14 public class PrintStack : IPrintStack { 14 private string currentTop; 15 private readonly IPushStack<string> stack = new PushStack<string>(); 15 private int lineCount = 0; 16 16 private readonly StringBuilder stringBuilder = new StringBuilder(); 17 17 18 private string CurrentTop19 {20 get21 {22 return currentTop ?? (currentTop = stringBuilder.ToString());23 }24 }25 26 public IEnumerator<string> GetEnumerator() {27 return stack.GetEnumerator();28 }29 30 18 IEnumerator IEnumerable.GetEnumerator() { 31 return GetEnumerator(); 19 var lines = AsStrings(); 20 return lines.GetEnumerator(); 32 21 } 33 22 … … 36 25 } 37 26 38 void IPushStack<string>.Clear() { 39 stack.Clear(); 27 void IPushStack.Clear() { 40 28 stringBuilder.Clear(); 41 currentTop = null;42 }43 44 public IReadOnlyList<string> Peek(int count) {45 if (count == 1)46 return new[] { CurrentTop };47 48 var peek = stack.Peek(count - 1);49 var result = new List<string>(peek) { CurrentTop };50 51 return result;52 }53 54 public void Insert(int index, string item) {55 if (index == 0)56 Add(item);57 58 stack.Insert(index - 1, item);59 }60 61 public string Pop() {62 var result = CurrentTop;63 64 var top = stack.Pop();65 SetBuilderToTop(top);66 67 return result;68 }69 70 public IReadOnlyList<string> Pop(int count) {71 if (count == 1)72 return new[] { Pop() };73 74 var popped = stack.Pop(count - 1);75 var result = new List<string>(popped) { CurrentTop };76 77 var newTop = stack.Pop();78 SetBuilderToTop(newTop);79 80 return result;81 }82 83 private void ClearTop() {84 stringBuilder.Clear();85 currentTop = null;86 }87 88 private void SetBuilderToTop(string top) {89 stringBuilder.Clear();90 stringBuilder.Append(top);91 currentTop = top;92 }93 94 public bool TryPop(out string item) {95 if (string.IsNullOrEmpty(CurrentTop)) {96 item = null;97 return false;98 }99 100 item = Pop();101 return true;102 }103 104 public string ElementAt(int index) {105 if (index == 0)106 return CurrentTop;107 108 return stack.ElementAt(index - 1);109 }110 111 public string Top112 {113 get114 {115 return CurrentTop;116 }117 set118 {119 SetBuilderToTop(value);120 }121 }122 123 public string TopOrDefault { get { return CurrentTop; } }124 125 public string Bottom { get { return Count > 1 ? stack.Bottom : CurrentTop; } }126 127 public string BottomOrDefault { get { return Bottom; } }128 129 public string this[int key]130 {131 get132 {133 return key == 0 ? CurrentTop : stack[key - 1];134 }135 set136 {137 if (key == 0)138 SetBuilderToTop(value);139 else140 stack[key - 1] = value;141 }142 }143 144 public int Count145 {146 get147 {148 return stack.Count + (string.IsNullOrEmpty(CurrentTop) ? 0 : 1);149 }150 29 } 151 30 152 31 public void NewLine() { 153 if (IsEmpty) return; 154 155 stack.Push(CurrentTop); 156 ClearTop(); 32 stringBuilder.Append(PushEnvironment.NewLine); 33 lineCount++; 157 34 } 158 35 159 36 public void Push<T>(T item) { 37 if (IsEmpty) lineCount = 1; 160 38 stringBuilder.Append(item); 161 currentTop = null;162 39 } 163 40 164 41 public void Push(float item) { 42 if (IsEmpty) lineCount = 1; 165 43 stringBuilder.Concat(item); 166 currentTop = null;167 44 } 168 45 169 46 public void Push(double item) { 47 if (IsEmpty) lineCount = 1; 170 48 stringBuilder.Concat(item); 171 currentTop = null;172 49 } 173 50 174 51 public void Push(long item) { 52 if (IsEmpty) lineCount = 1; 175 53 stringBuilder.Concat(item); 176 currentTop = null;177 54 } 178 55 179 56 public void Push(int item) { 57 if (IsEmpty) lineCount = 1; 180 58 stringBuilder.Concat(item); 181 currentTop = null;182 59 } 183 60 184 61 public void Push(char item) { 62 if (IsEmpty) lineCount = 1; 185 63 stringBuilder.Append(item); 186 currentTop = null;187 64 } 188 65 189 66 public void Push(bool item) { 67 if (IsEmpty) lineCount = 1; 190 68 stringBuilder.Append(item); 191 currentTop = null;192 69 } 193 70 194 71 195 72 public void Push(string item) { 73 if (IsEmpty) lineCount = 1; 196 74 stringBuilder.Append(item); 197 currentTop = null;198 }199 200 public void Push(string item1, string item2) {201 stringBuilder.Append(item1);202 stringBuilder.Append(item2);203 currentTop = null;204 }205 206 public void Push(string item1, string item2, string item3) {207 stringBuilder.Append(item1);208 stringBuilder.Append(item2);209 stringBuilder.Append(item3);210 currentTop = null;211 }212 213 public void Push(string item1, string item2, string item3, string item4) {214 stringBuilder.Append(item1);215 stringBuilder.Append(item2);216 stringBuilder.Append(item3);217 stringBuilder.Append(item4);218 currentTop = null;219 75 } 220 76 … … 222 78 for (var i = startIndex; i < items.Count; i++) 223 79 stringBuilder.Append(items[i]); 224 225 currentTop = null;226 80 } 227 81 … … 233 87 foreach (var item in items) 234 88 stringBuilder.Append(item); 235 236 currentTop = null;237 }238 239 void IPushStack.Clear() {240 stringBuilder.Clear();241 currentTop = null;242 stack.Clear();243 }244 245 public void Swap(int count) {246 stack.Push(CurrentTop);247 stack.Swap(count);248 249 var newTop = stack.Pop();250 SetBuilderToTop(newTop);251 }252 253 public void Yank(int index) {254 if (index == Count - 1) return;255 256 stack.Push(CurrentTop);257 258 var item = stack[index];259 stack.RemoveAt(index);260 SetBuilderToTop(item);261 }262 263 public void RemoveTop() {264 var newTop = stack.Pop();265 SetBuilderToTop(newTop);266 }267 268 public void Remove(int count) {269 if (count == 1)270 RemoveTop();271 272 stack.Remove(count - 1);273 var newTop = stack.Pop();274 SetBuilderToTop(newTop);275 }276 277 public void RemoveAt(int index) {278 if (index == 0)279 ClearTop();280 else281 stack.RemoveAt(index - 1);282 }283 284 public void RemoveAt(int index, int count) {285 if (index == 0)286 count--;287 288 stack.RemoveAt(index - 1, count);289 290 if (index == 0) {291 var newTop = stack.Pop();292 SetBuilderToTop(newTop);293 }294 89 } 295 90 296 91 public IEnumerable<string> AsStrings() { 297 foreach (var item in stack) 298 yield return item; 299 300 if (!IsEmpty) 301 yield return CurrentTop; 92 var lines = stringBuilder.ToString().Split(PushEnvironment.NewLine); 93 return lines; 302 94 } 303 95 … … 306 98 } 307 99 308 void ICollection<string>.Clear() { 309 stack.Clear(); 310 stringBuilder.Clear(); 311 } 312 313 public bool Contains(string item) { 314 315 return CurrentTop.Equals(item) || stack.Contains(item); 316 } 317 318 public void CopyTo(string[] array, int arrayIndex) { 319 stack.CopyTo(array, arrayIndex); 320 array[arrayIndex + stack.Count] = CurrentTop; 321 } 322 323 public bool Remove(string item) { 324 if (item.Equals(CurrentTop)) { 325 RemoveTop(); 326 return true; 327 } 328 329 return stack.Remove(item); 330 } 331 332 int IPushStack<string>.Count 100 int IPushStack.Count 333 101 { 334 102 get 335 103 { 336 return Count;104 return lineCount; 337 105 } 338 106 } 339 107 340 public bool IsEmpty { get { return st ack.IsEmpty && string.IsNullOrEmpty(CurrentTop); } }108 public bool IsEmpty { get { return stringBuilder.Length == 0; } } 341 109 342 110 public bool IsEnabled { get; set; } 343 111 344 int ICollection<string>.Count 345 { 346 get 347 { 348 return Count; 349 } 112 public bool IsReadOnly { get { return false; } } 113 114 public override string ToString() { 115 return stringBuilder.ToString(); 350 116 } 351 352 public bool IsReadOnly { get { return false; } }353 117 } 354 118 } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Views/PushDebuggerView.cs
r15273 r15289 9 9 using Core.Views; 10 10 using Expressions; 11 12 using HeuristicLab.Problems.ProgramSynthesis.Push.Solution; 13 11 14 using Interpreter; 12 15 using MainForm; 13 using Problem;14 16 using Stack; 15 17 … … 227 229 228 230 // align numbers right 229 var stackEntryType = type.GetStackEntryType(); 230 if (stackEntryType == typeof(double) || 231 stackEntryType == typeof(long)) { 231 if (type == StackTypes.Integer || 232 type == StackTypes.Float) { 232 233 list.DrawMode = DrawMode.OwnerDrawFixed; 233 234 list.DrawItem += (sender, e) => {
Note: See TracChangeset
for help on using the changeset viewer.