SHOGUN  3.2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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 

SHOGUN Machine Learning Toolbox - Documentation