[2388] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
| 4 | *
|
---|
| 5 | * This file is part of HeuristicLab.
|
---|
| 6 | *
|
---|
| 7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
| 8 | * it under the terms of the GNU General Public License as published by
|
---|
| 9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
| 10 | * (at your option) any later version.
|
---|
| 11 | *
|
---|
| 12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 15 | * GNU General Public License for more details.
|
---|
| 16 | *
|
---|
| 17 | * You should have received a copy of the GNU General Public License
|
---|
| 18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 19 | */
|
---|
| 20 | #endregion
|
---|
| 21 |
|
---|
| 22 | using HeuristicLab.Core;
|
---|
| 23 | using HeuristicLab.DataAnalysis;
|
---|
| 24 | using HeuristicLab.Operators;
|
---|
| 25 | using HeuristicLab.Modeling;
|
---|
| 26 | using HeuristicLab.Data;
|
---|
| 27 |
|
---|
| 28 | namespace HeuristicLab.Modeling {
|
---|
| 29 | public static class DefaultModelAnalyzerOperators {
|
---|
| 30 | public static IOperator CreatePostProcessingOperator(ModelType modelType) {
|
---|
| 31 | CombinedOperator op = new CombinedOperator();
|
---|
| 32 | op.Name = modelType + " model analyser";
|
---|
| 33 | SequentialProcessor seq = new SequentialProcessor();
|
---|
| 34 | var modelingResults = ModelingResultCalculators.GetModelingResult(modelType);
|
---|
| 35 | foreach (var r in modelingResults.Keys) {
|
---|
| 36 | seq.AddSubOperator(ModelingResultCalculators.CreateModelingResultEvaluator(r));
|
---|
| 37 | }
|
---|
| 38 |
|
---|
| 39 | #region variable impacts
|
---|
| 40 | VariableEvaluationImpactCalculator evaluationImpactCalculator = new VariableEvaluationImpactCalculator();
|
---|
| 41 | evaluationImpactCalculator.GetVariableInfo("SamplesStart").ActualName = "TrainingSamplesStart";
|
---|
| 42 | evaluationImpactCalculator.GetVariableInfo("SamplesEnd").ActualName = "TrainingSamplesEnd";
|
---|
| 43 | VariableQualityImpactCalculator qualityImpactCalculator = new VariableQualityImpactCalculator();
|
---|
| 44 | qualityImpactCalculator.GetVariableInfo("SamplesStart").ActualName = "TrainingSamplesStart";
|
---|
| 45 | qualityImpactCalculator.GetVariableInfo("SamplesEnd").ActualName = "TrainingSamplesEnd";
|
---|
| 46 |
|
---|
| 47 | seq.AddSubOperator(evaluationImpactCalculator);
|
---|
| 48 | seq.AddSubOperator(qualityImpactCalculator);
|
---|
| 49 | #endregion
|
---|
| 50 |
|
---|
| 51 | op.OperatorGraph.AddOperator(seq);
|
---|
| 52 | op.OperatorGraph.InitialOperator = seq;
|
---|
| 53 | return op;
|
---|
| 54 | }
|
---|
| 55 |
|
---|
| 56 | public static IAnalyzerModel PopulateAnalyzerModel(IScope modelScope, IAnalyzerModel model, ModelType modelType) {
|
---|
| 57 | model.Predictor = modelScope.GetVariableValue<IPredictor>("Predictor", false);
|
---|
| 58 | Dataset ds = modelScope.GetVariableValue<Dataset>("Dataset", true);
|
---|
| 59 | model.Dataset = ds;
|
---|
| 60 | model.TargetVariable = ds.GetVariableName(modelScope.GetVariableValue<IntData>("TargetVariable", true).Data);
|
---|
| 61 | model.Type = ModelType.Regression;
|
---|
| 62 | model.TrainingSamplesStart = modelScope.GetVariableValue<IntData>("TrainingSamplesStart", true).Data;
|
---|
| 63 | model.TrainingSamplesEnd = modelScope.GetVariableValue<IntData>("TrainingSamplesEnd", true).Data;
|
---|
| 64 | model.ValidationSamplesStart = modelScope.GetVariableValue<IntData>("ValidationSamplesStart", true).Data;
|
---|
| 65 | model.ValidationSamplesEnd = modelScope.GetVariableValue<IntData>("ValidationSamplesEnd", true).Data;
|
---|
| 66 | model.TestSamplesStart = modelScope.GetVariableValue<IntData>("TestSamplesStart", true).Data;
|
---|
| 67 | model.TestSamplesEnd = modelScope.GetVariableValue<IntData>("TestSamplesEnd", true).Data;
|
---|
| 68 |
|
---|
| 69 | var modelingResults = ModelingResultCalculators.GetModelingResult(modelType);
|
---|
| 70 | foreach (var r in modelingResults.Keys) {
|
---|
| 71 | model.ExtractResult(modelScope, r);
|
---|
| 72 | }
|
---|
| 73 |
|
---|
| 74 | ItemList evaluationImpacts = modelScope.GetVariableValue<ItemList>(ModelingResult.VariableEvaluationImpact.ToString(), false);
|
---|
| 75 | ItemList qualityImpacts = modelScope.GetVariableValue<ItemList>(ModelingResult.VariableQualityImpact.ToString(), false);
|
---|
| 76 | foreach (ItemList row in evaluationImpacts) {
|
---|
| 77 | string variableName = ((StringData)row[0]).Data;
|
---|
| 78 | double impact = ((DoubleData)row[1]).Data;
|
---|
| 79 | model.SetVariableResult(ModelingResult.VariableEvaluationImpact, variableName, impact);
|
---|
| 80 | model.AddInputVariable(variableName);
|
---|
| 81 | }
|
---|
| 82 | foreach (ItemList row in qualityImpacts) {
|
---|
| 83 | string variableName = ((StringData)row[0]).Data;
|
---|
| 84 | double impact = ((DoubleData)row[1]).Data;
|
---|
| 85 | model.SetVariableResult(ModelingResult.VariableQualityImpact, variableName, impact);
|
---|
| 86 | model.AddInputVariable(variableName);
|
---|
| 87 | }
|
---|
| 88 |
|
---|
| 89 | return model;
|
---|
| 90 | }
|
---|
| 91 | }
|
---|
| 92 | }
|
---|