Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/15/09 16:46:25 (15 years ago)
Author:
gkronber
Message:

Added variable impact calculation operators for support vector machines. #644 (Variable impact of CEDMA models should be calculated and stored in the result DB)

File:
1 edited

Legend:

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

    r1922 r2043  
    3434using HeuristicLab.Operators.Programmable;
    3535using HeuristicLab.Modeling;
     36using HeuristicLab.Random;
     37using HeuristicLab.Selection;
    3638
    3739namespace HeuristicLab.SupportVectorMachines {
     
    118120      main.AddSubOperator(CreateGlobalInjector());
    119121      main.AddSubOperator(new ProblemInjector());
    120 
    121       SequentialProcessor nuLoop = new SequentialProcessor();
    122       nuLoop.Name = "NuLoop";
    123       SequentialProcessor costLoop = new SequentialProcessor();
    124       costLoop.Name = "CostLoop";
    125       main.AddSubOperator(nuLoop);
    126       nuLoop.AddSubOperator(CreateResetOperator("CostIndex"));
    127       nuLoop.AddSubOperator(costLoop);
     122      main.AddSubOperator(new RandomInjector());
     123
    128124      SubScopesCreater modelScopeCreator = new SubScopesCreater();
    129125      modelScopeCreator.GetVariableInfo("SubScopes").Local = true;
    130126      modelScopeCreator.AddVariable(new HeuristicLab.Core.Variable("SubScopes", new IntData(1)));
     127      main.AddSubOperator(modelScopeCreator);
     128
     129      SequentialSubScopesProcessor seqSubScopesProc = new SequentialSubScopesProcessor();
     130      IOperator modelProcessor = CreateModelProcessor();
     131      seqSubScopesProc.AddSubOperator(modelProcessor);
     132      main.AddSubOperator(seqSubScopesProc);
     133
     134      SequentialProcessor nuLoop = new SequentialProcessor();
     135      nuLoop.Name = "NuLoop";
     136
     137      IOperator costCounter = CreateCounter("Cost");
     138      IOperator costComparator = CreateComparator("Cost");
     139      nuLoop.AddSubOperator(costCounter);
     140      nuLoop.AddSubOperator(costComparator);
     141      ConditionalBranch costBranch = new ConditionalBranch();
     142      costBranch.Name = "IfValidCostIndex";
     143      costBranch.GetVariableInfo("Condition").ActualName = "RepeatCostLoop";
     144
     145      // build cost loop
     146      SequentialProcessor costLoop = new SequentialProcessor();
     147      costLoop.Name = "CostLoop";
    131148      costLoop.AddSubOperator(modelScopeCreator);
    132149      SequentialSubScopesProcessor subScopesProcessor = new SequentialSubScopesProcessor();
    133150      costLoop.AddSubOperator(subScopesProcessor);
     151      subScopesProcessor.AddSubOperator(new EmptyOperator());
     152      subScopesProcessor.AddSubOperator(modelProcessor);
     153
     154      Sorter sorter = new Sorter();
     155      sorter.GetVariableInfo("Value").ActualName = "ValidationQuality";
     156      sorter.GetVariableInfo("Descending").Local = true;
     157      sorter.AddVariable(new Variable("Descending", new BoolData(false)));
     158      costLoop.AddSubOperator(sorter);
     159
     160      LeftSelector selector = new LeftSelector();
     161      selector.GetVariableInfo("Selected").Local = true;
     162      selector.AddVariable(new Variable("Selected", new IntData(1)));
     163      costLoop.AddSubOperator(selector);
     164
     165      RightReducer reducer = new RightReducer();
     166      costLoop.AddSubOperator(reducer);
     167
     168      costLoop.AddSubOperator(costCounter);
     169      costLoop.AddSubOperator(costComparator);
     170
     171      costBranch.AddSubOperator(costLoop);
     172      costLoop.AddSubOperator(costBranch);
     173
     174      nuLoop.AddSubOperator(costBranch);
     175      nuLoop.AddSubOperator(CreateResetOperator("CostIndex"));
     176
     177      nuLoop.AddSubOperator(CreateCounter("Nu"));
     178      nuLoop.AddSubOperator(CreateComparator("Nu"));
     179
     180      ConditionalBranch nuBranch = new ConditionalBranch();
     181      nuBranch.Name = "NuLoop";
     182      nuBranch.GetVariableInfo("Condition").ActualName = "RepeatNuLoop";
     183      nuBranch.AddSubOperator(nuLoop);
     184      nuLoop.AddSubOperator(nuBranch);
     185
     186      main.AddSubOperator(nuLoop);
     187      main.AddSubOperator(CreateModelAnalyser());
     188      return main;
     189    }
     190
     191    private IOperator CreateModelProcessor() {
    134192      SequentialProcessor modelProcessor = new SequentialProcessor();
    135       subScopesProcessor.AddSubOperator(modelProcessor);
    136193      modelProcessor.AddSubOperator(CreateSetNextParameterValueOperator("Nu"));
    137194      modelProcessor.AddSubOperator(CreateSetNextParameterValueOperator("Cost"));
     
    160217      ((ItemList<StringData>)collector.GetVariable("VariableNames").Value).Add(new StringData("ValidationQuality"));
    161218      modelProcessor.AddSubOperator(collector);
    162 
    163       BestSolutionStorer solStorer = new BestSolutionStorer();
    164       solStorer.GetVariableInfo("Quality").ActualName = "ValidationQuality";
    165       solStorer.GetVariableInfo("Maximization").Local = true;
    166       solStorer.GetVariableInfo("BestSolution").ActualName = "BestValidationSolution";
    167       solStorer.AddVariable(new HeuristicLab.Core.Variable("Maximization", new BoolData(false)));
    168 
    169       costLoop.AddSubOperator(solStorer);
    170       SubScopesRemover remover = new SubScopesRemover();
    171       costLoop.AddSubOperator(remover);
    172       costLoop.AddSubOperator(CreateCounter("Cost"));
    173       costLoop.AddSubOperator(CreateComparator("Cost"));
    174       ConditionalBranch costBranch = new ConditionalBranch();
    175       costBranch.Name = "CostLoop";
    176       costBranch.GetVariableInfo("Condition").ActualName = "RepeatCostLoop";
    177       costBranch.AddSubOperator(costLoop);
    178       costLoop.AddSubOperator(costBranch);
    179 
    180       nuLoop.AddSubOperator(CreateCounter("Nu"));
    181       nuLoop.AddSubOperator(CreateComparator("Nu"));
    182       ConditionalBranch nuBranch = new ConditionalBranch();
    183       nuBranch.Name = "NuLoop";
    184       nuBranch.GetVariableInfo("Condition").ActualName = "RepeatNuLoop";
    185       nuBranch.AddSubOperator(nuLoop);
    186       nuLoop.AddSubOperator(nuBranch);
    187       return main;
     219      return modelProcessor;
    188220    }
    189221
     
    271303      progOp.RemoveVariableInfo("Result");
    272304      progOp.AddVariableInfo(new VariableInfo("Value", "Value", typeof(IntData), VariableKind.In | VariableKind.Out));
    273       progOp.Code = "Value.Data = 0;";
     305      progOp.Code = "Value.Data = -1;";
    274306      progOp.GetVariableInfo("Value").ActualName = paramName;
    275307      return progOp;
     
    279311      VariableInjector injector = new VariableInjector();
    280312      injector.AddVariable(new HeuristicLab.Core.Variable("CostIndex", new IntData(0)));
    281       injector.AddVariable(new HeuristicLab.Core.Variable("CostList", new DoubleArrayData(new double[] { 0.1, 0.25, 0.5, 1.0, 2.0, 4.0, 8.0, 16.0, 32.0, 64.0, 128.0 })));
     313      injector.AddVariable(new HeuristicLab.Core.Variable("CostList", new DoubleArrayData(new double[] { 0.1, 0.25, 0.5, 1.0, 2.0, 4.0, 8.0 })));
    282314      injector.AddVariable(new HeuristicLab.Core.Variable("MaxCostIndex", new IntData()));
    283315      injector.AddVariable(new HeuristicLab.Core.Variable("NuIndex", new IntData(0)));
    284       injector.AddVariable(new HeuristicLab.Core.Variable("NuList", new DoubleArrayData(new double[] { 0.01, 0.05, 0.1, 0.5, 0.9 })));
     316      injector.AddVariable(new HeuristicLab.Core.Variable("NuList", new DoubleArrayData(new double[] { 0.01, 0.05, 0.1, 0.5 })));
    285317      injector.AddVariable(new HeuristicLab.Core.Variable("MaxNuIndex", new IntData()));
    286318      injector.AddVariable(new HeuristicLab.Core.Variable("Log", new ItemList()));
     
    291323      return injector;
    292324    }
     325
     326    private IOperator CreateModelAnalyser() {
     327      CombinedOperator modelAnalyser = new CombinedOperator();
     328      modelAnalyser.Name = "Model Analyzer";
     329      SequentialSubScopesProcessor seqSubScopeProc = new SequentialSubScopesProcessor();
     330      SequentialProcessor seqProc = new SequentialProcessor();
     331      VariableEvaluationImpactCalculator evalImpactCalc = new VariableEvaluationImpactCalculator();
     332      evalImpactCalc.GetVariableInfo("SVMModel").ActualName = "Model";
     333      VariableQualityImpactCalculator qualImpactCalc = new VariableQualityImpactCalculator();
     334      qualImpactCalc.GetVariableInfo("SVMModel").ActualName = "Model";
     335
     336      seqProc.AddSubOperator(evalImpactCalc);
     337      seqProc.AddSubOperator(qualImpactCalc);
     338      seqSubScopeProc.AddSubOperator(seqProc);
     339      modelAnalyser.OperatorGraph.InitialOperator = seqSubScopeProc;
     340      modelAnalyser.OperatorGraph.AddOperator(seqSubScopeProc);
     341      return modelAnalyser;
     342    }
     343
    293344
    294345    protected internal virtual Model CreateSVMModel(IScope bestModelScope) {
     
    309360      model.ValidationVarianceAccountedFor = bestModelScope.GetVariableValue<DoubleData>("ValidationVAF", false).Data;
    310361      model.TestVarianceAccountedFor = bestModelScope.GetVariableValue<DoubleData>("TestVAF", false).Data;
    311      
     362
    312363      model.Data = bestModelScope.GetVariableValue<SVMModel>("BestValidationModel", false);
    313364      HeuristicLab.DataAnalysis.Dataset ds = bestModelScope.GetVariableValue<Dataset>("Dataset", true);
    314365      model.Dataset = ds;
    315366      model.TargetVariable = ds.GetVariableName(bestModelScope.GetVariableValue<IntData>("TargetVariable", true).Data);
     367
     368      ItemList evaluationImpacts = bestModelScope.GetVariableValue<ItemList>("VariableEvaluationImpacts", false);
     369      ItemList qualityImpacts = bestModelScope.GetVariableValue<ItemList>("VariableQualityImpacts", false);
     370      foreach (ItemList row in evaluationImpacts) {
     371        string variableName = ((StringData)row[0]).Data;
     372        double impact = ((DoubleData)row[0]).Data;
     373        model.SetVariableEvaluationImpact(variableName, impact);
     374      }
     375      foreach (ItemList row in qualityImpacts) {
     376        string variableName = ((StringData)row[0]).Data;
     377        double impact = ((DoubleData)row[0]).Data;
     378        model.SetVariableQualityImpact(variableName, impact);
     379      }
     380
    316381      return model;
    317382    }
     
    337402
    338403    #endregion
    339 
    340404  }
    341405}
Note: See TracChangeset for help on using the changeset viewer.