- Timestamp:
- 04/05/10 18:52:23 (15 years ago)
- Location:
- trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/ArithmeticExpressionGrammar.cs
r3257 r3269 29 29 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.GeneralSymbols; 30 30 using HeuristicLab.Problems.DataAnalysis.Regression.Symbolic.Symbols; 31 using HeuristicLab.Data; 31 32 namespace HeuristicLab.Problems.DataAnalysis.Regression.Symbolic { 32 33 [StorableClass] 33 public class ArithmeticExpressionGrammar : Item, ISymbolicExpressionGrammar { 34 public class ArithmeticExpressionGrammar : NamedItemCollection<Symbol>, ISymbolicExpressionGrammar { 35 36 private List<string> variableNames = new List<string>(); 37 public IEnumerable<string> VariableNames { 38 get { return variableNames; } 39 set { 40 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))); 43 } 44 } 34 45 35 46 public ArithmeticExpressionGrammar() 36 : base() {47 : this(allSymbols) { 37 48 } 49 50 public ArithmeticExpressionGrammar(IEnumerable<Symbol> symbols) 51 : base(symbols) { 52 allSymbols = new List<Symbol>(symbols); 53 } 54 38 55 #region ISymbolicExpressionGrammar Members 39 56 [Storable] -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/SimpleArithmeticExpressionEvaluator.cs
r3257 r3269 53 53 if (node.Symbol is HeuristicLab.Problems.DataAnalysis.Regression.Symbolic.Symbols.Variable) { 54 54 var variableTreeNode = node as VariableTreeNode; 55 return dataset[row, 1 /*dataset.VariableIndex(variableTreeNode.VariableName)*/] * 1.0; //variableTreeNode.Weight;55 return dataset[row, dataset.VariableIndex(variableTreeNode.VariableName)] * variableTreeNode.Weight; 56 56 } else if (node.Symbol is Constant) { 57 57 return ((ConstantTreeNode)node).Value; -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/SymbolicRegressionProblem.cs
r3257 r3269 111 111 get { return EvaluatorParameter.Value; } 112 112 } 113 public ISymbolicExpressionGrammar FunctionTreeGrammar {114 get { return FunctionTreeGrammarParameter.Value; }113 public ArithmeticExpressionGrammar FunctionTreeGrammar { 114 get { return (ArithmeticExpressionGrammar)FunctionTreeGrammarParameter.Value; } 115 115 } 116 116 public ISingleObjectiveSolutionsVisualizer Visualizer { … … 147 147 creator.SymbolicExpressionTreeParameter.ActualName = "SymbolicRegressionModel"; 148 148 evaluator.QualityParameter.ActualName = "TrainingMeanSquaredError"; 149 InputVariablesParameter.ValueChanged += new EventHandler(InputVariablesParameter_ValueChanged); 149 150 ParameterizeSolutionCreator(); 150 151 ParameterizeEvaluator(); … … 152 153 153 154 Initialize(); 155 } 156 157 void InputVariablesParameter_ValueChanged(object sender, EventArgs e) { 158 FunctionTreeGrammar.VariableNames = InputVariablesParameter.Value.Select(x => x.Value); 154 159 } 155 160 -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/Symbols/Constant.cs
r3258 r3269 21 21 22 22 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 23 using HeuristicLab.Core; 24 using HeuristicLab.Operators; 25 using HeuristicLab.Random; 26 using HeuristicLab.Data; 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 28 using HeuristicLab.Parameters; 23 29 namespace HeuristicLab.Problems.DataAnalysis.Regression.Symbolic.Symbols { 30 [StorableClass] 31 [Item("Constant", "Represents a constant value.")] 24 32 public sealed class Constant : Symbol { 33 #region Parameter Properties 34 public IValueParameter<DoubleValue> MinValueParameter { 35 get { return (IValueParameter<DoubleValue>)Parameters["MinValue"]; } 36 } 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; } 49 } 50 #endregion 51 public Constant() 52 : 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 } 56 25 57 public override SymbolicExpressionTreeNode CreateTreeNode() { 26 58 return new ConstantTreeNode(this); -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/Symbols/ConstantTreeNode.cs
r3258 r3269 24 24 using System.Collections.Generic; 25 25 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 26 using HeuristicLab.Core; 27 using HeuristicLab.Data; 28 using HeuristicLab.Random; 26 29 namespace HeuristicLab.Problems.DataAnalysis.Regression.Symbolic.Symbols { 27 30 [StorableClass] 28 31 public sealed class ConstantTreeNode : SymbolicExpressionTreeTerminalNode { 32 public new Constant Symbol { 33 get { return (Constant)base.Symbol; } 34 } 29 35 public override bool HasLocalParameters { 30 36 get { … … 39 45 set { constantValue = value; } 40 46 } 41 42 47 // copy constructor 43 48 private ConstantTreeNode(ConstantTreeNode original) … … 48 53 public ConstantTreeNode(Constant constantSymbol) : base(constantSymbol) { } 49 54 55 public override void ResetLocalParameters(IRandom random) { 56 base.ResetLocalParameters(random); 57 var range = Symbol.MaxValue.Value - Symbol.MaxValue.Value; 58 Value = random.NextDouble() * range - Symbol.MinValue.Value; 59 } 60 50 61 public override object Clone() { 51 62 return new ConstantTreeNode(this); -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/Symbols/Variable.cs
r3258 r3269 21 21 22 22 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 23 using HeuristicLab.Core; 24 using HeuristicLab.Operators; 25 using HeuristicLab.Random; 26 using HeuristicLab.Data; 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 28 using HeuristicLab.Parameters; 23 29 namespace HeuristicLab.Problems.DataAnalysis.Regression.Symbolic.Symbols { 30 [StorableClass] 31 [Item("Variable", "Represents a variable value.")] 24 32 public sealed class Variable : Symbol { 33 #region Parameter Properties 34 public IValueParameter<DoubleValue> WeightNuParameter { 35 get { return (IValueParameter<DoubleValue>)Parameters["WeightNu"]; } 36 } 37 public IValueParameter<DoubleValue> WeightSigmaParameter { 38 get { return (IValueParameter<DoubleValue>)Parameters["WeightSigma"]; } 39 } 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; } 56 } 57 #endregion 58 public Variable() 59 : 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.")); 63 } 64 25 65 public override SymbolicExpressionTreeNode CreateTreeNode() { 26 66 return new VariableTreeNode(this); -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/Symbols/VariableTreeNode.cs
r3258 r3269 24 24 using System.Collections.Generic; 25 25 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 26 using HeuristicLab.Core; 27 using HeuristicLab.Data; 28 using HeuristicLab.Random; 26 29 namespace HeuristicLab.Problems.DataAnalysis.Regression.Symbolic.Symbols { 27 30 [StorableClass] 28 31 public sealed class VariableTreeNode : SymbolicExpressionTreeTerminalNode { 29 32 public new Variable Symbol { 33 get { return (Variable)base.Symbol; } 34 } 30 35 private double weight; 31 36 [Storable] … … 50 55 public VariableTreeNode(Variable variableSymbol) : base(variableSymbol) { } 51 56 57 public override void ResetLocalParameters(IRandom random) { 58 base.ResetLocalParameters(random); 59 var normalDistributedRNG = new NormalDistributedRandom(random, Symbol.WeightNu.Value, Symbol.WeightSigma.Value); 60 weight = normalDistributedRNG.NextDouble(); 61 int variableIndex = random.Next(0, Symbol.VariableNames.Count); 62 variableName = Symbol.VariableNames[variableIndex].Value; 63 } 64 52 65 public override object Clone() { 53 66 return new VariableTreeNode(this);
Note: See TracChangeset
for help on using the changeset viewer.