SHOGUN  4.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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/lib/config.h>
15 
16 #include <shogun/base/SGObject.h>
17 #include <shogun/lib/SGVector.h>
18 
19 namespace shogun
20 {
21 
24 class CFactorType : public CSGObject
25 {
26 public:
28  CFactorType();
29 
42 
44  virtual ~CFactorType();
45 
47  virtual const char* get_name() const { return "FactorType"; }
48 
50  virtual int32_t get_type_id() const;
51 
56  virtual void set_type_id(int32_t id);
57 
59  virtual SGVector<float64_t> get_w();
60 
62  virtual const SGVector<float64_t> get_w() const;
63 
68  void set_w(SGVector<float64_t> w);
69 
71  virtual int32_t get_w_dim() const;
72 
74  virtual const SGVector<int32_t> get_cardinalities() const;
75 
80  virtual void set_cardinalities(SGVector<int32_t> cards);
81 
83  virtual int32_t get_num_vars();
84 
86  virtual int32_t get_num_assignments() const;
87 
89  virtual bool is_table() const { return false; }
90 
91 protected:
93  void init_card();
94 
95 private:
97  void init();
98 
99 protected:
101  int32_t m_type_id;
102 
105 
108 
111 
113  int32_t m_data_size;
114 
117 };
118 
123 {
124 public:
127 
135 
137  virtual ~CTableFactorType();
138 
140  virtual const char* get_name() const { return "TableFactorType"; }
141 
143  virtual bool is_table() const { return true; }
144 
151  int32_t state_from_index(int32_t ei, int32_t var_index) const;
152 
158  SGVector<int32_t> assignment_from_index(int32_t ei) const;
159 
168  int32_t index_from_new_state(int32_t old_ei, int32_t var_index, int32_t var_state) const;
169 
175  int32_t index_from_assignment(const SGVector<int32_t> assig) const;
176 
184  const SGVector<int32_t> var_index) const;
185 
191  virtual void compute_energies(const SGVector<float64_t> factor_data,
192  SGVector<float64_t>& energies) const;
193 
199  virtual void compute_energies(const SGSparseVector<float64_t> factor_data_sparse,
200  SGVector<float64_t>& energies) const;
201 
209  virtual void compute_gradients(const SGVector<float64_t> factor_data,
210  const SGVector<float64_t> marginals,
211  SGVector<float64_t>& parameter_gradient, double mult) const;
212 
220  virtual void compute_gradients(const SGSparseVector<float64_t> factor_data_sparse,
221  const SGVector<float64_t> marginals,
222  SGVector<float64_t>& parameter_gradient, double mult) const;
223 
224 };
225 
226 }
227 
228 #endif
229 
virtual void set_type_id(int32_t id)
Definition: FactorType.cpp:72
Class CFactorType defines the way of factor parameterization.
Definition: FactorType.h:24
int32_t index_from_assignment(const SGVector< int32_t > assig) const
Definition: FactorType.cpp:170
virtual void compute_energies(const SGVector< float64_t > factor_data, SGVector< float64_t > &energies) const
Definition: FactorType.cpp:206
SGVector< float64_t > m_w
Definition: FactorType.h:116
virtual SGVector< float64_t > get_w()
Definition: FactorType.cpp:77
SGVector< int32_t > m_cards
Definition: FactorType.h:104
virtual bool is_table() const
Definition: FactorType.h:143
SGVector< int32_t > m_cumprod_cards
Definition: FactorType.h:107
virtual ~CFactorType()
Definition: FactorType.cpp:49
virtual int32_t get_type_id() const
Definition: FactorType.cpp:67
void set_w(SGVector< float64_t > w)
Definition: FactorType.cpp:87
Class SGObject is the base class of all shogun objects.
Definition: SGObject.h:115
virtual void compute_gradients(const SGVector< float64_t > factor_data, const SGVector< float64_t > marginals, SGVector< float64_t > &parameter_gradient, double mult) const
Definition: FactorType.cpp:276
int32_t m_num_assignments
Definition: FactorType.h:110
virtual void set_cardinalities(SGVector< int32_t > cards)
Definition: FactorType.cpp:102
int32_t index_from_new_state(int32_t old_ei, int32_t var_index, int32_t var_state) const
Definition: FactorType.cpp:180
int32_t state_from_index(int32_t ei, int32_t var_index) const
Definition: FactorType.cpp:155
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
virtual int32_t get_w_dim() const
Definition: FactorType.cpp:92
virtual const char * get_name() const
Definition: FactorType.h:47
virtual bool is_table() const
Definition: FactorType.h:89
Class CTableFactorType the way that store assignments of variables and energies in a table or a multi...
Definition: FactorType.h:122
virtual const SGVector< int32_t > get_cardinalities() const
Definition: FactorType.cpp:97
virtual int32_t get_num_vars()
Definition: FactorType.cpp:117
SGVector< int32_t > assignment_from_index(int32_t ei) const
Definition: FactorType.cpp:161
int32_t index_from_universe_assignment(const SGVector< int32_t > assig, const SGVector< int32_t > var_index) const
Definition: FactorType.cpp:190
virtual const char * get_name() const
Definition: FactorType.h:140
virtual int32_t get_num_assignments() const
Definition: FactorType.cpp:122

SHOGUN Machine Learning Toolbox - Documentation