SHOGUN
v3.0.0
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
structure
FactorType.h
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
* Written (W) 2013 Shell Hu
8
* Copyright (C) 2013 Shell Hu
9
*/
10
11
#ifndef __FACTOR_TYPE_H__
12
#define __FACTOR_TYPE_H__
13
14
#include <
shogun/base/SGObject.h
>
15
#include <
shogun/lib/SGVector.h
>
16
17
namespace
shogun
18
{
19
22
class
CFactorType
:
public
CSGObject
23
{
24
public
:
26
CFactorType
();
27
39
CFactorType
(int32_t
id
,
SGVector<int32_t>
card,
SGVector<float64_t>
w);
40
42
virtual
~CFactorType
();
43
45
virtual
const
char
*
get_name
()
const
{
return
"FactorType"
; }
46
48
virtual
int32_t
get_type_id
()
const
;
49
54
virtual
void
set_type_id
(int32_t
id
);
55
57
virtual
SGVector<float64_t>
get_w
();
58
60
virtual
const
SGVector<float64_t>
get_w
()
const
;
61
66
void
set_w
(
SGVector<float64_t>
w);
67
69
virtual
int32_t
get_w_dim
()
const
;
70
72
virtual
const
SGVector<int32_t>
get_cardinalities
()
const
;
73
78
virtual
void
set_cardinalities
(
SGVector<int32_t>
cards);
79
81
virtual
int32_t
get_num_vars
();
82
84
virtual
int32_t
get_num_assignments
()
const
;
85
87
virtual
bool
is_table
()
const
{
return
false
; }
88
89
protected
:
91
void
init_card
();
92
93
private
:
95
void
init();
96
97
protected
:
99
int32_t
m_type_id
;
100
102
SGVector<int32_t>
m_cards
;
103
105
SGVector<int32_t>
m_cumprod_cards
;
106
108
int32_t
m_num_assignments
;
109
111
int32_t
m_data_size
;
112
114
SGVector<float64_t>
m_w
;
115
};
116
120
class
CTableFactorType
:
public
CFactorType
121
{
122
public
:
124
CTableFactorType
();
125
132
CTableFactorType
(int32_t
id
,
SGVector<int32_t>
card,
SGVector<float64_t>
w);
133
135
virtual
~CTableFactorType
();
136
138
virtual
const
char
*
get_name
()
const
{
return
"TableFactorType"
; }
139
141
virtual
bool
is_table
()
const
{
return
true
; }
142
149
int32_t
state_from_index
(int32_t ei, int32_t var_index)
const
;
150
156
SGVector<int32_t>
assignment_from_index
(int32_t ei)
const
;
157
166
int32_t
index_from_new_state
(int32_t old_ei, int32_t var_index, int32_t var_state)
const
;
167
173
int32_t
index_from_assignment
(
const
SGVector<int32_t>
assig)
const
;
174
181
int32_t
index_from_universe_assignment
(
const
SGVector<int32_t>
assig,
182
const
SGVector<int32_t>
var_index)
const
;
183
189
virtual
void
compute_energies
(
const
SGVector<float64_t>
factor_data,
190
SGVector<float64_t>
& energies)
const
;
191
197
virtual
void
compute_energies
(
const
SGSparseVector<float64_t>
factor_data_sparse,
198
SGVector<float64_t>
& energies)
const
;
199
207
virtual
void
compute_gradients
(
const
SGVector<float64_t>
factor_data,
208
const
SGVector<float64_t>
marginals,
209
SGVector<float64_t>
& parameter_gradient,
double
mult)
const
;
210
218
virtual
void
compute_gradients
(
const
SGSparseVector<float64_t>
factor_data_sparse,
219
const
SGVector<float64_t>
marginals,
220
SGVector<float64_t>
& parameter_gradient,
double
mult)
const
;
221
222
};
223
224
}
225
226
#endif
227
SHOGUN
Machine Learning Toolbox - Documentation