96 SG_SDEBUG(
"\nTruncate initialized data to ensure submodularity.\n");
101 B = B + (delta - subtrA * 2) + 0.0001;
132 for (int32_t y = 0; y < N; ++y)
133 for (int32_t x = 0; x < N; ++x)
140 var_index[0] = y * N + x;
146 for (int32_t x = 0; x < N; x++)
148 for (int32_t y = 0; y < N; y++)
209 min_energy_expect = std::numeric_limits<double>::infinity();
210 for (
int v0 = 0; v0 < 2; ++v0)
213 for (
int v1 = 0; v1 < 2; ++v1)
216 for (
int v2 = 0; v2 < 2; ++v2)
219 for (
int v3 = 0; v3 < 2; ++v3)
224 if (orig_e < min_energy_expect)
226 assignment_expect = test_var.
clone();
227 min_energy_expect = orig_e;
342 ASSERT(size_data > len_label);
347 for (int32_t k = 0; k < size_data; k++)
352 int32_t i = k % len_label;
362 for (int32_t j = 0; j < 3 * (i + 1); j++)
364 int32_t r = random_indices[j];
368 for (int32_t f = 0; f < len_feat; f++)
369 feats(f, k) = v_feat[f];
371 for (int32_t l = 0; l < len_label; l++)
372 labels(l, k) = v_label[l];
380 int32_t num_rows = num_classes * (num_classes - 1) / 2;
386 for (int32_t i = 0; i < num_classes - 1; i++)
388 for (int32_t j = i + 1; j < num_classes; j++)
390 mat[num_rows + k] = j;
402 int32_t num_sample = labels.
num_cols;
403 int32_t num_classes = labels.
num_rows;
405 int32_t num_edges = edge_list.
num_rows;
408 for (int32_t n = 0; n < num_sample; n++)
420 for (int32_t u = 0; u < num_classes; u++)
424 CFactor* fac_u =
new CFactor(v_factor_type[u], var_index_u, feat_i);
429 for (int32_t t = 0; t < num_edges; t++)
434 CFactor* fac_t =
new CFactor(v_factor_type[t + num_classes], var_index_t, data_t);
444 memcpy(states_gt.
vector, plabs, num_classes *
sizeof(int32_t));
465 for (int32_t u = 0; u < num_classes; u++)
478 for (int32_t t = 0; t < num_edges; t++)
480 tid = t + num_classes;
500 int32_t num_sample_train = labels_train.
num_cols;
501 int32_t num_classes = labels_train.
num_rows;
506 int32_t num_edges = edge_table.
num_rows;
518 build_factor_graph(feats_train, labels_train, edge_table, v_factor_type, fg_feats_train, fg_labels_train);
525 for (int32_t u = 0; u < num_classes; u++)
528 for (int32_t t = 0; t < num_edges; t++)
546 for (int32_t i = 0; i < num_sample_train; ++i)
550 acc_loss_sgd += model->
delta_loss(y_truth, y_pred);
565 ave_loss_sgd = acc_loss_sgd /
static_cast<float64_t>(num_sample_train);
void truncate_energy(float64_t &A, float64_t &B, float64_t &C, float64_t &D)
CFactorGraph * multi_state_tree_graph()
void range_fill(T start=0)
static void permute(SGVector< T > v, CRandom *rand=NULL)
Base class of the labels used in Structured Output (SO) problems.
float64_t evaluate_energy(const SGVector< int32_t > state) const
static void fill_vector(T *vec, int32_t len, T value)
SGVector< int32_t > get_data() const
int32_t grid_to_index(int32_t x, int32_t y, int32_t w=10)
void add_factor(CFactor *factor)
bool append_element(T element)
SGMatrix< int32_t > get_edges_full(const int32_t num_classes)
CFactorGraph * random_chain_graph(SGVector< int > &assignment_expect, float64_t &min_energy_expect, int32_t N=2)
void build_factor_graph(SGMatrix< float64_t > feats, SGMatrix< int32_t > labels, SGMatrix< int32_t > edge_list, const DynArray< CTableFactorType * > &v_factor_type, CFactorGraphFeatures *fg_feats, CFactorGraphLabels *fg_labels)
void add_factor_type(CFactorType *ftype)
void set_num_iter(int32_t num_iter)
Class FactorGraphLabels used e.g. in the application of Structured Output (SO) learning with the Fact...
void define_factor_types(int32_t num_classes, int32_t dim, int32_t num_edges, DynArray< CTableFactorType * > &v_factor_type)
Class SGObject is the base class of all shogun objects.
static void init_random(uint32_t initseed=0)
Template Dynamic array class that creates an array that can be used like a list or an array...
bool add_sample(CFactorGraph *fg)
Class CFactorGraphObservation is used as the structured output.
CFactorGraphFeatures maintains an array of factor graphs, each graph is a sample, i...
CFactorGraphModel defines a model in terms of CFactorGraph and CMAPInference, where parameters are as...
T * get_column_vector(index_t col) const
static CFactorGraphObservation * obtain_from_generic(CStructuredData *base_data)
Class CStochasticSOSVM solves SOSVM using stochastic subgradient descent on the SVM primal problem [1...
void generate_data(int32_t len_label, int32_t len_feat, int32_t size_data, SGMatrix< float64_t > &feats, SGMatrix< int32_t > &labels)
virtual void add_label(CStructuredData *label)
all of classes and functions are contained in the shogun namespace
Class CFactorGraph a factor graph is a structured input in general.
float64_t test_sosvm(EMAPInferType infer_type)
void set_seed(uint32_t seed)
CFactorGraph * simple_chain_graph()
Class CTableFactorType the way that store assignments of variables and energies in a table or a multi...
virtual bool train(CFeatures *data=NULL)
void connect_components()
SGVector< T > clone() const
void set_lambda(float64_t lbda)
virtual CStructuredData * get_label(int32_t idx)
virtual float64_t delta_loss(CStructuredData *y1, CStructuredData *y2)
static CStructuredLabels * to_structured(CLabels *base_labels)
SGVector< T > get_row_vector(index_t row) const
CFactorGraphDataGenerator()
Class CFactor A factor is defined on a clique in the factor graph. Each factor can have its own data...
Base class of the components of StructuredLabels.
virtual CLabels * apply(CFeatures *data=NULL)