SHOGUN
3.2.1
首页
相关页面
模块
类
文件
文件列表
文件成员
全部
类
命名空间
文件
函数
变量
类型定义
枚举
枚举值
友元
宏定义
组
页
src
shogun
distributions
Distribution.cpp
浏览该文件的文档.
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
* Written (W) 1999-2009 Soeren Sonnenburg
8
* Copyright (C) 1999-2009 Fraunhofer Institute FIRST and Max-Planck-Society
9
*/
10
11
#include <
shogun/distributions/Distribution.h
>
12
#include <
shogun/mathematics/Math.h
>
13
14
using namespace
shogun;
15
16
CDistribution::CDistribution
()
17
:
CSGObject
(), features(NULL), pseudo_count(1e-10)
18
{
19
}
20
21
22
CDistribution::~CDistribution
()
23
{
24
}
25
26
float64_t
CDistribution::get_log_likelihood_sample
()
27
{
28
ASSERT
(
features
)
29
30
float64_t
sum=0;
31
for
(int32_t i=0; i<
features
->
get_num_vectors
(); i++)
32
sum+=
get_log_likelihood_example
(i);
33
34
return
sum/
features
->
get_num_vectors
();
35
}
36
37
SGVector<float64_t>
CDistribution::get_log_likelihood
()
38
{
39
ASSERT
(
features
)
40
41
int32_t num=
features
->
get_num_vectors
();
42
float64_t
* vec=SG_MALLOC(
float64_t
, num);
43
44
for
(int32_t i=0; i<num; i++)
45
vec[i]=
get_log_likelihood_example
(i);
46
47
return
SGVector<float64_t>
(vec,num);
48
}
49
50
int32_t
CDistribution::get_num_relevant_model_parameters
()
51
{
52
int32_t total_num=
get_num_model_parameters
();
53
int32_t num=0;
54
55
for
(int32_t i=0; i<total_num; i++)
56
{
57
if
(
get_log_model_parameter
(i)>
CMath::ALMOST_NEG_INFTY
)
58
num++;
59
}
60
return
num;
61
}
62
63
SGVector<float64_t>
CDistribution::get_likelihood_for_all_examples
()
64
{
65
ASSERT
(
features
);
66
int32_t num=
features
->
get_num_vectors
();
67
ASSERT
(num>0);
68
69
SGVector<float64_t>
result=
SGVector<float64_t>
(num);
70
for
(int32_t i=0; i<num; i++)
71
result[i]=
get_likelihood_example
(i);
72
73
return
result;
74
}
SHOGUN
机器学习工具包 - 项目文档