Free cookie consent management tool by TermsFeed Policy Generator

Changeset 2126


Ignore:
Timestamp:
07/01/09 21:32:22 (15 years ago)
Author:
gkronber
Message:

Implemented #682 (nu-SVR engine should also try to find the best value for the parameter gamma).

File:
1 edited

Legend:

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

    r2055 r2126  
    9898    }
    9999
     100    public DoubleArrayData GammaList {
     101      get { return GetVariableInjector().GetVariable("GammaList").GetValue<DoubleArrayData>(); }
     102      set { GetVariableInjector().GetVariable("GammaList").Value = value; }
     103    }
     104
     105    public int MaxGammaIndex {
     106      get { return GetVariableInjector().GetVariable("MaxGammaIndex").GetValue<IntData>().Data; }
     107      set { GetVariableInjector().GetVariable("MaxGammaIndex").GetValue<IntData>().Data = value; }
     108    }
     109
    100110    public SupportVectorRegression() {
    101111      engine = new SequentialEngine.SequentialEngine();
     
    105115      MaxCostIndex = CostList.Data.Length;
    106116      MaxNuIndex = NuList.Data.Length;
     117      MaxGammaIndex = GammaList.Data.Length;
    107118    }
    108119
    109120    private CombinedOperator CreateAlgorithm() {
    110121      CombinedOperator algo = new CombinedOperator();
     122      SequentialProcessor seq = new SequentialProcessor();
    111123      algo.Name = "SupportVectorRegression";
     124      seq.Name = "SupportVectorRegression";
     125
     126      IOperator initialization = CreateInitialization();
    112127      IOperator main = CreateMainLoop();
    113       algo.OperatorGraph.AddOperator(main);
    114       algo.OperatorGraph.InitialOperator = main;
     128      IOperator postProc = CreateModelAnalyser();
     129
     130      seq.AddSubOperator(initialization);
     131      seq.AddSubOperator(main);
     132      seq.AddSubOperator(postProc);
     133
     134      algo.OperatorGraph.InitialOperator = seq;
     135      algo.OperatorGraph.AddOperator(seq);
     136
    115137      return algo;
     138    }
     139
     140    private IOperator CreateInitialization() {
     141      SequentialProcessor seq = new SequentialProcessor();
     142      seq.Name = "Initialization";
     143      seq.AddSubOperator(CreateGlobalInjector());
     144      seq.AddSubOperator(new ProblemInjector());
     145      seq.AddSubOperator(new RandomInjector());
     146      return seq;
    116147    }
    117148
    118149    private IOperator CreateMainLoop() {
    119150      SequentialProcessor main = new SequentialProcessor();
    120       main.AddSubOperator(CreateGlobalInjector());
    121       main.AddSubOperator(new ProblemInjector());
    122       main.AddSubOperator(new RandomInjector());
    123 
     151      main.Name = "Main";
     152      #region initial solution
    124153      SubScopesCreater modelScopeCreator = new SubScopesCreater();
    125154      modelScopeCreator.GetVariableInfo("SubScopes").Local = true;
    126155      modelScopeCreator.AddVariable(new HeuristicLab.Core.Variable("SubScopes", new IntData(1)));
    127156      main.AddSubOperator(modelScopeCreator);
    128 
     157     
    129158      SequentialSubScopesProcessor seqSubScopesProc = new SequentialSubScopesProcessor();
    130159      IOperator modelProcessor = CreateModelProcessor();
     160
    131161      seqSubScopesProc.AddSubOperator(modelProcessor);
    132162      main.AddSubOperator(seqSubScopesProc);
     163      #endregion
    133164
    134165      SequentialProcessor nuLoop = new SequentialProcessor();
    135166      nuLoop.Name = "NuLoop";
    136167
     168      SequentialProcessor gammaLoop = new SequentialProcessor();
     169      gammaLoop.Name = "GammaLoop";
     170
     171      nuLoop.AddSubOperator(gammaLoop);
     172
    137173      IOperator costCounter = CreateCounter("Cost");
    138174      IOperator costComparator = CreateComparator("Cost");
    139       nuLoop.AddSubOperator(costCounter);
    140       nuLoop.AddSubOperator(costComparator);
     175      gammaLoop.AddSubOperator(costCounter);
     176      gammaLoop.AddSubOperator(costComparator);
     177
    141178      ConditionalBranch costBranch = new ConditionalBranch();
    142179      costBranch.Name = "IfValidCostIndex";
     
    146183      SequentialProcessor costLoop = new SequentialProcessor();
    147184      costLoop.Name = "CostLoop";
     185
     186      #region selection of better solution
    148187      costLoop.AddSubOperator(modelScopeCreator);
    149188      SequentialSubScopesProcessor subScopesProcessor = new SequentialSubScopesProcessor();
     
    165204      RightReducer reducer = new RightReducer();
    166205      costLoop.AddSubOperator(reducer);
     206      #endregion
    167207
    168208      costLoop.AddSubOperator(costCounter);
     
    172212      costLoop.AddSubOperator(costBranch);
    173213
    174       nuLoop.AddSubOperator(costBranch);
    175       nuLoop.AddSubOperator(CreateResetOperator("CostIndex"));
     214      gammaLoop.AddSubOperator(costBranch); // inner loop
     215      gammaLoop.AddSubOperator(CreateResetOperator("CostIndex", -1));
     216      gammaLoop.AddSubOperator(CreateCounter("Gamma"));
     217      gammaLoop.AddSubOperator(CreateComparator("Gamma"));
     218
     219      ConditionalBranch gammaBranch = new ConditionalBranch();
     220      gammaBranch.Name = "GammaLoop";
     221      gammaBranch.GetVariableInfo("Condition").ActualName = "RepeatGammaLoop";
     222      gammaBranch.AddSubOperator(gammaLoop);
     223      gammaLoop.AddSubOperator(gammaBranch);
     224
     225      nuLoop.AddSubOperator(CreateResetOperator("GammaIndex", 0));
    176226
    177227      nuLoop.AddSubOperator(CreateCounter("Nu"));
     
    181231      nuBranch.Name = "NuLoop";
    182232      nuBranch.GetVariableInfo("Condition").ActualName = "RepeatNuLoop";
     233     
    183234      nuBranch.AddSubOperator(nuLoop);
    184235      nuLoop.AddSubOperator(nuBranch);
    185236
    186237      main.AddSubOperator(nuLoop);
    187       main.AddSubOperator(CreateModelAnalyser());
    188238      return main;
    189239    }
     
    193243      modelProcessor.AddSubOperator(CreateSetNextParameterValueOperator("Nu"));
    194244      modelProcessor.AddSubOperator(CreateSetNextParameterValueOperator("Cost"));
     245      modelProcessor.AddSubOperator(CreateSetNextParameterValueOperator("Gamma"));
    195246
    196247      SupportVectorCreator modelCreator = new SupportVectorCreator();
     
    215266      ((ItemList<StringData>)collector.GetVariable("VariableNames").Value).Add(new StringData("Nu"));
    216267      ((ItemList<StringData>)collector.GetVariable("VariableNames").Value).Add(new StringData("Cost"));
     268      ((ItemList<StringData>)collector.GetVariable("VariableNames").Value).Add(new StringData("Gamma"));
    217269      ((ItemList<StringData>)collector.GetVariable("VariableNames").Value).Add(new StringData("ValidationQuality"));
    218270      modelProcessor.AddSubOperator(collector);
     
    298350    }
    299351
    300     private IOperator CreateResetOperator(string paramName) {
     352    private IOperator CreateResetOperator(string paramName, int value) {
    301353      ProgrammableOperator progOp = new ProgrammableOperator();
    302354      progOp.Name = "Reset" + paramName;
    303355      progOp.RemoveVariableInfo("Result");
    304356      progOp.AddVariableInfo(new VariableInfo("Value", "Value", typeof(IntData), VariableKind.In | VariableKind.Out));
    305       progOp.Code = "Value.Data = -1;";
     357      progOp.Code = "Value.Data = "+value+";";
    306358      progOp.GetVariableInfo("Value").ActualName = paramName;
    307359      return progOp;
     
    311363      VariableInjector injector = new VariableInjector();
    312364      injector.AddVariable(new HeuristicLab.Core.Variable("CostIndex", new IntData(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 })));
     365      injector.AddVariable(new HeuristicLab.Core.Variable("CostList", new DoubleArrayData(new double[] {
     366        Math.Pow(2,-5),
     367        Math.Pow(2,-3),
     368        Math.Pow(2,-1),
     369        2,
     370        Math.Pow(2,3),
     371        Math.Pow(2,5),
     372        Math.Pow(2,7),
     373        Math.Pow(2,9),
     374        Math.Pow(2,11),
     375        Math.Pow(2,13),
     376        Math.Pow(2,15)})));
    314377      injector.AddVariable(new HeuristicLab.Core.Variable("MaxCostIndex", new IntData()));
    315378      injector.AddVariable(new HeuristicLab.Core.Variable("NuIndex", new IntData(0)));
    316       injector.AddVariable(new HeuristicLab.Core.Variable("NuList", new DoubleArrayData(new double[] { 0.01, 0.05, 0.1, 0.5 })));
     379      injector.AddVariable(new HeuristicLab.Core.Variable("NuList", new DoubleArrayData(new double[] { 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.9, 0.8, 1 })));
    317380      injector.AddVariable(new HeuristicLab.Core.Variable("MaxNuIndex", new IntData()));
    318381      injector.AddVariable(new HeuristicLab.Core.Variable("Log", new ItemList()));
    319       injector.AddVariable(new HeuristicLab.Core.Variable("Gamma", new DoubleData(1)));
     382      injector.AddVariable(new HeuristicLab.Core.Variable("GammaIndex", new IntData(0)));
     383      injector.AddVariable(new HeuristicLab.Core.Variable("GammaList", new DoubleArrayData(new double[] {
     384        3.0517578125E-05, 0.0001220703125,0.00048828125,0.001953125,
     385        0.0078125,0.03125,0.125,0.5,2,4,8})));
     386      injector.AddVariable(new HeuristicLab.Core.Variable("MaxGammaIndex", new IntData()));
    320387      injector.AddVariable(new HeuristicLab.Core.Variable("KernelType", new StringData("RBF")));
    321388      injector.AddVariable(new HeuristicLab.Core.Variable("Type", new StringData("NU_SVR")));
     
    383450
    384451    private IOperator GetVariableInjector() {
    385       return GetMainOperator().SubOperators[0];
     452      return GetMainOperator().SubOperators[0].SubOperators[0];
    386453    }
    387454
Note: See TracChangeset for help on using the changeset viewer.