SHOGUN  5.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules
Factor.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_RELATED_H__
12 #define __FACTOR_RELATED_H__
13 
14 #include <shogun/lib/config.h>
15 
16 #include <shogun/base/SGObject.h>
17 #include <shogun/lib/SGVector.h>
20 
21 namespace shogun
22 {
23 
28 {
29 public:
32 
38 
44 
46  virtual ~CFactorDataSource();
47 
49  virtual const char* get_name() const { return "FactorDataSource"; }
50 
52  virtual bool is_sparse() const;
53 
55  virtual SGVector<float64_t> get_data() const;
56 
59 
64  virtual void set_data(SGVector<float64_t> dense);
65 
71  virtual void set_data_sparse(SGSparseVectorEntry<float64_t>* sparse, int32_t dlen);
72 
73 private:
75  void init();
76 
77 private:
79  SGVector<float64_t> m_dense;
80 
83 };
84 
89 class CFactor : public CSGObject
90 {
91 public:
93  CFactor();
94 
102 
109  CFactor(CTableFactorType* ftype, SGVector<int32_t> var_index,
110  SGSparseVector<float64_t> data_sparse);
111 
118  CFactor(CTableFactorType* ftype, SGVector<int32_t> var_index,
119  CFactorDataSource* data_source);
120 
122  virtual ~CFactor();
123 
125  virtual const char* get_name() const { return "Factor"; }
126 
129 
134  void set_factor_type(CTableFactorType* ftype);
135 
137  const SGVector<int32_t> get_variables() const;
138 
140  const int32_t get_num_vars() const;
141 
146  void set_variables(SGVector<int32_t> vars);
147 
149  const SGVector<int32_t> get_cardinalities() const;
150 
153 
156 
161  void set_data(SGVector<float64_t> data_dense);
162 
168  void set_data_sparse(SGSparseVectorEntry<float64_t>* data_sparse, int32_t dlen);
169 
171  bool is_data_dependent() const;
172 
174  bool is_data_sparse() const;
175 
180 
185  float64_t get_energy(int32_t index) const;
186 
190  void set_energies(SGVector<float64_t> ft_energies);
191 
196  void set_energy(int32_t ei, float64_t value);
197 
202  float64_t evaluate_energy(const SGVector<int32_t> state) const;
203 
205  void compute_energies();
206 
213  void compute_gradients(const SGVector<float64_t> marginals,
214  SGVector<float64_t>& parameter_gradient, double mult = 1.0) const;
215 
216 protected:
219 
222 
225 
228 
231 
234 
237 
238 private:
240  void init();
241 };
242 
243 }
244 
245 #endif
246 
void set_energy(int32_t ei, float64_t value)
Definition: Factor.cpp:193
bool is_data_sparse() const
Definition: Factor.cpp:161
float64_t get_energy(int32_t index) const
Definition: Factor.cpp:180
CTableFactorType * get_factor_type() const
Definition: Factor.cpp:95
SGSparseVector< float64_t > get_data_sparse() const
Definition: Factor.cpp:135
virtual SGVector< float64_t > get_data() const
Definition: Factor.cpp:286
const SGVector< int32_t > get_variables() const
Definition: Factor.cpp:107
void set_variables(SGVector< int32_t > vars)
Definition: Factor.cpp:117
void compute_energies()
Definition: Factor.cpp:210
SGVector< float64_t > get_data() const
Definition: Factor.cpp:127
virtual const char * get_name() const
Definition: Factor.h:125
virtual SGSparseVector< float64_t > get_data_sparse() const
Definition: Factor.cpp:291
void compute_gradients(const SGVector< float64_t > marginals, SGVector< float64_t > &parameter_gradient, double mult=1.0) const
Definition: Factor.cpp:229
float64_t evaluate_energy(const SGVector< int32_t > state) const
Definition: Factor.cpp:204
virtual void set_data_sparse(SGSparseVectorEntry< float64_t > *sparse, int32_t dlen)
Definition: Factor.cpp:301
bool m_is_data_dep
Definition: Factor.h:236
SGVector< float64_t > get_energies() const
Definition: Factor.cpp:169
bool is_data_dependent() const
Definition: Factor.cpp:156
Class SGObject is the base class of all shogun objects.
Definition: SGObject.h:115
SGSparseVector< float64_t > m_data_sparse
Definition: Factor.h:233
SGVector< int32_t > m_var_index
Definition: Factor.h:221
double float64_t
Definition: common.h:50
virtual ~CFactor()
Definition: Factor.cpp:89
Class CFactorDataSource Source for factor data. In some cases, the same data can be shared by many fa...
Definition: Factor.h:27
virtual void set_data(SGVector< float64_t > dense)
Definition: Factor.cpp:296
const int32_t get_num_vars() const
Definition: Factor.cpp:112
void set_energies(SGVector< float64_t > ft_energies)
Definition: Factor.cpp:185
virtual const char * get_name() const
Definition: Factor.h:49
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
void set_data_sparse(SGSparseVectorEntry< float64_t > *data_sparse, int32_t dlen)
Definition: Factor.cpp:149
virtual bool is_sparse() const
Definition: Factor.cpp:281
Class CTableFactorType the way that store assignments of variables and energies in a table or a multi...
Definition: FactorType.h:122
void set_factor_type(CTableFactorType *ftype)
Definition: Factor.cpp:101
virtual ~CFactorDataSource()
Definition: Factor.cpp:277
CTableFactorType * m_factor_type
Definition: Factor.h:218
Class CFactor A factor is defined on a clique in the factor graph. Each factor can have its own data...
Definition: Factor.h:89
void set_data(SGVector< float64_t > data_dense)
Definition: Factor.cpp:143
const SGVector< int32_t > get_cardinalities() const
Definition: Factor.cpp:122
SGVector< float64_t > m_data
Definition: Factor.h:230
CFactorDataSource * m_data_source
Definition: Factor.h:227
SGVector< float64_t > m_energies
Definition: Factor.h:224

SHOGUN Machine Learning Toolbox - Documentation