Changeset 2634
- Timestamp:
- 01/18/10 09:31:01 (15 years ago)
- Location:
- trunk/sources/HeuristicLab.GP.StructureIdentification/3.3
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/ScalingTreeEvaluator.cs
r2579 r2634 27 27 using System.Collections.Generic; // double.IsAlmost extension 28 28 using System.Linq; 29 using System.Xml; 29 30 namespace HeuristicLab.GP.StructureIdentification { 30 31 /// <summary> … … 37 38 public ScalingTreeEvaluator(double minValue, double maxValue) : base(minValue, maxValue) { } 38 39 40 private string targetVariable; 41 public string TargetVariable { 42 get { return targetVariable; } 43 set { targetVariable = value; } 44 } 45 39 46 public override IEnumerable<double> Evaluate(Dataset dataset, IFunctionTree tree, IEnumerable<int> rows) { 40 47 double[] result = base.Evaluate(dataset, tree, rows).ToArray(); 41 double tMean = dataset.GetMean(0); 48 int targetVariableIndex = dataset.GetVariableIndex(targetVariable); 49 double tMean = dataset.GetMean(targetVariableIndex); 42 50 double xMean = Statistics.Mean(result); 43 51 double sumXT = 0; … … 45 53 for (int i = 0; i < result.Length; i++) { 46 54 double x = result[i]; 47 double t = dataset.GetValue(rows.ElementAt(i), 0);55 double t = dataset.GetValue(rows.ElementAt(i), targetVariableIndex); 48 56 sumXT += (x - xMean) * (t - tMean); 49 57 sumXX += (x - xMean) * (x - xMean); … … 59 67 return result; 60 68 } 69 70 public override object Clone(IDictionary<Guid, object> clonedObjects) { 71 ScalingTreeEvaluator clone = (ScalingTreeEvaluator)base.Clone(clonedObjects); 72 clone.targetVariable = targetVariable; 73 return clone; 74 } 75 76 public override System.Xml.XmlNode GetXmlNode(string name, System.Xml.XmlDocument document, IDictionary<Guid, HeuristicLab.Core.IStorable> persistedObjects) { 77 XmlNode node = base.GetXmlNode(name, document, persistedObjects); 78 XmlAttribute targetVariableAttribute = document.CreateAttribute("TargetVariable"); 79 targetVariableAttribute.Value = targetVariable; 80 node.Attributes.Append(targetVariableAttribute); 81 return node; 82 } 83 84 public override void Populate(XmlNode node, IDictionary<Guid, HeuristicLab.Core.IStorable> restoredObjects) { 85 base.Populate(node, restoredObjects); 86 targetVariable = node.Attributes["TargetVariable"].Value; 87 } 61 88 } 62 89 } -
trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/ScalingTreeEvaluatorInjector.cs
r2579 r2634 57 57 double maxEstimatedValue = mean + punishmentFactor * range; 58 58 ScalingTreeEvaluator evaluator = new ScalingTreeEvaluator(minEstimatedValue, maxEstimatedValue); 59 evaluator.TargetVariable = targetVariable; 59 60 scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName("TreeEvaluator"), evaluator)); 60 61 return null;
Note: See TracChangeset
for help on using the changeset viewer.