SHOGUN  4.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules 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 
11 
13 #ifdef USE_GPL_SHOGUN
14 #include <shogun/base/Parameter.h>
16 
17 using namespace shogun;
18 
19 CSparseInverseCovariance::CSparseInverseCovariance() :
20  CSGObject(), m_lasso_max_iter(1000),
21  m_max_iter(1000), m_f_gap(1e-6), m_x_gap(1e-4),
22  m_xtol(1e-4)
23 {
24  register_parameters();
25 }
26 
27 CSparseInverseCovariance::~CSparseInverseCovariance()
28 {
29 }
30 
31 void CSparseInverseCovariance::register_parameters()
32 {
33  SG_ADD(&m_lasso_max_iter,"lasso_max_iter",
34  "maximum iteration of LASSO step",MS_NOT_AVAILABLE);
35  SG_ADD(&m_max_iter,"max_iter","maximum total iteration",
37  SG_ADD(&m_f_gap,"f_gap","f gap",MS_NOT_AVAILABLE);
38  SG_ADD(&m_x_gap,"x_gap","x gap",MS_NOT_AVAILABLE);
39  SG_ADD(&m_xtol,"xtol","xtol",MS_NOT_AVAILABLE);
40 }
41 
42 SGMatrix<float64_t> CSparseInverseCovariance::estimate(SGMatrix<float64_t> S, float64_t lambda_c)
43 {
45 
46  int32_t n = S.num_cols;
47  float64_t sum_S = 0.0;
48  for (int32_t i=0; i<n; i++)
49  sum_S += S(i,i);
50 
51  float64_t* Theta = SG_CALLOC(float64_t, n*n);
52  float64_t* W = SG_CALLOC(float64_t, n*n);
53 
54  invCov(Theta, W, S.matrix, lambda_c, sum_S, n, m_lasso_max_iter,
55  m_f_gap, m_x_gap, m_max_iter, m_xtol);
56 
57  SG_FREE(W);
58  return SGMatrix<float64_t>(Theta,n,n);
59 }
60 #endif //USE_GPL_SHOGUN
index_t num_cols
Definition: SGMatrix.h:376
index_t num_rows
Definition: SGMatrix.h:374
#define ASSERT(x)
Definition: SGIO.h:201
Class SGObject is the base class of all shogun objects.
Definition: SGObject.h:115
double float64_t
Definition: common.h:50
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
#define SG_ADD(...)
Definition: SGObject.h:84

SHOGUN Machine Learning Toolbox - Documentation