SHOGUN  3.2.1
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义 
HMSVMModel.cpp
浏览该文件的文档.
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) 2012 Fernando José Iglesias García
8  * Copyright (C) 2012 Fernando José Iglesias García
9  */
10 
14 #include <shogun/structure/Plif.h>
16 
17 using namespace shogun;
18 
21 {
22  init();
23 }
24 
25 CHMSVMModel::CHMSVMModel(CFeatures* features, CStructuredLabels* labels, EStateModelType smt, int32_t num_obs, bool use_plifs)
26 : CStructuredModel(features, labels)
27 {
28  init();
29  m_num_obs = num_obs;
30  m_num_plif_nodes = 20;
31  m_use_plifs = use_plifs;
32 
33  switch (smt)
34  {
35  case SMT_TWO_STATE:
36  m_state_model = new CTwoStateModel();
37  break;
38  case SMT_UNKNOWN:
39  default:
40  SG_ERROR("The EStateModelType given is not valid\n")
41  }
42 }
43 
45 {
46  SG_UNREF(m_state_model);
47  SG_UNREF(m_plif_matrix);
48 }
49 
50 int32_t CHMSVMModel::get_dim() const
51 {
52  // Shorthand for the number of free states
53  int32_t free_states = ((CSequenceLabels*) m_labels)->get_num_states();
55  int32_t D = mf->get_num_features();
56 
57  if ( m_use_plifs )
58  return free_states*(free_states + D*m_num_plif_nodes);
59  else
60  return free_states*(free_states + D*m_num_obs);
61 }
62 
64  int32_t feat_idx,
65  CStructuredData* y)
66 {
67  // Shorthand for the number of features of the feature vector
69  int32_t D = mf->get_num_features();
70 
71  // Get the sequence of labels
73 
74  // Initialize psi
76  psi.zero();
77 
78  // Translate from labels sequence to state sequence
79  SGVector< int32_t > state_seq = m_state_model->labels_to_states(label_seq);
80  m_transmission_weights.zero();
81 
82  for ( int32_t i = 0 ; i < state_seq.vlen-1 ; ++i )
83  m_transmission_weights(state_seq[i],state_seq[i+1]) += 1;
84 
85  SGMatrix< float64_t > obs = mf->get_feature_vector(feat_idx);
86  REQUIRE(obs.num_rows == D && obs.num_cols == state_seq.vlen,
87  "obs.num_rows (%d) != D (%d) OR obs.num_cols (%d) != state_seq.vlen (%d)\n",
88  obs.num_rows, D, obs.num_cols, state_seq.vlen)
89  m_emission_weights.zero();
90  index_t aux_idx, weight_idx;
91 
92  if ( !m_use_plifs ) // Do not use PLiFs
93  {
94  for ( int32_t f = 0 ; f < D ; ++f )
95  {
96  aux_idx = f*m_num_obs;
97 
98  for ( int32_t j = 0 ; j < state_seq.vlen ; ++j )
99  {
100  weight_idx = aux_idx + state_seq[j]*D*m_num_obs + obs(f,j);
101  m_emission_weights[weight_idx] += 1;
102  }
103  }
104 
105  m_state_model->weights_to_vector(psi, m_transmission_weights, m_emission_weights,
106  D, m_num_obs);
107  }
108  else // Use PLiFs
109  {
110  int32_t S = m_state_model->get_num_states();
111 
112  for ( int32_t f = 0 ; f < D ; ++f )
113  {
114  aux_idx = f*m_num_plif_nodes;
115 
116  for ( int32_t j = 0 ; j < state_seq.vlen ; ++j )
117  {
118  CPlif* plif = (CPlif*) m_plif_matrix->get_element(S*f + state_seq[j]);
119  SGVector<float64_t> limits = plif->get_plif_limits();
120  // The number of supporting points smaller or equal than value
121  int32_t count = 0;
122  // The observation value
123  float64_t value = obs(f,j);
124 
125  for ( int32_t i = 0 ; i < m_num_plif_nodes ; ++i )
126  {
127  if ( limits[i] <= value )
128  ++count;
129  else
130  break;
131  }
132 
133  weight_idx = aux_idx + state_seq[j]*D*m_num_plif_nodes;
134 
135  if ( count == 0 )
136  m_emission_weights[weight_idx] += 1;
137  else if ( count == m_num_plif_nodes )
138  m_emission_weights[weight_idx + m_num_plif_nodes-1] += 1;
139  else
140  {
141  m_emission_weights[weight_idx + count] +=
142  (value-limits[count-1]) / (limits[count]-limits[count-1]);
143 
144  m_emission_weights[weight_idx + count-1] +=
145  (limits[count]-value) / (limits[count]-limits[count-1]);
146  }
147 
148  SG_UNREF(plif);
149  }
150  }
151 
152  m_state_model->weights_to_vector(psi, m_transmission_weights, m_emission_weights,
153  D, m_num_plif_nodes);
154  }
155 
156  return psi;
157 }
158 
161  int32_t feat_idx,
162  bool const training)
163 {
164  int32_t dim = get_dim();
165  ASSERT( w.vlen == get_dim() )
166 
167  // Shorthand for the number of features of the feature vector
169  int32_t D = mf->get_num_features();
170  // Shorthand for the number of states
171  int32_t S = m_state_model->get_num_states();
172 
173  if ( m_use_plifs )
174  {
175  REQUIRE(m_plif_matrix, "PLiF matrix not allocated, has the SO machine been trained with "
176  "the use_plifs option?\n");
177  REQUIRE(m_plif_matrix->get_num_elements() == S*D, "Dimension mismatch in PLiF matrix, have the "
178  "feature dimension and/or number of states changed from training to prediction?\n");
179  }
180 
181  // Distribution of start states
182  SGVector< float64_t > p = m_state_model->get_start_states();
183  // Distribution of stop states
184  SGVector< float64_t > q = m_state_model->get_stop_states();
185 
186  // Compute the loss-augmented emission matrix:
187  // E_{s,i} = w^{em}_s \cdot x_i + Delta(y_i, s)
188 
189  SGMatrix< float64_t > x = mf->get_feature_vector(feat_idx);
190 
191  int32_t T = x.num_cols;
192  SGMatrix< float64_t > E(S, T);
193  E.zero();
194 
195  if ( !m_use_plifs ) // Do not use PLiFs
196  {
197  index_t em_idx;
198  m_state_model->reshape_emission_params(m_emission_weights, w, D, m_num_obs);
199 
200  for ( int32_t i = 0 ; i < T ; ++i )
201  {
202  for ( int32_t j = 0 ; j < D ; ++j )
203  {
204  //FIXME make independent of observation values
205  em_idx = j*m_num_obs + (index_t)CMath::round(x(j,i));
206 
207  for ( int32_t s = 0 ; s < S ; ++s )
208  E(s,i) += m_emission_weights[s*D*m_num_obs + em_idx];
209  }
210  }
211  }
212  else // Use PLiFs
213  {
214  m_state_model->reshape_emission_params(m_plif_matrix, w, D, m_num_plif_nodes);
215 
216  for ( int32_t i = 0 ; i < T ; ++i )
217  {
218  for ( int32_t f = 0 ; f < D ; ++f )
219  {
220  for ( int32_t s = 0 ; s < S ; ++s )
221  {
222  CPlif* plif = (CPlif*) m_plif_matrix->get_element(S*f + s);
223  E(s,i) += plif->lookup( x(f,i) );
224  SG_UNREF(plif);
225  }
226  }
227  }
228  }
229 
230  // If argmax used while training, add to E the loss matrix (loss-augmented inference)
231  if ( training )
232  {
233  CSequence* ytrue =
235 
236  REQUIRE(ytrue->get_data().size() == T, "T, the length of the feature "
237  "x^i (%d) and the length of its corresponding label y^i "
238  "(%d) must be the same.\n", T, ytrue->get_data().size());
239 
240  SGMatrix< float64_t > loss_matrix = m_state_model->loss_matrix(ytrue);
241 
242  ASSERT(loss_matrix.num_rows == E.num_rows &&
243  loss_matrix.num_cols == E.num_cols);
244 
246  1.0, loss_matrix.matrix, E.num_rows*E.num_cols);
247 
248  // Decrement the reference count corresponding to get_label above
249  SG_UNREF(ytrue);
250  }
251 
252  // Initialize the dynamic programming table and the traceback matrix
253  SGMatrix< float64_t > dp(T, S);
254  SGMatrix< float64_t > trb(T, S);
255  m_state_model->reshape_transmission_params(m_transmission_weights, w);
256 
257  for ( int32_t s = 0 ; s < S ; ++s )
258  {
259  if ( p[s] > -CMath::INFTY )
260  {
261  // dp(0,s) = E(s,0)
262  dp(0,s) = E[s];
263  }
264  else
265  {
266  dp(0,s) = -CMath::INFTY;
267  }
268  }
269 
270  // Viterbi algorithm
271  int32_t idx;
272  float64_t tmp_score, e, a;
273 
274  for ( int32_t i = 1 ; i < T ; ++i )
275  {
276  for ( int32_t cur = 0 ; cur < S ; ++cur )
277  {
278  idx = cur*T + i;
279 
280  dp[idx] = -CMath::INFTY;
281  trb[idx] = -1;
282 
283  // e = E(cur,i)
284  e = E[i*S + cur];
285 
286  for ( int32_t prev = 0 ; prev < S ; ++prev )
287  {
288  // aij = m_transmission_weights(prev, cur)
289  a = m_transmission_weights[cur*S + prev];
290 
291  if ( a > -CMath::INFTY )
292  {
293  // tmp_score = e + a + dp(i-1, prev)
294  tmp_score = e + a + dp[prev*T + i-1];
295 
296  if ( tmp_score > dp[idx] )
297  {
298  dp[idx] = tmp_score;
299  trb[idx] = prev;
300  }
301  }
302  }
303  }
304  }
305 
306  // Trace back the most likely sequence of states
307  SGVector< int32_t > opt_path(T);
308  CResultSet* ret = new CResultSet();
309  SG_REF(ret);
310  ret->psi_computed = true;
311  ret->score = -CMath::INFTY;
312  opt_path[T-1] = -1;
313 
314  for ( int32_t s = 0 ; s < S ; ++s )
315  {
316  idx = s*T + T-1;
317 
318  if ( q[s] > -CMath::INFTY && dp[idx] > ret->score )
319  {
320  ret->score = dp[idx];
321  opt_path[T-1] = s;
322  }
323  }
324 
325  REQUIRE(opt_path[T-1]!=-1, "Viterbi decoding found no possible sequence states.\n"
326  "Maybe the state model used cannot produce such sequence.\n"
327  "If using the TwoStateModel, please use sequences of length greater than two.\n");
328 
329  for ( int32_t i = T-1 ; i > 0 ; --i )
330  opt_path[i-1] = trb[opt_path[i]*T + i];
331 
332  // Populate the CResultSet object to return
333  CSequence* ypred = m_state_model->states_to_labels(opt_path);
334 
335  ret->psi_pred = get_joint_feature_vector(feat_idx, ypred);
336  ret->argmax = ypred;
337  if ( training )
338  {
339  ret->delta = CStructuredModel::delta_loss(feat_idx, ypred);
340  ret->psi_truth = CStructuredModel::get_joint_feature_vector(feat_idx, feat_idx);
342  }
343 
344  return ret;
345 }
346 
348 {
351 
352  // Compute the Hamming loss, number of distinct elements in the sequences
353  return m_state_model->loss(seq1, seq2);
354 }
355 
357  float64_t regularization,
365 {
366  // Shorthand for the number of free states (i.e. states for which parameters are learnt)
367  int32_t S = ((CSequenceLabels*) m_labels)->get_num_states();
368  // Shorthand for the number of features of the feature vector
369  int32_t D = ((CMatrixFeatures< float64_t >*) m_features)->get_num_features();
370 
371  // Monotonicity constraints for feature scoring functions
372  SGVector< int32_t > monotonicity = m_state_model->get_monotonicity(S,D);
373 
374  // Quadratic regularization
375 
376  float64_t C_small = regularization;
377  float64_t C_smooth = 0.02*regularization;
378  // TODO change the representation of C to sparse matrix
379  C = SGMatrix< float64_t >(get_dim()+m_num_aux, get_dim()+m_num_aux);
380  C.zero();
381  for ( int32_t i = 0 ; i < get_dim() ; ++i )
382  C(i,i) = C_small;
383  for ( int32_t i = get_dim() ; i < get_dim()+m_num_aux ; ++i )
384  C(i,i) = C_smooth;
385 
386  // Smoothness constraints
387 
388  // For each auxiliary variable, there are two different constraints
389  // TODO change the representation of A to sparse matrix
390  A = SGMatrix< float64_t >(2*m_num_aux, get_dim()+m_num_aux);
391  A.zero();
392 
393  // Indices to the beginning of the blocks of scores. Each block is
394  // formed by the scores of a pair (state, feature)
395  SGVector< int32_t > score_starts(S*D);
396  int32_t delta = m_use_plifs ? m_num_plif_nodes : m_num_obs;
397  for ( int32_t idx = S*S, k = 0 ; k < S*D ; idx += delta, ++k )
398  score_starts[k] = idx;
399 
400  // Indices to the beginning of the blocks of variables for smoothness
401  SGVector< int32_t > aux_starts_smooth(S*D);
402  for ( int32_t idx = get_dim(), k = 0 ; k < S*D ; idx += delta-1, ++k )
403  aux_starts_smooth[k] = idx;
404 
405  // Bound the difference between adjacent score values from above and
406  // below by an auxiliary variable (which then is regularized
407  // quadratically)
408 
409  int32_t con_idx = 0, scr_idx, aux_idx;
410 
411  for ( int32_t i = 0 ; i < score_starts.vlen ; ++i )
412  {
413  scr_idx = score_starts[i];
414  aux_idx = aux_starts_smooth[i];
415 
416  for ( int32_t j = 0 ; j < delta-1 ; ++j )
417  {
418  A(con_idx, scr_idx) = 1;
419  A(con_idx, scr_idx+1) = -1;
420 
421  if ( monotonicity[i] != 1 )
422  A(con_idx, aux_idx) = -1;
423  ++con_idx;
424 
425  A(con_idx, scr_idx) = -1;
426  A(con_idx, scr_idx+1) = 1;
427 
428  if ( monotonicity[i] != -1 )
429  A(con_idx, aux_idx) = -1;
430  ++con_idx;
431 
432  ++scr_idx, ++aux_idx;
433  }
434  }
435 
436  // Bounds for the smoothness constraints
437  b = SGVector< float64_t >(2*m_num_aux);
438  b.zero();
439 }
440 
442 {
443  // Shorthand for the labels in the correct type
444  CSequenceLabels* hmsvm_labels = (CSequenceLabels*) m_labels;
445  // Frequency of each state
446  SGVector< int32_t > state_freq( hmsvm_labels->get_num_states() );
447  state_freq.zero();
448 
449  CSequence* seq;
450  int32_t state;
451  for ( int32_t i = 0 ; i < hmsvm_labels->get_num_labels() ; ++i )
452  {
453  seq = CSequence::obtain_from_generic(hmsvm_labels->get_label(i));
454 
455  SGVector<int32_t> seq_data = seq->get_data();
456  for ( int32_t j = 0 ; j < seq_data.size() ; ++j )
457  {
458  state = seq_data[j];
459 
460  if ( state < 0 || state >= hmsvm_labels->get_num_states() )
461  {
462  SG_ERROR("Found state out of {0, 1, ..., "
463  "num_states-1}\n");
464  return false;
465  }
466  else
467  {
468  ++state_freq[state];
469  }
470  }
471 
472  // Decrement the reference count increased by get_label
473  SG_UNREF(seq);
474  }
475 
476  for ( int32_t i = 0 ; i < hmsvm_labels->get_num_states() ; ++i )
477  {
478  if ( state_freq[i] <= 0 )
479  {
480  SG_ERROR("What? State %d has never appeared\n", i)
481  return false;
482  }
483  }
484 
485  return true;
486 }
487 
488 void CHMSVMModel::init()
489 {
490  SG_ADD((CSGObject**) &m_state_model, "m_state_model", "The state model", MS_NOT_AVAILABLE);
491  SG_ADD(&m_transmission_weights, "m_transmission_weights",
492  "Transmission weights used in Viterbi", MS_NOT_AVAILABLE);
493  SG_ADD(&m_emission_weights, "m_emission_weights",
494  "Emission weights used in Viterbi", MS_NOT_AVAILABLE);
495  SG_ADD(&m_num_plif_nodes, "m_num_plif_nodes", "The number of points per PLiF",
496  MS_NOT_AVAILABLE); // FIXME It would actually make sense to do MS for this parameter
497  SG_ADD(&m_use_plifs, "m_use_plifs", "Whether to use plifs", MS_NOT_AVAILABLE);
498 
499  m_num_obs = 0;
500  m_num_aux = 0;
501  m_use_plifs = false;
502  m_state_model = NULL;
503  m_plif_matrix = NULL;
504  m_num_plif_nodes = 0;
505 }
506 
508 {
509  return m_num_aux;
510 }
511 
513 {
514  return 2*m_num_aux;
515 }
516 
517 void CHMSVMModel::set_use_plifs(bool use_plifs)
518 {
519  m_use_plifs = use_plifs;
520 }
521 
523 {
524  // Shorthands for the number of states, the matrix features and their dimension
525  int32_t S = m_state_model->get_num_states();
527  int32_t D = mf->get_num_features();
528 
529  // Transmission and emission weights allocation
530  m_transmission_weights = SGMatrix< float64_t >(S,S);
531  if ( m_use_plifs )
532  m_emission_weights = SGVector< float64_t >(S*D*m_num_plif_nodes);
533  else
534  m_emission_weights = SGVector< float64_t >(S*D*m_num_obs);
535 
536  // Auxiliary variables
537 
538  // Shorthand for the number of free states
539  int32_t free_states = ((CSequenceLabels*) m_labels)->get_num_states();
540  if ( m_use_plifs )
541  m_num_aux = free_states*D*(m_num_plif_nodes-1);
542  else
543  m_num_aux = free_states*D*(m_num_obs-1);
544 
545  if ( m_use_plifs )
546  {
547  // Initialize PLiF matrix
548  m_plif_matrix = new CDynamicObjectArray(S*D);
549  SG_REF(m_plif_matrix);
550 
551  // Determine the x values for the supporting points of the PLiFs
552 
553  // Count the number of points per feature, using all the feature vectors
554  int32_t N = 0;
555  for ( int32_t i = 0 ; i < mf->get_num_vectors() ; ++i )
556  {
557  SGMatrix<float64_t> feat_vec = mf->get_feature_vector(i);
558  N += feat_vec.num_cols;
559  }
560 
561  // Choose the supporting points so that roughly the same number of points fall in each bin
562  SGVector< float64_t > a = CMath::linspace_vec(1, N, m_num_plif_nodes+1);
563  SGVector< index_t > signal_idxs(m_num_plif_nodes);
564  for ( int32_t i = 0 ; i < signal_idxs.vlen ; ++i )
565  signal_idxs[i] = (index_t) CMath::round( (a[i] + a[i+1]) / 2 ) - 1;
566 
567  SGVector< float64_t > signal(N);
568  index_t idx; // used to populate signal
569  for ( int32_t f = 0 ; f < D ; ++f )
570  {
571  // Get the points of feature f of all the feature vectors
572  idx = 0;
573  for ( int32_t i = 0 ; i < mf->get_num_vectors() ; ++i )
574  {
575  SGMatrix<float64_t> feat_vec = mf->get_feature_vector(i);
576  for ( int32_t j = 0 ; j < feat_vec.num_cols ; ++j )
577  signal[idx++] = feat_vec(f,j);
578  }
579 
580  signal.qsort();
581  SGVector< float64_t > limits(m_num_plif_nodes);
582  for ( int32_t i = 0 ; i < m_num_plif_nodes ; ++i )
583  limits[i] = signal[ signal_idxs[i] ];
584 
585  // Set the PLiFs' supporting points
586  for ( int32_t s = 0 ; s < S ; ++s )
587  {
588  CPlif* plif = new CPlif(m_num_plif_nodes);
589  plif->set_plif_limits(limits);
590  plif->set_min_value(-CMath::INFTY);
592  m_plif_matrix->push_back(plif);
593  }
594  }
595  }
596 }
597 
599 {
600  return m_transmission_weights;
601 }
602 
604 {
605  return m_emission_weights;
606 }
607 
609 {
610  SG_REF(m_state_model);
611  return m_state_model;
612 }
SGVector< float64_t > psi_truth
CStateModel * get_state_model() const
Definition: HMSVMModel.cpp:608
Base class of the labels used in Structured Output (SO) problems.
virtual ~CHMSVMModel()
Definition: HMSVMModel.cpp:44
int32_t index_t
Definition: common.h:62
SGVector< float64_t > get_start_states() const
Definition: StateModel.cpp:56
virtual void init_primal_opt(float64_t regularization, SGMatrix< float64_t > &A, SGVector< float64_t > a, SGMatrix< float64_t > B, SGVector< float64_t > &b, SGVector< float64_t > &lb, SGVector< float64_t > &ub, SGMatrix< float64_t > &C)
Definition: HMSVMModel.cpp:356
void set_max_value(float64_t p_max_value)
Definition: Plif.h:331
static const float64_t INFTY
infinity
Definition: Math.h:1537
static SGVector< float64_t > linspace_vec(T start, T end, int32_t n)
Definition: Math.h:850
virtual bool check_training_setup() const
Definition: HMSVMModel.cpp:441
virtual int32_t get_num_vectors() const
class CTwoStateModel class for the internal two-state representation used in the CHMSVMModel.
Definition: TwoStateModel.h:26
#define SG_ERROR(...)
Definition: SGIO.h:129
#define REQUIRE(x,...)
Definition: SGIO.h:206
virtual CSequence * states_to_labels(SGVector< int32_t > state_seq) const =0
virtual void init_training()
Definition: HMSVMModel.cpp:522
index_t num_cols
Definition: SGMatrix.h:331
SGVector< float64_t > get_stop_states() const
Definition: StateModel.cpp:61
Class CSequenceLabels used e.g. in the application of Structured Output (SO) learning to Hidden Marko...
class CStateModel base, abstract class for the internal state representation used in the CHMSVMModel...
Definition: StateModel.h:30
virtual int32_t get_num_aux_con() const
Definition: HMSVMModel.cpp:512
SGVector< float64_t > get_joint_feature_vector(int32_t feat_idx, int32_t lab_idx)
void set_plif_limits(SGVector< float64_t > p_limits)
Definition: Plif.h:257
#define SG_REF(x)
Definition: SGObject.h:51
virtual void reshape_emission_params(SGVector< float64_t > &emission_weights, SGVector< float64_t > w, int32_t num_feats, int32_t num_obs)=0
class Plif
Definition: Plif.h:40
index_t num_rows
Definition: SGMatrix.h:329
Class CSequence to be used in the application of Structured Output (SO) learning to Hidden Markov Sup...
int32_t size() const
Definition: SGVector.h:108
index_t vlen
Definition: SGVector.h:637
#define ASSERT(x)
Definition: SGIO.h:201
Class SGObject is the base class of all shogun objects.
Definition: SGObject.h:112
SGVector< float64_t > get_emission_weights() const
Definition: HMSVMModel.cpp:603
virtual int32_t get_num_aux() const
Definition: HMSVMModel.cpp:507
double float64_t
Definition: common.h:50
int32_t get_num_states() const
SGMatrix< ST > get_feature_vector(int32_t num) const
int32_t get_num_features() const
virtual SGVector< float64_t > get_joint_feature_vector(int32_t feat_idx, CStructuredData *y)
Definition: HMSVMModel.cpp:63
Dynamic array class for CSGObject pointers that creates an array that can be used like a list or an a...
SGMatrix< float64_t > get_transmission_weights() const
Definition: HMSVMModel.cpp:598
float64_t delta_loss(int32_t ytrue_idx, CStructuredData *ypred)
int32_t get_num_states() const
Definition: StateModel.cpp:24
virtual CResultSet * argmax(SGVector< float64_t > w, int32_t feat_idx, bool const training=true)
Definition: HMSVMModel.cpp:159
virtual SGVector< int32_t > get_monotonicity(int32_t num_free_states, int32_t num_feats) const
Definition: StateModel.cpp:48
static float64_t dot(const bool *v1, const bool *v2, int32_t n)
Compute dot product between v1 and v2 (blas optimized)
Definition: SGVector.h:332
Class CStructuredModel that represents the application specific model and contains most of the applic...
virtual SGVector< int32_t > labels_to_states(CSequence *label_seq) const =0
SGVector< float64_t > get_plif_limits()
Definition: Plif.h:313
#define SG_UNREF(x)
Definition: SGObject.h:52
CStructuredLabels * m_labels
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
void set_use_plifs(bool use_plifs)
Definition: HMSVMModel.cpp:517
virtual int32_t get_num_labels() const
Class CMatrixFeatures used to represent data whose feature vectors are better represented with matric...
The class Features is the base class of all feature objects.
Definition: Features.h:68
virtual float64_t delta_loss(CStructuredData *y1, CStructuredData *y2)
Definition: HMSVMModel.cpp:347
virtual void reshape_transmission_params(SGMatrix< float64_t > &transmission_weights, SGVector< float64_t > w)=0
float64_t lookup(float64_t p_value)
Definition: Plif.h:84
CStructuredData * argmax
virtual float64_t loss(CSequence *label_seq_lhs, CSequence *label_seq_rhs)=0
virtual void weights_to_vector(SGVector< float64_t > &psi, SGMatrix< float64_t > transmission_weights, SGVector< float64_t > emission_weights, int32_t num_feats, int32_t num_obs) const =0
SGVector< int32_t > get_data() const
virtual CStructuredData * get_label(int32_t idx)
SGVector< float64_t > psi_pred
CSGObject * get_element(int32_t index) const
static CSequence * obtain_from_generic(CStructuredData *base_data)
void set_min_value(float64_t p_min_value)
Definition: Plif.h:350
static float64_t round(float64_t d)
Definition: Math.h:360
#define SG_ADD(...)
Definition: SGObject.h:81
virtual SGMatrix< float64_t > loss_matrix(CSequence *label_seq)=0
virtual int32_t get_dim() const
Definition: HMSVMModel.cpp:50
#define delta
Definition: sfa.cpp:23
Base class of the components of StructuredLabels.
void add(const SGVector< T > x)
Definition: SGVector.cpp:350

SHOGUN 机器学习工具包 - 项目文档