SHOGUN
3.2.1
首页
相关页面
模块
类
文件
文件列表
文件成员
全部
类
命名空间
文件
函数
变量
类型定义
枚举
枚举值
友元
宏定义
组
页
src
shogun
structure
Factor.h
浏览该文件的文档.
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) 2013 Shell Hu
8
* Copyright (C) 2013 Shell Hu
9
*/
10
11
#ifndef __FACTOR_RELATED_H__
12
#define __FACTOR_RELATED_H__
13
14
#include <
shogun/base/SGObject.h
>
15
#include <
shogun/lib/SGVector.h
>
16
#include <
shogun/lib/SGSparseVector.h
>
17
#include <
shogun/structure/FactorType.h
>
18
19
namespace
shogun
20
{
21
25
class
CFactorDataSource
:
public
CSGObject
26
{
27
public
:
29
CFactorDataSource
();
30
35
CFactorDataSource
(
SGVector<float64_t>
dense);
36
41
CFactorDataSource
(
SGSparseVector<float64_t>
sparse);
42
44
virtual
~CFactorDataSource
();
45
47
virtual
const
char
*
get_name
()
const
{
return
"FactorDataSource"
; }
48
50
virtual
bool
is_sparse
()
const
;
51
53
virtual
SGVector<float64_t>
get_data
()
const
;
54
56
virtual
SGSparseVector<float64_t>
get_data_sparse
()
const
;
57
62
virtual
void
set_data
(
SGVector<float64_t>
dense);
63
69
virtual
void
set_data_sparse
(
SGSparseVectorEntry<float64_t>
* sparse, int32_t dlen);
70
71
private
:
73
void
init();
74
75
private
:
77
SGVector<float64_t>
m_dense;
78
80
SGSparseVector<float64_t>
m_sparse;
81
};
82
87
class
CFactor
:
public
CSGObject
88
{
89
public
:
91
CFactor
();
92
99
CFactor
(
CTableFactorType
* ftype,
SGVector<int32_t>
var_index,
SGVector<float64_t>
data);
100
107
CFactor
(
CTableFactorType
* ftype,
SGVector<int32_t>
var_index,
108
SGSparseVector<float64_t>
data_sparse);
109
116
CFactor
(
CTableFactorType
* ftype,
SGVector<int32_t>
var_index,
117
CFactorDataSource
* data_source);
118
120
virtual
~CFactor
();
121
123
virtual
const
char
*
get_name
()
const
{
return
"Factor"
; }
124
126
CTableFactorType
*
get_factor_type
()
const
;
127
132
void
set_factor_type
(
CTableFactorType
* ftype);
133
135
const
SGVector<int32_t>
get_variables
()
const
;
136
141
void
set_variables
(
SGVector<int32_t>
vars);
142
144
const
SGVector<int32_t>
get_cardinalities
()
const
;
145
147
SGVector<float64_t>
get_data
()
const
;
148
150
SGSparseVector<float64_t>
get_data_sparse
()
const
;
151
156
void
set_data
(
SGVector<float64_t>
data_dense);
157
163
void
set_data_sparse
(
SGSparseVectorEntry<float64_t>
* data_sparse, int32_t dlen);
164
166
bool
is_data_dependent
()
const
;
167
169
bool
is_data_sparse
()
const
;
170
174
SGVector<float64_t>
get_energies
()
const
;
175
180
float64_t
get_energy
(int32_t index)
const
;
181
185
void
set_energies
(
SGVector<float64_t>
ft_energies);
186
191
void
set_energy
(int32_t ei,
float64_t
value);
192
197
float64_t
evaluate_energy
(
const
SGVector<int32_t>
state)
const
;
198
200
void
compute_energies
();
201
208
void
compute_gradients
(
const
SGVector<float64_t>
marginals,
209
SGVector<float64_t>
& parameter_gradient,
double
mult = 1.0)
const
;
210
211
protected
:
213
CTableFactorType
*
m_factor_type
;
214
216
SGVector<int32_t>
m_var_index
;
217
219
SGVector<float64_t>
m_energies
;
220
222
CFactorDataSource
*
m_data_source
;
223
225
SGVector<float64_t>
m_data
;
226
228
SGSparseVector<float64_t>
m_data_sparse
;
229
231
bool
m_is_data_dep
;
232
233
private
:
235
void
init();
236
};
237
238
}
239
240
#endif
241
SHOGUN
机器学习工具包 - 项目文档