- Timestamp:
- 08/13/09 17:28:07 (15 years ago)
- Location:
- trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/BaseClasses
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/BaseClasses/AlgorithmBase.cs
r2270 r2285 70 70 } 71 71 72 private I Model model;73 public virtual I Model Model {72 private IAnalyzerModel model; 73 public virtual IAnalyzerModel Model { 74 74 get { 75 75 if (!engine.Terminated) throw new InvalidOperationException("The algorithm is still running. Wait until the algorithm is terminated to retrieve the result."); … … 100 100 get { return GetVariableInjector().GetVariable("Parents").GetValue<IntData>().Data; } 101 101 set { GetVariableInjector().GetVariable("Parents").GetValue<IntData>().Data = value; } 102 }103 104 public virtual double PunishmentFactor {105 get { return GetVariableInjector().GetVariable("PunishmentFactor").GetValue<DoubleData>().Data; }106 set { GetVariableInjector().GetVariable("PunishmentFactor").GetValue<DoubleData>().Data = value; }107 102 } 108 103 … … 132 127 MaxTreeHeight = 10; 133 128 Parents = 2000; 134 PunishmentFactor = 10;135 129 UseEstimatedTargetValue = false; 136 130 } … … 212 206 injector.AddVariable(new HeuristicLab.Core.Variable("TotalEvaluatedNodes", new DoubleData(0))); 213 207 injector.AddVariable(new HeuristicLab.Core.Variable("Parents", new IntData())); 214 injector.AddVariable(new HeuristicLab.Core.Variable("PunishmentFactor", new DoubleData()));215 208 injector.AddVariable(new HeuristicLab.Core.Variable("UseEstimatedTargetValue", new BoolData())); 216 209 injector.AddVariable(new HeuristicLab.Core.Variable("TreeEvaluator", new HL2TreeEvaluator())); … … 416 409 } 417 410 418 protected internal virtual Model CreateGPModel(IScope bestModelScope) {411 protected internal virtual IAnalyzerModel CreateGPModel(IScope bestModelScope) { 419 412 Engine.GlobalScope.AddSubScope(bestModelScope); 420 Model model = new Model(); 413 IGeneticProgrammingModel tree = bestModelScope.GetVariableValue<IGeneticProgrammingModel>("FunctionTree", false); 414 ITreeEvaluator evaluator = bestModelScope.GetVariableValue<ITreeEvaluator>("TreeEvaluator", false); 415 IAnalyzerModel model = new AnalyzerModel(); 416 model.Predictor = new Predictor(evaluator, tree); 421 417 Dataset ds = bestModelScope.GetVariableValue<Dataset>("Dataset", true); 422 model.Data = bestModelScope.GetVariableValue<IGeneticProgrammingModel>("FunctionTree", false);423 418 model.Dataset = ds; 424 419 model.TargetVariable = ds.GetVariableName(bestModelScope.GetVariableValue<IntData>("TargetVariable", true).Data); … … 450 445 double impact = ((DoubleData)row[1]).Data; 451 446 model.SetVariableEvaluationImpact(variableName, impact); 452 model.AddInputVariable s(variableName);447 model.AddInputVariable(variableName); 453 448 } 454 449 foreach (ItemList row in qualityImpacts) { … … 456 451 double impact = ((DoubleData)row[1]).Data; 457 452 model.SetVariableQualityImpact(variableName, impact); 458 model.AddInputVariable s(variableName);453 model.AddInputVariable(variableName); 459 454 } 460 455 Engine.GlobalScope.RemoveSubScope(bestModelScope); -
trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/BaseClasses/TreeEvaluatorBase.cs
r2235 r2285 25 25 using HeuristicLab.DataAnalysis; 26 26 using HeuristicLab.GP.Interfaces; 27 using System.Xml; 27 28 28 29 namespace HeuristicLab.GP.StructureIdentification { … … 32 33 public abstract class TreeEvaluatorBase : ItemBase, ITreeEvaluator { 33 34 protected const double EPSILON = 1.0e-7; 34 protected double maxValue; 35 protected double minValue; 35 protected double maxValue = double.MaxValue; 36 protected double minValue = double.MinValue; 37 private double punishmentFactor = 10.0; // we should provide a view for treeevaluators that allows to change this value 36 38 37 39 protected class Instr { … … 48 50 protected int sampleIndex; 49 51 50 public void PrepareForEvaluation(Dataset dataset, int targetVariable, int start, int end, double punishmentFactor,IFunctionTree functionTree) {52 public void PrepareForEvaluation(Dataset dataset, IFunctionTree functionTree) { 51 53 this.dataset = dataset; 54 codeArr = new Instr[functionTree.GetSize()]; 55 int i = 0; 56 foreach (IFunctionTree tree in IteratePrefix(functionTree)) { 57 codeArr[i++] = TranslateToInstr(tree); 58 } 59 } 60 61 public void PrepareForEvaluation(Dataset dataset, int targetVariable, int start, int end, IFunctionTree functionTree) { 52 62 // calculate upper and lower bounds for the estimated value (mean +/- punishmentFactor * range) 53 63 double mean = dataset.GetMean(targetVariable, start, end); … … 55 65 maxValue = mean + punishmentFactor * range; 56 66 minValue = mean - punishmentFactor * range; 57 58 codeArr = new Instr[functionTree.GetSize()]; 59 int i = 0; 60 foreach (IFunctionTree tree in IteratePrefix(functionTree)) { 61 codeArr[i++] = TranslateToInstr(tree); 62 } 67 PrepareForEvaluation(dataset, functionTree); 63 68 } 64 69 … … 118 123 119 124 protected abstract double EvaluateBakedCode(); 125 126 public override object Clone(IDictionary<Guid, object> clonedObjects) { 127 TreeEvaluatorBase clone = (TreeEvaluatorBase)base.Clone(clonedObjects); 128 clone.maxValue = maxValue; 129 clone.minValue = minValue; 130 clone.punishmentFactor = punishmentFactor; 131 return clone; 132 } 133 134 public override System.Xml.XmlNode GetXmlNode(string name, System.Xml.XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) { 135 XmlNode node = base.GetXmlNode(name, document, persistedObjects); 136 XmlAttribute maxValueAttribute = document.CreateAttribute("MaxPredictionValue"); 137 XmlAttribute minValueAttribute = document.CreateAttribute("MinPredictionValue"); 138 XmlAttribute punishmentFactorAttribute = document.CreateAttribute("PunishmentFactor"); 139 maxValueAttribute.Value = XmlConvert.ToString(maxValue); 140 minValueAttribute.Value = XmlConvert.ToString(minValue); 141 punishmentFactorAttribute.Value = XmlConvert.ToString(punishmentFactor); 142 143 node.Attributes.Append(punishmentFactorAttribute); 144 node.Attributes.Append(minValueAttribute); 145 node.Attributes.Append(maxValueAttribute); 146 return node; 147 } 148 149 public override void Populate(System.Xml.XmlNode node, IDictionary<Guid, IStorable> restoredObjects) { 150 base.Populate(node, restoredObjects); 151 minValue = XmlConvert.ToDouble(node.Attributes["MinPredictionValue"].Value); 152 maxValue = XmlConvert.ToDouble(node.Attributes["MaxPredictionValue"].Value); 153 punishmentFactor = XmlConvert.ToDouble(node.Attributes["PunishmentFactor"].Value); 154 } 120 155 } 121 156 }
Note: See TracChangeset
for help on using the changeset viewer.