48 for (int32_t i = 0; i < num_factors; i++)
54 for (int32_t j = i; j < num_factors; j++)
74 for (int32_t c = 0; c < num_factors; c++)
92 for (int32_t i = 0; i < inds_s.size(); i++)
94 inds_s[i] = vars_c.
find(curr_intersection[i])[0];
96 "Intersection contains variable %d which is not in the region %d", curr_intersection[i], c);
98 dims_array[i] = fg_var_sizes[curr_intersection[i]];
106 message.set_const(0);
123 for (int32_t j = 0; j < dims_array.size(); j++)
124 dims_array[j] = fg_var_sizes[vars_intersection[j]];
127 curr_array.set_const(0);
139 if (cards.
size() == 1)
141 for (int32_t i = 0; i < energies.
size(); i++)
142 message.
array[i] = - energies[i];
144 else if (cards.
size() == 2)
146 for (int32_t y = 0; y < cards[1]; y++)
147 for (int32_t x = 0; x < cards[0]; x++)
148 message.
array[x*cards[1]+y] = - energies[y*cards[0]+x];
151 SG_ERROR(
"Index issue has not been solved for higher order (>=3) factors.");
153 return message.
clone();
160 for (int32_t i = 0; i < region_A.
size(); i++)
162 for (int32_t j = 0; j < region_B.
size(); j++)
164 if (region_A[i] == region_B[j])
165 tmp.push_back(region_A[i]);
170 if (tmp.size() == 0)
return -1;
174 for (uint32_t i = 0; i < tmp.size(); i++)
192 "%s::inference(): the output assignment should be prepared as"
193 "the same size as variables!\n",
get_name());
210 if (vars.
size() == 1 && it > 0)
238 for (int32_t i = 0; i < vars.
size(); i++)
239 var_assignment[i] = assignment[vars[i]];
250 SG_SDEBUG(
"Iter= %d Objective=%f ObjBest=%f ObjDel=%f Gap=%f \n", (it + 1), obj, int_val, obj_del, int_gap);
252 if (obj_del < m_param.m_obj_del_thr && it > 16)
262 SG_DEBUG(
"fg.evaluate_energy(assignment) = %f\n", energy);
267 void CGEMPLP::update_messages(int32_t id_region)
272 "Region id (%d) exceeds the factor elements' length (%d)!\n",
281 lam_sum.set_const(0);
286 vector<SGNDArray<float64_t> > lam_minus;
293 int32_t id_intersection = *t;
297 lam_minus.push_back(tmp);
305 lam_sum += tmp_expand;
321 int32_t id_intersection = *t;
323 lam_max *= 1.0/num_intersections;
340 max_res = tar_arr.
clone();
351 for (int32_t vi = 0; vi < tar_arr.
len_array; vi++)
355 if (subset_inds.
size() == 1)
356 y = inds_for_tar[subset_inds[0]];
357 else if (subset_inds.
size() == 2)
359 int32_t ind1 = subset_inds[0];
360 int32_t ind2 = subset_inds[1];
361 y = inds_for_tar[ind1] * max_res.
dims[1] + inds_for_tar[ind2];
363 max_res[y] =
max(max_res[y], tar_arr.
array[vi]);
float64_t evaluate_energy(const SGVector< int32_t > state) const
static const float64_t INFTY
infinity
SGNDArray< T > clone() const
const SGVector< int32_t > get_variables() const
CDynamicObjectArray * get_factors() const
int32_t get_num_elements() const
Class CMAPInferImpl abstract class of MAP inference implementation.
vector< SGVector< int32_t > > m_all_intersections
SGVector< float64_t > get_energies() const
vector< SGNDArray< float64_t > > m_theta_region
virtual float64_t inference(SGVector< int32_t > assignment)
vector< vector< SGNDArray< float64_t > > > m_msgs_from_region
void max_in_subdimension(SGNDArray< float64_t > tar_arr, SGVector< int32_t > &subset_inds, SGNDArray< float64_t > &max_res) const
virtual const char * get_name() const
virtual bool equals(CSGObject *other, float64_t accuracy=0.0, bool tolerant=false)
SGNDArray< float64_t > convert_energy_to_potential(CFactor *factor)
void set_const(T const_elem)
CDynamicObjectArray * m_factors
all of classes and functions are contained in the shogun namespace
int32_t find_intersection_index(SGVector< int32_t > region_A, SGVector< int32_t > region_B)
Class CFactorGraph a factor graph is a structured input in general.
CSGObject * get_element(int32_t index) const
vector< set< int32_t > > m_region_intersections
Matrix::Scalar max(Matrix m)
vector< vector< SGVector< int32_t > > > m_region_inds_intersections
SGVector< int32_t > get_cardinalities() const
vector< SGNDArray< float64_t > > m_msgs_into_intersections
void next_index(SGVector< index_t > &curr_index) const
SGVector< index_t > find(T elem)
Class CFactor A factor is defined on a clique in the factor graph. Each factor can have its own data...
const SGVector< int32_t > get_cardinalities() const
void expand(SGNDArray &big_array, SGVector< index_t > &axes)