Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
09/03/09 15:00:23 (15 years ago)
Author:
gkronber
Message:

this is the remaining part of changeset r2327.
Applied changes in modeling plugins that are necessary for the new model analyzer (#722)

  • predictor has properties for the lower and upper limit of the predicted value
  • added views for predictors that show the limits (also added a new view for GeneticProgrammingModel that shows the size and height of the model)
  • Reintroduced TreeEvaluatorInjectors that read a PunishmentFactor and calculate the lower and upper limits for estimated values (limits are set in the tree evaluators)
  • Added operators to create Predictors. Changed modeling algorithms to use the predictors for the calculation of final model qualities and variable impacts (to be compatible with the new model analyzer the predictors use a very large PunishmentFactor)
  • replaced all private implementations of double.IsAlmost and use HL.Commons instead (see #733 r2324)
  • Implemented operator SolutionExtractor and moved BestSolutionStorer from HL.Logging to HL.Modeling (fixes #734)
Location:
trunk/sources/HeuristicLab.SupportVectorMachines/3.2
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.SupportVectorMachines/3.2/HeuristicLab.SupportVectorMachines-3.2.csproj

    r2319 r2328  
    8383  </ItemGroup>
    8484  <ItemGroup>
     85    <Compile Include="PredictorView.cs">
     86      <SubType>UserControl</SubType>
     87    </Compile>
     88    <Compile Include="PredictorView.Designer.cs">
     89      <DependentUpon>PredictorView.cs</DependentUpon>
     90    </Compile>
    8591    <Compile Include="Predictor.cs" />
    8692    <Compile Include="PredictorBuilder.cs" />
     
    154160  </ItemGroup>
    155161  <ItemGroup>
     162    <EmbeddedResource Include="PredictorView.resx">
     163      <DependentUpon>PredictorView.cs</DependentUpon>
     164    </EmbeddedResource>
    156165    <EmbeddedResource Include="SVMModelView.resx">
    157166      <DependentUpon>SVMModelView.cs</DependentUpon>
  • trunk/sources/HeuristicLab.SupportVectorMachines/3.2/Predictor.cs

    r2290 r2328  
    3232
    3333namespace HeuristicLab.SupportVectorMachines {
    34   public class Predictor : ItemBase, IPredictor {
     34  public class Predictor : PredictorBase {
    3535    private SVMModel svmModel;
     36    public SVMModel Model {
     37      get { return svmModel; }
     38    }
     39
    3640    private Dictionary<string, int> variableNames = new Dictionary<string, int>();
    3741    private string targetVariable;
     
    4650    }
    4751
    48     public double[] Predict(Dataset input, int start, int end) {
     52    public override double[] Predict(Dataset input, int start, int end) {
    4953      if (start < 0 || end <= start) throw new ArgumentException("start must be larger than zero and strictly smaller than end");
    5054      if (end > input.Rows) throw new ArgumentOutOfRangeException("number of rows in input is smaller then end");
     
    6468      double[] result = new double[rows];
    6569      for (int row = 0; row < rows; row++) {
    66         result[row] = SVM.Prediction.Predict(model, scaledProblem.X[row]);
     70        result[row] = Math.Max(Math.Min(SVM.Prediction.Predict(model, scaledProblem.X[row]), UpperPredictionLimit), LowerPredictionLimit);
    6771      }
    6872      return result;
     
    7074
    7175    public override IView CreateView() {
    72       return svmModel.CreateView();
     76      return new PredictorView(this);
    7377    }
    7478
  • trunk/sources/HeuristicLab.SupportVectorMachines/3.2/PredictorBuilder.cs

    r2319 r2328  
    3737      AddVariableInfo(new VariableInfo("TargetVariable", "The target variable", typeof(StringData), VariableKind.In));
    3838      AddVariableInfo(new VariableInfo("InputVariables", "The input variable names", typeof(StringData), VariableKind.In));
     39      AddVariableInfo(new VariableInfo("TrainingSamplesStart", "Start index of the training set", typeof(IntData), VariableKind.In));
     40      AddVariableInfo(new VariableInfo("TrainingSamplesEnd", "End index of the training set", typeof(IntData), VariableKind.In));
     41      AddVariableInfo(new VariableInfo("PunishmentFactor", "The punishment factor limits the range of predicted values", typeof(DoubleData), VariableKind.In));
    3942      AddVariableInfo(new VariableInfo("Predictor", "The predictor can be used to generate estimated values", typeof(IPredictor), VariableKind.New));
    4043    }
     
    4851      SVMModel model = GetVariableValue<SVMModel>("SVMModel", scope, true);
    4952      int targetVariable = GetVariableValue<IntData>("TargetVariable", scope, true).Data;
     53      int start = GetVariableValue<IntData>("TrainingSamplesStart", scope, true).Data;
     54      int end = GetVariableValue<IntData>("TrainingSamplesEnd", scope, true).Data;
     55      double punishmentFactor = GetVariableValue<DoubleData>("PunishmentFactor", scope, true).Data;
     56
    5057      string targetVariableName = ds.GetVariableName(targetVariable);
    5158      ItemList inputVariables = GetVariableValue<ItemList>("InputVariables", scope, true);
     
    5360      for (int i = 0; i < ds.Columns; i++) variableNames[ds.GetVariableName(i)] = i;
    5461
    55       scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName("Predictor"), new Predictor(model, targetVariableName, variableNames)));
     62      double mean = ds.GetMean(targetVariable, start, end);
     63      double range = ds.GetRange(targetVariable, start, end);
     64
     65      Predictor predictor = new Predictor(model, targetVariableName, variableNames);
     66      predictor.LowerPredictionLimit = mean - punishmentFactor * range;
     67      predictor.UpperPredictionLimit = mean + punishmentFactor * range;
     68      scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName("Predictor"), predictor));
    5669      return null;
    5770    }
  • trunk/sources/HeuristicLab.SupportVectorMachines/3.2/SVMModelView.cs

    r2322 r2328  
    3333  public partial class SVMModelView : ViewBase {
    3434    private SVMModel model;
    35    
     35    public SVMModelView() : base() {
     36      InitializeComponent();
     37    }   
    3638    public SVMModelView(SVMModel model) : base() {
    3739      InitializeComponent();
    3840      this.model = model;
    39       model.Changed += (sender, args) => UpdateControls();
     41      model.Changed += (sender, args) => Refresh();
    4042
    41       UpdateControls();
    42     }
    43 
    44     protected override void UpdateControls() {
    45       base.UpdateControls();
    46       numberOfSupportVectors.Text = model.Model.SupportVectorCount.ToString();
    47       rho.Text = model.Model.Rho[0].ToString();
    48       svmType.Text = model.Model.Parameter.SvmType.ToString();
    49       kernelType.Text = model.Model.Parameter.KernelType.ToString();
    50       gamma.Text = model.Model.Parameter.Gamma.ToString();
     43      numberOfSupportVectors.DataBindings.Add(new Binding("Text", model.Model, "SupportVectorCount"));
     44      rho.DataBindings.Add(new Binding("Text", model.Model, "Rho"));
     45      svmType.DataBindings.Add(new Binding("Text", model.Model.Parameter, "SvmType"));
     46      kernelType.DataBindings.Add(new Binding("Text", model.Model.Parameter, "KernelType"));
     47      gamma.DataBindings.Add(new Binding("Text", model.Model.Parameter, "Gamma"));
    5148    }
    5249  }
  • trunk/sources/HeuristicLab.SupportVectorMachines/3.2/SupportVectorRegression.cs

    r2319 r2328  
    394394      injector.AddVariable(new HeuristicLab.Core.Variable("KernelType", new StringData("RBF")));
    395395      injector.AddVariable(new HeuristicLab.Core.Variable("Type", new StringData("NU_SVR")));
     396      injector.AddVariable(new HeuristicLab.Core.Variable("PunishmentFactor", new DoubleData(1000.0)));
    396397
    397398      return injector;
Note: See TracChangeset for help on using the changeset viewer.