Free cookie consent management tool by TermsFeed Policy Generator

Changeset 2353


Ignore:
Timestamp:
09/14/09 18:43:04 (15 years ago)
Author:
gkronber
Message:

Added default engine for linear regression based classification. #739

Location:
trunk/sources
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.GP.StructureIdentification.Classification/3.3/DefaultClassificationAlgorithmOperators.cs

    r2351 r2353  
    2828
    2929namespace HeuristicLab.GP.StructureIdentification.Classification {
    30   internal static class DefaultClassificationAlgorithmOperators {
    31     internal static IOperator CreatePostProcessingOperator() {
     30  public static class DefaultClassificationAlgorithmOperators {
     31    public static IOperator CreatePostProcessingOperator() {
    3232      SequentialProcessor seq = new SequentialProcessor();
    3333      seq.AddSubOperator(DefaultStructureIdentificationAlgorithmOperators.CreatePostProcessingOperator());
     
    5858    }
    5959
    60     internal static IOperator CreateProblemInjector() {
     60    public static IOperator CreateProblemInjector() {
    6161      CombinedOperator op = new CombinedOperator();
    6262      op.Name = "ProblemInjector";
     
    6969    }
    7070
    71     internal static void SetModelData(IAnalyzerModel model, IScope scope) {
     71    public static void SetModelData(IAnalyzerModel model, IScope scope) {
    7272      model.SetResult("TrainingAccuracy", scope.GetVariableValue<DoubleData>("TrainingAccuracy", true).Data);
    7373      model.SetResult("ValidationAccuracy", scope.GetVariableValue<DoubleData>("ValidationAccuracy", true).Data);
  • trunk/sources/HeuristicLab.LinearRegression/3.2/HeuristicLab.LinearRegression-3.2.csproj

    r2324 r2353  
    9191    <Compile Include="alglib\spline3.cs" />
    9292    <Compile Include="alglib\svd.cs" />
     93    <Compile Include="LinearClassification.cs" />
    9394    <Compile Include="HeuristicLabLinearRegressionPlugin.cs" />
    9495    <Compile Include="LinearRegression.cs" />
     
    120121      <Project>{924B6BEA-9A99-40FE-9334-5C01E8D540EC}</Project>
    121122      <Name>HeuristicLab.GP.Interfaces-3.3</Name>
     123    </ProjectReference>
     124    <ProjectReference Include="..\..\HeuristicLab.GP.StructureIdentification.Classification\3.3\HeuristicLab.GP.StructureIdentification.Classification-3.3.csproj">
     125      <Project>{7C20D100-8BEB-433A-9499-F075E2CB9297}</Project>
     126      <Name>HeuristicLab.GP.StructureIdentification.Classification-3.3</Name>
     127    </ProjectReference>
     128    <ProjectReference Include="..\..\HeuristicLab.GP.StructureIdentification.TimeSeries\3.3\HeuristicLab.GP.StructureIdentification.TimeSeries-3.3.csproj">
     129      <Project>{6084CFB5-733F-449D-9F92-2E40D13F0514}</Project>
     130      <Name>HeuristicLab.GP.StructureIdentification.TimeSeries-3.3</Name>
    122131    </ProjectReference>
    123132    <ProjectReference Include="..\..\HeuristicLab.GP.StructureIdentification\3.3\HeuristicLab.GP.StructureIdentification-3.3.csproj">
  • trunk/sources/HeuristicLab.LinearRegression/3.2/HeuristicLabLinearRegressionPlugin.cs

    r2324 r2353  
    2424using HeuristicLab.PluginInfrastructure;
    2525
    26 namespace HeuristicLab.LinearRegression{
     26namespace HeuristicLab.LinearRegression {
    2727  [ClassInfo(Name = "HeuristicLab.LinearRegression-3.2")]
    2828  [PluginFile(Filename = "HeuristicLab.LinearRegression-3.2.dll", Filetype = PluginFileType.Assembly)]
     
    3535  [Dependency(Dependency = "HeuristicLab.GP.Interfaces-3.3")]
    3636  [Dependency(Dependency = "HeuristicLab.GP.StructureIdentification-3.3")]
     37  [Dependency(Dependency = "HeuristicLab.GP.StructureIdentification.Classification-3.3")]
     38  [Dependency(Dependency = "HeuristicLab.GP.StructureIdentification.TimeSeries-3.3")]
    3739  [Dependency(Dependency = "HeuristicLab.Modeling-3.2")]
    3840  [Dependency(Dependency = "HeuristicLab.Random-3.2")]
  • trunk/sources/HeuristicLab.LinearRegression/3.2/LinearRegression.cs

    r2344 r2353  
    3939  public class LinearRegression : ItemBase, IEditable, IAlgorithm {
    4040
    41     public string Name { get { return "LinearRegression"; } }
    42     public string Description { get { return "TODO"; } }
     41    public virtual string Name { get { return "LinearRegression"; } }
     42    public virtual string Description { get { return "TODO"; } }
    4343
    4444    private SequentialEngine.SequentialEngine engine;
    45     public IEngine Engine {
     45    public virtual IEngine Engine {
    4646      get { return engine; }
    4747    }
    4848
    49     public Dataset Dataset {
     49    public virtual Dataset Dataset {
    5050      get { return ProblemInjector.GetVariableValue<Dataset>("Dataset", null, false); }
    5151      set { ProblemInjector.GetVariable("Dataset").Value = value; }
    5252    }
    5353
    54     public int TargetVariable {
     54    public virtual int TargetVariable {
    5555      get { return ProblemInjector.GetVariableValue<IntData>("TargetVariable", null, false).Data; }
    5656      set { ProblemInjector.GetVariableValue<IntData>("TargetVariable", null, false).Data = value; }
    5757    }
    5858
    59     public IOperator ProblemInjector {
     59    public virtual IOperator ProblemInjector {
    6060      get {
    6161        IOperator main = GetMainOperator();
     
    6969    }
    7070
    71     public IAnalyzerModel Model {
     71    public virtual IAnalyzerModel Model {
    7272      get {
    7373        if (!engine.Terminated) throw new InvalidOperationException("The algorithm is still running. Wait until the algorithm is terminated to retrieve the result.");
     
    8484    }
    8585
    86     private CombinedOperator CreateAlgorithm() {
     86    protected virtual CombinedOperator CreateAlgorithm() {
    8787      CombinedOperator algo = new CombinedOperator();
    8888      SequentialProcessor seq = new SequentialProcessor();
     
    121121    }
    122122
    123     private IOperator CreateGlobalInjector() {
     123    protected virtual VariableInjector CreateGlobalInjector() {
    124124      VariableInjector injector = new VariableInjector();
    125125      injector.AddVariable(new HeuristicLab.Core.Variable("PunishmentFactor", new DoubleData(1000)));
     
    129129    }
    130130
    131     private IOperator CreateModelAnalyser() {
    132       CombinedOperator modelAnalyser = new CombinedOperator();
    133       modelAnalyser.Name = "Model Analyzer";
    134       SequentialProcessor seqProc = new SequentialProcessor();
    135       #region MSE
    136       MeanSquaredErrorEvaluator trainingMSE = new MeanSquaredErrorEvaluator();
    137       trainingMSE.Name = "TrainingMseEvaluator";
    138       trainingMSE.GetVariableInfo("FunctionTree").ActualName = "LinearRegressionModel";
    139       trainingMSE.GetVariableInfo("MSE").ActualName = "TrainingQuality";
    140       trainingMSE.GetVariableInfo("SamplesStart").ActualName = "ActualTrainingSamplesStart";
    141       trainingMSE.GetVariableInfo("SamplesEnd").ActualName = "ActualTrainingSamplesEnd";
    142       MeanSquaredErrorEvaluator validationMSE = new MeanSquaredErrorEvaluator();
    143       validationMSE.Name = "ValidationMseEvaluator";
    144       validationMSE.GetVariableInfo("FunctionTree").ActualName = "LinearRegressionModel";
    145       validationMSE.GetVariableInfo("MSE").ActualName = "ValidationQuality";
    146       validationMSE.GetVariableInfo("SamplesStart").ActualName = "ValidationSamplesStart";
    147       validationMSE.GetVariableInfo("SamplesEnd").ActualName = "ValidationSamplesEnd";
    148       MeanSquaredErrorEvaluator testMSE = new MeanSquaredErrorEvaluator();
    149       testMSE.Name = "TestMseEvaluator";
    150       testMSE.GetVariableInfo("FunctionTree").ActualName = "LinearRegressionModel";
    151       testMSE.GetVariableInfo("MSE").ActualName = "TestQuality";
    152       testMSE.GetVariableInfo("SamplesStart").ActualName = "TestSamplesStart";
    153       testMSE.GetVariableInfo("SamplesEnd").ActualName = "TestSamplesEnd";
    154       #endregion
     131    protected virtual IOperator CreateModelAnalyser() {
     132      CombinedOperator op = new CombinedOperator();
     133      op.AddVariableInfo(new VariableInfo("FunctionTree", "The model to analyze", typeof(IGeneticProgrammingModel), VariableKind.In));
     134      op.Name = "Model Analyzer";
     135      op.GetVariableInfo("FunctionTree").ActualName = "LinearRegressionModel";
    155136
    156       #region R2
    157       CoefficientOfDeterminationEvaluator trainingR2 = new CoefficientOfDeterminationEvaluator();
    158       trainingR2.Name = "TrainingR2Evaluator";
    159       trainingR2.GetVariableInfo("FunctionTree").ActualName = "LinearRegressionModel";
    160       trainingR2.GetVariableInfo("R2").ActualName = "TrainingR2";
    161       trainingR2.GetVariableInfo("SamplesStart").ActualName = "ActualTrainingSamplesStart";
    162       trainingR2.GetVariableInfo("SamplesEnd").ActualName = "ActualTrainingSamplesEnd";
    163       CoefficientOfDeterminationEvaluator validationR2 = new CoefficientOfDeterminationEvaluator();
    164       validationR2.Name = "ValidationR2Evaluator";
    165       validationR2.GetVariableInfo("FunctionTree").ActualName = "LinearRegressionModel";
    166       validationR2.GetVariableInfo("R2").ActualName = "ValidationR2";
    167       validationR2.GetVariableInfo("SamplesStart").ActualName = "ValidationSamplesStart";
    168       validationR2.GetVariableInfo("SamplesEnd").ActualName = "ValidationSamplesEnd";
    169       CoefficientOfDeterminationEvaluator testR2 = new CoefficientOfDeterminationEvaluator();
    170       testR2.Name = "TestR2Evaluator";
    171       testR2.GetVariableInfo("FunctionTree").ActualName = "LinearRegressionModel";
    172       testR2.GetVariableInfo("R2").ActualName = "TestR2";
    173       testR2.GetVariableInfo("SamplesStart").ActualName = "TestSamplesStart";
    174       testR2.GetVariableInfo("SamplesEnd").ActualName = "TestSamplesEnd";
    175       #endregion
    176 
    177       #region MAPE
    178       MeanAbsolutePercentageErrorEvaluator trainingMAPE = new MeanAbsolutePercentageErrorEvaluator();
    179       trainingMAPE.Name = "TrainingMapeEvaluator";
    180       trainingMAPE.GetVariableInfo("FunctionTree").ActualName = "LinearRegressionModel";
    181       trainingMAPE.GetVariableInfo("MAPE").ActualName = "TrainingMAPE";
    182       trainingMAPE.GetVariableInfo("SamplesStart").ActualName = "ActualTrainingSamplesStart";
    183       trainingMAPE.GetVariableInfo("SamplesEnd").ActualName = "ActualTrainingSamplesEnd";
    184       MeanAbsolutePercentageErrorEvaluator validationMAPE = new MeanAbsolutePercentageErrorEvaluator();
    185       validationMAPE.Name = "ValidationMapeEvaluator";
    186       validationMAPE.GetVariableInfo("FunctionTree").ActualName = "LinearRegressionModel";
    187       validationMAPE.GetVariableInfo("MAPE").ActualName = "ValidationMAPE";
    188       validationMAPE.GetVariableInfo("SamplesStart").ActualName = "ValidationSamplesStart";
    189       validationMAPE.GetVariableInfo("SamplesEnd").ActualName = "ValidationSamplesEnd";
    190       MeanAbsolutePercentageErrorEvaluator testMAPE = new MeanAbsolutePercentageErrorEvaluator();
    191       testMAPE.Name = "TestMapeEvaluator";
    192       testMAPE.GetVariableInfo("FunctionTree").ActualName = "LinearRegressionModel";
    193       testMAPE.GetVariableInfo("MAPE").ActualName = "TestMAPE";
    194       testMAPE.GetVariableInfo("SamplesStart").ActualName = "TestSamplesStart";
    195       testMAPE.GetVariableInfo("SamplesEnd").ActualName = "TestSamplesEnd";
    196       #endregion
    197 
    198       #region MAPRE
    199       MeanAbsolutePercentageOfRangeErrorEvaluator trainingMAPRE = new MeanAbsolutePercentageOfRangeErrorEvaluator();
    200       trainingMAPRE.Name = "TrainingMapreEvaluator";
    201       trainingMAPRE.GetVariableInfo("FunctionTree").ActualName = "LinearRegressionModel";
    202       trainingMAPRE.GetVariableInfo("MAPRE").ActualName = "TrainingMAPRE";
    203       trainingMAPRE.GetVariableInfo("SamplesStart").ActualName = "ActualTrainingSamplesStart";
    204       trainingMAPRE.GetVariableInfo("SamplesEnd").ActualName = "ActualTrainingSamplesEnd";
    205       MeanAbsolutePercentageOfRangeErrorEvaluator validationMAPRE = new MeanAbsolutePercentageOfRangeErrorEvaluator();
    206       validationMAPRE.Name = "ValidationMapreEvaluator";
    207       validationMAPRE.GetVariableInfo("FunctionTree").ActualName = "LinearRegressionModel";
    208       validationMAPRE.GetVariableInfo("MAPRE").ActualName = "ValidationMAPRE";
    209       validationMAPRE.GetVariableInfo("SamplesStart").ActualName = "ValidationSamplesStart";
    210       validationMAPRE.GetVariableInfo("SamplesEnd").ActualName = "ValidationSamplesEnd";
    211       MeanAbsolutePercentageOfRangeErrorEvaluator testMAPRE = new MeanAbsolutePercentageOfRangeErrorEvaluator();
    212       testMAPRE.Name = "TestMapreEvaluator";
    213       testMAPRE.GetVariableInfo("FunctionTree").ActualName = "LinearRegressionModel";
    214       testMAPRE.GetVariableInfo("MAPRE").ActualName = "TestMAPRE";
    215       testMAPRE.GetVariableInfo("SamplesStart").ActualName = "TestSamplesStart";
    216       testMAPRE.GetVariableInfo("SamplesEnd").ActualName = "TestSamplesEnd";
    217       #endregion
    218 
    219       #region VAF
    220       VarianceAccountedForEvaluator trainingVAF = new VarianceAccountedForEvaluator();
    221       trainingVAF.Name = "TrainingVafEvaluator";
    222       trainingVAF.GetVariableInfo("FunctionTree").ActualName = "LinearRegressionModel";
    223       trainingVAF.GetVariableInfo("VAF").ActualName = "TrainingVAF";
    224       trainingVAF.GetVariableInfo("SamplesStart").ActualName = "ActualTrainingSamplesStart";
    225       trainingVAF.GetVariableInfo("SamplesEnd").ActualName = "ActualTrainingSamplesEnd";
    226       VarianceAccountedForEvaluator validationVAF = new VarianceAccountedForEvaluator();
    227       validationVAF.Name = "ValidationVafEvaluator";
    228       validationVAF.GetVariableInfo("FunctionTree").ActualName = "LinearRegressionModel";
    229       validationVAF.GetVariableInfo("VAF").ActualName = "ValidationVAF";
    230       validationVAF.GetVariableInfo("SamplesStart").ActualName = "ValidationSamplesStart";
    231       validationVAF.GetVariableInfo("SamplesEnd").ActualName = "ValidationSamplesEnd";
    232       VarianceAccountedForEvaluator testVAF = new VarianceAccountedForEvaluator();
    233       testVAF.Name = "TestVafEvaluator";
    234       testVAF.GetVariableInfo("FunctionTree").ActualName = "LinearRegressionModel";
    235       testVAF.GetVariableInfo("VAF").ActualName = "TestVAF";
    236       testVAF.GetVariableInfo("SamplesStart").ActualName = "TestSamplesStart";
    237       testVAF.GetVariableInfo("SamplesEnd").ActualName = "TestSamplesEnd";
    238       #endregion
    239 
    240       VariableNamesExtractor namesExtractor = new VariableNamesExtractor();
    241       namesExtractor.GetVariableInfo("FunctionTree").ActualName = "LinearRegressionModel";
    242       namesExtractor.GetVariableInfo("VariableNames").ActualName = "InputVariableNames";
    243       PredictorBuilder predictorBuilder = new PredictorBuilder();
    244       predictorBuilder.GetVariableInfo("FunctionTree").ActualName = "LinearRegressionModel";
    245       VariableEvaluationImpactCalculator evalImpactCalc = new VariableEvaluationImpactCalculator();
    246       evalImpactCalc.GetVariableInfo("SamplesStart").ActualName = "ActualTrainingSamplesStart";
    247       evalImpactCalc.GetVariableInfo("SamplesEnd").ActualName = "ActualTrainingSamplesEnd";
    248       VariableQualityImpactCalculator qualImpactCalc = new VariableQualityImpactCalculator();
    249       qualImpactCalc.GetVariableInfo("SamplesStart").ActualName = "ActualTrainingSamplesStart";
    250       qualImpactCalc.GetVariableInfo("SamplesEnd").ActualName = "ActualTrainingSamplesEnd";
    251       seqProc.AddSubOperator(trainingMSE);
    252       seqProc.AddSubOperator(validationMSE);
    253       seqProc.AddSubOperator(testMSE);
    254       seqProc.AddSubOperator(trainingR2);
    255       seqProc.AddSubOperator(validationR2);
    256       seqProc.AddSubOperator(testR2);
    257       seqProc.AddSubOperator(trainingMAPE);
    258       seqProc.AddSubOperator(validationMAPE);
    259       seqProc.AddSubOperator(testMAPE);
    260       seqProc.AddSubOperator(trainingMAPRE);
    261       seqProc.AddSubOperator(validationMAPRE);
    262       seqProc.AddSubOperator(testMAPRE);
    263       seqProc.AddSubOperator(trainingVAF);
    264       seqProc.AddSubOperator(validationVAF);
    265       seqProc.AddSubOperator(testVAF);
    266       seqProc.AddSubOperator(namesExtractor);
    267       seqProc.AddSubOperator(predictorBuilder);
    268       seqProc.AddSubOperator(qualImpactCalc);
    269       seqProc.AddSubOperator(evalImpactCalc);
    270       modelAnalyser.OperatorGraph.InitialOperator = seqProc;
    271       modelAnalyser.OperatorGraph.AddOperator(seqProc);
    272       return modelAnalyser;
     137      IOperator maOp = DefaultStructureIdentificationAlgorithmOperators.CreatePostProcessingOperator();
     138      op.OperatorGraph.AddOperator(maOp);
     139      op.OperatorGraph.InitialOperator = maOp;
     140      return op;
    273141    }
    274142
    275     protected internal virtual IAnalyzerModel CreateLRModel(IScope bestModelScope) {
    276       IAnalyzerModel model = new AnalyzerModel();
    277       model.Predictor = bestModelScope.GetVariableValue<IPredictor>("Predictor", true);
    278       model.SetResult("TrainingMeanSquaredError", bestModelScope.GetVariableValue<DoubleData>("TrainingQuality", false).Data);
    279       model.SetResult("ValidationMeanSquaredError", bestModelScope.GetVariableValue<DoubleData>("ValidationQuality", false).Data);
    280       model.SetResult("TestMeanSquaredError", bestModelScope.GetVariableValue<DoubleData>("TestQuality", false).Data);
    281       model.SetResult("TrainingCoefficientOfDetermination", bestModelScope.GetVariableValue<DoubleData>("TrainingR2", false).Data);
    282       model.SetResult("ValidationCoefficientOfDetermination", bestModelScope.GetVariableValue<DoubleData>("ValidationR2", false).Data);
    283       model.SetResult("TestCoefficientOfDetermination", bestModelScope.GetVariableValue<DoubleData>("TestR2", false).Data);
    284       model.SetResult("TrainingMeanAbsolutePercentageError", bestModelScope.GetVariableValue<DoubleData>("TrainingMAPE", false).Data);
    285       model.SetResult("ValidationMeanAbsolutePercentageError", bestModelScope.GetVariableValue<DoubleData>("ValidationMAPE", false).Data);
    286       model.SetResult("TestMeanAbsolutePercentageError", bestModelScope.GetVariableValue<DoubleData>("TestMAPE", false).Data);
    287       model.SetResult("TrainingMeanAbsolutePercentageOfRangeError", bestModelScope.GetVariableValue<DoubleData>("TrainingMAPRE", false).Data);
    288       model.SetResult("ValidationMeanAbsolutePercentageOfRangeError", bestModelScope.GetVariableValue<DoubleData>("ValidationMAPRE", false).Data);
    289       model.SetResult("TestMeanAbsolutePercentageOfRangeError", bestModelScope.GetVariableValue<DoubleData>("TestMAPRE", false).Data);
    290       model.SetResult("TrainingVarianceAccountedFor", bestModelScope.GetVariableValue<DoubleData>("TrainingVAF", false).Data);
    291       model.SetResult("ValidationVarianceAccountedFor", bestModelScope.GetVariableValue<DoubleData>("ValidationVAF", false).Data);
    292       model.SetResult("TestVarianceAccountedFor", bestModelScope.GetVariableValue<DoubleData>("TestVAF", false).Data);
    293 
    294       IGeneticProgrammingModel gpModel = bestModelScope.GetVariableValue<IGeneticProgrammingModel>("LinearRegressionModel", false);
    295       model.SetMetaData("TreeSize", gpModel.Size);
    296       model.SetMetaData("TreeHeight", gpModel.Height);
    297 
    298       HeuristicLab.DataAnalysis.Dataset ds = bestModelScope.GetVariableValue<Dataset>("Dataset", true);
    299       model.Dataset = ds;
    300       model.TargetVariable = ds.GetVariableName(bestModelScope.GetVariableValue<IntData>("TargetVariable", true).Data);
    301       model.TrainingSamplesStart = bestModelScope.GetVariableValue<IntData>("TrainingSamplesStart", true).Data;
    302       model.TrainingSamplesEnd = bestModelScope.GetVariableValue<IntData>("TrainingSamplesEnd", true).Data;
    303       model.ValidationSamplesStart = bestModelScope.GetVariableValue<IntData>("ValidationSamplesStart", true).Data;
    304       model.ValidationSamplesEnd = bestModelScope.GetVariableValue<IntData>("ValidationSamplesEnd", true).Data;
    305       model.TestSamplesStart = bestModelScope.GetVariableValue<IntData>("TestSamplesStart", true).Data;
    306       model.TestSamplesEnd = bestModelScope.GetVariableValue<IntData>("TestSamplesEnd", true).Data;
    307 
    308       ItemList evaluationImpacts = bestModelScope.GetVariableValue<ItemList>("VariableEvaluationImpacts", false);
    309       ItemList qualityImpacts = bestModelScope.GetVariableValue<ItemList>("VariableQualityImpacts", false);
    310       foreach (ItemList row in evaluationImpacts) {
    311         string variableName = ((StringData)row[0]).Data;
    312         double impact = ((DoubleData)row[1]).Data;
    313         model.SetVariableEvaluationImpact(variableName, impact);
    314         model.AddInputVariable(variableName);
    315       }
    316       foreach (ItemList row in qualityImpacts) {
    317         string variableName = ((StringData)row[0]).Data;
    318         double impact = ((DoubleData)row[1]).Data;
    319         model.SetVariableQualityImpact(variableName, impact);
    320         model.AddInputVariable(variableName);
    321       }
    322 
    323       return model;
     143    protected virtual IAnalyzerModel CreateLRModel(IScope bestModelScope) {
     144      return DefaultStructureIdentificationAlgorithmOperators.CreateGPModel(bestModelScope);
    324145    }
    325146
    326     private IOperator GetMainOperator() {
     147    protected virtual IOperator GetMainOperator() {
    327148      CombinedOperator lr = (CombinedOperator)Engine.OperatorGraph.InitialOperator;
    328149      return lr.OperatorGraph.InitialOperator;
     
    335156    #region IEditable Members
    336157
    337     public IEditor CreateEditor() {
     158    public virtual IEditor CreateEditor() {
    338159      return engine.CreateEditor();
    339160    }
Note: See TracChangeset for help on using the changeset viewer.