Changeset 9241 for branches/HeuristicLab.EvolutionaryTracking
- Timestamp:
- 02/21/13 16:55:07 (12 years ago)
- Location:
- branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Problems.DataAnalysis.Symbolic
- Files:
-
- 1 added
- 2 deleted
- 40 edited
- 4 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Problems.DataAnalysis.Symbolic ¶
- Property svn:mergeinfo changed
-
branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4 ¶
- Property svn:ignore
-
TabularUnified
old new 1 *.user 2 Plugin.cs 1 3 bin 2 *.user3 HeuristicLabProblemsDataAnalysisSymbolicPlugin.cs4 4 obj 5 *.vs10x6 Plugin.cs
-
- Property svn:ignore
-
TabularUnified branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/SymbolicDataAnalysisMultiObjectiveAnalyzer.cs ¶
r7259 r9241 20 20 #endregion 21 21 22 using System.Collections.Generic;23 using System.Linq;24 22 using HeuristicLab.Common; 25 23 using HeuristicLab.Core; 26 24 using HeuristicLab.Data; 27 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;28 using HeuristicLab.Operators;29 25 using HeuristicLab.Parameters; 30 26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 31 using HeuristicLab.Optimization;32 27 33 28 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { … … 39 34 private const string QualitiesParameterName = "Qualities"; 40 35 private const string MaximizationParameterName = "Maximization"; 36 private const string ApplyLinearScalingParameterName = "ApplyLinearScaling"; 41 37 #region parameter properties 42 38 public IScopeTreeLookupParameter<DoubleArray> QualitiesParameter { … … 45 41 public ILookupParameter<BoolArray> MaximizationParameter { 46 42 get { return (ILookupParameter<BoolArray>)Parameters[MaximizationParameterName]; } 43 } 44 public ILookupParameter<BoolValue> ApplyLinearScalingParameter { 45 get { return (ILookupParameter<BoolValue>)Parameters[ApplyLinearScalingParameterName]; } 47 46 } 48 47 #endregion … … 64 63 Parameters.Add(new ScopeTreeLookupParameter<DoubleArray>(QualitiesParameterName, "The qualities of the trees that should be analyzed.")); 65 64 Parameters.Add(new LookupParameter<BoolArray>(MaximizationParameterName, "The directions of optimization for each dimension.")); 65 Parameters.Add(new LookupParameter<BoolValue>(ApplyLinearScalingParameterName, "Flag that indicates if the individual should be linearly scaled before evaluating.")); 66 } 67 68 [StorableHook(HookType.AfterDeserialization)] 69 private void AfterDeserialization() { 70 if (Parameters.ContainsKey(ApplyLinearScalingParameterName) && Parameters[ApplyLinearScalingParameterName] is LookupParameter<BoolValue>) 71 Parameters.Remove(ApplyLinearScalingParameterName); 72 if (!Parameters.ContainsKey(ApplyLinearScalingParameterName)) 73 Parameters.Add(new LookupParameter<BoolValue>(ApplyLinearScalingParameterName, "Flag that indicates if the individual should be linearly scaled before evaluating.")); 66 74 } 67 75 } -
TabularUnified branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/SymbolicDataAnalysisMultiObjectiveTrainingBestSolutionAnalyzer.cs ¶
r7259 r9241 20 20 #endregion 21 21 22 using System; 22 23 using System.Collections.Generic; 23 24 using System.Linq; … … 26 27 using HeuristicLab.Data; 27 28 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 28 using HeuristicLab.Operators;29 29 using HeuristicLab.Optimization; 30 30 using HeuristicLab.Parameters; 31 31 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 32 using System;33 32 34 33 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { … … 42 41 private const string TrainingBestSolutionsParameterName = "Best training solutions"; 43 42 private const string TrainingBestSolutionQualitiesParameterName = "Best training solution qualities"; 43 private const string UpdateAlwaysParameterName = "Always update best solutions"; 44 44 45 45 #region parameter properties … … 49 49 public ILookupParameter<ItemList<DoubleArray>> TrainingBestSolutionQualitiesParameter { 50 50 get { return (ILookupParameter<ItemList<DoubleArray>>)Parameters[TrainingBestSolutionQualitiesParameterName]; } 51 } 52 public IFixedValueParameter<BoolValue> UpdateAlwaysParameter { 53 get { return (IFixedValueParameter<BoolValue>)Parameters[UpdateAlwaysParameterName]; } 51 54 } 52 55 #endregion … … 60 63 set { TrainingBestSolutionQualitiesParameter.ActualValue = value; } 61 64 } 65 public BoolValue UpdateAlways { 66 get { return UpdateAlwaysParameter.Value; } 67 } 62 68 #endregion 63 69 … … 69 75 Parameters.Add(new LookupParameter<ItemList<T>>(TrainingBestSolutionsParameterName, "The training best (Pareto-optimal) symbolic data analysis solutions.")); 70 76 Parameters.Add(new LookupParameter<ItemList<DoubleArray>>(TrainingBestSolutionQualitiesParameterName, "The qualities of the training best (Pareto-optimal) solutions.")); 77 Parameters.Add(new FixedValueParameter<BoolValue>(UpdateAlwaysParameterName, "Determines if the best training solutions should always be updated regardless of its quality.", new BoolValue(false))); 78 UpdateAlwaysParameter.Hidden = true; 79 } 80 81 [StorableHook(HookType.AfterDeserialization)] 82 private void AfterDeserialization() { 83 if (!Parameters.ContainsKey(UpdateAlwaysParameterName)) { 84 Parameters.Add(new FixedValueParameter<BoolValue>(UpdateAlwaysParameterName, "Determines if the best training solutions should always be updated regardless of its quality.", new BoolValue(false))); 85 UpdateAlwaysParameter.Hidden = true; 86 } 71 87 } 72 88 … … 81 97 } 82 98 83 IList<double[]> trainingBestQualities = TrainingBestSolutionQualities 84 .Select(x => x.ToArray()) 85 .ToList(); 99 //if the pareto front of best solutions shall be updated regardless of the quality, the list initialized empty to discard old solutions 100 IList<double[]> trainingBestQualities; 101 if (UpdateAlways.Value) { 102 trainingBestQualities = new List<double[]>(); 103 } else { 104 trainingBestQualities = TrainingBestSolutionQualities.Select(x => x.ToArray()).ToList(); 105 } 86 106 87 107 #region find best trees … … 131 151 public bool Equals(double[] x, double[] y) { 132 152 if (y.Length != x.Length) throw new ArgumentException(); 133 for (int i = 0; i < x.Length; i++) {153 for (int i = 0; i < x.Length; i++) { 134 154 if (!x[i].IsAlmost(y[i])) return false; 135 155 } -
TabularUnified branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/SymbolicDataAnalysisMultiObjectiveValidationBestSolutionAnalyzer.cs ¶
r7259 r9241 44 44 private const string ValidationBestSolutionsParameterName = "Best validation solutions"; 45 45 private const string ValidationBestSolutionQualitiesParameterName = "Best validation solution qualities"; 46 private const string UpdateAlwaysParameterName = "Always update best solutions"; 46 47 47 48 #region parameter properties … … 51 52 public ILookupParameter<ItemList<DoubleArray>> ValidationBestSolutionQualitiesParameter { 52 53 get { return (ILookupParameter<ItemList<DoubleArray>>)Parameters[ValidationBestSolutionQualitiesParameterName]; } 54 } 55 public IFixedValueParameter<BoolValue> UpdateAlwaysParameter { 56 get { return (IFixedValueParameter<BoolValue>)Parameters[UpdateAlwaysParameterName]; } 53 57 } 54 58 #endregion … … 62 66 set { ValidationBestSolutionQualitiesParameter.ActualValue = value; } 63 67 } 68 public BoolValue UpdateAlways { 69 get { return UpdateAlwaysParameter.Value; } 70 } 64 71 #endregion 65 72 … … 71 78 Parameters.Add(new LookupParameter<ItemList<S>>(ValidationBestSolutionsParameterName, "The validation best (Pareto-optimal) symbolic data analysis solutions.")); 72 79 Parameters.Add(new LookupParameter<ItemList<DoubleArray>>(ValidationBestSolutionQualitiesParameterName, "The qualities of the validation best (Pareto-optimal) solutions.")); 80 Parameters.Add(new FixedValueParameter<BoolValue>(UpdateAlwaysParameterName, "Determines if the best validation solutions should always be updated regardless of its quality.", new BoolValue(false))); 81 UpdateAlwaysParameter.Hidden = true; 82 } 83 84 [StorableHook(HookType.AfterDeserialization)] 85 private void AfterDeserialization() { 86 if (!Parameters.ContainsKey(UpdateAlwaysParameterName)) { 87 Parameters.Add(new FixedValueParameter<BoolValue>(UpdateAlwaysParameterName, "Determines if the best training solutions should always be updated regardless of its quality.", new BoolValue(false))); 88 UpdateAlwaysParameter.Hidden = true; 89 } 73 90 } 74 91 … … 86 103 } 87 104 88 IList<double[]> trainingBestQualities = ValidationBestSolutionQualities 89 .Select(x => x.ToArray()) 90 .ToList(); 105 //if the pareto front of best solutions shall be updated regardless of the quality, the list initialized empty to discard old solutions 106 IList<double[]> trainingBestQualities; 107 if (UpdateAlways.Value) { 108 trainingBestQualities = new List<double[]>(); 109 } else { 110 trainingBestQualities = ValidationBestSolutionQualities.Select(x => x.ToArray()).ToList(); 111 } 91 112 92 113 #region find best trees -
TabularUnified branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/SymbolicDataAnalysisSingleObjectiveAnalyzer.cs ¶
r7259 r9241 20 20 #endregion 21 21 22 using System.Collections.Generic;23 using System.Linq;24 22 using HeuristicLab.Common; 25 23 using HeuristicLab.Core; 26 24 using HeuristicLab.Data; 27 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;28 using HeuristicLab.Operators;29 25 using HeuristicLab.Parameters; 30 26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 31 using HeuristicLab.Optimization;32 27 33 28 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { … … 39 34 private const string QualityParameterName = "Quality"; 40 35 private const string MaximizationParameterName = "Maximization"; 36 private const string ApplyLinearScalingParameterName = "ApplyLinearScaling"; 37 41 38 #region parameter properties 42 39 public IScopeTreeLookupParameter<DoubleValue> QualityParameter { … … 45 42 public ILookupParameter<BoolValue> MaximizationParameter { 46 43 get { return (ILookupParameter<BoolValue>)Parameters[MaximizationParameterName]; } 44 } 45 public ILookupParameter<BoolValue> ApplyLinearScalingParameter { 46 get { return (ILookupParameter<BoolValue>)Parameters[ApplyLinearScalingParameterName]; } 47 47 } 48 48 #endregion … … 64 64 Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>(QualityParameterName, "The qualities of the trees that should be analyzed.")); 65 65 Parameters.Add(new LookupParameter<BoolValue>(MaximizationParameterName, "The direction of optimization.")); 66 Parameters.Add(new LookupParameter<BoolValue>(ApplyLinearScalingParameterName, "Flag that indicates if the individual should be linearly scaled before evaluating.")); 67 } 68 69 [StorableHook(HookType.AfterDeserialization)] 70 private void AfterDeserialization() { 71 if (Parameters.ContainsKey(ApplyLinearScalingParameterName) && !(Parameters[ApplyLinearScalingParameterName] is LookupParameter<BoolValue>)) 72 Parameters.Remove(ApplyLinearScalingParameterName); 73 if (!Parameters.ContainsKey(ApplyLinearScalingParameterName)) 74 Parameters.Add(new LookupParameter<BoolValue>(ApplyLinearScalingParameterName, "Flag that indicates if the individual should be linearly scaled before evaluating.")); 66 75 } 67 76 } -
TabularUnified branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/SymbolicDataAnalysisSingleObjectiveTrainingBestSolutionAnalyzer.cs ¶
r7259 r9241 20 20 #endregion 21 21 22 using System.Collections.Generic;23 22 using System.Linq; 24 23 using HeuristicLab.Common; … … 26 25 using HeuristicLab.Data; 27 26 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 28 using HeuristicLab.Operators;29 27 using HeuristicLab.Optimization; 30 28 using HeuristicLab.Parameters; … … 41 39 private const string TrainingBestSolutionParameterName = "Best training solution"; 42 40 private const string TrainingBestSolutionQualityParameterName = "Best training solution quality"; 41 private const string UpdateAlwaysParameterName = "Always update best solution"; 43 42 44 43 #region parameter properties … … 48 47 public ILookupParameter<DoubleValue> TrainingBestSolutionQualityParameter { 49 48 get { return (ILookupParameter<DoubleValue>)Parameters[TrainingBestSolutionQualityParameterName]; } 49 } 50 public IFixedValueParameter<BoolValue> UpdateAlwaysParameter { 51 get { return (IFixedValueParameter<BoolValue>)Parameters[UpdateAlwaysParameterName]; } 50 52 } 51 53 #endregion … … 59 61 set { TrainingBestSolutionQualityParameter.ActualValue = value; } 60 62 } 63 public BoolValue UpdateAlways { 64 get { return UpdateAlwaysParameter.Value; } 65 } 61 66 #endregion 62 67 … … 68 73 Parameters.Add(new LookupParameter<T>(TrainingBestSolutionParameterName, "The training best symbolic data analyis solution.")); 69 74 Parameters.Add(new LookupParameter<DoubleValue>(TrainingBestSolutionQualityParameterName, "The quality of the training best symbolic data analysis solution.")); 75 Parameters.Add(new FixedValueParameter<BoolValue>(UpdateAlwaysParameterName, "Determines if the best training solution should always be updated regardless of its quality.", new BoolValue(false))); 76 UpdateAlwaysParameter.Hidden = true; 77 } 78 79 [StorableHook(HookType.AfterDeserialization)] 80 private void AfterDeserialization() { 81 if (!Parameters.ContainsKey(UpdateAlwaysParameterName)) { 82 Parameters.Add(new FixedValueParameter<BoolValue>(UpdateAlwaysParameterName, "Determines if the best training solution should always be updated regardless of its quality.", new BoolValue(false))); 83 UpdateAlwaysParameter.Hidden = true; 84 } 70 85 } 71 86 … … 85 100 86 101 var results = ResultCollection; 87 if ( TrainingBestSolutionQuality == null ||88 IsBetter(bestQuality, TrainingBestSolutionQuality.Value, Maximization.Value)) {102 if (bestTree != null && (UpdateAlways.Value || TrainingBestSolutionQuality == null || 103 IsBetter(bestQuality, TrainingBestSolutionQuality.Value, Maximization.Value))) { 89 104 TrainingBestSolution = CreateSolution(bestTree, bestQuality); 90 105 TrainingBestSolutionQuality = new DoubleValue(bestQuality); -
TabularUnified branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/SymbolicDataAnalysisSingleObjectiveValidationAnalyzer.cs ¶
r7721 r9241 76 76 : base(original, cloner) { 77 77 } 78 public SymbolicDataAnalysisSingleObjectiveValidationAnalyzer() 79 78 79 protected SymbolicDataAnalysisSingleObjectiveValidationAnalyzer(): base() { 80 80 Parameters.Add(new LookupParameter<IRandom>(RandomParameterName, "The random generator.")); 81 81 Parameters.Add(new LookupParameter<U>(ProblemDataParameterName, "The problem data of the symbolic data analysis problem.")); 82 82 Parameters.Add(new LookupParameter<T>(EvaluatorParameterName, "The operator to use for fitness evaluation on the validation partition.")); 83 83 Parameters.Add(new LookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>(SymbolicDataAnalysisTreeInterpreterParameterName, "The interpreter for symbolic data analysis expression trees.")); 84 Parameters.Add(new ValueLookupParameter<IntRange>(ValidationPartitionParameterName, "The svalidation partition."));84 Parameters.Add(new ValueLookupParameter<IntRange>(ValidationPartitionParameterName, "The validation partition.")); 85 85 Parameters.Add(new ValueLookupParameter<PercentValue>(RelativeNumberOfEvaluatedSamplesParameterName, "The relative number of samples of the dataset partition, which should be randomly chosen for evaluation between the start and end index.")); 86 86 Parameters.Add(new ValueLookupParameter<PercentValue>(PercentageOfBestSolutionsParameterName, -
TabularUnified branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/SymbolicDataAnalysisSingleObjectiveValidationBestSolutionAnalyzer.cs ¶
r7721 r9241 43 43 private const string ValidationBestSolutionParameterName = "Best validation solution"; 44 44 private const string ValidationBestSolutionQualityParameterName = "Best validation solution quality"; 45 private const string UpdateAlwaysParameterName = "Always update best solution"; 45 46 46 47 #region parameter properties … … 50 51 public ILookupParameter<DoubleValue> ValidationBestSolutionQualityParameter { 51 52 get { return (ILookupParameter<DoubleValue>)Parameters[ValidationBestSolutionQualityParameterName]; } 53 } 54 public IFixedValueParameter<BoolValue> UpdateAlwaysParameter { 55 get { return (IFixedValueParameter<BoolValue>)Parameters[UpdateAlwaysParameterName]; } 52 56 } 53 57 #endregion … … 61 65 set { ValidationBestSolutionQualityParameter.ActualValue = value; } 62 66 } 67 public BoolValue UpdateAlways { 68 get { return UpdateAlwaysParameter.Value; } 69 } 63 70 #endregion 64 71 … … 70 77 Parameters.Add(new LookupParameter<S>(ValidationBestSolutionParameterName, "The validation best symbolic data analyis solution.")); 71 78 Parameters.Add(new LookupParameter<DoubleValue>(ValidationBestSolutionQualityParameterName, "The quality of the validation best symbolic data analysis solution.")); 79 Parameters.Add(new FixedValueParameter<BoolValue>(UpdateAlwaysParameterName, "Determines if the best validation solution should always be updated regardless of its quality.", new BoolValue(false))); 80 UpdateAlwaysParameter.Hidden = true; 81 } 82 83 [StorableHook(HookType.AfterDeserialization)] 84 private void AfterDeserialization() { 85 if (!Parameters.ContainsKey(UpdateAlwaysParameterName)) { 86 Parameters.Add(new FixedValueParameter<BoolValue>(UpdateAlwaysParameterName, "Determines if the best training solution should always be updated regardless of its quality.", new BoolValue(false))); 87 UpdateAlwaysParameter.Hidden = true; 88 } 72 89 } 73 90 … … 117 134 118 135 var results = ResultCollection; 119 if ( ValidationBestSolutionQuality == null ||136 if (UpdateAlways.Value || ValidationBestSolutionQuality == null || 120 137 IsBetter(bestValidationQuality, ValidationBestSolutionQuality.Value, Maximization.Value)) { 121 138 ValidationBestSolution = CreateSolution(bestTree, bestValidationQuality); -
TabularUnified branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/SymbolicDataAnalysisVariableFrequencyAnalyzer.cs ¶
r7259 r9241 109 109 // update variable impacts matrix 110 110 var orderedImpacts = (from row in datatable.Rows 111 select new { Name = row.Name, Impact = datatable.Rows[row.Name].Values.Average() })111 select new { Name = row.Name, Impact = Math.Round(datatable.Rows[row.Name].Values.Average(), 3) }) 112 112 .OrderByDescending(p => p.Impact) 113 113 .ToList(); -
TabularUnified branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Crossovers/MultiSymbolicDataAnalysisExpressionCrossover.cs ¶
r7521 r9241 35 35 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { 36 36 [Item("MultiSymbolicDataAnalysisExpressionCrossover", "Randomly selects and applies one of its crossovers every time it is called.")] 37 public class MultiSymbolicDataAnalysisExpressionCrossover<T> : StochasticMultiBranch<ISymbolicExpressionTreeCrossover>, 37 public class MultiSymbolicDataAnalysisExpressionCrossover<T> : StochasticMultiBranch<ISymbolicExpressionTreeCrossover>, ITracingSymbolicExpressionTreeOperator, 38 38 ISymbolicDataAnalysisExpressionCrossover<T> where T : class, IDataAnalysisProblemData { 39 39 private const string ParentsParameterName = "Parents"; … … 46 46 private const string RelativeNumberOfEvaluatedSamplesParameterName = "RelativeNumberOfEvaluatedSamples"; 47 47 private const string ProblemDataParameterName = "ProblemData"; 48 49 private const string SymbolicExpressionTreeNodeComparerParameterName = "SymbolicExpressionTreeNodeComparer"; 50 private const string SymbolicExpressionTreeNodeComparerParameterDescription = "The comparison operator used to check if two symbolic expression tree nodes are equal or similar."; 48 51 49 52 protected override bool CreateChildOperation { … … 83 86 get { return (IValueLookupParameter<T>)Parameters[ProblemDataParameterName]; } 84 87 } 88 public ValueParameter<ISymbolicExpressionTreeNodeComparer> SymbolicExpressionTreeNodeComparerParameter { 89 get { return (ValueParameter<ISymbolicExpressionTreeNodeComparer>)Parameters[SymbolicExpressionTreeNodeComparerParameterName]; } 90 } 91 #endregion 92 93 #region Properties 94 public ISymbolicExpressionTreeNodeComparer SymbolicExpressionTreeNodeComparer { 95 get { return (ISymbolicExpressionTreeNodeComparer)SymbolicExpressionTreeNodeComparerParameter.ActualValue; } 96 } 85 97 #endregion 86 98 … … 100 112 Parameters.Add(new ScopeTreeLookupParameter<ISymbolicExpressionTree>(ParentsParameterName, "The parent symbolic expression trees which should be crossed.")); 101 113 Parameters.Add(new LookupParameter<ISymbolicExpressionTree>(ChildParameterName, "The child symbolic expression tree resulting from the crossover.")); 114 Parameters.Add(new ValueParameter<ISymbolicExpressionTreeNodeComparer>(SymbolicExpressionTreeNodeComparerParameterName, SymbolicExpressionTreeNodeComparerParameterDescription)); 102 115 103 116 EvaluatorParameter.Hidden = true; … … 163 176 op.MaximumSymbolicExpressionTreeLengthParameter.ActualName = MaximumSymbolicExpressionTreeLengthParameter.Name; 164 177 } 165 166 178 foreach (ISymbolicDataAnalysisInterpreterOperator op in Operators.OfType<ISymbolicDataAnalysisInterpreterOperator>()) { 167 179 op.SymbolicDataAnalysisTreeInterpreterParameter.ActualName = SymbolicDataAnalysisTreeInterpreterParameter.Name; … … 173 185 op.EvaluatorParameter.ActualName = EvaluatorParameter.Name; 174 186 } 187 var comparers = ApplicationManager.Manager.GetInstances<ISymbolicExpressionTreeNodeComparer>(); 188 foreach (var op in Operators.OfType<ITracingSymbolicExpressionTreeOperator>()) { 189 op.SymbolicExpressionTreeNodeComparerParameter.ActualValue = comparers.First(); 190 } 175 191 } 176 192 } -
TabularUnified branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Crossovers/SymbolicDataAnalysisExpressionCrossover.cs ¶
r7521 r9241 32 32 33 33 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { 34 public abstract class SymbolicDataAnalysisExpressionCrossover<T> : SymbolicExpressionTreeCrossover, ISymbolicDataAnalysisExpressionCrossover<T> where T : class, IDataAnalysisProblemData {34 public abstract class SymbolicDataAnalysisExpressionCrossover<T> : TracingSymbolicExpressionTreeCrossover, ISymbolicDataAnalysisExpressionCrossover<T> where T : class, IDataAnalysisProblemData { 35 35 private const string SymbolicDataAnalysisTreeInterpreterParameterName = "SymbolicExpressionTreeInterpreter"; 36 36 private const string ProblemDataParameterName = "ProblemData"; -
TabularUnified branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Crossovers/SymbolicDataAnalysisExpressionDepthConstrainedCrossover.cs ¶
r7521 r9241 41 41 42 42 #region Parameter properties 43 public ConstrainedValueParameter<StringValue> DepthRangeParameter {44 get { return ( ConstrainedValueParameter<StringValue>)Parameters[DepthRangeParameterName]; }43 public IConstrainedValueParameter<StringValue> DepthRangeParameter { 44 get { return (IConstrainedValueParameter<StringValue>)Parameters[DepthRangeParameterName]; } 45 45 } 46 46 #endregion … … 89 89 var depthRange = new IntRange(); 90 90 const int depthOffset = 2; // skip the first 2 levels (root + startNode) 91 switch (( int)Enum.Parse(typeof(Ranges), mode)) {92 case (int)Ranges.HighLevel:91 switch ((Ranges)Enum.Parse(typeof(Ranges), mode)) { 92 case Ranges.HighLevel: 93 93 depthRange.Start = depthOffset; // skip the first 2 levels (root + startNode) 94 94 depthRange.End = depthRange.Start + (int)Math.Round(depth * 0.25); 95 95 break; 96 case (int)Ranges.Standard:96 case Ranges.Standard: 97 97 depthRange.Start = depthOffset + (int)Math.Round(depth * 0.25); 98 98 depthRange.End = depthRange.Start + (int)Math.Round(depth * 0.5); 99 99 break; 100 case (int)Ranges.LowLevel:100 case Ranges.LowLevel: 101 101 depthRange.Start = depthOffset + (int)Math.Round(depth * 0.75); 102 102 depthRange.End = Math.Max(depthRange.Start, depth); -
TabularUnified branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Evaluators/SymbolicDataAnalysisEvaluator.cs ¶
r7259 r9241 28 28 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 29 29 using HeuristicLab.Operators; 30 using HeuristicLab.Optimization; 30 31 using HeuristicLab.Parameters; 31 32 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; … … 35 36 [StorableClass] 36 37 public abstract class SymbolicDataAnalysisEvaluator<T> : SingleSuccessorOperator, 37 ISymbolicDataAnalysisEvaluator<T>, ISymbolicDataAnalysisInterpreterOperator, ISymbolicDataAnalysisBoundedOperator 38 ISymbolicDataAnalysisEvaluator<T>, ISymbolicDataAnalysisInterpreterOperator, ISymbolicDataAnalysisBoundedOperator, IStochasticOperator 38 39 where T : class, IDataAnalysisProblemData { 39 40 private const string RandomParameterName = "Random"; … … 44 45 private const string EvaluationPartitionParameterName = "EvaluationPartition"; 45 46 private const string RelativeNumberOfEvaluatedSamplesParameterName = "RelativeNumberOfEvaluatedSamples"; 47 private const string ApplyLinearScalingParameterName = "ApplyLinearScaling"; 48 private const string ValidRowIndicatorParameterName = "ValidRowIndicator"; 46 49 47 50 public override bool CanChangeName { get { return false; } } 48 51 49 52 #region parameter properties 53 ILookupParameter<IRandom> IStochasticOperator.RandomParameter { 54 get { return RandomParameter; } 55 } 56 50 57 public IValueLookupParameter<IRandom> RandomParameter { 51 58 get { return (IValueLookupParameter<IRandom>)Parameters[RandomParameterName]; } … … 70 77 get { return (IValueLookupParameter<PercentValue>)Parameters[RelativeNumberOfEvaluatedSamplesParameterName]; } 71 78 } 79 public ILookupParameter<BoolValue> ApplyLinearScalingParameter { 80 get { return (ILookupParameter<BoolValue>)Parameters[ApplyLinearScalingParameterName]; } 81 } 82 public IValueLookupParameter<StringValue> ValidRowIndicatorParameter { 83 get { return (IValueLookupParameter<StringValue>)Parameters[ValidRowIndicatorParameterName]; } 84 } 72 85 #endregion 73 86 … … 87 100 Parameters.Add(new ValueLookupParameter<DoubleLimit>(EstimationLimitsParameterName, "The upper and lower limit that should be used as cut off value for the output values of symbolic data analysis trees.")); 88 101 Parameters.Add(new ValueLookupParameter<PercentValue>(RelativeNumberOfEvaluatedSamplesParameterName, "The relative number of samples of the dataset partition, which should be randomly chosen for evaluation between the start and end index.")); 102 Parameters.Add(new LookupParameter<BoolValue>(ApplyLinearScalingParameterName, "Flag that indicates if the individual should be linearly scaled before evaluating.")); 103 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).")); 104 } 105 106 [StorableHook(HookType.AfterDeserialization)] 107 private void AfterDeserialization() { 108 if (Parameters.ContainsKey(ApplyLinearScalingParameterName) && !(Parameters[ApplyLinearScalingParameterName] is LookupParameter<BoolValue>)) 109 Parameters.Remove(ApplyLinearScalingParameterName); 110 if (!Parameters.ContainsKey(ApplyLinearScalingParameterName)) 111 Parameters.Add(new LookupParameter<BoolValue>(ApplyLinearScalingParameterName, "Flag that indicates if the individual should be linearly scaled before evaluating.")); 112 if (!Parameters.ContainsKey(ValidRowIndicatorParameterName)) 113 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).")); 89 114 } 90 115 … … 94 119 95 120 protected IEnumerable<int> GenerateRowsToEvaluate(double percentageOfRows) { 96 97 98 121 IEnumerable<int> rows; 99 122 int samplesStart = EvaluationPartitionParameter.ActualValue.Start; … … 101 124 int testPartitionStart = ProblemDataParameter.ActualValue.TestPartition.Start; 102 125 int testPartitionEnd = ProblemDataParameter.ActualValue.TestPartition.End; 103 104 126 if (samplesEnd < samplesStart) throw new ArgumentException("Start value is larger than end value."); 105 127 … … 113 135 } 114 136 115 return rows.Where(i => i < testPartitionStart || testPartitionEnd <= i); 137 rows = rows.Where(i => i < testPartitionStart || testPartitionEnd <= i); 138 if (ValidRowIndicatorParameter.ActualValue != null) { 139 string indicatorVar = ValidRowIndicatorParameter.ActualValue.Value; 140 var problemData = ProblemDataParameter.ActualValue; 141 var indicatorRow = problemData.Dataset.GetReadOnlyDoubleValues(indicatorVar); 142 rows = rows.Where(r => !indicatorRow[r].IsAlmost(0.0)); 143 } 144 return rows; 145 } 146 147 [ThreadStatic] 148 private static double[] cache; 149 protected static void CalculateWithScaling(IEnumerable<double> targetValues, IEnumerable<double> estimatedValues, 150 double lowerEstimationLimit, double upperEstimationLimit, 151 IOnlineCalculator calculator, int maxRows) { 152 if (cache == null || cache.Length < maxRows) { 153 cache = new double[maxRows]; 154 } 155 156 // calculate linear scaling 157 int i = 0; 158 var linearScalingCalculator = new OnlineLinearScalingParameterCalculator(); 159 var targetValuesEnumerator = targetValues.GetEnumerator(); 160 var estimatedValuesEnumerator = estimatedValues.GetEnumerator(); 161 while (targetValuesEnumerator.MoveNext() & estimatedValuesEnumerator.MoveNext()) { 162 double target = targetValuesEnumerator.Current; 163 double estimated = estimatedValuesEnumerator.Current; 164 cache[i] = estimated; 165 if (!double.IsNaN(estimated) && !double.IsInfinity(estimated)) 166 linearScalingCalculator.Add(estimated, target); 167 i++; 168 } 169 if (linearScalingCalculator.ErrorState == OnlineCalculatorError.None && (targetValuesEnumerator.MoveNext() || estimatedValuesEnumerator.MoveNext())) 170 throw new ArgumentException("Number of elements in target and estimated values enumeration do not match."); 171 172 double alpha = linearScalingCalculator.Alpha; 173 double beta = linearScalingCalculator.Beta; 174 if (linearScalingCalculator.ErrorState != OnlineCalculatorError.None) { 175 alpha = 0.0; 176 beta = 1.0; 177 } 178 179 //calculate the quality by using the passed online calculator 180 targetValuesEnumerator = targetValues.GetEnumerator(); 181 var scaledBoundedEstimatedValuesEnumerator = Enumerable.Range(0, i).Select(x => cache[x] * beta + alpha) 182 .LimitToRange(lowerEstimationLimit, upperEstimationLimit).GetEnumerator(); 183 184 while (targetValuesEnumerator.MoveNext() & scaledBoundedEstimatedValuesEnumerator.MoveNext()) { 185 calculator.Add(targetValuesEnumerator.Current, scaledBoundedEstimatedValuesEnumerator.Current); 186 } 116 187 } 117 188 } -
TabularUnified branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionLatexFormatter.cs ¶
r7708 r9241 33 33 [StorableClass] 34 34 public sealed class SymbolicDataAnalysisExpressionLatexFormatter : NamedItem, ISymbolicExpressionTreeStringFormatter { 35 private List<double> constants; 35 private readonly List<double> constants; 36 private int targetCount; 36 37 private int currentLag; 37 38 … … 98 99 } else if (node.Symbol is Division) { 99 100 if (node.SubtreeCount == 1) { 100 strBuilder.Append(@" \cfrac{1 }{");101 strBuilder.Append(@" \cfrac{1"); 101 102 } else { 102 103 strBuilder.Append(@" \cfrac{ "); … … 196 197 strBuilder.Append(invokeNode.Symbol.FunctionName + @" \left( "); 197 198 } else if (node.Symbol is StartSymbol) { 198 strBuilder.Append(" Result& = ");199 strBuilder.Append("target_" + (targetCount++) + "(t) & = "); 199 200 } else if (node.Symbol is Argument) { 200 201 var argSym = node.Symbol as Argument; … … 301 302 strBuilder.Append(" , "); 302 303 } else if (node.Symbol is StartSymbol) { 303 strBuilder.Append(@"\\" + Environment.NewLine + " & "); 304 strBuilder.Append(@"\\" + Environment.NewLine); 305 strBuilder.Append("target_" + (targetCount++) + "(t) & = "); 304 306 } else if (node.Symbol is Power) { 305 307 strBuilder.Append(@"\right) ^ { \operatorname{round} \left("); -
TabularUnified branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Grammars/FullFunctionalExpressionGrammar.cs ¶
r7707 r9241 116 116 var laggedVariable = new LaggedVariable(); 117 117 laggedVariable.InitialFrequency = 0.0; 118 var autoregressiveVariable = new AutoregressiveTargetVariable(); 119 autoregressiveVariable.InitialFrequency = 0.0; 120 autoregressiveVariable.Enabled = false; 118 121 119 122 var allSymbols = new List<Symbol>() { add, sub, mul, div, mean, sin, cos, tan, log, square, pow, sqrt, root, exp, 120 123 airyA, airyB, bessel, cosineIntegral, dawson, erf, expIntegralEi, fresnelCosineIntegral, fresnelSineIntegral, gamma, hypCosineIntegral, hypSineIntegral, norm, psi, sineIntegral, 121 @if, gt, lt, and, or, not, timeLag, integral, derivative, constant, variableSymbol, laggedVariable, variableCondition };124 @if, gt, lt, and, or, not, timeLag, integral, derivative, constant, variableSymbol, laggedVariable,autoregressiveVariable, variableCondition }; 122 125 var unaryFunctionSymbols = new List<Symbol>() { square, sqrt, sin, cos, tan, log, exp, not, timeLag, integral, derivative, 123 126 airyA, airyB, bessel, cosineIntegral, dawson, erf, expIntegralEi, fresnelCosineIntegral, fresnelSineIntegral, gamma, hypCosineIntegral, hypSineIntegral, norm, psi, sineIntegral … … 126 129 var binaryFunctionSymbols = new List<Symbol>() { pow, root, gt, lt, variableCondition }; 127 130 var ternarySymbols = new List<Symbol>() { add, sub, mul, div, mean, and, or }; 128 var terminalSymbols = new List<Symbol>() { variableSymbol, constant, laggedVariable };131 var terminalSymbols = new List<Symbol>() { variableSymbol, constant, laggedVariable, autoregressiveVariable }; 129 132 130 133 foreach (var symb in allSymbols) -
TabularUnified branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Grammars/TypeCoherentExpressionGrammar.cs ¶
r7696 r9241 102 102 constant.MinValue = -20; 103 103 constant.MaxValue = 20; 104 // var integerConstant = new IntegerConstant { MinValue = 0, MaxValue = 10; } 104 105 var variableSymbol = new Variable(); 105 106 var laggedVariable = new LaggedVariable(); 107 var autoregressiveVariable = new AutoregressiveTargetVariable(); 106 108 #endregion 107 109 … … 122 124 var conditionalSymbols = new GroupSymbol(ConditionalSymbolsName, new List<ISymbol> { conditionSymbols, comparisonSymbols, booleanOperationSymbols }); 123 125 124 var timeSeriesSymbols = new GroupSymbol(TimeSeriesSymbolsName, new List<ISymbol> { timeLag, integral, derivative, laggedVariable });126 var timeSeriesSymbols = new GroupSymbol(TimeSeriesSymbolsName, new List<ISymbol> { timeLag, integral, derivative, laggedVariable, autoregressiveVariable }); 125 127 #endregion 126 128 … … 152 154 SetSubtreeCount(derivative, 1, 1); 153 155 SetSubtreeCount(laggedVariable, 0, 0); 156 SetSubtreeCount(autoregressiveVariable, 0, 0); 154 157 #endregion 155 158 … … 225 228 Symbols.First(s => s.Name == TimeSeriesSymbolsName).Enabled = false; 226 229 } 230 231 public void ConfigureAsDefaultTimeSeriesPrognosisGrammar() { 232 Symbols.First(s => s is Average).Enabled = false; 233 Symbols.First(s => s.Name == TrigonometricFunctionsName).Enabled = false; 234 Symbols.First(s => s.Name == PowerFunctionsName).Enabled = false; 235 Symbols.First(s => s.Name == ConditionalSymbolsName).Enabled = false; 236 Symbols.First(s => s.Name == SpecialFunctionsName).Enabled = false; 237 238 Symbols.First(s => s.Name == TimeSeriesSymbolsName).Enabled = true; 239 Symbols.First(s => s is Derivative).Enabled = false; 240 Symbols.First(s => s is Integral).Enabled = false; 241 Symbols.First(s => s is TimeLag).Enabled = false; 242 } 227 243 } 228 244 } -
TabularUnified branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.csproj ¶
r8557 r9241 58 58 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x64' "> 59 59 <DebugSymbols>true</DebugSymbols> 60 <OutputPath> ..\..\..\..\trunk\sources\bin\</OutputPath>60 <OutputPath>$(SolutionDir)\bin\</OutputPath> 61 61 <DefineConstants>DEBUG;TRACE</DefineConstants> 62 62 <DebugType>full</DebugType> … … 66 66 </PropertyGroup> 67 67 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x64' "> 68 <OutputPath> ..\..\..\..\trunk\sources\bin\</OutputPath>68 <OutputPath>$(SolutionDir)\bin\</OutputPath> 69 69 <DefineConstants>TRACE</DefineConstants> 70 70 <Optimize>true</Optimize> … … 76 76 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' "> 77 77 <DebugSymbols>true</DebugSymbols> 78 <OutputPath> ..\..\..\..\trunk\sources\bin\</OutputPath>78 <OutputPath>$(SolutionDir)\bin\</OutputPath> 79 79 <DefineConstants>DEBUG;TRACE</DefineConstants> 80 80 <DebugType>full</DebugType> … … 84 84 </PropertyGroup> 85 85 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' "> 86 <OutputPath> ..\..\..\..\trunk\sources\bin\</OutputPath>86 <OutputPath>$(SolutionDir)\bin\</OutputPath> 87 87 <DefineConstants>TRACE</DefineConstants> 88 88 <Optimize>true</Optimize> … … 93 93 </PropertyGroup> 94 94 <ItemGroup> 95 <Reference Include="ALGLIB-3.5.0"> 96 <HintPath>..\..\..\..\trunk\sources\bin\ALGLIB-3.5.0.dll</HintPath> 95 <Reference Include="ALGLIB-3.6.0, Version=3.6.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 96 <HintPath>..\..\bin\ALGLIB-3.6.0.dll</HintPath> 97 <Private>False</Private> 97 98 </Reference> 98 99 <Reference Include="HeuristicLab.Analysis-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 99 100 <SpecificVersion>False</SpecificVersion> 100 <HintPath>..\..\..\..\ trunk\sources\bin\HeuristicLab.Analysis-3.3.dll</HintPath>101 <HintPath>..\..\..\..\Trunk\sources\bin\HeuristicLab.Analysis-3.3.dll</HintPath> 101 102 </Reference> 102 103 <Reference Include="HeuristicLab.Collections-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 103 104 <SpecificVersion>False</SpecificVersion> 104 <HintPath>..\..\..\..\ trunk\sources\bin\HeuristicLab.Collections-3.3.dll</HintPath>105 <HintPath>..\..\..\..\Trunk\sources\bin\HeuristicLab.Collections-3.3.dll</HintPath> 105 106 </Reference> 106 107 <Reference Include="HeuristicLab.Common-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 107 108 <SpecificVersion>False</SpecificVersion> 108 <HintPath>..\..\..\..\ trunk\sources\bin\HeuristicLab.Common-3.3.dll</HintPath>109 <HintPath>..\..\..\..\Trunk\sources\bin\HeuristicLab.Common-3.3.dll</HintPath> 109 110 </Reference> 110 111 <Reference Include="HeuristicLab.Common.Resources-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 111 112 <SpecificVersion>False</SpecificVersion> 112 <HintPath>..\..\..\..\ trunk\sources\bin\HeuristicLab.Common.Resources-3.3.dll</HintPath>113 <HintPath>..\..\..\..\Trunk\sources\bin\HeuristicLab.Common.Resources-3.3.dll</HintPath> 113 114 </Reference> 114 115 <Reference Include="HeuristicLab.Core-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 115 116 <SpecificVersion>False</SpecificVersion> 116 <HintPath>..\..\..\..\ trunk\sources\bin\HeuristicLab.Core-3.3.dll</HintPath>117 <HintPath>..\..\..\..\Trunk\sources\bin\HeuristicLab.Core-3.3.dll</HintPath> 117 118 </Reference> 118 119 <Reference Include="HeuristicLab.Data-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 119 120 <SpecificVersion>False</SpecificVersion> 120 <HintPath>..\..\..\..\ trunk\sources\bin\HeuristicLab.Data-3.3.dll</HintPath>121 <HintPath>..\..\..\..\Trunk\sources\bin\HeuristicLab.Data-3.3.dll</HintPath> 121 122 </Reference> 122 123 <Reference Include="HeuristicLab.Operators-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 123 124 <SpecificVersion>False</SpecificVersion> 124 <HintPath>..\..\..\..\ trunk\sources\bin\HeuristicLab.Operators-3.3.dll</HintPath>125 <HintPath>..\..\..\..\Trunk\sources\bin\HeuristicLab.Operators-3.3.dll</HintPath> 125 126 </Reference> 126 127 <Reference Include="HeuristicLab.Optimization-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 127 128 <SpecificVersion>False</SpecificVersion> 128 <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Optimization-3.3.dll</HintPath> 129 </Reference> 130 <Reference Include="HeuristicLab.Optimization.Operators-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 131 <SpecificVersion>False</SpecificVersion> 132 <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Optimization.Operators-3.3.dll</HintPath> 129 <HintPath>..\..\..\..\Trunk\sources\bin\HeuristicLab.Optimization-3.3.dll</HintPath> 133 130 </Reference> 134 131 <Reference Include="HeuristicLab.Parameters-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 135 132 <SpecificVersion>False</SpecificVersion> 136 <HintPath>..\..\..\..\ trunk\sources\bin\HeuristicLab.Parameters-3.3.dll</HintPath>133 <HintPath>..\..\..\..\Trunk\sources\bin\HeuristicLab.Parameters-3.3.dll</HintPath> 137 134 </Reference> 138 135 <Reference Include="HeuristicLab.Persistence-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 139 136 <SpecificVersion>False</SpecificVersion> 140 <HintPath>..\..\..\..\ trunk\sources\bin\HeuristicLab.Persistence-3.3.dll</HintPath>137 <HintPath>..\..\..\..\Trunk\sources\bin\HeuristicLab.Persistence-3.3.dll</HintPath> 141 138 </Reference> 142 139 <Reference Include="HeuristicLab.PluginInfrastructure-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 143 140 <SpecificVersion>False</SpecificVersion> 144 <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.PluginInfrastructure-3.3.dll</HintPath> 145 </Reference> 146 <Reference Include="HeuristicLab.Problems.DataAnalysis-3.4"> 147 <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Problems.DataAnalysis-3.4.dll</HintPath> 148 </Reference> 149 <Reference Include="HeuristicLab.Problems.Instances-3.3"> 150 <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Problems.Instances-3.3.dll</HintPath> 141 <HintPath>..\..\..\..\Trunk\sources\bin\HeuristicLab.PluginInfrastructure-3.3.dll</HintPath> 142 </Reference> 143 <Reference Include="HeuristicLab.Problems.DataAnalysis-3.4, Version=3.4.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 144 <SpecificVersion>False</SpecificVersion> 145 <HintPath>..\..\..\..\Trunk\sources\bin\HeuristicLab.Problems.DataAnalysis-3.4.dll</HintPath> 146 </Reference> 147 <Reference Include="HeuristicLab.Problems.Instances-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 148 <SpecificVersion>False</SpecificVersion> 149 <HintPath>..\..\..\..\Trunk\sources\bin\HeuristicLab.Problems.Instances-3.3.dll</HintPath> 151 150 </Reference> 152 151 <Reference Include="HeuristicLab.Random-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 153 152 <SpecificVersion>False</SpecificVersion> 154 <HintPath>..\..\..\..\ trunk\sources\bin\HeuristicLab.Random-3.3.dll</HintPath>153 <HintPath>..\..\..\..\Trunk\sources\bin\HeuristicLab.Random-3.3.dll</HintPath> 155 154 </Reference> 156 155 <Reference Include="System" /> … … 159 158 </Reference> 160 159 <Reference Include="System.Drawing" /> 161 <Reference Include="System.Xml.Linq">162 <RequiredTargetFramework>3.5</RequiredTargetFramework>163 </Reference>164 <Reference Include="System.Data.DataSetExtensions">165 <RequiredTargetFramework>3.5</RequiredTargetFramework>166 </Reference>167 <Reference Include="System.Data" />168 <Reference Include="System.Xml" />169 160 </ItemGroup> 170 161 <ItemGroup> 171 <Compile Include="Analyzers\SymbolicDataAnalysisComplexityAnalyzer.cs" />172 162 <Compile Include="Analyzers\SymbolicDataAnalysisSingleObjectiveValidationParetoBestSolutionAnalyzer.cs" /> 173 163 <Compile Include="Analyzers\SymbolicDataAnalysisSingleObjectiveTrainingParetoBestSolutionAnalyzer.cs" /> … … 198 188 <Compile Include="Crossovers\SymbolicDataAnalysisExpressionSemanticSimilarityCrossover.cs" /> 199 189 <Compile Include="Interfaces\ISymbolicDataAnalysisExpressionCrossover.cs" /> 190 <Compile Include="Interfaces\ISymbolicDataAnalysisImpactValuesCalculator.cs" /> 191 <Compile Include="Interpreter\InterpreterState.cs" /> 192 <Compile Include="Interpreter\OpCodes.cs" /> 193 <Compile Include="Interpreter\SymbolicDataAnalysisExpressionTreeILEmittingInterpreter.cs" /> 194 <Compile Include="Interpreter\SymbolicDataAnalysisExpressionTreeInterpreter.cs" /> 200 195 <Compile Include="Plugin.cs" /> 201 <Compile Include="SymbolicDataAnalysisExpressionTreeILEmittingInterpreter.cs" />202 196 <Compile Include="Formatters\SymbolicDataAnalysisExpressionLatexFormatter.cs" /> 203 197 <Compile Include="Formatters\SymbolicDataAnalysisExpressionMATLABFormatter.cs" /> … … 205 199 <Compile Include="Interfaces\ISymbolicDataAnalysisExpressionTreeInterpreter.cs" /> 206 200 <Compile Include="Interfaces\ISymbolicDataAnalysisProblem.cs" /> 201 <Compile Include="SymbolicDataAnalysisExpressionTreeMatching.cs" /> 207 202 <Compile Include="SymbolicDataAnalysisModel.cs"> 208 203 <SubType>Code</SubType> … … 217 212 <Compile Include="Interfaces\ISymbolicDataAnalysisAnalyzer.cs" /> 218 213 <Compile Include="SymbolicDataAnalysisSingleObjectiveProblem.cs" /> 219 <Compile Include="SymbolicDataAnalysisExpressionTreeInterpreter.cs" />220 214 <Compile Include="SymbolicDataAnalysisExpressionTreeSimplifier.cs" /> 221 215 <Compile Include="SymbolicDataAnalysisProblem.cs" /> 222 <Compile Include="SymbolicDataAnalysisSolution ValuesCalculator.cs" />223 <Compile Include="SymbolicDataAnalysis ExpressionTreeMatching.cs" />216 <Compile Include="SymbolicDataAnalysisSolutionImpactValuesCalculator.cs" /> 217 <Compile Include="SymbolicDataAnalysisSolutionTextRenderer.cs" /> 224 218 <Compile Include="Symbols\Addition.cs" /> 225 219 <Compile Include="Symbols\And.cs" /> 220 <Compile Include="Symbols\AutoregressiveVariable.cs" /> 226 221 <Compile Include="Symbols\Average.cs" /> 227 222 <Compile Include="Symbols\Constant.cs" /> … … 306 301 <ItemGroup> 307 302 <ProjectReference Include="..\..\HeuristicLab.Encodings.SymbolicExpressionTreeEncoding\3.4\HeuristicLab.Encodings.SymbolicExpressionTreeEncoding-3.4.csproj"> 308 <Project>{06 D4A186-9319-48A0-BADE-A2058D462EEA}</Project>303 <Project>{06d4a186-9319-48a0-bade-a2058d462eea}</Project> 309 304 <Name>HeuristicLab.Encodings.SymbolicExpressionTreeEncoding-3.4</Name> 310 305 </ProjectReference> … … 319 314 --> 320 315 <PropertyGroup> 321 <PreBuildEvent >set Path=%25Path%25;$(ProjectDir);$(SolutionDir)316 <PreBuildEvent Condition=" '$(OS)' == 'Windows_NT' ">set Path=%25Path%25;$(ProjectDir);$(SolutionDir) 322 317 set ProjectDir=$(ProjectDir) 323 318 set SolutionDir=$(SolutionDir) … … 326 321 call PreBuildEvent.cmd 327 322 </PreBuildEvent> 323 <PreBuildEvent Condition=" '$(OS)' != 'Windows_NT' "> 324 export ProjectDir=$(ProjectDir) 325 export SolutionDir=$(SolutionDir) 326 327 $SolutionDir/PreBuildEvent.sh 328 </PreBuildEvent> 328 329 </PropertyGroup> 329 330 </Project> -
TabularUnified branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interfaces/ISymbolicDataAnalysisEvaluator.cs ¶
r7259 r9241 29 29 IValueLookupParameter<IntRange> EvaluationPartitionParameter { get; } 30 30 IValueLookupParameter<PercentValue> RelativeNumberOfEvaluatedSamplesParameter { get; } 31 ILookupParameter<BoolValue> ApplyLinearScalingParameter { get; } 31 32 32 33 IValueLookupParameter<T> ProblemDataParameter { get; } -
TabularUnified branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interfaces/ISymbolicDataAnalysisMultiObjectiveAnalyzer.cs ¶
r7259 r9241 21 21 using HeuristicLab.Core; 22 22 using HeuristicLab.Data; 23 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;24 using HeuristicLab.Optimization;25 using HeuristicLab.Parameters;26 23 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { 27 24 public interface ISymbolicDataAnalysisMultiObjectiveAnalyzer : ISymbolicDataAnalysisAnalyzer { 28 25 IScopeTreeLookupParameter<DoubleArray> QualitiesParameter { get; } 29 26 ILookupParameter<BoolArray> MaximizationParameter { get; } 27 ILookupParameter<BoolValue> ApplyLinearScalingParameter { get; } 30 28 31 29 } -
TabularUnified branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interfaces/ISymbolicDataAnalysisProblem.cs ¶
r7259 r9241 22 22 using HeuristicLab.Core; 23 23 using HeuristicLab.Data; 24 using HeuristicLab.Optimization; 24 25 25 26 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { 26 public interface ISymbolicDataAnalysisProblem : IDataAnalysisProblem {27 public interface ISymbolicDataAnalysisProblem : IDataAnalysisProblem, IHeuristicOptimizationProblem { 27 28 IValueParameter<ISymbolicDataAnalysisGrammar> SymbolicExpressionTreeGrammarParameter { get; } 28 29 IValueParameter<ISymbolicDataAnalysisExpressionTreeInterpreter> SymbolicExpressionTreeInterpreterParameter { get; } … … 45 46 IntRange ValidationPartition { get; } 46 47 } 48 49 public interface ISymbolicDataAnalysisSingleObjectiveProblem : ISymbolicDataAnalysisProblem, ISingleObjectiveHeuristicOptimizationProblem { } 50 public interface ISymbolicDataAnalysisMultiObjectiveProblem : ISymbolicDataAnalysisProblem, IMultiObjectiveHeuristicOptimizationProblem { } 47 51 } -
TabularUnified branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interfaces/ISymbolicDataAnalysisSingleObjectiveAnalyzer.cs ¶
r7259 r9241 28 28 IScopeTreeLookupParameter<DoubleValue> QualityParameter { get; } 29 29 ILookupParameter<BoolValue> MaximizationParameter { get; } 30 ILookupParameter<BoolValue> ApplyLinearScalingParameter { get; } 30 31 } 31 32 } -
TabularUnified branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/OpCodes.cs ¶
r8477 r9241 105 105 { typeof(AutoregressiveTargetVariable),OpCodes.LagVariable}, 106 106 { typeof(Constant), OpCodes.Constant }, 107 // { typeof(IntegerConstant), OpCodes.Constant}, 107 108 { typeof(Argument), OpCodes.Arg }, 108 109 { typeof(Power),OpCodes.Power}, -
TabularUnified branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeInterpreter.cs ¶
r8486 r9241 99 99 throw new NotSupportedException("Interval arithmetic is not yet supported in the symbolic data analysis interpreter."); 100 100 101 EvaluatedSolutions.Value++; // increment the evaluated solutions counter 101 lock (EvaluatedSolutions) { 102 EvaluatedSolutions.Value++; // increment the evaluated solutions counter 103 } 102 104 var state = PrepareInterpreterState(tree, dataset); 103 105 … … 109 111 } 110 112 111 private InterpreterState PrepareInterpreterState(ISymbolicExpressionTree tree, Dataset dataset) {113 private static InterpreterState PrepareInterpreterState(ISymbolicExpressionTree tree, Dataset dataset) { 112 114 Instruction[] code = SymbolicExpressionTreeCompiler.Compile(tree, OpCodes.MapSymbolToOpCode); 113 115 int necessaryArgStackSize = 0; -
TabularUnified branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Plugin.cs.frame ¶
r7834 r9241 26 26 27 27 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { 28 [Plugin("HeuristicLab.Problems.DataAnalysis.Symbolic","Provides base classes for symbolic data analysis tasks.", "3.4. 2.$WCREV$")]28 [Plugin("HeuristicLab.Problems.DataAnalysis.Symbolic","Provides base classes for symbolic data analysis tasks.", "3.4.3.$WCREV$")] 29 29 [PluginFile("HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.dll", PluginFileType.Assembly)] 30 [PluginDependency("HeuristicLab.ALGLIB", "3. 5.0")]30 [PluginDependency("HeuristicLab.ALGLIB", "3.6.0")] 31 31 [PluginDependency("HeuristicLab.Analysis", "3.3")] 32 32 [PluginDependency("HeuristicLab.Collections", "3.3")] -
branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Properties ¶
- Property svn:ignore
--- +++
- Property svn:ignore
-
TabularUnified branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Properties/AssemblyInfo.cs.frame ¶
r7259 r9241 53 53 // by using the '*' as shown below: 54 54 [assembly: AssemblyVersion("3.4.0.0")] 55 [assembly: AssemblyFileVersion("3.4. 2.$WCREV$")]55 [assembly: AssemblyFileVersion("3.4.3.$WCREV$")] -
TabularUnified branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisExpressionTreeMatching.cs ¶
r8557 r9241 1 1 using System; 2 2 using System.Collections.Generic; 3 using System.IO;4 3 using System.Linq; 5 4 using HeuristicLab.Common; … … 7 6 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 8 7 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 8 using HeuristicLab.Problems.DataAnalysis.Symbolic; 9 9 10 10 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { 11 public enum SimilarityLevel {12 Exact, // everything is matched bit by bit (functions and terminals)13 High, // symbols are matched. leaf node types are matched14 Relaxed // only symbols are matched, leafs count as wildcards15 }16 11 [Item("SymbolicExpressionTreeNodeSimilarityComparer", "A comparison operator that checks node equality based on different similarity measures.")] 17 12 [StorableClass] … … 19 14 [StorableConstructor] 20 15 private SymbolicExpressionTreeNodeSimilarityComparer(bool deserializing) : base(deserializing) { } 21 private SymbolicExpressionTreeNodeSimilarityComparer(SymbolicExpressionTreeNodeSimilarityComparer original, Cloner cloner) : base(original, cloner) { } 16 private SymbolicExpressionTreeNodeSimilarityComparer(SymbolicExpressionTreeNodeSimilarityComparer original, Cloner cloner) 17 : base(original, cloner) { 18 matchConstantValues = original.matchConstantValues; 19 matchVariableNames = original.matchVariableNames; 20 matchVariableWeights = original.matchVariableWeights; 21 } 22 22 public override IDeepCloneable Clone(Cloner cloner) { return new SymbolicExpressionTreeNodeSimilarityComparer(this, cloner); } 23 23 24 private SimilarityLevel similarityLevel; 25 public SimilarityLevel SimilarityLevel { 26 get { return similarityLevel; } 27 set { similarityLevel = value; } 24 // more flexible matching criteria 25 [Storable] 26 private bool matchConstantValues; 27 public bool MatchConstantValues { 28 get { return matchConstantValues; } 29 set { matchConstantValues = value; } 30 } 31 32 [Storable] 33 private bool matchVariableNames; 34 public bool MatchVariableNames { 35 get { return matchVariableNames; } 36 set { matchVariableNames = value; } 37 } 38 39 [Storable] 40 private bool matchVariableWeights; 41 public bool MatchVariableWeights { 42 get { return matchVariableWeights; } 43 set { matchVariableWeights = value; } 44 } 45 46 [StorableHook(HookType.AfterDeserialization)] 47 private void AfterDeserialization() { 28 48 } 29 49 30 50 public SymbolicExpressionTreeNodeSimilarityComparer() { 31 this.similarityLevel = SimilarityLevel.Exact; 32 } 33 34 public SymbolicExpressionTreeNodeSimilarityComparer(SimilarityLevel similarityLevel) { 35 this.similarityLevel = similarityLevel; 51 matchConstantValues = true; 52 matchVariableNames = true; 53 matchVariableWeights = true; 36 54 } 37 55 … … 41 59 42 60 public bool Equals(ISymbolicExpressionTreeNode a, ISymbolicExpressionTreeNode b) { 61 if (!(a is SymbolicExpressionTreeTerminalNode)) 62 // if a and b are non terminal nodes, check equality of symbol names 63 return !(b is SymbolicExpressionTreeTerminalNode) && a.Symbol.Name.Equals(b.Symbol.Name); 64 var va = a as VariableTreeNode; 65 if (va != null) { 66 var vb = b as VariableTreeNode; 67 if (vb == null) return false; 68 69 return (!MatchVariableNames || va.VariableName.Equals(vb.VariableName)) && (!MatchVariableWeights || va.Weight.Equals(vb.Weight)); 70 } 43 71 var ca = a as ConstantTreeNode; 44 var cb = b as ConstantTreeNode; 72 if (ca != null) { 73 var cb = b as ConstantTreeNode; 74 if (cb == null) return false; 75 return (!MatchConstantValues || ca.Value.Equals(cb.Value)); 76 } 77 return false; 78 } 79 } 80 81 public class SymbolicExpressionTreeFragmentSimilarityComparer : IEqualityComparer<IFragment> { 82 public SymbolicExpressionTreeNodeSimilarityComparer SimilarityComparer { get; set; } 83 84 public bool Equals(IFragment x, IFragment y) { 85 if (SimilarityComparer == null) 86 throw new ArgumentNullException("SimilarityComparer needs to be initialized first."); 87 return x.Length == y.Length && 88 SymbolicExpressionTreeMatching.Match(x.Root, y.Root, SimilarityComparer) == x.Length; 89 } 90 91 public int GetHashCode(IFragment fragment) { 92 return fragment.Root.Symbol.Name.ToLower().GetHashCode(); 93 } 94 } 95 96 // this comparer considers that a < b if the type of a is "greater" than the type of b, for example: 97 // - A function node is "greater" than a terminal node 98 // - A variable terminal is "greater" than a constant terminal 99 public class SymbolicExpressionTreeNodeComparer : IComparer<ISymbolicExpressionTreeNode> { 100 public int Compare(ISymbolicExpressionTreeNode a, ISymbolicExpressionTreeNode b) { 101 if (!(a is SymbolicExpressionTreeTerminalNode)) { 102 if (b is SymbolicExpressionTreeTerminalNode) return -1; 103 return string.Compare(a.Symbol.Name, b.Symbol.Name, StringComparison.Ordinal); 104 } 105 if (!(b is SymbolicExpressionTreeTerminalNode)) return 1; 106 // at this point we know a and b are terminal nodes 45 107 var va = a as VariableTreeNode; 46 var vb = b as VariableTreeNode; 47 48 var aIsConstant = ca != null; 49 var aIsVariable = va != null; 50 var bIsConstant = cb != null; 51 var bIsVariable = vb != null; 52 var aIsFunction = (!(aIsConstant | aIsVariable)); 53 var bIsFunction = (!(bIsConstant | bIsVariable)); 54 55 if (aIsFunction) 56 return bIsFunction && a.Symbol.Name.Equals(b.Symbol.Name); 57 if (bIsFunction) // one is function and the other is not, return false 58 return false; 59 60 switch (similarityLevel) { 61 case (SimilarityLevel.Exact): 62 if (aIsConstant & bIsConstant) 63 return ca.Value.Equals(cb.Value); 64 if (aIsVariable & bIsVariable) 65 return va.Weight.Equals(vb.Weight); 66 return false; 67 case (SimilarityLevel.High): 68 return ((aIsConstant & bIsConstant) || (aIsVariable & bIsVariable)); 69 case (SimilarityLevel.Relaxed): 70 return true; 71 default: 72 return false; 73 } 74 } 75 76 public static bool ExactlySimilar(ISymbolicExpressionTreeNode a, ISymbolicExpressionTreeNode b) { 77 return Similar(a, b, SimilarityLevel.Exact); 78 } 79 80 public static bool Similar(ISymbolicExpressionTreeNode a, ISymbolicExpressionTreeNode b, SimilarityLevel level) { 81 var comp = new SymbolicExpressionTreeNodeSimilarityComparer(level); 82 return comp.Equals(a, b); 83 } 84 } 85 86 public class SymbolicExpressionTreeNodeOrderingComparer : IComparer<ISymbolicExpressionTreeNode> { 87 public int Compare(ISymbolicExpressionTreeNode a, ISymbolicExpressionTreeNode b) { 88 var ca = a as ConstantTreeNode; 89 var cb = b as ConstantTreeNode; 90 var va = a as VariableTreeNode; 91 var vb = b as VariableTreeNode; 92 93 var aIsConstant = ca != null; 94 var aIsVariable = va != null; 95 var bIsConstant = cb != null; 96 var bIsVariable = vb != null; 97 var aIsFunction = (!(aIsConstant | aIsVariable)); 98 var bIsFunction = (!(bIsConstant | bIsVariable)); 99 100 if (aIsFunction) 101 return bIsFunction ? a.Symbol.Name.CompareTo(b.Symbol.Name) : -1; 102 if (bIsFunction) // a is Constant or Variables 103 return 1; 104 if (aIsVariable) 105 return bIsVariable ? va.Weight.CompareTo(vb.Weight) : -1; 106 return 107 bIsVariable ? 1 : ca.Value.CompareTo(cb.Value); 108 if (va != null) { 109 if (b is ConstantTreeNode) return -1; 110 var vb = (VariableTreeNode)b; 111 return (va.VariableName.Equals(vb.VariableName) 112 ? va.Weight.CompareTo(vb.Weight) 113 : string.Compare(va.VariableName, vb.VariableName, StringComparison.Ordinal)); 114 } 115 // at this point we know for sure that a is a constant tree node 116 if (b is VariableTreeNode) return 1; 117 var ca = (ConstantTreeNode)a; 118 var cb = (ConstantTreeNode)b; 119 return ca.Value.CompareTo(cb.Value); 108 120 } 109 121 } … … 111 123 // tree equality 112 124 public class SymbolicExpressionTreeEqualityComparer : IEqualityComparer<ISymbolicExpressionTree> { 125 public SymbolicExpressionTreeNodeSimilarityComparer SimilarityComparer { get; set; } 126 113 127 public bool Equals(ISymbolicExpressionTree a, ISymbolicExpressionTree b) { 114 return SymbolicExpressionTreeMatching.FindMatch(a, b, similarityLevel) == 0; 128 if (SimilarityComparer == null) throw new ArgumentNullException("SimilarityComparer needs to be initialized first."); 129 return SymbolicExpressionTreeMatching.Match(a.Root, b.Root, SimilarityComparer) == Math.Min(a.Length, b.Length); 115 130 } 116 131 … … 118 133 return (tree.Length << 8) % 12345; 119 134 } 120 121 private SimilarityLevel similarityLevel; 122 public void SetComparisonMode(SimilarityLevel simLevel) { 123 similarityLevel = simLevel; 124 } 125 } 126 127 public static class SymbolicExpressionTreeMatching { 128 public static bool IsSimilarTo(this ISymbolicExpressionTree t1, ISymbolicExpressionTree t2, SimilarityLevel mode) { 129 return FindMatch(t1, t2, mode) == 0; 130 } 131 132 public static bool IsSimilarTo(this ISymbolicExpressionTreeNode t1, ISymbolicExpressionTreeNode t2, SimilarityLevel mode) { 133 return FindMatch(t1, t2, mode) == 0; 134 } 135 136 public static bool ContainsFragment(this ISymbolicExpressionTree tree, ISymbolicExpressionTreeNode fragment, SimilarityLevel mode) { 137 var matches = FindMatches(tree, fragment, mode); 138 return matches.Count > 0; 139 } 140 141 public static void SortSubtrees(this ISymbolicExpressionTree tree) { 135 } 136 137 public class SymbolicExpressionTreeCanonicalSorter { 138 private readonly HashSet<Type> nonSymmetricSymbols = new HashSet<Type> { typeof(Subtraction), typeof(Division) }; 139 140 public void SortSubtrees(ISymbolicExpressionTree tree) { 142 141 SortSubtrees(tree.Root); 143 142 } 144 143 145 public static void SortSubtrees(thisISymbolicExpressionTreeNode node) {144 public void SortSubtrees(ISymbolicExpressionTreeNode node) { 146 145 if (node.SubtreeCount == 0) return; 147 var subtrees = node.Subtrees as List<ISymbolicExpressionTreeNode>; 148 if (subtrees == null) return; 149 var comparer = new SymbolicExpressionTreeNodeOrderingComparer(); 150 subtrees.Sort(comparer); 151 foreach (var subtree in subtrees) 152 subtree.SortSubtrees(); 153 } 154 155 // return child that is the same as node 156 public static ISymbolicExpressionTreeNode FindChild(this ISymbolicExpressionTreeNode parent, ISymbolicExpressionTreeNode node) { 157 var subtrees = parent.Subtrees as List<ISymbolicExpressionTreeNode>; 158 var comparer = new SymbolicExpressionTreeNodeSimilarityComparer(SimilarityLevel.Exact); 159 return subtrees.Find(x => comparer.Equals(x, node)); 160 } 161 162 public static int FindMatch(ISymbolicExpressionTree a, ISymbolicExpressionTree b, SimilarityLevel similarityLevel) { 163 var nodesA = a.IterateNodesPostfix() as List<ISymbolicExpressionTreeNode>; 164 var nodesB = b.IterateNodesPostfix() as List<ISymbolicExpressionTreeNode>; 165 return FindMatch(nodesA, nodesB, similarityLevel); 166 } 167 168 public static int FindMatch(ISymbolicExpressionTreeNode a, ISymbolicExpressionTreeNode b, SimilarityLevel similarityLevel) { 169 var nodesA = a.IterateNodesPostfix() as List<ISymbolicExpressionTreeNode>; 170 var nodesB = b.IterateNodesPostfix() as List<ISymbolicExpressionTreeNode>; 171 return FindMatch(nodesA, nodesB, similarityLevel); 172 } 173 174 // returns the index in the sequence 'seq', where pattern 'pat' is matched, or -1 for no match 175 // -1 means no match, 0 means perfect match (the sequences overlap, hence the match index is 0) 176 public static int FindMatch(List<ISymbolicExpressionTreeNode> seq, List<ISymbolicExpressionTreeNode> pat, SimilarityLevel similarityLevel) { 177 int patlen = pat.Count; 178 int seqlen = seq.Count; 179 if (patlen == 0 || seqlen == 0) return -1; 180 var comparer = new SymbolicExpressionTreeNodeSimilarityComparer(similarityLevel); 181 if (patlen == seqlen) return seq.SequenceEqual(pat, comparer) ? 0 : -1; 182 for (int i = patlen; i <= seqlen; ++i) { 183 if (comparer.Equals(seq[i - 1], pat.Last())) // first check if last element is a match 184 if (seq.Skip(i - patlen).Take(patlen).SequenceEqual(pat, comparer)) // then check the whole sequence 185 return i - patlen; 186 } 187 return -1; 188 } 189 190 public static List<ISymbolicExpressionTreeNode> FindMatches(ISymbolicExpressionTree tree, ISymbolicExpressionTreeNode fragment, SimilarityLevel similarityLevel) { 191 var comp = new SymbolicExpressionTreeNodeSimilarityComparer(similarityLevel); 192 return FindMatches(tree.Root, fragment, comp); 193 } 194 195 public static List<ISymbolicExpressionTreeNode> 146 var subtrees = node.Subtrees as List<ISymbolicExpressionTreeNode> ?? node.Subtrees.ToList(); 147 if (IsSymmetric(node.Symbol)) { 148 var comparer = new SymbolicExpressionTreeNodeComparer(); 149 subtrees.Sort(comparer); 150 } 151 foreach (var s in subtrees) 152 SortSubtrees(s); 153 } 154 155 private bool IsSymmetric(ISymbol s) { 156 return !nonSymmetricSymbols.Contains(s.GetType()); 157 } 158 } 159 } 160 161 public static class SymbolicExpressionTreeMatching { 162 public static bool IsSimilarTo(this ISymbolicExpressionTree t1, ISymbolicExpressionTree t2, SymbolicExpressionTreeNodeSimilarityComparer comparer) { 163 return t1.Root.IsSimilarTo(t2.Root, comparer); 164 } 165 public static bool IsSimilarTo(this ISymbolicExpressionTreeNode t1, ISymbolicExpressionTreeNode t2, SymbolicExpressionTreeNodeSimilarityComparer comparer) { 166 return Match(t1, t2, comparer) == Math.Min(t1.GetLength(), t2.GetLength()); 167 } 168 public static bool ContainsFragment(this ISymbolicExpressionTreeNode root, IFragment fragment, SymbolicExpressionTreeNodeSimilarityComparer comparer) { 169 return FindMatches(root, fragment.Root, comparer).Any(); 170 } 171 public static IEnumerable<ISymbolicExpressionTreeNode> FindMatches(ISymbolicExpressionTree tree, ISymbolicExpressionTreeNode fragment, SymbolicExpressionTreeNodeSimilarityComparer comparer) { 172 return FindMatches(tree.Root, fragment, comparer); 173 } 174 175 public static IEnumerable<ISymbolicExpressionTreeNode> 196 176 FindMatches(ISymbolicExpressionTreeNode root, ISymbolicExpressionTreeNode fragment, SymbolicExpressionTreeNodeSimilarityComparer comp) { 197 var matches = new List<ISymbolicExpressionTreeNode>(); 198 root.ForEachNodePostfix(node => { 199 if (Match(node, fragment, comp) == fragment.GetLength()) matches.Add(node); 200 }); 201 return matches; 202 } 203 204 ///<summary> 205 /// Finds the longest common subsequence in quadratic time and linear space 206 /// Variant of: 207 /// D . S. Hirschberg. A linear space algorithm for or computing maximal common subsequences. 1975. 208 /// http://dl.acm.org/citation.cfm?id=360861 209 /// </summary> 210 /// <returns>Number of pairs that were matched</returns> 211 public static int 212 Match(ISymbolicExpressionTreeNode a, ISymbolicExpressionTreeNode b, SymbolicExpressionTreeNodeSimilarityComparer comp) { 213 if (!comp.Equals(a, b)) 214 return 0; 215 216 int m = a.SubtreeCount; 217 int n = b.SubtreeCount; 218 if (m == 0 || n == 0) return 1; 219 220 var matrix = new int[m + 1, n + 1]; 221 for (int i = 1; i <= m; ++i) 222 for (int j = 1; j <= n; ++j) { 223 var ai = a.GetSubtree(i - 1); 224 var bj = b.GetSubtree(j - 1); 225 int match = Match(ai, bj, comp); 226 matrix[i, j] = Math.Max(Math.Max(matrix[i, j - 1], matrix[i - 1, j]), matrix[i - 1, j - 1] + match); 227 } 228 return matrix[m, n] + 1; 229 } 230 231 public static int 232 LCS(ISymbolicExpressionTreeNode a, ISymbolicExpressionTreeNode b, SymbolicExpressionTreeNodeSimilarityComparer comp) { 233 var nodesA = a.IterateNodesPrefix().ToList(); 234 var nodesB = b.IterateNodesPrefix().ToList(); 235 int m = nodesA.Count; 236 int n = nodesB.Count; 237 var matrix = new int[m + 1, n + 1]; 238 for (int i = 1; i <= m; ++i) { 239 for (int j = 1; j <= n; ++j) { 240 int w = comp.Equals(a, b) ? 1 : 0; 241 matrix[i, j] = Math.Max(Math.Max(matrix[i, j - 1], matrix[i - 1, j]), matrix[i - 1, j - 1] + w); 242 } 243 } 244 return matrix[m, n]; 245 } 246 247 public static void RenderTree(TextWriter writer, ISymbolicExpressionTree tree) { 248 RenderNode(writer, tree.Root, string.Empty); 249 } 250 251 public static void RenderNode(TextWriter writer, ISymbolicExpressionTreeNode node, string prefix) { 252 string label; 253 if (node is VariableTreeNode) { 254 var variable = node as VariableTreeNode; 255 label = string.Concat(string.Format("{0:0.000}", variable.Weight), '·', variable.VariableName); 256 } else if (node is ConstantTreeNode) { 257 var constant = node as ConstantTreeNode; 258 label = string.Format("{0:0.000}", constant.Value); 259 } else { 260 label = node.Symbol.ToString(); 261 } 262 263 writer.Write(label); 264 if (node.SubtreeCount > 0) { 265 char connector, extender = ' '; 266 var padding = prefix + new string(' ', label.Length); 267 for (int i = 0; i != node.SubtreeCount; ++i) { 268 if (i == 0) { 269 if (node.SubtreeCount > 1) { 270 connector = RenderChars.JunctionDown; 271 extender = RenderChars.VerticalLine; 272 } else { 273 connector = RenderChars.HorizontalLine; 274 extender = ' '; 275 } 276 } else { 277 writer.Write(padding); 278 if (i == node.SubtreeCount - 1) { 279 connector = RenderChars.CornerRight; 280 extender = ' '; 281 } else { 282 connector = RenderChars.JunctionRight; 283 extender = RenderChars.VerticalLine; 284 } 285 } 286 writer.Write(string.Concat(connector, RenderChars.HorizontalLine)); 287 var newPrefix = string.Concat(padding, extender, ' '); 288 RenderNode(writer, node.GetSubtree(i), newPrefix); 289 } 290 } else 291 writer.WriteLine(); 292 } 293 } 294 295 // helper class providing characters for displaying a tree in the console 296 public static class RenderChars { 297 public const char JunctionDown = '┬'; 298 public const char HorizontalLine = '─'; 299 public const char VerticalLine = '│'; 300 public const char JunctionRight = '├'; 301 public const char CornerRight = '└'; 177 var fragmentLength = fragment.GetLength(); 178 // below, we use ">=" for Match(n, fragment, comp) >= fragmentLength because in case of relaxed conditions, 179 // we can have multiple matches of the same node 180 return root.IterateNodesBreadth().Where(n => n.GetLength() >= fragmentLength && Match(n, fragment, comp) == fragmentLength); 181 } 182 183 ///<summary> 184 /// Finds the longest common subsequence in quadratic time and linear space 185 /// Variant of: 186 /// D. S. Hirschberg. A linear space algorithm for or computing maximal common subsequences. 1975. 187 /// http://dl.acm.org/citation.cfm?id=360861 188 /// </summary> 189 /// <returns>Number of pairs that were matched</returns> 190 public static int Match(ISymbolicExpressionTreeNode a, ISymbolicExpressionTreeNode b, SymbolicExpressionTreeNodeSimilarityComparer comp) { 191 if (!comp.Equals(a, b)) return 0; 192 int m = a.SubtreeCount; 193 int n = b.SubtreeCount; 194 if (m == 0 || n == 0) return 1; 195 var matrix = new int[m + 1, n + 1]; 196 for (int i = 1; i <= m; ++i) { 197 var ai = a.GetSubtree(i - 1); 198 for (int j = 1; j <= n; ++j) { 199 var bj = b.GetSubtree(j - 1); 200 int match = Match(ai, bj, comp); 201 matrix[i, j] = Math.Max(Math.Max(matrix[i, j - 1], matrix[i - 1, j]), matrix[i - 1, j - 1] + match); 202 } 203 } 204 return matrix[m, n] + 1; 302 205 } 303 206 } -
TabularUnified branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisExpressionTreeSimplifier.cs ¶
r8213 r9241 52 52 private GreaterThan gtSymbol = new GreaterThan(); 53 53 private LessThan ltSymbol = new LessThan(); 54 private Integral integralSymbol = new Integral(); 55 private LaggedVariable laggedVariableSymbol = new LaggedVariable(); 56 private TimeLag timeLagSymbol = new TimeLag(); 54 57 55 58 public ISymbolicExpressionTree Simplify(ISymbolicExpressionTree originalTree) { … … 182 185 private bool IsConstant(ISymbolicExpressionTreeNode node) { 183 186 return node.Symbol is Constant; 187 } 188 189 // dynamic 190 private bool IsTimeLag(ISymbolicExpressionTreeNode node) { 191 return node.Symbol is TimeLag; 192 } 193 private bool IsIntegral(ISymbolicExpressionTreeNode node) { 194 return node.Symbol is Integral; 184 195 } 185 196 … … 234 245 } else if (IsNot(original)) { 235 246 return SimplifyNot(original); 247 } else if (IsTimeLag(original)) { 248 return SimplifyTimeLag(original); 249 } else if (IsIntegral(original)) { 250 return SimplifyIntegral(original); 236 251 } else { 237 252 return SimplifyAny(original); … … 376 391 return MakePower(GetSimplifiedTree(original.GetSubtree(0)), GetSimplifiedTree(original.GetSubtree(1))); 377 392 } 393 private ISymbolicExpressionTreeNode SimplifyTimeLag(ISymbolicExpressionTreeNode original) { 394 var laggedTreeNode = original as ILaggedTreeNode; 395 var simplifiedSubtree = GetSimplifiedTree(original.GetSubtree(0)); 396 if (!ContainsVariableCondition(simplifiedSubtree)) { 397 return AddLagToDynamicNodes(simplifiedSubtree, laggedTreeNode.Lag); 398 } else { 399 return MakeTimeLag(simplifiedSubtree, laggedTreeNode.Lag); 400 } 401 } 402 private ISymbolicExpressionTreeNode SimplifyIntegral(ISymbolicExpressionTreeNode original) { 403 var laggedTreeNode = original as ILaggedTreeNode; 404 var simplifiedSubtree = GetSimplifiedTree(original.GetSubtree(0)); 405 if (IsConstant(simplifiedSubtree)) { 406 return GetSimplifiedTree(MakeProduct(simplifiedSubtree, MakeConstant(-laggedTreeNode.Lag))); 407 } else { 408 return MakeIntegral(simplifiedSubtree, laggedTreeNode.Lag); 409 } 410 } 411 378 412 #endregion 379 413 380 414 #region low level tree restructuring 415 private ISymbolicExpressionTreeNode MakeTimeLag(ISymbolicExpressionTreeNode subtree, int lag) { 416 if (lag == 0) return subtree; 417 if (IsConstant(subtree)) return subtree; 418 var lagNode = (LaggedTreeNode)timeLagSymbol.CreateTreeNode(); 419 lagNode.Lag = lag; 420 lagNode.AddSubtree(subtree); 421 return lagNode; 422 } 423 424 private ISymbolicExpressionTreeNode MakeIntegral(ISymbolicExpressionTreeNode subtree, int lag) { 425 if (lag == 0) return subtree; 426 else if (lag == -1 || lag == 1) { 427 return MakeSum(subtree, AddLagToDynamicNodes((ISymbolicExpressionTreeNode)subtree.Clone(), lag)); 428 } else { 429 var node = (LaggedTreeNode)integralSymbol.CreateTreeNode(); 430 node.Lag = lag; 431 node.AddSubtree(subtree); 432 return node; 433 } 434 } 435 381 436 private ISymbolicExpressionTreeNode MakeNot(ISymbolicExpressionTreeNode t) { 382 437 if (IsConstant(t)) { … … 847 902 848 903 #region helper functions 904 private bool ContainsVariableCondition(ISymbolicExpressionTreeNode node) { 905 if (node.Symbol is VariableCondition) return true; 906 foreach (var subtree in node.Subtrees) 907 if (ContainsVariableCondition(subtree)) return true; 908 return false; 909 } 910 911 private ISymbolicExpressionTreeNode AddLagToDynamicNodes(ISymbolicExpressionTreeNode node, int lag) { 912 var laggedTreeNode = node as ILaggedTreeNode; 913 var variableNode = node as VariableTreeNode; 914 var variableConditionNode = node as VariableConditionTreeNode; 915 if (laggedTreeNode != null) 916 laggedTreeNode.Lag += lag; 917 else if (variableNode != null) { 918 var laggedVariableNode = (LaggedVariableTreeNode)laggedVariableSymbol.CreateTreeNode(); 919 laggedVariableNode.Lag = lag; 920 laggedVariableNode.VariableName = variableNode.VariableName; 921 return laggedVariableNode; 922 } else if (variableConditionNode != null) { 923 throw new NotSupportedException("Removal of time lags around variable condition symbols is not allowed."); 924 } 925 var subtrees = new List<ISymbolicExpressionTreeNode>(node.Subtrees); 926 while (node.SubtreeCount > 0) node.RemoveSubtree(0); 927 foreach (var subtree in subtrees) { 928 node.AddSubtree(AddLagToDynamicNodes(subtree, lag)); 929 } 930 return node; 931 } 849 932 850 933 private bool AreSameVariable(ISymbolicExpressionTreeNode a, ISymbolicExpressionTreeNode b) { -
TabularUnified branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisModel.cs ¶
r7259 r9241 20 20 #endregion 21 21 22 using System; 22 23 using System.Drawing; 23 24 using HeuristicLab.Common; … … 66 67 this.interpreter = interpreter; 67 68 } 69 70 #region Scaling 71 protected void Scale(IDataAnalysisProblemData problemData, string targetVariable) { 72 var dataset = problemData.Dataset; 73 var rows = problemData.TrainingIndices; 74 var estimatedValues = Interpreter.GetSymbolicExpressionTreeValues(SymbolicExpressionTree, dataset, rows); 75 var targetValues = dataset.GetDoubleValues(targetVariable, rows); 76 77 var linearScalingCalculator = new OnlineLinearScalingParameterCalculator(); 78 var targetValuesEnumerator = targetValues.GetEnumerator(); 79 var estimatedValuesEnumerator = estimatedValues.GetEnumerator(); 80 while (targetValuesEnumerator.MoveNext() & estimatedValuesEnumerator.MoveNext()) { 81 double target = targetValuesEnumerator.Current; 82 double estimated = estimatedValuesEnumerator.Current; 83 if (!double.IsNaN(estimated) && !double.IsInfinity(estimated)) 84 linearScalingCalculator.Add(estimated, target); 85 } 86 if (linearScalingCalculator.ErrorState == OnlineCalculatorError.None && (targetValuesEnumerator.MoveNext() || estimatedValuesEnumerator.MoveNext())) 87 throw new ArgumentException("Number of elements in target and estimated values enumeration do not match."); 88 89 double alpha = linearScalingCalculator.Alpha; 90 double beta = linearScalingCalculator.Beta; 91 if (linearScalingCalculator.ErrorState != OnlineCalculatorError.None) return; 92 93 ConstantTreeNode alphaTreeNode = null; 94 ConstantTreeNode betaTreeNode = null; 95 // check if model has been scaled previously by analyzing the structure of the tree 96 var startNode = SymbolicExpressionTree.Root.GetSubtree(0); 97 if (startNode.GetSubtree(0).Symbol is Addition) { 98 var addNode = startNode.GetSubtree(0); 99 if (addNode.SubtreeCount == 2 && addNode.GetSubtree(0).Symbol is Multiplication && addNode.GetSubtree(1).Symbol is Constant) { 100 alphaTreeNode = addNode.GetSubtree(1) as ConstantTreeNode; 101 var mulNode = addNode.GetSubtree(0); 102 if (mulNode.SubtreeCount == 2 && mulNode.GetSubtree(1).Symbol is Constant) { 103 betaTreeNode = mulNode.GetSubtree(1) as ConstantTreeNode; 104 } 105 } 106 } 107 // if tree structure matches the structure necessary for linear scaling then reuse the existing tree nodes 108 if (alphaTreeNode != null && betaTreeNode != null) { 109 betaTreeNode.Value *= beta; 110 alphaTreeNode.Value *= beta; 111 alphaTreeNode.Value += alpha; 112 } else { 113 var mainBranch = startNode.GetSubtree(0); 114 startNode.RemoveSubtree(0); 115 var scaledMainBranch = MakeSum(MakeProduct(mainBranch, beta), alpha); 116 startNode.AddSubtree(scaledMainBranch); 117 } 118 } 119 120 private static ISymbolicExpressionTreeNode MakeSum(ISymbolicExpressionTreeNode treeNode, double alpha) { 121 if (alpha.IsAlmost(0.0)) { 122 return treeNode; 123 } else { 124 var addition = new Addition(); 125 var node = addition.CreateTreeNode(); 126 var alphaConst = MakeConstant(alpha); 127 node.AddSubtree(treeNode); 128 node.AddSubtree(alphaConst); 129 return node; 130 } 131 } 132 133 private static ISymbolicExpressionTreeNode MakeProduct(ISymbolicExpressionTreeNode treeNode, double beta) { 134 if (beta.IsAlmost(1.0)) { 135 return treeNode; 136 } else { 137 var multipliciation = new Multiplication(); 138 var node = multipliciation.CreateTreeNode(); 139 var betaConst = MakeConstant(beta); 140 node.AddSubtree(treeNode); 141 node.AddSubtree(betaConst); 142 return node; 143 } 144 } 145 146 private static ISymbolicExpressionTreeNode MakeConstant(double c) { 147 var node = (ConstantTreeNode)(new Constant()).CreateTreeNode(); 148 node.Value = c; 149 return node; 150 } 151 #endregion 68 152 } 69 153 } -
TabularUnified branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisMultiObjectiveProblem.cs ¶
r7259 r9241 30 30 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { 31 31 [StorableClass] 32 public abstract class SymbolicDataAnalysisMultiObjectiveProblem<T, U, V> : SymbolicDataAnalysisProblem<T, U, V>, I MultiObjectiveHeuristicOptimizationProblem32 public abstract class SymbolicDataAnalysisMultiObjectiveProblem<T, U, V> : SymbolicDataAnalysisProblem<T, U, V>, ISymbolicDataAnalysisMultiObjectiveProblem 33 33 where T : class,IDataAnalysisProblemData 34 34 where U : class, ISymbolicDataAnalysisMultiObjectiveEvaluator<T> -
TabularUnified branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisProblem.cs ¶
r8557 r9241 53 53 private const string FitnessCalculationPartitionParameterName = "FitnessCalculationPartition"; 54 54 private const string ValidationPartitionParameterName = "ValidationPartition"; 55 private const string ApplyLinearScalingParameterName = "ApplyLinearScaling"; 55 56 56 57 private const string ProblemDataParameterDescription = ""; … … 64 65 private const string FitnessCalculationPartitionParameterDescription = "The partition of the problem data training partition, that should be used to calculate the fitness of an individual."; 65 66 private const string ValidationPartitionParameterDescription = "The partition of the problem data training partition, that should be used to select the best model from (optional)."; 67 private const string ApplyLinearScalingParameterDescription = "Flag that indicates if the individual should be linearly scaled before evaluating."; 66 68 #endregion 67 69 … … 100 102 get { return (IFixedValueParameter<IntRange>)Parameters[ValidationPartitionParameterName]; } 101 103 } 104 public IFixedValueParameter<BoolValue> ApplyLinearScalingParameter { 105 get { return (IFixedValueParameter<BoolValue>)Parameters[ApplyLinearScalingParameterName]; } 106 } 102 107 #endregion 103 108 … … 144 149 public IntRange ValidationPartition { 145 150 get { return ValidationPartitionParameter.Value; } 151 } 152 public BoolValue ApplyLinearScaling { 153 get { return ApplyLinearScalingParameter.Value; } 146 154 } 147 155 #endregion … … 151 159 [StorableHook(HookType.AfterDeserialization)] 152 160 private void AfterDeserialization() { 161 if (!Parameters.ContainsKey(ApplyLinearScalingParameterName)) { 162 Parameters.Add(new FixedValueParameter<BoolValue>(ApplyLinearScalingParameterName, ApplyLinearScalingParameterDescription, new BoolValue(false))); 163 ApplyLinearScalingParameter.Hidden = true; 164 165 //it is assumed that for all symbolic regression algorithms linear scaling was set to true 166 //there is no possibility to determine the previous value of the parameter as it was stored in the evaluator 167 if (GetType().Name.Contains("SymbolicRegression")) 168 ApplyLinearScaling.Value = true; 169 } 170 153 171 RegisterEventHandlers(); 154 172 } … … 170 188 Parameters.Add(new FixedValueParameter<IntRange>(ValidationPartitionParameterName, ValidationPartitionParameterDescription)); 171 189 Parameters.Add(new FixedValueParameter<PercentValue>(RelativeNumberOfEvaluatedSamplesParameterName, RelativeNumberOfEvaluatedSamplesParameterDescription, new PercentValue(1))); 190 Parameters.Add(new FixedValueParameter<BoolValue>(ApplyLinearScalingParameterName, ApplyLinearScalingParameterDescription, new BoolValue(false))); 172 191 173 192 SymbolicExpressionTreeInterpreterParameter.Hidden = true; 174 193 MaximumFunctionArgumentsParameter.Hidden = true; 175 194 MaximumFunctionDefinitionsParameter.Hidden = true; 195 ApplyLinearScalingParameter.Hidden = true; 176 196 177 197 SymbolicExpressionTreeGrammar = new TypeCoherentExpressionGrammar(); … … 191 211 SymbolicExpressionTreeGrammar.MaximumFunctionDefinitions = MaximumFunctionDefinitions.Value; 192 212 foreach (var varSymbol in SymbolicExpressionTreeGrammar.Symbols.OfType<HeuristicLab.Problems.DataAnalysis.Symbolic.Variable>()) { 193 if (!varSymbol.Fixed) varSymbol.VariableNames = ProblemData.AllowedInputVariables; 213 if (!varSymbol.Fixed) { 214 varSymbol.AllVariableNames = ProblemData.InputVariables.Select(x => x.Value); 215 varSymbol.VariableNames = ProblemData.AllowedInputVariables; 216 } 194 217 } 195 218 foreach (var varSymbol in SymbolicExpressionTreeGrammar.Symbols.OfType<HeuristicLab.Problems.DataAnalysis.Symbolic.VariableCondition>()) { 196 if (!varSymbol.Fixed) varSymbol.VariableNames = ProblemData.AllowedInputVariables; 219 if (!varSymbol.Fixed) { 220 varSymbol.AllVariableNames = ProblemData.InputVariables.Select(x => x.Value); 221 varSymbol.VariableNames = ProblemData.AllowedInputVariables; 222 } 197 223 } 198 224 } … … 274 300 275 301 foreach (var op in operators.OfType<ISymbolicExpressionTreeGrammarBasedOperator>()) { 276 op.SymbolicExpressionTreeGrammarParameter.ActualName = SymbolicExpressionTreeGrammarParameter Name;302 op.SymbolicExpressionTreeGrammarParameter.ActualName = SymbolicExpressionTreeGrammarParameter.Name; 277 303 } 278 304 foreach (var op in operators.OfType<ISymbolicExpressionTreeSizeConstraintOperator>()) { 279 op.MaximumSymbolicExpressionTreeDepthParameter.ActualName = MaximumSymbolicExpressionTreeDepthParameter Name;280 op.MaximumSymbolicExpressionTreeLengthParameter.ActualName = MaximumSymbolicExpressionTreeLengthParameter Name;305 op.MaximumSymbolicExpressionTreeDepthParameter.ActualName = MaximumSymbolicExpressionTreeDepthParameter.Name; 306 op.MaximumSymbolicExpressionTreeLengthParameter.ActualName = MaximumSymbolicExpressionTreeLengthParameter.Name; 281 307 } 282 308 foreach (var op in operators.OfType<ISymbolicExpressionTreeArchitectureAlteringOperator>()) { 283 op.MaximumFunctionArgumentsParameter.ActualName = MaximumFunctionArgumentsParameter Name;284 op.MaximumFunctionDefinitionsParameter.ActualName = MaximumFunctionDefinitionsParameter Name;309 op.MaximumFunctionArgumentsParameter.ActualName = MaximumFunctionArgumentsParameter.Name; 310 op.MaximumFunctionDefinitionsParameter.ActualName = MaximumFunctionDefinitionsParameter.Name; 285 311 } 286 312 foreach (var op in operators.OfType<ISymbolicDataAnalysisEvaluator<T>>()) { … … 289 315 op.EvaluationPartitionParameter.ActualName = FitnessCalculationPartitionParameter.Name; 290 316 op.RelativeNumberOfEvaluatedSamplesParameter.ActualName = RelativeNumberOfEvaluatedSamplesParameter.Name; 317 op.ApplyLinearScalingParameter.ActualName = ApplyLinearScalingParameter.Name; 291 318 } 292 319 foreach (var op in operators.OfType<ISymbolicExpressionTreeCrossover>()) { … … 300 327 op.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName; 301 328 } 329 foreach (var op in operators.OfType<ISymbolicDataAnalysisSingleObjectiveAnalyzer>()) { 330 op.ApplyLinearScalingParameter.ActualName = ApplyLinearScalingParameter.Name; 331 } 332 foreach (var op in operators.OfType<ISymbolicDataAnalysisMultiObjectiveAnalyzer>()) { 333 op.ApplyLinearScalingParameter.ActualName = ApplyLinearScalingParameter.Name; 334 } 302 335 foreach (var op in operators.OfType<ISymbolicDataAnalysisAnalyzer>()) { 303 336 op.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName; … … 308 341 } 309 342 foreach (var op in operators.OfType<ISymbolicDataAnalysisInterpreterOperator>()) { 310 op.SymbolicDataAnalysisTreeInterpreterParameter.ActualName = SymbolicExpressionTreeInterpreterParameter Name;343 op.SymbolicDataAnalysisTreeInterpreterParameter.ActualName = SymbolicExpressionTreeInterpreterParameter.Name; 311 344 } 312 345 foreach (var op in operators.OfType<ISymbolicDataAnalysisExpressionCrossover<T>>()) { 313 op.EvaluationPartitionParameter.ActualName = FitnessCalculationPartitionParameterName; 314 } 315 foreach (var op in operators.OfType<ISymbolicDataAnalysisExpressionCrossover<T>>()) { 346 op.EvaluationPartitionParameter.ActualName = FitnessCalculationPartitionParameter.Name; 316 347 op.ProblemDataParameter.ActualName = ProblemDataParameter.Name; 317 348 op.EvaluationPartitionParameter.ActualName = FitnessCalculationPartitionParameter.Name; … … 331 362 Description = data.Description; 332 363 ProblemData = data; 333 OnReset();334 364 } 335 365 -
TabularUnified branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisSingleObjectiveProblem.cs ¶
r7259 r9241 31 31 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { 32 32 [StorableClass] 33 public abstract class SymbolicDataAnalysisSingleObjectiveProblem<T, U, V> : SymbolicDataAnalysisProblem<T, U, V>, IS ingleObjectiveHeuristicOptimizationProblem33 public abstract class SymbolicDataAnalysisSingleObjectiveProblem<T, U, V> : SymbolicDataAnalysisProblem<T, U, V>, ISymbolicDataAnalysisSingleObjectiveProblem 34 34 where T : class,IDataAnalysisProblemData 35 35 where U : class, ISymbolicDataAnalysisSingleObjectiveEvaluator<T> -
TabularUnified branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/Constant.cs ¶
r7259 r9241 28 28 [StorableClass] 29 29 [Item("Constant", "Represents a constant value.")] 30 public sealedclass Constant : Symbol {30 public class Constant : Symbol { 31 31 #region Properties 32 32 [Storable] … … 100 100 101 101 [StorableConstructor] 102 pr ivateConstant(bool deserializing) : base(deserializing) { }103 pr ivateConstant(Constant original, Cloner cloner)102 protected Constant(bool deserializing) : base(deserializing) { } 103 protected Constant(Constant original, Cloner cloner) 104 104 : base(original, cloner) { 105 105 minValue = original.minValue; -
TabularUnified branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/ConstantTreeNode.cs ¶
r7259 r9241 27 27 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { 28 28 [StorableClass] 29 public sealedclass ConstantTreeNode : SymbolicExpressionTreeTerminalNode {29 public class ConstantTreeNode : SymbolicExpressionTreeTerminalNode { 30 30 public new Constant Symbol { 31 31 get { return (Constant)base.Symbol; } … … 34 34 private double constantValue; 35 35 [Storable] 36 public double Value {36 public virtual double Value { 37 37 get { return constantValue; } 38 38 set { constantValue = value; } … … 40 40 41 41 [StorableConstructor] 42 pr ivateConstantTreeNode(bool deserializing) : base(deserializing) { }42 protected ConstantTreeNode(bool deserializing) : base(deserializing) { } 43 43 44 pr ivateConstantTreeNode(ConstantTreeNode original, Cloner cloner)44 protected ConstantTreeNode(ConstantTreeNode original, Cloner cloner) 45 45 : base(original, cloner) { 46 46 constantValue = original.constantValue; 47 47 } 48 48 49 pr ivateConstantTreeNode() : base() { }49 protected ConstantTreeNode() : base() { } 50 50 public ConstantTreeNode(Constant constantSymbol) : base(constantSymbol) { } 51 51 … … 55 55 } 56 56 } 57 public overridevoid ResetLocalParameters(IRandom random) {57 public virtual void ResetLocalParameters(IRandom random) { 58 58 base.ResetLocalParameters(random); 59 59 var range = Symbol.MaxValue - Symbol.MinValue; … … 61 61 } 62 62 63 public overridevoid ShakeLocalParameters(IRandom random, double shakingFactor) {63 public virtual void ShakeLocalParameters(IRandom random, double shakingFactor) { 64 64 base.ShakeLocalParameters(random, shakingFactor); 65 65 // 50% additive & 50% multiplicative -
TabularUnified branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/LaggedSymbol.cs ¶
r5809 r9241 1 using HeuristicLab.Common; 1 #region License Information 2 /* HeuristicLab 3 * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 * 5 * This file is part of HeuristicLab. 6 * 7 * HeuristicLab is free software: you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation, either version 3 of the License, or 10 * (at your option) any later version. 11 * 12 * HeuristicLab is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>. 19 */ 20 #endregion 21 22 using HeuristicLab.Common; 2 23 using HeuristicLab.Core; 3 24 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; -
TabularUnified branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/LaggedVariable.cs ¶
r7259 r9241 27 27 [StorableClass] 28 28 [Item("LaggedVariable", "Represents a variable value with a time offset.")] 29 public sealedclass LaggedVariable : Variable {29 public class LaggedVariable : Variable { 30 30 [Storable] 31 31 private int minLag; … … 41 41 } 42 42 [StorableConstructor] 43 pr ivateLaggedVariable(bool deserializing) : base(deserializing) { }44 pr ivateLaggedVariable(LaggedVariable original, Cloner cloner)43 protected LaggedVariable(bool deserializing) : base(deserializing) { } 44 protected LaggedVariable(LaggedVariable original, Cloner cloner) 45 45 : base(original, cloner) { 46 46 minLag = original.minLag; 47 47 maxLag = original.maxLag; 48 48 } 49 public LaggedVariable() 50 : base("LaggedVariable", "Represents a variable value with a time offset.") { 51 minLag = -1; maxLag = -1; 49 public LaggedVariable() : this("LaggedVariable", "Represents a variable value with a time offset.") { } 50 protected LaggedVariable(string name, string description) 51 : base(name, description) { 52 MinLag = -1; 53 MaxLag = -1; 52 54 } 53 55 -
TabularUnified branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/LaggedVariableTreeNode.cs ¶
r7259 r9241 37 37 } 38 38 39 public override bool HasLocalParameters { 40 get { return true; } 41 } 42 39 43 [StorableConstructor] 40 44 private LaggedVariableTreeNode(bool deserializing) : base(deserializing) { } … … 43 47 lag = original.lag; 44 48 } 45 private LaggedVariableTreeNode() { }46 49 47 50 public LaggedVariableTreeNode(LaggedVariable variableSymbol) : base(variableSymbol) { } 48 51 49 public override bool HasLocalParameters {50 get {51 return true;52 }53 }54 52 55 53 public override void ResetLocalParameters(IRandom random) { -
TabularUnified branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/Variable.cs ¶
r7259 r9241 101 101 } 102 102 103 private List<string> allVariableNames; 104 [Storable] 105 public IEnumerable<string> AllVariableNames { 106 get { return allVariableNames; } 107 set { 108 if (value == null) throw new ArgumentNullException(); 109 allVariableNames.Clear(); 110 allVariableNames.AddRange(value); 111 } 112 } 113 114 public override bool Enabled { 115 get { 116 if (variableNames.Count == 0) return false; 117 return base.Enabled; 118 } 119 set { 120 if (variableNames.Count == 0) base.Enabled = false; 121 else base.Enabled = value; 122 } 123 } 124 103 125 private const int minimumArity = 0; 104 126 private const int maximumArity = 0; … … 112 134 #endregion 113 135 136 [StorableHook(HookType.AfterDeserialization)] 137 private void AfterDeserialization() { 138 if (allVariableNames == null || (allVariableNames.Count == 0 && variableNames.Count > 0)) { 139 allVariableNames = variableNames; 140 } 141 } 142 114 143 [StorableConstructor] 115 144 protected Variable(bool deserializing) 116 145 : base(deserializing) { 117 146 variableNames = new List<string>(); 147 allVariableNames = new List<string>(); 118 148 } 119 149 protected Variable(Variable original, Cloner cloner) … … 122 152 weightSigma = original.weightSigma; 123 153 variableNames = new List<string>(original.variableNames); 154 allVariableNames = new List<string>(original.allVariableNames); 124 155 weightManipulatorMu = original.weightManipulatorMu; 125 156 weightManipulatorSigma = original.weightManipulatorSigma; … … 135 166 multiplicativeWeightManipulatorSigma = 0.03; 136 167 variableNames = new List<string>(); 137 } 138 139 protected override void OnChanged(EventArgs e) { 140 if (@Fixed) { 141 weightManipulatorMu = 1; 142 weightManipulatorSigma = 0; 143 weightMu = 1; 144 weightSigma = 0; 145 multiplicativeWeightManipulatorSigma = 0; 146 } 147 base.OnChanged(e); 168 allVariableNames = new List<string>(); 148 169 } 149 170 -
TabularUnified branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/VariableCondition.cs ¶
r8099 r9241 86 86 set { 87 87 if (value == null) throw new ArgumentNullException(); 88 variableNames = new List<string>(value); 88 variableNames.Clear(); 89 variableNames.AddRange(value); 89 90 OnChanged(EventArgs.Empty); 91 } 92 } 93 94 private List<string> allVariableNames; 95 [Storable] 96 public IEnumerable<string> AllVariableNames { 97 get { return allVariableNames; } 98 set { 99 if (value == null) throw new ArgumentNullException(); 100 allVariableNames.Clear(); 101 allVariableNames.AddRange(value); 102 VariableNames = value; 90 103 } 91 104 } … … 151 164 152 165 #region persistence and cloning 166 [StorableHook(HookType.AfterDeserialization)] 167 private void AfterDeserialization() { 168 if (allVariableNames == null || (allVariableNames.Count == 0 && variableNames.Count > 0)) { 169 allVariableNames = variableNames; 170 } 171 } 172 153 173 [StorableConstructor] 154 private VariableCondition(bool deserializing) : base(deserializing) { } 174 private VariableCondition(bool deserializing) 175 : base(deserializing) { 176 variableNames = new List<string>(); 177 allVariableNames = new List<string>(); 178 } 155 179 private VariableCondition(VariableCondition original, Cloner cloner) 156 180 : base(original, cloner) { … … 161 185 162 186 variableNames = new List<string>(original.variableNames); 187 allVariableNames = new List<string>(original.allVariableNames); 163 188 164 189 slopeInitializerMu = original.slopeInitializerMu; … … 181 206 182 207 variableNames = new List<string>(); 208 allVariableNames = new List<string>(); 183 209 184 210 slopeInitializerMu = 0.0;
Note: See TracChangeset
for help on using the changeset viewer.