Changeset 15289 for branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Analyzer/PushExpressionFrequencyAnalyzer.cs
- Timestamp:
- 07/26/17 19:34:13 (7 years ago)
- Location:
- branches/PushGP/HeuristicLab.PushGP
- Files:
-
- 2 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/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
Note: See TracChangeset
for help on using the changeset viewer.