SHOGUN  6.0.0
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 {
34  "maximum iteration of LASSO step",MS_NOT_AVAILABLE);
35  SG_ADD(&m_max_iter,"max_iter","maximum total iteration",
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:465
index_t num_rows
Definition: SGMatrix.h:463
#define ASSERT(x)
Definition: SGIO.h:200
Class SGObject is the base class of all shogun objects.
Definition: SGObject.h:125
double float64_t
Definition: common.h:60
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18