#region License Information
/* HeuristicLab
* Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
*
* This file is part of HeuristicLab.
*
* HeuristicLab is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* HeuristicLab is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with HeuristicLab. If not, see .
*/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HeuristicLab.Core;
using HeuristicLab.Data;
using HeuristicLab.GP.Interfaces;
using HeuristicLab.Modeling;
using HeuristicLab.DataAnalysis;
namespace HeuristicLab.GP.StructureIdentification {
public class HL3TreeEvaluatorInjector : OperatorBase {
public HL3TreeEvaluatorInjector()
: base() {
AddVariableInfo(new VariableInfo("Dataset", "The dataset", typeof(Dataset), VariableKind.In));
AddVariableInfo(new VariableInfo("TrainingSamplesStart", "Start index of training set", typeof(DoubleData), VariableKind.In));
AddVariableInfo(new VariableInfo("TrainingSamplesEnd", "End index of training set", typeof(DoubleData), VariableKind.In));
AddVariableInfo(new VariableInfo("TargetVariable", "Name of the target variable", typeof(StringData), VariableKind.In));
AddVariableInfo(new VariableInfo("PunishmentFactor", "The punishment factor limits the estimated values to a certain range", typeof(DoubleData), VariableKind.In));
AddVariableInfo(new VariableInfo("TreeEvaluator", "The tree evaluator to evaluate models", typeof(ITreeEvaluator), VariableKind.New));
}
public override string Description {
get { return "Injects a tree evaluator."; }
}
public override IOperation Apply(IScope scope) {
double punishmentFactor = GetVariableValue("PunishmentFactor", scope, true).Data;
Dataset dataset = GetVariableValue("Dataset", scope, true);
int start = GetVariableValue("TrainingSamplesStart", scope, true).Data;
int end = GetVariableValue("TrainingSamplesEnd", scope, true).Data;
string targetVariable = GetVariableValue("TargetVariable", scope, true).Data;
double mean = dataset.GetMean(targetVariable, start, end);
double range = dataset.GetRange(targetVariable, start, end);
double minEstimatedValue = mean - punishmentFactor * range;
double maxEstimatedValue = mean + punishmentFactor * range;
HL3TreeEvaluator evaluator = new HL3TreeEvaluator(minEstimatedValue, maxEstimatedValue);
scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName("TreeEvaluator"), evaluator));
return null;
}
}
}