Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
09/15/09 14:01:47 (15 years ago)
Author:
gkronber
Message:

Moved common (not algorithm specific) model analyzer code (same operator tree in all regression/classification/time-series-prognosis engines) to HL.Modeling. #625, #705, #739.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.SupportVectorMachines/3.2/SupportVectorRegression.cs

    r2351 r2356  
    125125      CombinedOperator algo = new CombinedOperator();
    126126      SequentialProcessor seq = new SequentialProcessor();
    127       algo.Name = "SupportVectorRegression";
    128       seq.Name = "SupportVectorRegression";
     127      algo.Name = Name;
     128      seq.Name = Name;
    129129
    130130      IOperator initialization = CreateInitialization();
    131131      IOperator main = CreateMainLoop();
    132       IOperator postProc = CreateModelAnalyser();
     132      IOperator postProc = CreatePostProcessingOperator();
    133133
    134134      seq.AddSubOperator(initialization);
     
    145145      SequentialProcessor seq = new SequentialProcessor();
    146146      seq.Name = "Initialization";
     147      seq.AddSubOperator(new RandomInjector());
    147148      seq.AddSubOperator(CreateGlobalInjector());
    148       ProblemInjector probInjector = new ProblemInjector();
    149       probInjector.GetVariableInfo("MaxNumberOfTrainingSamples").Local = true;
    150       probInjector.AddVariable(new Variable("MaxNumberOfTrainingSamples", new IntData(1000)));
    151       seq.AddSubOperator(probInjector);
    152       seq.AddSubOperator(new RandomInjector());
    153 
    154       DatasetShuffler shuffler = new DatasetShuffler();
    155       shuffler.GetVariableInfo("ShuffleStart").ActualName = "TrainingSamplesStart";
    156       shuffler.GetVariableInfo("ShuffleEnd").ActualName = "TrainingSamplesEnd";
    157       seq.AddSubOperator(shuffler);
     149      seq.AddSubOperator(CreateProblemInjector());
    158150      return seq;
     151    }
     152
     153    protected virtual IOperator CreateProblemInjector() {
     154      return DefaultRegressionOperators.CreateProblemInjector();
    159155    }
    160156
     
    402398    }
    403399
    404     protected virtual IOperator CreateModelAnalyser() {
     400    protected virtual IOperator CreatePostProcessingOperator() {
    405401      CombinedOperator modelAnalyser = new CombinedOperator();
    406402      modelAnalyser.Name = "Model Analyzer";
     
    410406      PredictorBuilder predictorBuilder = new PredictorBuilder();
    411407      predictorBuilder.GetVariableInfo("SVMModel").ActualName = "Model";
    412       VariableEvaluationImpactCalculator evalImpactCalc = new VariableEvaluationImpactCalculator();
    413       evalImpactCalc.GetVariableInfo("SamplesStart").ActualName = "ActualTrainingSamplesStart";
    414       evalImpactCalc.GetVariableInfo("SamplesEnd").ActualName = "ActualTrainingSamplesEnd";
    415       VariableQualityImpactCalculator qualImpactCalc = new VariableQualityImpactCalculator();
    416       qualImpactCalc.GetVariableInfo("SamplesStart").ActualName = "ActualTrainingSamplesStart";
    417       qualImpactCalc.GetVariableInfo("SamplesEnd").ActualName = "ActualTrainingSamplesEnd";
    418408
    419409      seqProc.AddSubOperator(CreateEvaluator("Test"));
     410      seqProc.AddSubOperator(CreateEvaluator("Training"));
    420411      seqProc.AddSubOperator(predictorBuilder);
    421       seqProc.AddSubOperator(evalImpactCalc);
    422       seqProc.AddSubOperator(qualImpactCalc);
     412      seqProc.AddSubOperator(CreateModelAnalyzerOperator());
     413
    423414      seqSubScopeProc.AddSubOperator(seqProc);
    424415      modelAnalyser.OperatorGraph.InitialOperator = seqSubScopeProc;
     
    427418    }
    428419
     420    protected virtual IOperator CreateModelAnalyzerOperator() {
     421      return DefaultRegressionOperators.CreatePostProcessingOperator();
     422    }
     423
    429424
    430425    protected virtual IAnalyzerModel CreateSVMModel(IScope bestModelScope) {
    431426      AnalyzerModel model = new AnalyzerModel();
    432       model.SetResult("TrainingMeanSquaredError", bestModelScope.GetVariableValue<DoubleData>("Quality", false).Data);
    433       model.SetResult("ValidationMeanSquaredError", bestModelScope.GetVariableValue<DoubleData>("ValidationQuality", false).Data);
    434       model.SetResult("TestMeanSquaredError", bestModelScope.GetVariableValue<DoubleData>("TestQuality", false).Data);
    435       model.SetResult("TrainingCoefficientOfDetermination", bestModelScope.GetVariableValue<DoubleData>("ActualTrainingR2", false).Data);
    436       model.SetResult("ValidationCoefficientOfDetermination", bestModelScope.GetVariableValue<DoubleData>("ValidationR2", false).Data);
    437       model.SetResult("TestCoefficientOfDetermination", bestModelScope.GetVariableValue<DoubleData>("TestR2", false).Data);
    438       model.SetResult("TrainingMeanAbsolutePercentageError", bestModelScope.GetVariableValue<DoubleData>("ActualTrainingMAPE", false).Data);
    439       model.SetResult("ValidationMeanAbsolutePercentageError", bestModelScope.GetVariableValue<DoubleData>("ValidationMAPE", false).Data);
    440       model.SetResult("TestMeanAbsolutePercentageError", bestModelScope.GetVariableValue<DoubleData>("TestMAPE", false).Data);
    441       model.SetResult("TrainingMeanAbsolutePercentageOfRangeError", bestModelScope.GetVariableValue<DoubleData>("ActualTrainingMAPRE", false).Data);
    442       model.SetResult("ValidationMeanAbsolutePercentageOfRangeError", bestModelScope.GetVariableValue<DoubleData>("ValidationMAPRE", false).Data);
    443       model.SetResult("TestMeanAbsolutePercentageOfRangeError", bestModelScope.GetVariableValue<DoubleData>("TestMAPRE", false).Data);
    444       model.SetResult("TrainingVarianceAccountedFor", bestModelScope.GetVariableValue<DoubleData>("ActualTrainingVAF", false).Data);
    445       model.SetResult("ValidationVarianceAccountedFor", bestModelScope.GetVariableValue<DoubleData>("ValidationVAF", false).Data);
    446       model.SetResult("TestVarianceAccountedFor", bestModelScope.GetVariableValue<DoubleData>("TestVAF", false).Data);
    447 
    448427      model.SetMetaData("Cost", bestModelScope.GetVariableValue<DoubleData>("Cost", false).Data);
    449428      model.SetMetaData("Nu", bestModelScope.GetVariableValue<DoubleData>("Nu", false).Data);
    450 
    451       HeuristicLab.DataAnalysis.Dataset ds = bestModelScope.GetVariableValue<Dataset>("Dataset", true);
    452       model.Dataset = ds;
    453       model.TargetVariable = ds.GetVariableName(bestModelScope.GetVariableValue<IntData>("TargetVariable", true).Data);
    454       model.TrainingSamplesStart = bestModelScope.GetVariableValue<IntData>("TrainingSamplesStart", true).Data;
    455       model.TrainingSamplesEnd = bestModelScope.GetVariableValue<IntData>("TrainingSamplesEnd", true).Data;
    456       model.ValidationSamplesStart = bestModelScope.GetVariableValue<IntData>("ValidationSamplesStart", true).Data;
    457       model.ValidationSamplesEnd = bestModelScope.GetVariableValue<IntData>("ValidationSamplesEnd", true).Data;
    458       model.TestSamplesStart = bestModelScope.GetVariableValue<IntData>("TestSamplesStart", true).Data;
    459       model.TestSamplesEnd = bestModelScope.GetVariableValue<IntData>("TestSamplesEnd", true).Data;
    460       model.Predictor = bestModelScope.GetVariableValue<IPredictor>("Predictor", true);
    461 
    462       ItemList evaluationImpacts = bestModelScope.GetVariableValue<ItemList>("VariableEvaluationImpacts", false);
    463       ItemList qualityImpacts = bestModelScope.GetVariableValue<ItemList>("VariableQualityImpacts", false);
    464       foreach (ItemList row in evaluationImpacts) {
    465         string variableName = ((StringData)row[0]).Data;
    466         double impact = ((DoubleData)row[1]).Data;
    467         model.SetVariableEvaluationImpact(variableName, impact);
    468         model.AddInputVariable(variableName);
    469       }
    470       foreach (ItemList row in qualityImpacts) {
    471         string variableName = ((StringData)row[0]).Data;
    472         double impact = ((DoubleData)row[1]).Data;
    473         model.SetVariableQualityImpact(variableName, impact);
    474         model.AddInputVariable(variableName);
    475       }
     429      DefaultRegressionOperators.PopulateAnalyzerModel(bestModelScope, model);
    476430
    477431      return model;
     
    479433
    480434    protected IOperator GetVariableInjector() {
    481       return GetMainOperator().SubOperators[0].SubOperators[0];
     435      return GetMainOperator().SubOperators[0].SubOperators[1];
    482436    }
    483437
Note: See TracChangeset for help on using the changeset viewer.