Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include <shogun/mathematics/SparseInverseCovariance.h>
00012 #include <shogun/base/Parameter.h>
00013 #include <shogun/lib/slep/SpInvCoVa/invCov.h>
00014
00015 using namespace shogun;
00016
00017 CSparseInverseCovariance::CSparseInverseCovariance() :
00018 CSGObject(), m_lasso_max_iter(1000),
00019 m_max_iter(1000), m_f_gap(1e-6), m_x_gap(1e-4),
00020 m_xtol(1e-4)
00021 {
00022 register_parameters();
00023 }
00024
00025 CSparseInverseCovariance::~CSparseInverseCovariance()
00026 {
00027 }
00028
00029 void CSparseInverseCovariance::register_parameters()
00030 {
00031 SG_ADD(&m_lasso_max_iter,"lasso_max_iter",
00032 "maximum iteration of LASSO step",MS_NOT_AVAILABLE);
00033 SG_ADD(&m_max_iter,"max_iter","maximum total iteration",
00034 MS_NOT_AVAILABLE);
00035 SG_ADD(&m_f_gap,"f_gap","f gap",MS_NOT_AVAILABLE);
00036 SG_ADD(&m_x_gap,"x_gap","x gap",MS_NOT_AVAILABLE);
00037 SG_ADD(&m_xtol,"xtol","xtol",MS_NOT_AVAILABLE);
00038 }
00039
00040 SGMatrix<float64_t> CSparseInverseCovariance::estimate(SGMatrix<float64_t> S, float64_t lambda_c)
00041 {
00042 ASSERT(S.num_cols==S.num_rows);
00043
00044 int32_t n = S.num_cols;
00045 float64_t sum_S = 0.0;
00046 for (int32_t i=0; i<n; i++)
00047 sum_S += S(i,i);
00048
00049 float64_t* Theta = SG_CALLOC(float64_t, n*n);
00050 float64_t* W = SG_CALLOC(float64_t, n*n);
00051
00052 invCov(Theta, W, S.matrix, lambda_c, sum_S, n, m_lasso_max_iter,
00053 m_f_gap, m_x_gap, m_max_iter, m_xtol);
00054
00055 SG_FREE(W);
00056 return SGMatrix<float64_t>(Theta,n,n);
00057 }