- Timestamp:
- 04/09/10 17:28:32 (15 years ago)
- Location:
- trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/ArithmeticExpressionGrammar.cs
r3269 r3294 32 32 namespace HeuristicLab.Problems.DataAnalysis.Regression.Symbolic { 33 33 [StorableClass] 34 public class ArithmeticExpressionGrammar : NamedItemCollection<Symbol>, ISymbolicExpressionGrammar { 35 34 [Item("ArithmeticExpressionGrammar", "Represents a grammar for functional expressions using only arithmetic operations.")] 35 public class ArithmeticExpressionGrammar : DefaultSymbolicExpressionGrammar { 36 [Storable] 36 37 private List<string> variableNames = new List<string>(); 37 38 public IEnumerable<string> VariableNames { … … 39 40 set { 40 41 variableNames = new List<string>(value); 41 var variable = (HeuristicLab.Problems.DataAnalysis.Regression.Symbolic.Symbols.Variable)allSymbols[5]; 42 variable.VariableNames = new ItemList<HeuristicLab.Data.StringValue>(variableNames.Select(x => new StringValue(x))); 42 variableSymbol.VariableNames = variableNames; 43 43 } 44 44 } 45 45 46 [Storable] 47 private HeuristicLab.Problems.DataAnalysis.Regression.Symbolic.Symbols.Variable variableSymbol; 48 46 49 public ArithmeticExpressionGrammar() 47 : this(allSymbols) { 50 : base(0, 0, 0, 0) { 51 Initialize(); 48 52 } 49 53 50 public ArithmeticExpressionGrammar(IEnumerable<Symbol> symbols) 51 : base(symbols) { 52 allSymbols = new List<Symbol>(symbols); 53 } 54 private void Initialize() { 55 var add = new Addition(); 56 var sub = new Subtraction(); 57 var mul = new Multiplication(); 58 var div = new Division(); 59 var constant = new Constant(); 60 variableSymbol = new HeuristicLab.Problems.DataAnalysis.Regression.Symbolic.Symbols.Variable(); 54 61 55 #region ISymbolicExpressionGrammar Members 56 [Storable] 57 private StartSymbol startSymbol = new StartSymbol(); 58 public Symbol StartSymbol { 59 get { return startSymbol; } 60 } 61 62 [Storable] 63 private static List<Symbol> allSymbols = new List<Symbol>() { 64 new Addition(), 65 new Subtraction(), 66 new Multiplication(), 67 new Division(), 68 new Constant(), 69 new HeuristicLab.Problems.DataAnalysis.Regression.Symbolic.Symbols.Variable() 70 }; 71 [Storable] 72 private Dictionary<Type, Dictionary<int, IEnumerable<Symbol>>> allowedSymbols = new Dictionary<Type, Dictionary<int, IEnumerable<Symbol>>>() { 73 { 74 typeof(StartSymbol), 75 new Dictionary<int, IEnumerable<Symbol>>() 76 { 77 { 0, allSymbols}, 78 } 79 }, { 80 typeof(Addition), 81 new Dictionary<int, IEnumerable<Symbol>>() 82 { 83 { 0, allSymbols}, 84 { 1, allSymbols} 85 } 86 }, 87 { 88 typeof(Subtraction), 89 new Dictionary<int, IEnumerable<Symbol>>() 90 { 91 { 0, allSymbols}, 92 { 1, allSymbols} 93 } 94 }, 95 { 96 typeof(Multiplication), 97 new Dictionary<int, IEnumerable<Symbol>>() 98 { 99 { 0, allSymbols}, 100 { 1, allSymbols} 101 } 102 }, 103 { 104 typeof(Division), 105 new Dictionary<int, IEnumerable<Symbol>>() 106 { 107 { 0, allSymbols}, 108 { 1, allSymbols} 109 } 110 }, 111 }; 112 public IEnumerable<Symbol> AllowedSymbols(Symbol parent, int argumentIndex) { 113 return allowedSymbols[parent.GetType()][argumentIndex]; 114 } 115 116 [Storable] 117 private Dictionary<Type, int> minLength = new Dictionary<Type, int>() { 118 {typeof(StartSymbol), 1}, 119 {typeof(Addition), 3}, 120 {typeof(Subtraction), 3}, 121 {typeof(Multiplication), 4}, 122 {typeof(Division), 4}, 123 {typeof(Constant), 1}, 124 {typeof(HeuristicLab.Problems.DataAnalysis.Regression.Symbolic.Symbols.Variable), 1}, 125 }; 126 public int MinimalExpressionLength(Symbol start) { 127 return minLength[start.GetType()]; 128 } 129 130 [Storable] 131 private Dictionary<Type, int> maxLength = new Dictionary<Type, int>() { 132 {typeof(StartSymbol), int.MaxValue}, 133 {typeof(Addition), int.MaxValue}, 134 {typeof(Subtraction), int.MaxValue}, 135 {typeof(Multiplication), int.MaxValue}, 136 {typeof(Division), int.MaxValue}, 137 {typeof(HeuristicLab.Problems.DataAnalysis.Regression.Symbolic.Symbols.Variable), 1}, 138 {typeof(Constant), 1}, 139 }; 140 public int MaximalExpressionLength(Symbol start) { 141 return maxLength[start.GetType()]; 142 } 143 144 [Storable] 145 private Dictionary<Type, int> minDepth = new Dictionary<Type, int>() { 146 {typeof(StartSymbol), 1}, 147 {typeof(Addition), 1}, 148 {typeof(Subtraction), 1}, 149 {typeof(Multiplication), 1}, 150 {typeof(Division), 1}, 151 {typeof(Constant), 0}, 152 {typeof(HeuristicLab.Problems.DataAnalysis.Regression.Symbolic.Symbols.Variable), 0} 153 }; 154 public int MinimalExpressionDepth(Symbol start) { 155 return minDepth[start.GetType()]; 156 } 157 158 [Storable] 159 private Dictionary<Type, int> subTrees = new Dictionary<Type, int>() { 160 {typeof(StartSymbol), 1}, 161 {typeof(Addition), 2}, 162 {typeof(Subtraction), 2}, 163 {typeof(Multiplication), 2}, 164 {typeof(Division), 2}, 165 {typeof(HeuristicLab.Problems.DataAnalysis.Regression.Symbolic.Symbols.Variable), 0}, 166 {typeof(Constant), 0}, 167 }; 168 public int MinSubTrees(Symbol start) { 169 return subTrees[start.GetType()]; 170 } 171 public int MaxSubTrees(Symbol start) { 172 return subTrees[start.GetType()]; 173 } 174 175 #endregion 176 177 #region ISymbolicExpressionGrammar Members 62 var allSymbols = new List<Symbol>() { add, sub, mul, div, constant, variableSymbol }; 63 var functionSymbols = new List<Symbol>() { add, sub, mul, div }; 64 allSymbols.ForEach(s => AddAllowedSymbols(StartSymbol, 0, s)); 178 65 179 66 180 public bool IsValidExpression(SymbolicExpressionTree expression) {181 if (expression.Root.Symbol != StartSymbol) return false;182 return IsValidExpression(expression.Root);183 }184 185 #endregion186 187 private bool IsValidExpression(SymbolicExpressionTreeNode root) {188 if (root.SubTrees.Count < MinSubTrees(root.Symbol)) return false;189 if (root.SubTrees.Count > MaxSubTrees(root.Symbol)) return false;190 for (int i = 0; i < root.SubTrees.Count; i++) {191 if (!AllowedSymbols(root.Symbol, i).Contains(root.SubTrees[i].Symbol)) return false;192 if (!IsValidExpression(root.SubTrees[i])) return false;67 SetMinSubTreeCount(constant, 0); 68 SetMaxSubTreeCount(constant, 0); 69 SetMinSubTreeCount(variableSymbol, 0); 70 SetMaxSubTreeCount(variableSymbol, 0); 71 int maxSubTrees = 3; 72 foreach (var functionSymbol in functionSymbols) { 73 SetMinSubTreeCount(functionSymbol, 1); 74 SetMaxSubTreeCount(functionSymbol, maxSubTrees); 75 foreach (var childSymbol in allSymbols) { 76 for (int argumentIndex = 0; argumentIndex < maxSubTrees; argumentIndex++) { 77 AddAllowedSymbols(functionSymbol, argumentIndex, childSymbol); 78 } 79 } 193 80 } 194 return true;195 81 } 196 82 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/ISymbolicRegressionEvaluator.cs
r3253 r3294 37 37 public interface ISymbolicRegressionEvaluator : ISingleObjectiveEvaluator { 38 38 ILookupParameter<SymbolicExpressionTree> FunctionTreeParameter { get; } 39 ILookupParameter<Dataset> DatasetParameter { get; } 40 ILookupParameter<StringValue> TargetVariableParameter { get; } 41 ILookupParameter<IntValue> SamplesStartParameter { get; } 42 ILookupParameter<IntValue> SamplesEndParameter { get; } 39 ILookupParameter<RegressionProblemData> RegressionProblemDataParameter { get; } 43 40 ILookupParameter<DoubleValue> NumberOfEvaluatedNodesParameter { get; } 44 41 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/SimpleArithmeticExpressionEvaluator.cs
r3269 r3294 30 30 31 31 namespace HeuristicLab.Problems.DataAnalysis.Regression.Symbolic { 32 /// <summary>33 /// Evaluates FunctionTrees recursively by interpretation of the function symbols in each node.34 /// Simple unoptimized code, arithmetic expressions only.35 /// Not thread-safe!36 /// </summary>37 32 [StorableClass] 38 33 [Item("SimpleArithmeticExpressionEvaluator", "Default evaluator for arithmetic symbolic expression trees.")] 39 public class SimpleArithmeticExpressionEvaluator : GeneralSymbolicExpressionTreeEvaluator{34 public class SimpleArithmeticExpressionEvaluator { 40 35 private Dataset dataset; 41 36 private int row; 37 private Instruction[] code; 38 private int pc; 42 39 public IEnumerable<double> EstimatedValues(SymbolicExpressionTree tree, Dataset dataset, IEnumerable<int> rows) { 43 40 this.dataset = dataset; 41 var compiler = new SymbolicExpressionTreeCompiler(); 42 code = compiler.Compile(tree); 44 43 foreach (var row in rows) { 45 44 this.row = row; 46 var estimatedValue = Evaluate(tree.Root.SubTrees[0]); 45 pc = 0; 46 var estimatedValue = Evaluate(); 47 47 if (double.IsNaN(estimatedValue) || double.IsInfinity(estimatedValue)) yield return 0.0; 48 48 else yield return estimatedValue; … … 50 50 } 51 51 52 public override double Evaluate(SymbolicExpressionTreeNode node) { 53 if (node.Symbol is HeuristicLab.Problems.DataAnalysis.Regression.Symbolic.Symbols.Variable) { 54 var variableTreeNode = node as VariableTreeNode; 55 return dataset[row, dataset.VariableIndex(variableTreeNode.VariableName)] * variableTreeNode.Weight; 56 } else if (node.Symbol is Constant) { 57 return ((ConstantTreeNode)node).Value; 58 } else { 59 return base.Evaluate(node); 52 public double Evaluate() { 53 var currentInstr = code[pc++]; 54 switch (currentInstr.symbol) { 55 case CodeSymbol.Add: { 56 double s = 0.0; 57 for (int i = 0; i < currentInstr.nArguments; i++) { 58 s += Evaluate(); 59 } 60 return s; 61 } 62 case CodeSymbol.Sub: { 63 double s = Evaluate(); 64 for (int i = 1; i < currentInstr.nArguments; i++) { 65 s -= Evaluate(); 66 } 67 return s; 68 } 69 case CodeSymbol.Mul: { 70 double p = Evaluate(); 71 for (int i = 1; i < currentInstr.nArguments; i++) { 72 p *= Evaluate(); 73 } 74 return p; 75 } 76 case CodeSymbol.Div: { 77 double p = Evaluate(); 78 for (int i = 1; i < currentInstr.nArguments; i++) { 79 p /= Evaluate(); 80 } 81 return p; 82 } 83 case CodeSymbol.Dynamic: { 84 if (currentInstr.dynamicNode is VariableTreeNode) { 85 var variableTreeNode = currentInstr.dynamicNode as VariableTreeNode; 86 return dataset[row, dataset.GetVariableIndex(variableTreeNode.VariableName)] * variableTreeNode.Weight; 87 } else if (currentInstr.dynamicNode is ConstantTreeNode) { 88 return ((ConstantTreeNode)currentInstr.dynamicNode).Value; 89 } else throw new NotSupportedException(); 90 } 91 default: throw new NotSupportedException(); 60 92 } 61 93 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/SymbolicRegressionEvaluator.cs
r3253 r3294 39 39 [StorableClass] 40 40 public abstract class SymbolicRegressionEvaluator : SingleSuccessorOperator, ISymbolicRegressionEvaluator { 41 private const string QualityParameterName = "Quality"; 42 private const string FunctionTreeParameterName = "FunctionTree"; 43 private const string RegressionProblemDataParameterName = "RegressionProblemData"; 44 private const string NumberOfEvaluatedNodexParameterName = "NumberOfEvaluatedNodes"; 41 45 #region ISymbolicRegressionEvaluator Members 42 46 43 47 public ILookupParameter<DoubleValue> QualityParameter { 44 get { return (ILookupParameter<DoubleValue>)Parameters[ "Quality"]; }48 get { return (ILookupParameter<DoubleValue>)Parameters[QualityParameterName]; } 45 49 } 46 50 47 51 public ILookupParameter<SymbolicExpressionTree> FunctionTreeParameter { 48 get { return (ILookupParameter<SymbolicExpressionTree>)Parameters[ "FunctionTree"]; }52 get { return (ILookupParameter<SymbolicExpressionTree>)Parameters[FunctionTreeParameterName]; } 49 53 } 50 54 51 public ILookupParameter< Dataset> DatasetParameter {52 get { return (ILookupParameter< Dataset>)Parameters["Dataset"]; }55 public ILookupParameter<RegressionProblemData> RegressionProblemDataParameter { 56 get { return (ILookupParameter<RegressionProblemData>)Parameters[RegressionProblemDataParameterName]; } 53 57 } 54 58 55 public ILookupParameter<StringValue> TargetVariableParameter {56 get { return (ILookupParameter<StringValue>)Parameters["TargetVariable"]; }57 }59 //public ILookupParameter<IntValue> SamplesStartParameter { 60 // get { return (ILookupParameter<IntValue>)Parameters["SamplesStart"]; } 61 //} 58 62 59 public ILookupParameter<IntValue> SamplesStartParameter { 60 get { return (ILookupParameter<IntValue>)Parameters["SamplesStart"]; } 61 } 62 63 public ILookupParameter<IntValue> SamplesEndParameter { 64 get { return (ILookupParameter<IntValue>)Parameters["SamplesEnd"]; } 65 } 63 //public ILookupParameter<IntValue> SamplesEndParameter { 64 // get { return (ILookupParameter<IntValue>)Parameters["SamplesEnd"]; } 65 //} 66 66 67 67 public ILookupParameter<DoubleValue> NumberOfEvaluatedNodesParameter { 68 get { return (ILookupParameter<DoubleValue>)Parameters[ "NumberOfEvaluatedNodes"]; }68 get { return (ILookupParameter<DoubleValue>)Parameters[NumberOfEvaluatedNodexParameterName]; } 69 69 } 70 70 … … 73 73 public SymbolicRegressionEvaluator() 74 74 : base() { 75 Parameters.Add(new LookupParameter<DoubleValue>("Quality", "The quality of the evaluated symbolic regression solution.")); 76 Parameters.Add(new LookupParameter<SymbolicExpressionTree>("FunctionTree", "The symbolic regression solution encoded as a symbolic expression tree.")); 77 Parameters.Add(new LookupParameter<Dataset>("Dataset", "The data set on which the symbolic regression solution should be evaluated.")); 78 Parameters.Add(new LookupParameter<StringValue>("TargetVariable", "The target variable of the symbolic regression solution.")); 79 Parameters.Add(new LookupParameter<IntValue>("SamplesStart", "The start index of the partition of the data set on which the symbolic regression solution should be evaluated.")); 80 Parameters.Add(new LookupParameter<IntValue>("SamplesEnd", "The end index of the partition of the data set on which the symbolic regression solution should be evaluated.")); 81 Parameters.Add(new LookupParameter<DoubleValue>("NumberOfEvaluatedNodes", "The number of evaluated nodes so far (for performance measurements.)")); 75 Parameters.Add(new LookupParameter<DoubleValue>(QualityParameterName, "The quality of the evaluated symbolic regression solution.")); 76 Parameters.Add(new LookupParameter<SymbolicExpressionTree>(FunctionTreeParameterName, "The symbolic regression solution encoded as a symbolic expression tree.")); 77 Parameters.Add(new LookupParameter<RegressionProblemData>(RegressionProblemDataParameterName, "The data set on which the symbolic regression solution should be evaluated.")); 78 Parameters.Add(new LookupParameter<DoubleValue>(NumberOfEvaluatedNodexParameterName, "The number of evaluated nodes so far (for performance measurements.)")); 82 79 } 83 80 84 81 public override IOperation Apply() { 85 82 SymbolicExpressionTree solution = FunctionTreeParameter.ActualValue; 86 Dataset dataset = DatasetParameter.ActualValue; 87 StringValue targetVariable = TargetVariableParameter.ActualValue; 88 IntValue samplesStart = SamplesStartParameter.ActualValue; 89 IntValue samplesEnd = SamplesEndParameter.ActualValue; 83 RegressionProblemData regressionProblemData = RegressionProblemDataParameter.ActualValue; 90 84 DoubleValue numberOfEvaluatedNodes = NumberOfEvaluatedNodesParameter.ActualValue; 91 85 92 QualityParameter.ActualValue = new DoubleValue(Evaluate(solution, dataset, targetVariable, samplesStart, samplesEnd, numberOfEvaluatedNodes));86 QualityParameter.ActualValue = new DoubleValue(Evaluate(solution, regressionProblemData.Dataset, regressionProblemData.TargetVariable, regressionProblemData.TrainingSamplesStart, regressionProblemData.TrainingSamplesEnd, numberOfEvaluatedNodes)); 93 87 return null; 94 88 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/SymbolicRegressionMeanSquaredErrorEvaluator.cs
r3257 r3294 41 41 public class SymbolicRegressionMeanSquaredErrorEvaluator : SymbolicRegressionEvaluator { 42 42 protected override double Evaluate(SymbolicExpressionTree solution, Dataset dataset, StringValue targetVariable, IntValue samplesStart, IntValue samplesEnd, DoubleValue numberOfEvaluatedNodes) { 43 double mse = Apply(solution, dataset, targetVariable.Value, samplesStart.Value, samplesEnd.Value);43 double mse = Calculate(solution, dataset, targetVariable.Value, samplesStart.Value, samplesEnd.Value); 44 44 numberOfEvaluatedNodes.Value += solution.Size * (samplesEnd.Value - samplesStart.Value); 45 45 return mse; 46 46 } 47 47 48 public static double Apply(SymbolicExpressionTree solution, Dataset dataset, string targetVariable, int start, int end) {48 public static double Calculate(SymbolicExpressionTree solution, Dataset dataset, string targetVariable, int start, int end) { 49 49 SimpleArithmeticExpressionEvaluator evaluator = new SimpleArithmeticExpressionEvaluator(); 50 int targetVariableIndex = dataset.GetVariableIndex(targetVariable); 50 51 var estimatedValues = evaluator.EstimatedValues(solution, dataset, Enumerable.Range(start, end - start)); 51 var originalValues = dataset.VariableValues(targetVariable, start, end); 52 var values = new DoubleMatrix(MatrixExtensions<double>.Create(estimatedValues.ToArray(), originalValues)); 53 return SimpleMSEEvaluator.Calculate(values); 52 var originalValues = from row in Enumerable.Range(start, end - start) select dataset[row, targetVariableIndex]; 53 return SimpleMSEEvaluator.Calculate(originalValues, estimatedValues); 54 54 } 55 55 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/SymbolicRegressionProblem.cs
r3269 r3294 71 71 get { return (ValueParameter<DoubleValue>)Parameters["NumberOfEvaluatedNodes"]; } 72 72 } 73 public ValueParameter<IntValue> MaxFunctionDefiningBranchesParameter { 74 get { return (ValueParameter<IntValue>)Parameters["MaxFunctionDefiningBranches"]; } 75 } 76 public ValueParameter<IntValue> MaxFunctionArgumentsParameter { 77 get { return (ValueParameter<IntValue>)Parameters["MaxFunctionArguments"]; } 78 } 73 79 public OptionalValueParameter<ISingleObjectiveSolutionsVisualizer> VisualizerParameter { 74 80 get { return (OptionalValueParameter<ISingleObjectiveSolutionsVisualizer>)Parameters["Visualizer"]; } … … 142 148 Parameters.Add(new ValueParameter<IntValue>("MaxExpressionLength", "Maximal length of the symbolic expression.", new IntValue(100))); 143 149 Parameters.Add(new ValueParameter<IntValue>("MaxExpressionDepth", "Maximal depth of the symbolic expression.", new IntValue(10))); 150 Parameters.Add(new ValueParameter<IntValue>("MaxFunctionDefiningBranches", "Maximal number of automatically defined functions.", new IntValue(3))); 151 Parameters.Add(new ValueParameter<IntValue>("MaxFunctionArguments", "Maximal number of arguments of automatically defined functions.", new IntValue(3))); 144 152 Parameters.Add(new ValueParameter<DoubleValue>("NumberOfEvaluatedNodes", "The total number of evaluated function tree nodes (for performance measurements.)", new DoubleValue())); 145 153 Parameters.Add(new ValueParameter<ISingleObjectiveSolutionsVisualizer>("Visualizer", "The operator which should be used to visualize artificial ant solutions.", null)); … … 147 155 creator.SymbolicExpressionTreeParameter.ActualName = "SymbolicRegressionModel"; 148 156 evaluator.QualityParameter.ActualName = "TrainingMeanSquaredError"; 149 InputVariablesParameter.ValueChanged += new EventHandler(InputVariablesParameter_ValueChanged); 157 RegressionProblemDataParameter.ValueChanged += new EventHandler(RegressionProblemDataParameter_ValueChanged); 158 RegressionProblemData.InputVariablesChanged += new EventHandler(RegressionProblemData_InputVariablesChanged); 150 159 ParameterizeSolutionCreator(); 151 160 ParameterizeEvaluator(); … … 155 164 } 156 165 157 void InputVariablesParameter_ValueChanged(object sender, EventArgs e) { 158 FunctionTreeGrammar.VariableNames = InputVariablesParameter.Value.Select(x => x.Value); 166 void RegressionProblemDataParameter_ValueChanged(object sender, EventArgs e) { 167 RegressionProblemData.InputVariablesChanged += new EventHandler(RegressionProblemData_InputVariablesChanged); 168 } 169 170 void RegressionProblemData_InputVariablesChanged(object sender, EventArgs e) { 171 FunctionTreeGrammar.VariableNames = RegressionProblemData.InputVariables.Select(x => x.Value); 159 172 } 160 173 … … 250 263 private void ParameterizeEvaluator() { 251 264 Evaluator.FunctionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName; 252 Evaluator.SamplesStartParameter.ActualName = TrainingSamplesStartParameter.Name; 253 Evaluator.SamplesEndParameter.ActualName = TrainingSamplesEndParameter.Name; 265 Evaluator.RegressionProblemDataParameter.ActualName = RegressionProblemDataParameter.Name; 254 266 } 255 267 private void ParameterizeVisualizer() { … … 277 289 foreach (ISymbolicRegressionEvaluator op in Operators.OfType<ISymbolicRegressionEvaluator>()) { 278 290 op.FunctionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName; 279 op. DatasetParameter.ActualName = DatasetParameter.Name;291 op.RegressionProblemDataParameter.ActualName = RegressionProblemDataParameter.Name; 280 292 op.NumberOfEvaluatedNodesParameter.ActualName = NumberOfEvaluatedNodesParameter.Name; 281 op.TargetVariableParameter.ActualName = TargetVariableParameter.Name;282 op.SamplesStartParameter.ActualName = TrainingSamplesStartParameter.Name;283 op.SamplesEndParameter.ActualName = TrainingSamplesEndParameter.Name;284 293 } 285 294 foreach (SymbolicExpressionTreeCrossover op in Operators.OfType<SymbolicExpressionTreeCrossover>()) { … … 287 296 op.ChildParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName; 288 297 } 298 foreach (SymbolicExpressionTreeManipulator op in Operators.OfType<SymbolicExpressionTreeManipulator>()) { 299 op.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName; 300 } 301 foreach (SymbolicExpressionTreeArchitectureAlteringOperator op in Operators.OfType<SymbolicExpressionTreeArchitectureAlteringOperator>()) { 302 } 289 303 } 290 304 #endregion -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/Symbols/Constant.cs
r3269 r3294 31 31 [Item("Constant", "Represents a constant value.")] 32 32 public sealed class Constant : Symbol { 33 #region Parameter Properties 34 public IValueParameter<DoubleValue> MinValueParameter { 35 get { return (IValueParameter<DoubleValue>)Parameters["MinValue"]; } 33 #region Propeties 34 private double minValue; 35 public double MinValue { 36 get { return minValue; } 37 set { minValue = value; } 36 38 } 37 public IValueParameter<DoubleValue> MaxValueParameter { 38 get { return (IValueParameter<DoubleValue>)Parameters["MaxValue"]; } 39 } 40 #endregion 41 #region Propeties 42 public DoubleValue MinValue { 43 get { return MinValueParameter.Value; } 44 set { MinValueParameter.Value = value; } 45 } 46 public DoubleValue MaxValue { 47 get { return MaxValueParameter.Value; } 48 set { MaxValueParameter.Value = value; } 39 private double maxValue; 40 public double MaxValue { 41 get { return maxValue; } 42 set { maxValue = value; } 49 43 } 50 44 #endregion 51 45 public Constant() 52 46 : base() { 53 Parameters.Add(new ValueParameter<DoubleValue>("MinValue", "The minimal value of the constant.", new DoubleValue(-20.0)));54 Parameters.Add(new ValueParameter<DoubleValue>("MaxValue", "The maximal value of the constant.", new DoubleValue(20.0)));55 47 } 56 48 -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/Symbols/ConstantTreeNode.cs
r3269 r3294 55 55 public override void ResetLocalParameters(IRandom random) { 56 56 base.ResetLocalParameters(random); 57 var range = Symbol.MaxValue .Value - Symbol.MaxValue.Value;58 Value = random.NextDouble() * range - Symbol.MinValue .Value;57 var range = Symbol.MaxValue - Symbol.MaxValue; 58 Value = random.NextDouble() * range - Symbol.MinValue; 59 59 } 60 60 -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/Symbols/Variable.cs
r3269 r3294 27 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 28 28 using HeuristicLab.Parameters; 29 using System.Collections.Generic; 30 using System; 29 31 namespace HeuristicLab.Problems.DataAnalysis.Regression.Symbolic.Symbols { 30 32 [StorableClass] 31 33 [Item("Variable", "Represents a variable value.")] 32 34 public sealed class Variable : Symbol { 33 #region Parameter Properties 34 public IValueParameter<DoubleValue> WeightNuParameter { 35 get { return (IValueParameter<DoubleValue>)Parameters["WeightNu"]; } 35 #region Properties 36 private double weightNu; 37 [Storable] 38 public double WeightNu { 39 get { return weightNu; } 40 set { weightNu = value; } 36 41 } 37 public IValueParameter<DoubleValue> WeightSigmaParameter { 38 get { return (IValueParameter<DoubleValue>)Parameters["WeightSigma"]; } 42 private double weightSigma; 43 [Storable] 44 public double WeightSigma { 45 get { return weightSigma; } 46 set { 47 if (weightSigma < 0.0) throw new ArgumentException("Negative sigma is not allowed."); 48 weightSigma = value; 49 } 39 50 } 40 public IValueParameter<ItemList<StringValue>> VariableNamesParameter { 41 get { return (IValueParameter<ItemList<StringValue>>)Parameters["VariableNames"]; } 42 } 43 #endregion 44 #region Properties 45 public DoubleValue WeightNu { 46 get { return WeightNuParameter.Value; } 47 set { WeightNuParameter.Value = value; } 48 } 49 public DoubleValue WeightSigma { 50 get { return WeightSigmaParameter.Value; } 51 set { WeightSigmaParameter.Value = value; } 52 } 53 public ItemList<StringValue> VariableNames { 54 get { return VariableNamesParameter.Value; } 55 set { VariableNamesParameter.Value = value; } 51 private List<string> variableNames; 52 [Storable] 53 public ICollection<string> VariableNames { 54 get { return variableNames; } 55 set { 56 if (value == null) throw new ArgumentNullException(); 57 variableNames.Clear(); 58 variableNames.AddRange(value); 59 } 56 60 } 57 61 #endregion 58 62 public Variable() 59 63 : base() { 60 Parameters.Add(new ValueParameter<DoubleValue>("WeightNu", "The mean value for the initialization of weight ((N(nu, sigma)).", new DoubleValue(1.0)));61 Parameters.Add(new ValueParameter<DoubleValue>("WeightSigma", "The sigma value for the initialization of weight (N(nu, sigma))", new DoubleValue(1.0)));62 Parameters.Add(new ValueParameter<ItemList<StringValue>>("VariableNames", "The list of possible variable names for initialization."));64 weightNu = 1.0; 65 weightSigma = 1.0; 66 variableNames = new List<string>(); 63 67 } 64 68 -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/Symbols/VariableTreeNode.cs
r3269 r3294 57 57 public override void ResetLocalParameters(IRandom random) { 58 58 base.ResetLocalParameters(random); 59 var normalDistributedRNG = new NormalDistributedRandom(random, Symbol.WeightNu .Value, Symbol.WeightSigma.Value);59 var normalDistributedRNG = new NormalDistributedRandom(random, Symbol.WeightNu, Symbol.WeightSigma); 60 60 weight = normalDistributedRNG.NextDouble(); 61 int variableIndex = random.Next(0, Symbol.VariableNames.Count); 62 variableName = Symbol.VariableNames[variableIndex].Value; 61 var variableList = new List<string>(Symbol.VariableNames); 62 int variableIndex = random.Next(0, variableList.Count); 63 variableName = variableList[variableIndex]; 63 64 } 64 65
Note: See TracChangeset
for help on using the changeset viewer.