Changeset 12891 for branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic
- Timestamp:
- 08/22/15 14:27:37 (9 years ago)
- Location:
- branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic
- Files:
-
- 26 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic
- Property svn:mergeinfo changed
-
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/BuildingBlockAnalyzers/SymbolicDataAnalysisPoly10Analyzer.cs
r12406 r12891 153 153 var values = interpreter.GetValues(s, dataset, rows); 154 154 OnlineCalculatorError error; 155 var r2 = OnlinePearsonsRSquaredCalculator.Calculate(values, evaluationMap[key], out error); 156 if (error == OnlineCalculatorError.None && r2 >= PhenotypicSimilarityThreshold) { 155 var r = OnlinePearsonsRCalculator.Calculate(values, evaluationMap[key], out error); 156 var r2 = error == OnlineCalculatorError.None ? r * r : double.NaN; 157 if (!double.IsNaN(r2) && r2 >= PhenotypicSimilarityThreshold) { 157 158 bbFrequencies[key]++; 158 159 i += s.GetLength(); … … 162 163 } 163 164 var table = (DataTable)results[BuildingBlocksFrequenciesTableName].Value; 164 double max = bbFrequencies.Max(x => x.Value);165 165 foreach (var pair in bbFrequencies) { 166 166 var formatter = new SymbolicExpressionTreeStringFormatter(); … … 169 169 if (table.Rows.ContainsKey(label)) { 170 170 var row = table.Rows[label]; 171 row.Values.Add( max > 0 ? pair.Value / max : 0);171 row.Values.Add(pair.Value); 172 172 } 173 173 } -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/SymbolicDataAnalysisSingleObjectivePruningAnalyzer.cs
r12155 r12891 45 45 private const string TotalNumberOfPrunedSubtreesParameterName = "Number of pruned subtrees"; 46 46 private const string TotalNumberOfPrunedTreesParameterName = "Number of pruned trees"; 47 private const string TotalNumberOfPrunedNodesParameterName = "Number of pruned nodes"; 47 48 private const string RandomParameterName = "Random"; 48 private const string PruneOnlyZeroImpactNodesParameterName = "PruneOnlyZeroImpactNodes";49 private const string NodeImpactThresholdParameterName = "ImpactThreshold";50 private const string PruningOperatorParameterName = "PruningOperator";51 49 private const string ResultsParameterName = "Results"; 52 50 private const string PopulationSizeParameterName = "PopulationSize"; … … 54 52 55 53 #region private members 54 private DataReducer prunedNodesReducer; 56 55 private DataReducer prunedSubtreesReducer; 57 56 private DataReducer prunedTreesReducer; … … 61 60 62 61 #region parameter properties 63 public IValueParameter<SymbolicDataAnalysisExpressionPruningOperator> PruningOperatorParameter {64 get { return (IValueParameter<SymbolicDataAnalysisExpressionPruningOperator>)Parameters[PruningOperatorParameterName]; }65 }66 public IFixedValueParameter<BoolValue> PruneOnlyZeroImpactNodesParameter {67 get { return (IFixedValueParameter<BoolValue>)Parameters[PruneOnlyZeroImpactNodesParameterName]; }68 }69 public IFixedValueParameter<DoubleValue> NodeImpactThresholdParameter {70 get { return (IFixedValueParameter<DoubleValue>)Parameters[NodeImpactThresholdParameterName]; }71 }72 62 public ILookupParameter<IRandom> RandomParameter { 73 63 get { return (ILookupParameter<IRandom>)Parameters[RandomParameterName]; } … … 91 81 92 82 #region properties 93 protected SymbolicDataAnalysisExpressionPruningOperator PruningOperator { get { return PruningOperatorParameter.Value; }}83 protected abstract SymbolicDataAnalysisExpressionPruningOperator PruningOperator { get; } 94 84 protected int UpdateInterval { get { return UpdateIntervalParameter.Value.Value; } } 95 85 … … 112 102 get { return PruningProbabilityParameter.Value.Value; } 113 103 set { PruningProbabilityParameter.Value.Value = value; } 114 }115 116 protected bool PruneOnlyZeroImpactNodes {117 get { return PruneOnlyZeroImpactNodesParameter.Value.Value; }118 set { PruneOnlyZeroImpactNodesParameter.Value.Value = value; }119 }120 protected double NodeImpactThreshold {121 get { return NodeImpactThresholdParameter.Value.Value; }122 set { NodeImpactThresholdParameter.Value.Value = value; }123 104 } 124 105 #endregion … … 140 121 protected SymbolicDataAnalysisSingleObjectivePruningAnalyzer(SymbolicDataAnalysisSingleObjectivePruningAnalyzer original, Cloner cloner) 141 122 : base(original, cloner) { 123 if (original.prunedNodesReducer != null) 124 this.prunedNodesReducer = (DataReducer)original.prunedNodesReducer.Clone(); 142 125 if (original.prunedSubtreesReducer != null) 143 126 this.prunedSubtreesReducer = (DataReducer)original.prunedSubtreesReducer.Clone(); … … 197 180 Parameters.Add(new LookupParameter<IRandom>(RandomParameterName, "The random number generator.")); 198 181 Parameters.Add(new LookupParameter<IDataAnalysisProblemData>(ProblemDataParameterName, "The problem data.")); 199 Parameters.Add(new FixedValueParameter<DoubleValue>(NodeImpactThresholdParameterName, "The impact threshold below which an individual should be pruned.", new DoubleValue(0.0)));200 Parameters.Add(new FixedValueParameter<BoolValue>(PruneOnlyZeroImpactNodesParameterName, "Switch to determine of only zero impact individuals should be pruned.", new BoolValue(false)));201 182 Parameters.Add(new LookupParameter<IntValue>(PopulationSizeParameterName, "The population of individuals.")); 202 183 #endregion … … 225 206 var qualities = Quality.Select(x => x.Value).ToArray(); 226 207 var indices = Enumerable.Range(0, qualities.Length).ToArray(); 227 Array.Sort(qualities, indices); 208 indices.StableSort((a, b) => qualities[a].CompareTo(qualities[b])); 209 228 210 if (!Maximization.Value) Array.Reverse(indices); 229 211 … … 233 215 var empty = new EmptyOperator(); 234 216 235 for (int i = 0; i < subscopes.Count; ++i) {217 for (int i = 0; i < indices.Length; ++i) { 236 218 IOperator @operator; 237 219 if (range.Start <= i && i < range.End && random.NextDouble() <= PruningProbability) … … 250 232 UpdateCounter = 0; 251 233 252 if (pruned SubtreesReducer == null || prunedTreesReducer == null || valuesCollector == null || resultsCollector == null) { InitializeOperators(); }234 if (prunedNodesReducer == null || prunedSubtreesReducer == null || prunedTreesReducer == null || valuesCollector == null || resultsCollector == null) { InitializeOperators(); } 253 235 254 236 var prune = CreatePruningOperation(); 237 var reducePrunedNodes = ExecutionContext.CreateChildOperation(prunedNodesReducer); 255 238 var reducePrunedSubtrees = ExecutionContext.CreateChildOperation(prunedSubtreesReducer); 256 239 var reducePrunedTrees = ExecutionContext.CreateChildOperation(prunedTreesReducer); … … 258 241 var collectResults = ExecutionContext.CreateChildOperation(resultsCollector); 259 242 260 return new OperationCollection { prune, reducePruned Subtrees, reducePrunedTrees, collectValues, collectResults, base.Apply() };243 return new OperationCollection { prune, reducePrunedNodes, reducePrunedSubtrees, reducePrunedTrees, collectValues, collectResults, base.Apply() }; 261 244 } 262 245 263 246 private void InitializeOperators() { 247 prunedNodesReducer = new DataReducer(); 248 prunedNodesReducer.ParameterToReduce.ActualName = PruningOperator.PrunedNodesParameter.ActualName; 249 prunedNodesReducer.ReductionOperation.Value = new ReductionOperation(ReductionOperations.Sum); // sum all the pruned subtrees parameter values 250 prunedNodesReducer.TargetOperation.Value = new ReductionOperation(ReductionOperations.Assign); // asign the sum to the target parameter 251 prunedNodesReducer.TargetParameter.ActualName = TotalNumberOfPrunedNodesParameterName; 252 264 253 prunedSubtreesReducer = new DataReducer(); 265 254 prunedSubtreesReducer.ParameterToReduce.ActualName = PruningOperator.PrunedSubtreesParameter.ActualName; … … 275 264 276 265 valuesCollector = new DataTableValuesCollector(); 266 valuesCollector.CollectedValues.Add(new LookupParameter<IntValue>(TotalNumberOfPrunedNodesParameterName)); 277 267 valuesCollector.CollectedValues.Add(new LookupParameter<IntValue>(TotalNumberOfPrunedSubtreesParameterName)); 278 268 valuesCollector.CollectedValues.Add(new LookupParameter<IntValue>(TotalNumberOfPrunedTreesParameterName)); -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Crossovers/MultiSymbolicDataAnalysisExpressionCrossover.cs
r12155 r12891 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 [StorableClass] 37 38 public class MultiSymbolicDataAnalysisExpressionCrossover<T> : StochasticMultiBranch<ISymbolicExpressionTreeCrossover>, 38 39 ISymbolicDataAnalysisExpressionCrossover<T> where T : class, IDataAnalysisProblemData { 39 40 private const string ParentsParameterName = "Parents"; 40 private const string ChildParameterName = "Child";41 private const string SymbolicExpressionTreeParameterName = "SymbolicExpressionTree"; 41 42 private const string MaximumSymbolicExpressionTreeLengthParameterName = "MaximumSymbolicExpressionTreeLength"; 42 43 private const string MaximumSymbolicExpressionTreeDepthParameterName = "MaximumSymbolicExpressionTreeDepth"; … … 62 63 get { return (ScopeTreeLookupParameter<ISymbolicExpressionTree>)Parameters[ParentsParameterName]; } 63 64 } 64 public ILookupParameter<ISymbolicExpressionTree> ChildParameter {65 get { return (ILookupParameter<ISymbolicExpressionTree>)Parameters[ ChildParameterName]; }65 public ILookupParameter<ISymbolicExpressionTree> SymbolicExpressionTreeParameter { 66 get { return (ILookupParameter<ISymbolicExpressionTree>)Parameters[SymbolicExpressionTreeParameterName]; } 66 67 } 67 68 public IValueLookupParameter<IntValue> MaximumSymbolicExpressionTreeLengthParameter { … … 99 100 Parameters.Add(new ValueLookupParameter<IntRange>(SymbolicDataAnalysisEvaluationPartitionParameterName, "The start index of the dataset partition on which the symbolic data analysis solution should be evaluated.")); 100 101 Parameters.Add(new ScopeTreeLookupParameter<ISymbolicExpressionTree>(ParentsParameterName, "The parent symbolic expression trees which should be crossed.")); 101 Parameters.Add(new LookupParameter<ISymbolicExpressionTree>( ChildParameterName, "The child symbolic expression tree resulting from the crossover."));102 Parameters.Add(new LookupParameter<ISymbolicExpressionTree>(SymbolicExpressionTreeParameterName, "The child symbolic expression tree resulting from the crossover.")); 102 103 103 104 EvaluatorParameter.Hidden = true; … … 111 112 112 113 SelectedOperatorParameter.ActualName = "SelectedCrossoverOperator"; 114 } 115 116 [StorableHook(HookType.AfterDeserialization)] 117 private void AfterDeserialization() { 118 // BackwardsCompatibility3.3 119 #region Backwards compatible code, remove with 3.4 120 if (!Parameters.ContainsKey(SymbolicExpressionTreeParameterName)) 121 Parameters.Add(new LookupParameter<ISymbolicExpressionTree>(SymbolicExpressionTreeParameterName, "The symbolic expression tree on which the operator should be applied.")); 122 #endregion 113 123 } 114 124 … … 155 165 private void ParameterizeCrossovers() { 156 166 foreach (ISymbolicExpressionTreeCrossover op in Operators) { 157 op. ChildParameter.ActualName = ChildParameter.Name;167 op.SymbolicExpressionTreeParameter.ActualName = SymbolicExpressionTreeParameter.Name; 158 168 op.ParentsParameter.ActualName = ParentsParameter.Name; 159 169 } -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Crossovers/SymbolicDataAnalysisExpressionContextAwareCrossover.cs
r12155 r12891 27 27 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 28 28 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 29 using HeuristicLab.Random; 29 30 30 31 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { … … 68 69 possibleChildren.Add(n); 69 70 }); 70 var selectedChild = possibleChildren.SelectRandom(random); 71 72 var selectedChild = possibleChildren.SampleRandom(random); 71 73 var crossoverPoints = new List<CutPoint>(); 72 74 var qualities = new List<Tuple<CutPoint, double>>(); -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Crossovers/SymbolicDataAnalysisExpressionDepthConstrainedCrossover.cs
r12155 r12891 29 29 using HeuristicLab.Parameters; 30 30 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 31 using HeuristicLab.Random; 31 32 32 33 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { … … 115 116 throw new Exception("No crossover points available in the first parent"); 116 117 117 var crossoverPoint0 = crossoverPoints0.SelectRandom(random); 118 118 var crossoverPoint0 = crossoverPoints0.SampleRandom(random); 119 119 int level = parent0.Root.GetBranchLevel(crossoverPoint0.Child); 120 120 int length = parent0.Root.GetLength() - crossoverPoint0.Child.GetLength(); … … 126 126 select s).ToList(); 127 127 if (allowedBranches.Count == 0) return parent0; 128 var selectedBranch = allowedBranches.SelectRandom(random); 128 129 var selectedBranch = allowedBranches.SampleRandom(random); 129 130 Swap(crossoverPoint0, selectedBranch); 130 131 return parent0; -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Crossovers/SymbolicDataAnalysisExpressionDeterministicBestCrossover.cs
r12155 r12891 27 27 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 28 28 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 29 using HeuristicLab.Random; 29 30 30 31 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { … … 67 68 crossoverPoints0.Add(new CutPoint(n.Parent, n)); 68 69 }); 69 CutPoint crossoverPoint0 = crossoverPoints0.SelectRandom(random); 70 71 CutPoint crossoverPoint0 = crossoverPoints0.SampleRandom(random); 70 72 int level = parent0.Root.GetBranchLevel(crossoverPoint0.Child); 71 73 int length = parent0.Root.GetLength() - crossoverPoint0.Child.GetLength(); -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Crossovers/SymbolicDataAnalysisExpressionProbabilisticFunctionalCrossover.cs
r12155 r12891 27 27 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 28 28 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 29 using HeuristicLab.Random; 29 30 30 31 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { … … 69 70 } 70 71 }); 71 var crossoverPoint0 = crossoverPoints0.SelectRandom(random); 72 73 var crossoverPoint0 = crossoverPoints0.SampleRandom(random); 72 74 int level = parent0.Root.GetBranchLevel(crossoverPoint0.Child); 73 75 int length = parent0.Root.GetLength() - crossoverPoint0.Child.GetLength(); … … 137 139 weights[i] /= sum; 138 140 141 #pragma warning disable 612, 618 139 142 selectedBranch = allowedBranches.SelectRandom(weights, random); 143 #pragma warning restore 612, 618 140 144 } 141 145 Swap(crossoverPoint0, selectedBranch); -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Crossovers/SymbolicDataAnalysisExpressionSemanticSimilarityCrossover.cs
r12155 r12891 28 28 using HeuristicLab.Parameters; 29 29 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 30 using HeuristicLab.Random; 30 31 31 32 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { … … 81 82 crossoverPoints0.Add(new CutPoint(n.Parent, n)); 82 83 }); 83 var crossoverPoint0 = crossoverPoints0.SelectRandom(random); 84 85 var crossoverPoint0 = crossoverPoints0.SampleRandom(random); 84 86 int level = parent0.Root.GetBranchLevel(crossoverPoint0.Child); 85 87 int length = parent0.Root.GetLength() - crossoverPoint0.Child.GetLength(); -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionExcelFormatter.cs
r12155 r12891 71 71 } 72 72 73 public string Format(ISymbolicExpressionTree symbolicExpressionTree, Dataset dataset) {73 public string Format(ISymbolicExpressionTree symbolicExpressionTree, IDataset dataset) { 74 74 var stringBuilder = new StringBuilder(); 75 75 if (dataset != null) CalculateVariableMapping(symbolicExpressionTree, dataset); … … 85 85 } 86 86 87 private void CalculateVariableMapping(ISymbolicExpressionTree tree, Dataset dataset) {87 private void CalculateVariableMapping(ISymbolicExpressionTree tree, IDataset dataset) { 88 88 int columnIndex = 0; 89 89 int inputIndex = 0; -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interfaces/ISymbolicDataAnalysisExpressionTreeInterpreter.cs
r12155 r12891 27 27 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { 28 28 public interface ISymbolicDataAnalysisExpressionTreeInterpreter : INamedItem, IStatefulItem { 29 IEnumerable<double> GetSymbolicExpressionTreeValues(ISymbolicExpressionTree tree, Dataset dataset, IEnumerable<int> rows);29 IEnumerable<double> GetSymbolicExpressionTreeValues(ISymbolicExpressionTree tree, IDataset dataset, IEnumerable<int> rows); 30 30 IntValue EvaluatedSolutions { get; set; } 31 31 } -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interfaces/ISymbolicDataAnalysisImpactValuesCalculator.cs
r10459 r12891 6 6 public interface ISymbolicDataAnalysisSolutionImpactValuesCalculator : IItem { 7 7 double CalculateReplacementValue(ISymbolicDataAnalysisModel model, ISymbolicExpressionTreeNode node, IDataAnalysisProblemData problemData, IEnumerable<int> rows); 8 double CalculateImpactValue(ISymbolicDataAnalysisModel model, ISymbolicExpressionTreeNode node, IDataAnalysisProblemData problemData, IEnumerable<int> rows, double originalQuality= double.NaN);8 double CalculateImpactValue(ISymbolicDataAnalysisModel model, ISymbolicExpressionTreeNode node, IDataAnalysisProblemData problemData, IEnumerable<int> rows, double qualityForImpactsCalculation = double.NaN); 9 9 void CalculateImpactAndReplacementValues(ISymbolicDataAnalysisModel model, ISymbolicExpressionTreeNode node, IDataAnalysisProblemData problemData, 10 IEnumerable<int> rows, out double impactValue, out double replacementValue, double originalQuality= double.NaN);10 IEnumerable<int> rows, out double impactValue, out double replacementValue, out double newQualityForImpactsCalculation, double qualityForImpactsCalculation = double.NaN); 11 11 } 12 12 } -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeILEmittingInterpreter.cs
r12155 r12891 138 138 #endregion 139 139 140 public IEnumerable<double> GetSymbolicExpressionTreeValues(ISymbolicExpressionTree tree, Dataset dataset, IEnumerable<int> rows) {140 public IEnumerable<double> GetSymbolicExpressionTreeValues(ISymbolicExpressionTree tree, IDataset dataset, IEnumerable<int> rows) { 141 141 if (CheckExpressionsWithIntervalArithmetic.Value) 142 142 throw new NotSupportedException("Interval arithmetic is not yet supported in the symbolic data analysis interpreter."); … … 161 161 } 162 162 163 private InterpreterState PrepareInterpreterState(ISymbolicExpressionTree tree, Dataset dataset) {163 private InterpreterState PrepareInterpreterState(ISymbolicExpressionTree tree, IDataset dataset) { 164 164 Instruction[] code = SymbolicExpressionTreeCompiler.Compile(tree, OpCodes.MapSymbolToOpCode); 165 165 Dictionary<string, int> doubleVariableNames = dataset.DoubleVariables.Select((x, i) => new { x, i }).ToDictionary(e => e.x, e => e.i); … … 182 182 } 183 183 184 private void CompileInstructions(ILGenerator il, InterpreterState state, Dataset ds) {184 private void CompileInstructions(ILGenerator il, InterpreterState state, IDataset ds) { 185 185 Instruction currentInstr = state.NextInstruction(); 186 186 int nArgs = currentInstr.nArguments; -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeInterpreter.cs
r12155 r12891 95 95 #endregion 96 96 97 public IEnumerable<double> GetSymbolicExpressionTreeValues(ISymbolicExpressionTree tree, Dataset dataset, IEnumerable<int> rows) {97 public IEnumerable<double> GetSymbolicExpressionTreeValues(ISymbolicExpressionTree tree, IDataset dataset, IEnumerable<int> rows) { 98 98 if (CheckExpressionsWithIntervalArithmetic.Value) 99 99 throw new NotSupportedException("Interval arithmetic is not yet supported in the symbolic data analysis interpreter."); … … 111 111 } 112 112 113 private static InterpreterState PrepareInterpreterState(ISymbolicExpressionTree tree, Dataset dataset) {113 private static InterpreterState PrepareInterpreterState(ISymbolicExpressionTree tree, IDataset dataset) { 114 114 Instruction[] code = SymbolicExpressionTreeCompiler.Compile(tree, OpCodes.MapSymbolToOpCode); 115 115 int necessaryArgStackSize = 0; … … 132 132 133 133 134 public virtual double Evaluate( Dataset dataset, ref int row, InterpreterState state) {134 public virtual double Evaluate(IDataset dataset, ref int row, InterpreterState state) { 135 135 Instruction currentInstr = state.NextInstruction(); 136 136 switch (currentInstr.opCode) { -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeLinearInterpreter.cs
r12155 r12891 102 102 #endregion 103 103 104 public IEnumerable<double> GetSymbolicExpressionTreeValues(ISymbolicExpressionTree tree, Dataset dataset, IEnumerable<int> rows) {104 public IEnumerable<double> GetSymbolicExpressionTreeValues(ISymbolicExpressionTree tree, IDataset dataset, IEnumerable<int> rows) { 105 105 if (CheckExpressionsWithIntervalArithmetic.Value) 106 106 throw new NotSupportedException("Interval arithmetic is not yet supported in the symbolic data analysis interpreter."); … … 116 116 117 117 // NOTE: do not use this method when evaluating trees. this method is provided as a shortcut for evaluating subtrees ad-hoc 118 public IEnumerable<double> GetValues(ISymbolicExpressionTreeNode node, Dataset dataset, IEnumerable<int> rows) {118 public IEnumerable<double> GetValues(ISymbolicExpressionTreeNode node, IDataset dataset, IEnumerable<int> rows) { 119 119 var code = SymbolicExpressionTreeLinearCompiler.Compile(node, OpCodes.MapSymbolToOpCode); 120 120 PrepareInstructions(code, dataset); … … 122 122 } 123 123 124 private double Evaluate( Dataset dataset, int row, LinearInstruction[] code) {124 private double Evaluate(IDataset dataset, int row, LinearInstruction[] code) { 125 125 for (int i = code.Length - 1; i >= 0; --i) { 126 126 if (code[i].skip) continue; … … 361 361 } 362 362 363 public static void PrepareInstructions(LinearInstruction[] code, Dataset dataset) {363 public static void PrepareInstructions(LinearInstruction[] code, IDataset dataset) { 364 364 for (int i = 0; i != code.Length; ++i) { 365 365 var instr = code[i]; -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Plugin.cs.frame
r12155 r12891 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. 7.$WCREV$")]28 [Plugin("HeuristicLab.Problems.DataAnalysis.Symbolic","Provides base classes for symbolic data analysis tasks.", "3.4.8.$WCREV$")] 29 29 [PluginFile("HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.dll", PluginFileType.Assembly)] 30 30 [PluginDependency("HeuristicLab.ALGLIB", "3.7.0")] -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Properties/AssemblyInfo.cs.frame
r12155 r12891 53 53 // by using the '*' as shown below: 54 54 [assembly: AssemblyVersion("3.4.0.0")] 55 [assembly: AssemblyFileVersion("3.4. 7.$WCREV$")]55 [assembly: AssemblyFileVersion("3.4.8.$WCREV$")] -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisExpressionPruningOperator.cs
r12208 r12891 34 34 [StorableClass] 35 35 [Item("SymbolicExpressionTreePruningOperator", "An operator that replaces introns with constant values in a symbolic expression tree.")] 36 public abstract class SymbolicDataAnalysisExpressionPruningOperator : SingleSuccessorOperator {36 public abstract class SymbolicDataAnalysisExpressionPruningOperator : SingleSuccessorOperator, ISymbolicExpressionTreeOperator { 37 37 #region parameter names 38 38 private const string ProblemDataParameterName = "ProblemData"; … … 41 41 private const string PrunedSubtreesParameterName = "PrunedSubtrees"; 42 42 private const string PrunedTreesParameterName = "PrunedTrees"; 43 private const string PrunedNodesParameterName = "PrunedNodes"; 43 44 private const string FitnessCalculationPartitionParameterName = "FitnessCalculationPartition"; 44 45 private const string NodeImpactThresholdParameterName = "ImpactThreshold"; … … 48 49 private const string EstimationLimitsParameterName = "EstimationLimits"; 49 50 private const string InterpreterParameterName = "SymbolicExpressionTreeInterpreter"; 51 private const string ApplyLinearScalingParameterName = "ApplyLinearScaling"; 50 52 #endregion 51 53 … … 72 74 get { return (ILookupParameter<IntValue>)Parameters[PrunedTreesParameterName]; } 73 75 } 76 public ILookupParameter<IntValue> PrunedNodesParameter { 77 get { return (ILookupParameter<IntValue>)Parameters[PrunedNodesParameterName]; } 78 } 74 79 public IFixedValueParameter<DoubleValue> NodeImpactThresholdParameter { 75 80 get { return (IFixedValueParameter<DoubleValue>)Parameters[NodeImpactThresholdParameterName]; } … … 84 89 get { return (ILookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>)Parameters[InterpreterParameterName]; } 85 90 } 91 public ILookupParameter<BoolValue> ApplyLinearScalingParameter { 92 get { return (ILookupParameter<BoolValue>)Parameters[ApplyLinearScalingParameterName]; } 93 } 86 94 #endregion 87 95 88 96 #region properties 89 protected IDataAnalysisProblemData ProblemData { get { return ProblemDataParameter.ActualValue; } } 90 protected ISymbolicDataAnalysisSolutionImpactValuesCalculator ImpactValuesCalculator { get { return ImpactValuesCalculatorParameter.Value; } } 91 protected IntRange FitnessCalculationPartition { get { return FitnessCalculationPartitionParameter.ActualValue; } } 92 protected bool PruneOnlyZeroImpactNodes { 97 public ISymbolicDataAnalysisSolutionImpactValuesCalculator ImpactValuesCalculator { 98 get { return ImpactValuesCalculatorParameter.Value; } 99 set { ImpactValuesCalculatorParameter.Value = value; } 100 } 101 public bool PruneOnlyZeroImpactNodes { 93 102 get { return PruneOnlyZeroImpactNodesParameter.Value.Value; } 94 103 set { PruneOnlyZeroImpactNodesParameter.Value.Value = value; } 95 104 } 96 p rotecteddouble NodeImpactThreshold {105 public double NodeImpactThreshold { 97 106 get { return NodeImpactThresholdParameter.Value.Value; } 98 107 set { NodeImpactThresholdParameter.Value.Value = value; } 99 108 } 100 protected ISymbolicExpressionTree SymbolicExpressionTree { get { return SymbolicExpressionTreeParameter.ActualValue; } }101 protected DoubleValue Quality { get { return QualityParameter.ActualValue; } }102 protected DoubleLimit EstimationLimits { get { return EstimationLimitsParameter.ActualValue; } }103 protected ISymbolicDataAnalysisExpressionTreeInterpreter Interpreter { get { return InterpreterParameter.ActualValue; } }104 109 #endregion 105 110 … … 114 119 Parameters.Add(new LookupParameter<ISymbolicDataAnalysisModel>(SymbolicDataAnalysisModelParameterName)); 115 120 Parameters.Add(new LookupParameter<IntRange>(FitnessCalculationPartitionParameterName)); 121 Parameters.Add(new LookupParameter<IntValue>(PrunedNodesParameterName, "A counter of how many nodes were pruned.")); 116 122 Parameters.Add(new LookupParameter<IntValue>(PrunedSubtreesParameterName, "A counter of how many subtrees were replaced.")); 117 123 Parameters.Add(new LookupParameter<IntValue>(PrunedTreesParameterName, "A counter of how many trees were pruned.")); … … 122 128 Parameters.Add(new LookupParameter<ISymbolicExpressionTree>(SymbolicExpressionTreeParameterName)); 123 129 Parameters.Add(new LookupParameter<DoubleValue>(QualityParameterName)); 130 Parameters.Add(new LookupParameter<BoolValue>(ApplyLinearScalingParameterName)); 124 131 Parameters.Add(new ValueParameter<ISymbolicDataAnalysisSolutionImpactValuesCalculator>(ImpactValuesCalculatorParameterName, impactValuesCalculator)); 125 132 #endregion 126 133 } 127 134 135 [StorableHook(HookType.AfterDeserialization)] 136 private void AfterDeserialization() { 137 // BackwardsCompatibility3.3 138 #region Backwards compatible code, remove with 3.4 139 if (!Parameters.ContainsKey(PrunedNodesParameterName)) { 140 Parameters.Add(new LookupParameter<IntValue>(PrunedNodesParameterName, "A counter of how many nodes were pruned.")); 141 } 142 if (!Parameters.ContainsKey(ApplyLinearScalingParameterName)) { 143 Parameters.Add(new LookupParameter<BoolValue>(ApplyLinearScalingParameterName)); 144 } 145 if (!Parameters.ContainsKey(ImpactValuesCalculatorParameterName)) { 146 // value must be set by derived operators (regression/classification) 147 Parameters.Add(new ValueParameter<ISymbolicDataAnalysisSolutionImpactValuesCalculator>(ImpactValuesCalculatorParameterName)); 148 } 149 #endregion 150 } 151 128 152 protected abstract ISymbolicDataAnalysisModel CreateModel(ISymbolicExpressionTree tree, ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, IDataAnalysisProblemData problemData, DoubleLimit estimationLimits); 129 153 … … 131 155 132 156 public override IOperation Apply() { 133 var model = CreateModel(SymbolicExpressionTree, Interpreter, ProblemData, EstimationLimits); 134 var nodes = SymbolicExpressionTree.Root.GetSubtree(0).GetSubtree(0).IterateNodesPrefix().ToList(); 135 var rows = Enumerable.Range(FitnessCalculationPartition.Start, FitnessCalculationPartition.Size); 157 var tree = SymbolicExpressionTreeParameter.ActualValue; 158 var problemData = ProblemDataParameter.ActualValue; 159 var fitnessCalculationPartition = FitnessCalculationPartitionParameter.ActualValue; 160 var estimationLimits = EstimationLimitsParameter.ActualValue; 161 var interpreter = InterpreterParameter.ActualValue; 162 163 var model = CreateModel(tree, interpreter, problemData, estimationLimits); 164 var nodes = tree.Root.GetSubtree(0).GetSubtree(0).IterateNodesPrefix().ToList(); 165 var rows = Enumerable.Range(fitnessCalculationPartition.Start, fitnessCalculationPartition.Size).ToList(); 136 166 var prunedSubtrees = 0; 137 167 var prunedTrees = 0; 138 139 double quality = Evaluate(model); 168 var prunedNodes = 0; 169 170 double qualityForImpactsCalculation = double.NaN; 140 171 141 172 for (int i = 0; i < nodes.Count; ++i) { … … 144 175 145 176 double impactValue, replacementValue; 146 ImpactValuesCalculator.CalculateImpactAndReplacementValues(model, node, ProblemData, rows, out impactValue, out replacementValue, quality); 147 148 if (PruneOnlyZeroImpactNodes) { 149 if (!impactValue.IsAlmost(0.0)) continue; 150 } else if (NodeImpactThreshold < impactValue) { 151 continue; 152 } 177 double newQualityForImpacts; 178 ImpactValuesCalculator.CalculateImpactAndReplacementValues(model, node, problemData, rows, out impactValue, out replacementValue, out newQualityForImpacts, qualityForImpactsCalculation); 179 180 if (PruneOnlyZeroImpactNodes && !impactValue.IsAlmost(0.0)) continue; 181 if (!PruneOnlyZeroImpactNodes && impactValue > NodeImpactThreshold) continue; 153 182 154 183 var constantNode = (ConstantTreeNode)node.Grammar.GetSymbol("Constant").CreateTreeNode(); 155 184 constantNode.Value = replacementValue; 156 185 186 var length = node.GetLength(); 157 187 ReplaceWithConstant(node, constantNode); 158 i += node.GetLength() - 1; // skip subtrees under the node that was folded 159 160 quality -= impactValue; 188 i += length - 1; // skip subtrees under the node that was folded 161 189 162 190 prunedSubtrees++; 191 prunedNodes += length; 192 193 qualityForImpactsCalculation = newQualityForImpacts; 163 194 } 164 195 … … 166 197 PrunedSubtreesParameter.ActualValue = new IntValue(prunedSubtrees); 167 198 PrunedTreesParameter.ActualValue = new IntValue(prunedTrees); 199 PrunedNodesParameter.ActualValue = new IntValue(prunedNodes); 200 201 if (prunedSubtrees > 0) // if nothing was pruned then there's no need to re-evaluate the tree 202 QualityParameter.ActualValue.Value = Evaluate(model); 168 203 169 204 return base.Apply(); 170 }171 172 public ISymbolicExpressionTree Prune(ISymbolicExpressionTree tree, ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, IDataAnalysisProblemData problemData, DoubleLimit estimationLimits) {173 var model = CreateModel((ISymbolicExpressionTree)tree.Clone(), Interpreter, ProblemData, EstimationLimits);174 var nodes = SymbolicExpressionTree.Root.GetSubtree(0).GetSubtree(0).IterateNodesPrefix().ToList();175 var rows = Enumerable.Range(FitnessCalculationPartition.Start, FitnessCalculationPartition.Size);176 177 double quality = Evaluate(model);178 179 for (int i = 0; i < nodes.Count; ++i) {180 var node = nodes[i];181 if (node is ConstantTreeNode) continue;182 183 double impactValue, replacementValue;184 ImpactValuesCalculator.CalculateImpactAndReplacementValues(model, node, ProblemData, rows, out impactValue, out replacementValue, quality);185 186 if (PruneOnlyZeroImpactNodes) {187 if (!impactValue.IsAlmost(0.0)) continue;188 } else if (NodeImpactThreshold < impactValue) {189 continue;190 }191 192 var constantNode = (ConstantTreeNode)node.Grammar.GetSymbol("Constant").CreateTreeNode();193 constantNode.Value = replacementValue;194 195 ReplaceWithConstant(node, constantNode);196 i += node.GetLength() - 1; // skip subtrees under the node that was folded197 198 quality -= impactValue;199 }200 return model.SymbolicExpressionTree;201 205 } 202 206 -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisExpressionTreeSimplifier.cs
r12155 r12891 287 287 // make sum(x0..xn) / n 288 288 var sum = original.Subtrees 289 .Select( x => GetSimplifiedTree(x))290 .Aggregate( (a, b) => MakeSum(a, b));289 .Select(GetSimplifiedTree) 290 .Aggregate(MakeSum); 291 291 return MakeFraction(sum, MakeConstant(original.Subtrees.Count())); 292 292 } … … 299 299 // simplify expressions x0..xn 300 300 // make multiplication (x0 * 1/(x1 * x1 * .. * xn)) 301 var simplifiedTrees = original.Subtrees.Select(x => GetSimplifiedTree(x)); 301 var first = original.GetSubtree(0); 302 var second = original.GetSubtree(1); 303 var remaining = original.Subtrees.Skip(2); 302 304 return 303 MakeProduct( simplifiedTrees.First(), Invert(simplifiedTrees.Skip(1).Aggregate((a, b) => MakeProduct(a, b))));305 MakeProduct(GetSimplifiedTree(first), Invert(remaining.Aggregate(GetSimplifiedTree(second), (a, b) => MakeProduct(a, GetSimplifiedTree(b))))); 304 306 } 305 307 } … … 310 312 } else { 311 313 return original.Subtrees 312 .Select( x => GetSimplifiedTree(x))313 .Aggregate( (a, b) => MakeProduct(a, b));314 .Select(GetSimplifiedTree) 315 .Aggregate(MakeProduct); 314 316 } 315 317 } … … 321 323 // simplify expressions x0..xn 322 324 // make addition (x0,-x1..-xn) 323 var simplifiedTrees = original.Subtrees.Select(x => GetSimplifiedTree(x)); 324 return simplifiedTrees.Take(1) 325 .Concat(simplifiedTrees.Skip(1).Select(x => Negate(x))) 326 .Aggregate((a, b) => MakeSum(a, b)); 325 var first = original.Subtrees.First(); 326 var remaining = original.Subtrees.Skip(1); 327 return remaining.Aggregate(GetSimplifiedTree(first), (a, b) => MakeSum(a, Negate(GetSimplifiedTree(b)))); 327 328 } 328 329 } … … 335 336 // make addition (x0..xn) 336 337 return original.Subtrees 337 .Select( x => GetSimplifiedTree(x))338 .Aggregate( (a, b) => MakeSum(a, b));338 .Select(GetSimplifiedTree) 339 .Aggregate(MakeSum); 339 340 } 340 341 } … … 345 346 private ISymbolicExpressionTreeNode SimplifyOr(ISymbolicExpressionTreeNode original) { 346 347 return original.Subtrees 347 .Select( x => GetSimplifiedTree(x))348 .Aggregate( (a, b) => MakeOr(a, b));348 .Select(GetSimplifiedTree) 349 .Aggregate(MakeOr); 349 350 } 350 351 private ISymbolicExpressionTreeNode SimplifyAnd(ISymbolicExpressionTreeNode original) { 351 352 return original.Subtrees 352 .Select( x => GetSimplifiedTree(x))353 .Aggregate( (a, b) => MakeAnd(a, b));353 .Select(GetSimplifiedTree) 354 .Aggregate(MakeAnd); 354 355 } 355 356 private ISymbolicExpressionTreeNode SimplifyLessThan(ISymbolicExpressionTreeNode original) { … … 831 832 private void MergeVariablesInSum(ISymbolicExpressionTreeNode sum) { 832 833 var subtrees = new List<ISymbolicExpressionTreeNode>(sum.Subtrees); 833 while (sum.Subtrees. Count() > 0) sum.RemoveSubtree(0);834 while (sum.Subtrees.Any()) sum.RemoveSubtree(0); 834 835 var groupedVarNodes = from node in subtrees.OfType<VariableTreeNode>() 835 836 let lag = (node is LaggedVariableTreeNode) ? ((LaggedVariableTreeNode)node).Lag : 0 … … 949 950 private void MergeVariablesAndConstantsInProduct(ISymbolicExpressionTreeNode prod) { 950 951 var subtrees = new List<ISymbolicExpressionTreeNode>(prod.Subtrees); 951 while (prod.Subtrees. Count() > 0) prod.RemoveSubtree(0);952 while (prod.Subtrees.Any()) prod.RemoveSubtree(0); 952 953 var groupedVarNodes = from node in subtrees.OfType<VariableTreeNode>() 953 954 let lag = (node is LaggedVariableTreeNode) ? ((LaggedVariableTreeNode)node).Lag : 0 … … 1004 1005 } else if (IsAddition(x)) { 1005 1006 // (x0 + x1 + .. + xn) * -1 => (-x0 + -x1 + .. + -xn) 1006 List<ISymbolicExpressionTreeNode>subtrees = new List<ISymbolicExpressionTreeNode>(x.Subtrees);1007 while (x.Subtrees. Count() > 0) x.RemoveSubtree(0);1007 var subtrees = new List<ISymbolicExpressionTreeNode>(x.Subtrees); 1008 while (x.Subtrees.Any()) x.RemoveSubtree(0); 1008 1009 foreach (var subtree in subtrees) { 1009 1010 x.AddSubtree(Negate(subtree)); -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisProblem.cs
r12155 r12891 300 300 301 301 protected virtual void ParameterizeOperators() { 302 var operators = Parameters.OfType<IValueParameter>().Select(p => p.Value).OfType<IOperator>().Union(Operators).ToList(); 302 var operators = 303 Parameters.OfType<IValueParameter>().Select(p => p.Value).OfType<IOperator>().Union(Operators).ToList(); 303 304 304 305 foreach (var op in operators.OfType<ISymbolicExpressionTreeGrammarBasedOperator>()) { … … 322 323 foreach (var op in operators.OfType<ISymbolicExpressionTreeCrossover>()) { 323 324 op.ParentsParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName; 324 op. ChildParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;325 op.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName; 325 326 } 326 327 foreach (var op in operators.OfType<ISymbolicExpressionTreeManipulator>()) { … … 357 358 op.BeforeCrossoverOperatorParameter.ActualValue = new SymbolicDataAnalysisExpressionBeforeCrossoverOperator(); 358 359 op.AfterCrossoverOperatorParameter.ActualValue = new SymbolicDataAnalysisExpressionAfterCrossoverOperator(); 359 op.BeforeManipulatorOperatorParameter.ActualValue = new SymbolicDataAnalysisExpressionBeforeManipulatorOperator(); 360 op.BeforeManipulatorOperatorParameter.ActualValue = 361 new SymbolicDataAnalysisExpressionBeforeManipulatorOperator(); 360 362 op.AfterManipulatorOperatorParameter.ActualValue = new SymbolicDataAnalysisExpressionAfterManipulatorOperator(); 361 363 // get crossover parameter names … … 364 366 op.BeforeCrossoverOperator.ParentsParameter.ActualName = crossover.ParentsParameter.Name; 365 367 op.AfterCrossoverOperator.ParentsParameter.ActualName = crossover.ParentsParameter.Name; 366 op.BeforeCrossoverOperator.ChildParameter.ActualName = crossover. ChildParameter.Name;367 op.AfterCrossoverOperator.ChildParameter.ActualName = crossover. ChildParameter.Name;368 }369 // get manipulator parameter names370 var manipulator = operators.OfType<ISymbolicExpressionTreeManipulator>().FirstOrDefault();371 if (manipulator != null) {372 op.BeforeManipulatorOperator.ChildParameter.ActualName = manipulator.SymbolicExpressionTreeParameter.Name;373 op.AfterManipulatorOperator.ChildParameter.ActualName = manipulator.SymbolicExpressionTreeParameter.Name;374 }375 var creator = operators.OfType<ISymbolicExpressionTreeCreator>().FirstOrDefault();376 if (creator != null) {377 op.PopulationParameter.ActualName = creator.SymbolicExpressionTreeParameter.ActualName;368 op.BeforeCrossoverOperator.ChildParameter.ActualName = crossover.SymbolicExpressionTreeParameter.Name; 369 op.AfterCrossoverOperator.ChildParameter.ActualName = crossover.SymbolicExpressionTreeParameter.Name; 370 // get manipulator parameter names 371 var manipulator = operators.OfType<ISymbolicExpressionTreeManipulator>().FirstOrDefault(); 372 if (manipulator != null) { 373 op.BeforeManipulatorOperator.ChildParameter.ActualName = manipulator.SymbolicExpressionTreeParameter.Name; 374 op.AfterManipulatorOperator.ChildParameter.ActualName = manipulator.SymbolicExpressionTreeParameter.Name; 375 } 376 var creator = operators.OfType<ISymbolicExpressionTreeCreator>().FirstOrDefault(); 377 if (creator != null) { 378 op.PopulationParameter.ActualName = creator.SymbolicExpressionTreeParameter.ActualName; 379 } 378 380 } 379 381 } -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisSolutionImpactValuesCalculator.cs
r12155 r12891 37 37 protected SymbolicDataAnalysisSolutionImpactValuesCalculator(bool deserializing) : base(deserializing) { } 38 38 public abstract double CalculateReplacementValue(ISymbolicDataAnalysisModel model, ISymbolicExpressionTreeNode node, IDataAnalysisProblemData problemData, IEnumerable<int> rows); 39 public abstract double CalculateImpactValue(ISymbolicDataAnalysisModel model, ISymbolicExpressionTreeNode node, IDataAnalysisProblemData problemData, IEnumerable<int> rows, double originalQuality= double.NaN);40 public abstract void CalculateImpactAndReplacementValues(ISymbolicDataAnalysisModel model, ISymbolicExpressionTreeNode node, IDataAnalysisProblemData problemData, IEnumerable<int> rows, out double impactValue, out double replacementValue, double originalQuality= double.NaN);39 public abstract double CalculateImpactValue(ISymbolicDataAnalysisModel model, ISymbolicExpressionTreeNode node, IDataAnalysisProblemData problemData, IEnumerable<int> rows, double qualityForImpactsCalculation = double.NaN); 40 public abstract void CalculateImpactAndReplacementValues(ISymbolicDataAnalysisModel model, ISymbolicExpressionTreeNode node, IDataAnalysisProblemData problemData, IEnumerable<int> rows, out double impactValue, out double replacementValue, out double newQualityForImpactsCalculation, double qualityForImpactsCalculation = double.NaN); 41 41 42 42 protected static double CalculateReplacementValue(ISymbolicExpressionTreeNode node, ISymbolicExpressionTree sourceTree, ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, 43 Dataset dataset, IEnumerable<int> rows) {43 IDataset dataset, IEnumerable<int> rows) { 44 44 //optimization: constant nodes return always the same value 45 45 ConstantTreeNode constantNode = node as ConstantTreeNode; -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/VariableConditionTreeNode.cs
r12155 r12891 74 74 base.ResetLocalParameters(random); 75 75 threshold = NormalDistributedRandom.NextDouble(random, Symbol.ThresholdInitializerMu, Symbol.ThresholdInitializerSigma); 76 77 #pragma warning disable 612, 618 76 78 variableName = Symbol.VariableNames.SelectRandom(random); 79 #pragma warning restore 612, 618 80 77 81 slope = NormalDistributedRandom.NextDouble(random, Symbol.SlopeInitializerMu, Symbol.SlopeInitializerSigma); 78 82 } … … 82 86 double x = NormalDistributedRandom.NextDouble(random, Symbol.ThresholdManipulatorMu, Symbol.ThresholdManipulatorSigma); 83 87 threshold = threshold + x * shakingFactor; 88 89 #pragma warning disable 612, 618 84 90 variableName = Symbol.VariableNames.SelectRandom(random); 91 #pragma warning restore 612, 618 92 85 93 x = NormalDistributedRandom.NextDouble(random, Symbol.SlopeManipulatorMu, Symbol.SlopeManipulatorSigma); 86 94 slope = slope + x * shakingFactor; -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/VariableTreeNode.cs
r12155 r12891 61 61 base.ResetLocalParameters(random); 62 62 weight = NormalDistributedRandom.NextDouble(random, Symbol.WeightMu, Symbol.WeightSigma); 63 64 #pragma warning disable 612, 618 63 65 variableName = Symbol.VariableNames.SelectRandom(random); 66 #pragma warning restore 612, 618 64 67 } 65 68 … … 70 73 double x = NormalDistributedRandom.NextDouble(random, Symbol.WeightManipulatorMu, Symbol.WeightManipulatorSigma); 71 74 weight = weight + x * shakingFactor; 72 } else { 75 } else { 73 76 double x = NormalDistributedRandom.NextDouble(random, 1.0, Symbol.MultiplicativeWeightManipulatorSigma); 74 77 weight = weight * x; 75 78 } 79 #pragma warning disable 612, 618 76 80 variableName = Symbol.VariableNames.SelectRandom(random); 81 #pragma warning restore 612, 618 77 82 } 78 83 -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/TreeMatching/SymbolicExpressionTreeBottomUpSimilarityCalculator.cs
r12287 r12891 1 1 #region License Information 2 2 3 /* HeuristicLab 3 4 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL) … … 18 19 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>. 19 20 */ 20 #endregion 21 22 #endregion License Information 21 23 22 24 using System; … … 32 34 33 35 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { 36 34 37 [StorableClass] 35 38 [Item("SymbolicExpressionTreeBottomUpSimilarityCalculator", "A similarity calculator which uses the tree bottom-up distance as a similarity metric.")] … … 37 40 private readonly HashSet<string> commutativeSymbols = new HashSet<string> { "Addition", "Multiplication", "Average", "And", "Or", "Xor" }; 38 41 39 public SymbolicExpressionTreeBottomUpSimilarityCalculator() { } 42 public SymbolicExpressionTreeBottomUpSimilarityCalculator() { 43 } 44 40 45 protected override bool IsCommutative { get { return true; } } 41 46 … … 107 112 108 113 // at this point we know that v and w are isomorphic, however, the mapping cannot be done directly 109 // (as in the paper) because the trees are unordered (subtree order might differ). the solution is 114 // (as in the paper) because the trees are unordered (subtree order might differ). the solution is 110 115 // to sort subtrees from under commutative labels (this will work because the subtrees are isomorphic!) 111 116 // while iterating over the two subtrees -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/TreeMatching/SymbolicExpressionTreeNodeComparer.cs
r12155 r12891 18 18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>. 19 19 */ 20 #endregion 20 #endregion License Information 21 21 22 22 using System; … … 29 29 // - used for bringing subtrees to a "canonical" form when the operation allows reordering of arguments 30 30 public class SymbolicExpressionTreeNodeComparer : ISymbolicExpressionTreeNodeComparer { 31 31 32 public static int CompareNodes(ISymbolicExpressionTreeNode a, ISymbolicExpressionTreeNode b) { 32 33 var ta = a as SymbolicExpressionTreeTerminalNode; … … 69 70 } 70 71 } 71 72 72 } -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/TreeMatching/SymbolicExpressionTreePhenotypicSimilarityCalculator.cs
r12155 r12891 65 65 66 66 OnlineCalculatorError error; 67 var r2 = OnlinePearsonsRSquaredCalculator.Calculate(v1, v2, out error); 67 var r = OnlinePearsonsRCalculator.Calculate(v1, v2, out error); 68 69 var r2 = error == OnlineCalculatorError.None ? r * r : 0; 68 70 69 71 if (r2 > 1.0) 70 72 r2 = 1.0; 71 73 72 return error == OnlineCalculatorError.None ? r2 : 0;74 return r2; 73 75 } 74 76 … … 87 89 88 90 OnlineCalculatorError error; 89 var r2 = OnlinePearsonsRSquaredCalculator.Calculate(leftValues, rightValues, out error); 91 var r = OnlinePearsonsRCalculator.Calculate(leftValues, rightValues, out error); 92 93 var r2 = error == OnlineCalculatorError.None ? r * r : 0; 90 94 91 95 if (r2 > 1.0) 92 r2 = 1.0; // sometimes due to fp errors it can happen that the r2 is over 1 (like 1.0000000009)96 r2 = 1.0; 93 97 94 return error == OnlineCalculatorError.None ? r2 : 0;98 return r2; 95 99 } 96 100 }
Note: See TracChangeset
for help on using the changeset viewer.