SHOGUN  v2.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SparseInverseCovariance.cpp
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 3 of the License, or
5  * (at your option) any later version.
6  *
7  * Copyright (C) 2009-2011 Jun Liu, Jieping Ye
8  * Copyright (C) 2012 Sergey Lisitsyn
9  */
10 
12 #include <shogun/base/Parameter.h>
14 
15 using namespace shogun;
16 
18  CSGObject(), m_lasso_max_iter(1000),
19  m_max_iter(1000), m_f_gap(1e-6), m_x_gap(1e-4),
20  m_xtol(1e-4)
21 {
22  register_parameters();
23 }
24 
26 {
27 }
28 
29 void CSparseInverseCovariance::register_parameters()
30 {
31  SG_ADD(&m_lasso_max_iter,"lasso_max_iter",
32  "maximum iteration of LASSO step",MS_NOT_AVAILABLE);
33  SG_ADD(&m_max_iter,"max_iter","maximum total iteration",
35  SG_ADD(&m_f_gap,"f_gap","f gap",MS_NOT_AVAILABLE);
36  SG_ADD(&m_x_gap,"x_gap","x gap",MS_NOT_AVAILABLE);
37  SG_ADD(&m_xtol,"xtol","xtol",MS_NOT_AVAILABLE);
38 }
39 
41 {
42  ASSERT(S.num_cols==S.num_rows);
43 
44  int32_t n = S.num_cols;
45  float64_t sum_S = 0.0;
46  for (int32_t i=0; i<n; i++)
47  sum_S += S(i,i);
48 
49  float64_t* Theta = SG_CALLOC(float64_t, n*n);
50  float64_t* W = SG_CALLOC(float64_t, n*n);
51 
52  invCov(Theta, W, S.matrix, lambda_c, sum_S, n, m_lasso_max_iter,
54 
55  SG_FREE(W);
56  return SGMatrix<float64_t>(Theta,n,n);
57 }

SHOGUN Machine Learning Toolbox - Documentation