Changeset 2634


Ignore:
Timestamp:
01/18/10 09:31:01 (10 years ago)
Author:
gkronber
Message:

Added target variable property for the scaling tree evaluator. #823

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  
    2727using System.Collections.Generic; // double.IsAlmost extension
    2828using System.Linq;
     29using System.Xml;
    2930namespace HeuristicLab.GP.StructureIdentification {
    3031  /// <summary>
     
    3738    public ScalingTreeEvaluator(double minValue, double maxValue) : base(minValue, maxValue) { }
    3839
     40    private string targetVariable;
     41    public string TargetVariable {
     42      get { return targetVariable; }
     43      set { targetVariable = value; }
     44    }
     45
    3946    public override IEnumerable<double> Evaluate(Dataset dataset, IFunctionTree tree, IEnumerable<int> rows) {
    4047      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);
    4250      double xMean = Statistics.Mean(result);
    4351      double sumXT = 0;
     
    4553      for (int i = 0; i < result.Length; i++) {
    4654        double x = result[i];
    47         double t = dataset.GetValue(rows.ElementAt(i), 0);
     55        double t = dataset.GetValue(rows.ElementAt(i), targetVariableIndex);
    4856        sumXT += (x - xMean) * (t - tMean);
    4957        sumXX += (x - xMean) * (x - xMean);
     
    5967      return result;
    6068    }
     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    }
    6188  }
    6289}
  • trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/ScalingTreeEvaluatorInjector.cs

    r2579 r2634  
    5757      double maxEstimatedValue = mean + punishmentFactor * range;
    5858      ScalingTreeEvaluator evaluator = new ScalingTreeEvaluator(minEstimatedValue, maxEstimatedValue);
     59      evaluator.TargetVariable = targetVariable;
    5960      scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName("TreeEvaluator"), evaluator));
    6061      return null;
Note: See TracChangeset for help on using the changeset viewer.