SHOGUN
v3.1.1
Main Page
Related Pages
Modules
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
src
shogun
mathematics
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
#include <
shogun/mathematics/SparseInverseCovariance.h
>
12
#include <
shogun/base/Parameter.h
>
13
#include <
shogun/lib/slep/SpInvCoVa/invCov.h
>
14
15
using namespace
shogun;
16
17
CSparseInverseCovariance::CSparseInverseCovariance
() :
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
25
CSparseInverseCovariance::~CSparseInverseCovariance
()
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"
,
34
MS_NOT_AVAILABLE
);
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
40
SGMatrix<float64_t>
CSparseInverseCovariance::estimate
(
SGMatrix<float64_t>
S,
float64_t
lambda_c)
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
,
53
m_f_gap
,
m_x_gap
,
m_max_iter
,
m_xtol
);
54
55
SG_FREE(W);
56
return
SGMatrix<float64_t>
(Theta,n,n);
57
}
shogun::SGMatrix::matrix
T * matrix
Definition:
SGMatrix.h:299
shogun::CSparseInverseCovariance::m_x_gap
float64_t m_x_gap
Definition:
SparseInverseCovariance.h:117
shogun::CSparseInverseCovariance::m_lasso_max_iter
int32_t m_lasso_max_iter
Definition:
SparseInverseCovariance.h:108
shogun::CSparseInverseCovariance::CSparseInverseCovariance
CSparseInverseCovariance()
Definition:
SparseInverseCovariance.cpp:17
shogun::CSparseInverseCovariance::m_f_gap
float64_t m_f_gap
Definition:
SparseInverseCovariance.h:114
shogun::CSparseInverseCovariance::m_xtol
float64_t m_xtol
Definition:
SparseInverseCovariance.h:120
shogun::MS_NOT_AVAILABLE
Definition:
SGObject.h:79
Parameter.h
invCov.h
ASSERT
#define ASSERT(x)
Definition:
SGIO.h:203
shogun::CSGObject
Class SGObject is the base class of all shogun objects.
Definition:
SGObject.h:102
SparseInverseCovariance.h
float64_t
double float64_t
Definition:
common.h:48
shogun::SGMatrix::num_rows
index_t num_rows
Definition:
SGMatrix.h:301
shogun::SGMatrix::num_cols
index_t num_cols
Definition:
SGMatrix.h:303
shogun::SGMatrix< float64_t >
invCov
void invCov(double *Theta, double *W, double *S, double lambda, double sum_S, int n, int LassoMaxIter, double fGap, double xGap, int maxIter, double xtol)
Definition:
invCov.cpp:167
shogun::CSparseInverseCovariance::~CSparseInverseCovariance
virtual ~CSparseInverseCovariance()
Definition:
SparseInverseCovariance.cpp:25
shogun::CSparseInverseCovariance::estimate
SGMatrix< float64_t > estimate(SGMatrix< float64_t > S, float64_t lambda_c)
Definition:
SparseInverseCovariance.cpp:40
SG_ADD
#define SG_ADD(...)
Definition:
SGObject.h:71
shogun::CSparseInverseCovariance::m_max_iter
int32_t m_max_iter
Definition:
SparseInverseCovariance.h:111
SHOGUN
Machine Learning Toolbox - Documentation