- Timestamp:
- 04/02/10 16:49:20 (15 years ago)
- Location:
- trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic
- Files:
-
- 2 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/ArithmeticExpressionGrammar.cs
r3255 r3257 26 26 using System.Linq; 27 27 using HeuristicLab.Core; 28 using HeuristicLab.Problems.DataAnalysis.Symbolic.Symbols;29 28 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 30 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { 29 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.GeneralSymbols; 30 using HeuristicLab.Problems.DataAnalysis.Regression.Symbolic.Symbols; 31 namespace HeuristicLab.Problems.DataAnalysis.Regression.Symbolic { 31 32 [StorableClass] 32 33 public class ArithmeticExpressionGrammar : Item, ISymbolicExpressionGrammar { 33 34 private class EmptySymbol : Symbol {35 public EmptySymbol() {36 Name = "Start";37 }38 }39 34 40 35 public ArithmeticExpressionGrammar() … … 43 38 #region ISymbolicExpressionGrammar Members 44 39 [Storable] 45 private EmptySymbol startSymbol = new EmptySymbol();40 private StartSymbol startSymbol = new StartSymbol(); 46 41 public Symbol StartSymbol { 47 42 get { return startSymbol; } … … 55 50 new Division(), 56 51 new Constant(), 57 new HeuristicLab.Problems.DataAnalysis. Symbolic.Symbols.Variable()52 new HeuristicLab.Problems.DataAnalysis.Regression.Symbolic.Symbols.Variable() 58 53 }; 59 54 [Storable] 60 55 private Dictionary<Type, Dictionary<int, IEnumerable<Symbol>>> allowedSymbols = new Dictionary<Type, Dictionary<int, IEnumerable<Symbol>>>() { 61 56 { 62 typeof( EmptySymbol),57 typeof(StartSymbol), 63 58 new Dictionary<int, IEnumerable<Symbol>>() 64 59 { … … 104 99 [Storable] 105 100 private Dictionary<Type, int> minLength = new Dictionary<Type, int>() { 106 {typeof( EmptySymbol), 1},101 {typeof(StartSymbol), 1}, 107 102 {typeof(Addition), 3}, 108 103 {typeof(Subtraction), 3}, … … 110 105 {typeof(Division), 4}, 111 106 {typeof(Constant), 1}, 112 {typeof(HeuristicLab.Problems.DataAnalysis. Symbolic.Symbols.Variable), 1},107 {typeof(HeuristicLab.Problems.DataAnalysis.Regression.Symbolic.Symbols.Variable), 1}, 113 108 }; 114 109 public int MinimalExpressionLength(Symbol start) { … … 118 113 [Storable] 119 114 private Dictionary<Type, int> maxLength = new Dictionary<Type, int>() { 120 {typeof( EmptySymbol), int.MaxValue},115 {typeof(StartSymbol), int.MaxValue}, 121 116 {typeof(Addition), int.MaxValue}, 122 117 {typeof(Subtraction), int.MaxValue}, 123 118 {typeof(Multiplication), int.MaxValue}, 124 119 {typeof(Division), int.MaxValue}, 125 {typeof(HeuristicLab.Problems.DataAnalysis. Symbolic.Symbols.Variable), 1},120 {typeof(HeuristicLab.Problems.DataAnalysis.Regression.Symbolic.Symbols.Variable), 1}, 126 121 {typeof(Constant), 1}, 127 122 }; … … 132 127 [Storable] 133 128 private Dictionary<Type, int> minDepth = new Dictionary<Type, int>() { 134 {typeof( EmptySymbol), 1},129 {typeof(StartSymbol), 1}, 135 130 {typeof(Addition), 1}, 136 131 {typeof(Subtraction), 1}, … … 138 133 {typeof(Division), 1}, 139 134 {typeof(Constant), 0}, 140 {typeof(HeuristicLab.Problems.DataAnalysis. Symbolic.Symbols.Variable), 0}135 {typeof(HeuristicLab.Problems.DataAnalysis.Regression.Symbolic.Symbols.Variable), 0} 141 136 }; 142 137 public int MinimalExpressionDepth(Symbol start) { … … 146 141 [Storable] 147 142 private Dictionary<Type, int> subTrees = new Dictionary<Type, int>() { 148 {typeof( EmptySymbol), 1},143 {typeof(StartSymbol), 1}, 149 144 {typeof(Addition), 2}, 150 145 {typeof(Subtraction), 2}, 151 146 {typeof(Multiplication), 2}, 152 147 {typeof(Division), 2}, 153 {typeof(HeuristicLab.Problems.DataAnalysis. Symbolic.Symbols.Variable), 0},148 {typeof(HeuristicLab.Problems.DataAnalysis.Regression.Symbolic.Symbols.Variable), 0}, 154 149 {typeof(Constant), 0}, 155 150 }; -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/SimpleArithmeticExpressionEvaluator.cs
r3255 r3257 26 26 using System.Collections.Generic; 27 27 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 28 using HeuristicLab.Problems.DataAnalysis.Symbolic.Symbols; 28 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.GeneralSymbols; 29 using HeuristicLab.Problems.DataAnalysis.Regression.Symbolic.Symbols; 29 30 30 namespace HeuristicLab.Problems.DataAnalysis. Symbolic {31 namespace HeuristicLab.Problems.DataAnalysis.Regression.Symbolic { 31 32 /// <summary> 32 33 /// Evaluates FunctionTrees recursively by interpretation of the function symbols in each node. … … 36 37 [StorableClass] 37 38 [Item("SimpleArithmeticExpressionEvaluator", "Default evaluator for arithmetic symbolic expression trees.")] 38 public class SimpleArithmeticExpressionEvaluator : Item { 39 public class SimpleArithmeticExpressionEvaluator : GeneralSymbolicExpressionTreeEvaluator { 40 private Dataset dataset; 41 private int row; 39 42 public IEnumerable<double> EstimatedValues(SymbolicExpressionTree tree, Dataset dataset, IEnumerable<int> rows) { 43 this.dataset = dataset; 40 44 foreach (var row in rows) { 41 var estimatedValue = Evaluate(tree.Root.SubTrees[0], dataset, row); 45 this.row = row; 46 var estimatedValue = Evaluate(tree.Root.SubTrees[0]); 42 47 if (double.IsNaN(estimatedValue) || double.IsInfinity(estimatedValue)) yield return 0.0; 43 48 else yield return estimatedValue; … … 45 50 } 46 51 47 p rivate double Evaluate(SymbolicExpressionTreeNode node, Dataset dataset, int row) {48 if (node.Symbol is HeuristicLab.Problems.DataAnalysis. Symbolic.Symbols.Variable) {52 public override double Evaluate(SymbolicExpressionTreeNode node) { 53 if (node.Symbol is HeuristicLab.Problems.DataAnalysis.Regression.Symbolic.Symbols.Variable) { 49 54 var variableTreeNode = node as VariableTreeNode; 50 55 return dataset[row, 1 /*dataset.VariableIndex(variableTreeNode.VariableName)*/] * 1.0; //variableTreeNode.Weight; 51 56 } else if (node.Symbol is Constant) { 52 57 return ((ConstantTreeNode)node).Value; 53 } else if (node.Symbol is Addition) {54 return Evaluate(node.SubTrees[0], dataset, row) + Evaluate(node.SubTrees[1], dataset, row);55 } else if (node.Symbol is Subtraction) {56 return Evaluate(node.SubTrees[0], dataset, row) - Evaluate(node.SubTrees[1], dataset, row);57 } else if (node.Symbol is Multiplication) {58 return Evaluate(node.SubTrees[0], dataset, row) * Evaluate(node.SubTrees[1], dataset, row);59 } else if (node.Symbol is Division) {60 return Evaluate(node.SubTrees[0], dataset, row) / Evaluate(node.SubTrees[1], dataset, row);61 58 } else { 62 throw new NotSupportedException("Tree contains unknown symbol: " + node.Symbol.Name);59 return base.Evaluate(node); 63 60 } 64 61 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/SymbolicRegressionMeanSquaredErrorEvaluator.cs
r3253 r3257 34 34 using HeuristicLab.Problems.DataAnalysis; 35 35 using HeuristicLab.Operators; 36 using HeuristicLab.Problems.DataAnalysis.Symbolic;37 36 using HeuristicLab.Problems.DataAnalysis.Evaluators; 38 37 -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/SymbolicRegressionProblem.cs
r3253 r3257 33 33 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 34 34 using HeuristicLab.Problems.DataAnalysis.Regression; 35 using HeuristicLab.Problems.DataAnalysis.Symbolic;36 35 37 36 namespace HeuristicLab.Problems.DataAnalysis.Regression.Symbolic {
Note: See TracChangeset
for help on using the changeset viewer.