Free cookie consent management tool by TermsFeed Policy Generator

Changeset 3858


Ignore:
Timestamp:
05/20/10 16:47:12 (14 years ago)
Author:
mkommend
Message:

added calculation and view for support vectors (ticket #1009)

Location:
trunk/sources
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.ExtLibs/HeuristicLab.LibSVM/1.6.3/LibSVM-1.6.3/Model.cs

    r2645 r3858  
    3333    private int _numberOfClasses;
    3434    private int _supportVectorCount;
     35    private int[] _supportVectorIndizes;
    3536    private Node[][] _supportVectors;
    3637    private double[][] _supportVectorCoefficients;
     
    7879      set {
    7980        _supportVectorCount = value;
     81      }
     82    }
     83
     84    /// <summary>
     85    /// Indizes of support vectors identified in the training.
     86    /// </summary>
     87    public int[] SupportVectorIndizes {
     88      get {
     89        return _supportVectorIndizes;
     90      }
     91      set {
     92        _supportVectorIndizes = value;
    8093      }
    8194    }
  • trunk/sources/HeuristicLab.ExtLibs/HeuristicLab.LibSVM/1.6.3/LibSVM-1.6.3/Solver.cs

    r2645 r3858  
    16731673                    if (Math.Abs(f.alpha[i]) > 0) ++nSV;               
    16741674                model.SupportVectorCount = nSV;
     1675                model.SupportVectorIndizes = new int[nSV];
    16751676                model.SupportVectors = new Node[nSV][];
    16761677                model.SupportVectorCoefficients[0] = new double[nSV];
     1678               
    16771679                int j = 0;
    16781680                for (i = 0; i < prob.Count; i++)
     
    16801682                    {
    16811683                        model.SupportVectors[j] = prob.X[i];
     1684                        model.SupportVectorIndizes[j] = i;
    16821685                        model.SupportVectorCoefficients[0][j] = f.alpha[i];
     1686                       
    16831687                        ++j;
    16841688                    }
     
    18201824                model.SupportVectorCount = nnz;
    18211825                model.SupportVectors = new Node[nnz][];
     1826                model.SupportVectorIndizes = new int[nnz];
    18221827                p = 0;
    1823                 for (i = 0; i < l; i++)
    1824                     if (nonzero[i]) model.SupportVectors[p++] = x[i];
     1828                for (i = 0; i < l; i++) {
     1829                  if (nonzero[i]) {
     1830                    model.SupportVectors[p] = x[i];
     1831                    model.SupportVectorIndizes[p] = i;
     1832                    p++;
     1833                  }
     1834                }
    18251835
    18261836                int[] nz_start = new int[nr_class];
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/SupportVectorRegression/SupportVectorRegressionSolution.cs

    r3842 r3858  
    4949    }
    5050
    51     [Storable]
    52     private List<string> inputVariables;
     51    public Dataset SupportVectors {
     52      get { return CalculateSupportVectors(); }
     53    }
    5354
    5455    public SupportVectorRegressionSolution() : base() { }
     
    5657      : base(problemData, lowerEstimationLimit, upperEstimationLimit) {
    5758      this.model = model;
    58       this.inputVariables = new List<string>(inputVariables);
    5959    }
    6060
    6161    protected override void OnProblemDataChanged(EventArgs e) {
    6262      RecalculateEstimatedValues();
     63      model.Model.SupportVectorIndizes = new int[0];
     64    }
     65
     66    private Dataset CalculateSupportVectors() {
     67      if (model.Model.SupportVectorIndizes.Length == 0)
     68        return new Dataset();
     69
     70      Dataset dataset = new Dataset(ProblemData.Dataset.VariableNames, new double[model.Model.SupportVectorCount, ProblemData.Dataset.Columns]);
     71      for (int i = 0; i < model.Model.SupportVectorIndizes.Length; i++) {
     72        for (int column = 0; column < ProblemData.Dataset.Columns; column++)
     73          dataset[i, column] = ProblemData.Dataset[model.Model.SupportVectorIndizes[i], column];
     74      }
     75      return dataset;
    6376    }
    6477
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.3/SupportVectorRegressionSolutionView.Designer.cs

    r3853 r3858  
    4646      this.modelTabControl = new System.Windows.Forms.TabControl();
    4747      this.modelTabPage = new System.Windows.Forms.TabPage();
     48      this.modelPanel = new HeuristicLab.MainForm.WindowsForms.ViewHost();
    4849      this.dataTabPage = new System.Windows.Forms.TabPage();
    49       this.modelPanel = new HeuristicLab.MainForm.WindowsForms.ViewHost();
    5050      this.dataPanel = new HeuristicLab.MainForm.WindowsForms.ViewHost();
     51      this.supportVectorTabControl = new System.Windows.Forms.TabPage();
     52      this.supportVectorViewHost = new HeuristicLab.MainForm.WindowsForms.ViewHost();
    5153      this.modelTabControl.SuspendLayout();
    5254      this.modelTabPage.SuspendLayout();
    5355      this.dataTabPage.SuspendLayout();
     56      this.supportVectorTabControl.SuspendLayout();
    5457      this.SuspendLayout();
    5558      //
     
    6164      this.modelTabControl.Controls.Add(this.modelTabPage);
    6265      this.modelTabControl.Controls.Add(this.dataTabPage);
     66      this.modelTabControl.Controls.Add(this.supportVectorTabControl);
    6367      this.modelTabControl.Location = new System.Drawing.Point(3, 3);
    6468      this.modelTabControl.Name = "modelTabControl";
     
    7882      this.modelTabPage.UseVisualStyleBackColor = true;
    7983      //
     84      // modelPanel
     85      //
     86      this.modelPanel.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
     87                  | System.Windows.Forms.AnchorStyles.Left)
     88                  | System.Windows.Forms.AnchorStyles.Right)));
     89      this.modelPanel.Caption = "View";
     90      this.modelPanel.Content = null;
     91      this.modelPanel.Location = new System.Drawing.Point(6, 6);
     92      this.modelPanel.Name = "modelPanel";
     93      this.modelPanel.ReadOnly = false;
     94      this.modelPanel.Size = new System.Drawing.Size(227, 207);
     95      this.modelPanel.TabIndex = 0;
     96      this.modelPanel.ViewType = null;
     97      //
    8098      // dataTabPage
    8199      //
     
    89107      this.dataTabPage.UseVisualStyleBackColor = true;
    90108      //
    91       // modelPanel
    92       //
    93       this.modelPanel.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    94                   | System.Windows.Forms.AnchorStyles.Left)
    95                   | System.Windows.Forms.AnchorStyles.Right)));
    96       this.modelPanel.Location = new System.Drawing.Point(6, 6);
    97       this.modelPanel.Name = "modelPanel";
    98       this.modelPanel.Size = new System.Drawing.Size(227, 207);
    99       this.modelPanel.TabIndex = 0;
    100       //
    101109      // dataPanel
    102110      //
     
    104112                  | System.Windows.Forms.AnchorStyles.Left)
    105113                  | System.Windows.Forms.AnchorStyles.Right)));
     114      this.dataPanel.Caption = "View";
     115      this.dataPanel.Content = null;
    106116      this.dataPanel.Location = new System.Drawing.Point(6, 6);
    107117      this.dataPanel.Name = "dataPanel";
     118      this.dataPanel.ReadOnly = false;
    108119      this.dataPanel.Size = new System.Drawing.Size(227, 207);
    109120      this.dataPanel.TabIndex = 0;
     121      this.dataPanel.ViewType = null;
     122      //
     123      // supportVectorTabControl
     124      //
     125      this.supportVectorTabControl.Controls.Add(this.supportVectorViewHost);
     126      this.supportVectorTabControl.Location = new System.Drawing.Point(4, 22);
     127      this.supportVectorTabControl.Name = "supportVectorTabControl";
     128      this.supportVectorTabControl.Padding = new System.Windows.Forms.Padding(3);
     129      this.supportVectorTabControl.Size = new System.Drawing.Size(239, 219);
     130      this.supportVectorTabControl.TabIndex = 2;
     131      this.supportVectorTabControl.Text = "Support vectors";
     132      this.supportVectorTabControl.UseVisualStyleBackColor = true;
     133      //
     134      // supportVectorViewHost
     135      //
     136      this.supportVectorViewHost.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
     137                  | System.Windows.Forms.AnchorStyles.Left)
     138                  | System.Windows.Forms.AnchorStyles.Right)));
     139      this.supportVectorViewHost.Caption = "SupportVectors";
     140      this.supportVectorViewHost.Content = null;
     141      this.supportVectorViewHost.Location = new System.Drawing.Point(6, 6);
     142      this.supportVectorViewHost.Name = "supportVectorViewHost";
     143      this.supportVectorViewHost.ReadOnly = false;
     144      this.supportVectorViewHost.Size = new System.Drawing.Size(227, 207);
     145      this.supportVectorViewHost.TabIndex = 1;
     146      this.supportVectorViewHost.ViewType = null;
    110147      //
    111148      // SupportVectorRegressionSolutionView
     
    120157      this.modelTabPage.ResumeLayout(false);
    121158      this.dataTabPage.ResumeLayout(false);
     159      this.supportVectorTabControl.ResumeLayout(false);
    122160      this.ResumeLayout(false);
    123161
     
    131169    private System.Windows.Forms.TabPage dataTabPage;
    132170    private HeuristicLab.MainForm.WindowsForms.ViewHost dataPanel;
     171    private System.Windows.Forms.TabPage supportVectorTabControl;
     172    private HeuristicLab.MainForm.WindowsForms.ViewHost supportVectorViewHost;
    133173
    134174
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.3/SupportVectorRegressionSolutionView.cs

    r3855 r3858  
    5959        dataPanel.Content = Content.ProblemData;
    6060        modelPanel.Content = Content.Model;
     61        supportVectorViewHost.Content = Content.SupportVectors;
    6162      } else {
    6263        dataPanel.Content = null;
    6364        modelPanel.Content = null;
     65        supportVectorViewHost.Content = null;
    6466      }
    6567    }
Note: See TracChangeset for help on using the changeset viewer.