49 for (int32_t i = 0; i < num_factors; i++)
55 for (int32_t j = i; j < num_factors; j++)
75 for (int32_t c = 0; c < num_factors; c++)
93 for (int32_t i = 0; i < inds_s.size(); i++)
95 inds_s[i] = vars_c.
find(curr_intersection[i])[0];
97 "Intersection contains variable %d which is not in the region %d", curr_intersection[i], c);
99 dims_array[i] = fg_var_sizes[curr_intersection[i]];
107 message.set_const(0);
124 for (int32_t j = 0; j < dims_array.size(); j++)
125 dims_array[j] = fg_var_sizes[vars_intersection[j]];
128 curr_array.set_const(0);
140 if (cards.
size() == 1)
142 for (int32_t i = 0; i < energies.
size(); i++)
143 message.
array[i] = - energies[i];
145 else if (cards.
size() == 2)
147 for (int32_t y = 0; y < cards[1]; y++)
148 for (int32_t x = 0; x < cards[0]; x++)
149 message.
array[x*cards[1]+y] = - energies[y*cards[0]+x];
152 SG_ERROR(
"Index issue has not been solved for higher order (>=3) factors.");
154 return message.
clone();
161 for (int32_t i = 0; i < region_A.
size(); i++)
163 for (int32_t j = 0; j < region_B.
size(); j++)
165 if (region_A[i] == region_B[j])
166 tmp.push_back(region_A[i]);
171 if (tmp.size() == 0)
return -1;
175 for (uint32_t i = 0; i < tmp.size(); i++)
193 "%s::inference(): the output assignment should be prepared as"
194 "the same size as variables!\n",
get_name());
211 if (vars.
size() == 1 && it > 0)
239 for (int32_t i = 0; i < vars.
size(); i++)
240 var_assignment[i] = assignment[vars[i]];
251 SG_SDEBUG(
"Iter= %d Objective=%f ObjBest=%f ObjDel=%f Gap=%f \n", (it + 1), obj, int_val, obj_del, int_gap);
253 if (obj_del < m_param.m_obj_del_thr && it > 16)
263 SG_DEBUG(
"fg.evaluate_energy(assignment) = %f\n", energy);
268 void CGEMPLP::update_messages(int32_t id_region)
273 "Region id (%d) exceeds the factor elements' length (%d)!\n",
282 lam_sum.set_const(0);
287 vector<SGNDArray<float64_t> > lam_minus;
294 int32_t id_intersection = *t;
298 lam_minus.push_back(tmp);
306 lam_sum += tmp_expand;
322 int32_t id_intersection = *t;
324 lam_max *= 1.0/num_intersections;
341 max_res = tar_arr.
clone();
352 for (int32_t vi = 0; vi < tar_arr.
len_array; vi++)
356 if (subset_inds.
size() == 1)
357 y = inds_for_tar[subset_inds[0]];
358 else if (subset_inds.
size() == 2)
360 int32_t ind1 = subset_inds[0];
361 int32_t ind2 = subset_inds[1];
362 y = inds_for_tar[ind1] * max_res.
dims[1] + inds_for_tar[ind2];
364 max_res[y] =
max(max_res[y], tar_arr.
array[vi]);
std::vector< SGVector< int32_t > > m_all_intersections
float64_t evaluate_energy(const SGVector< int32_t > state) const
std::vector< std::vector< SGNDArray< float64_t > > > m_msgs_from_region
static const float64_t INFTY
infinity
std::vector< std::vector< SGVector< int32_t > > > m_region_inds_intersections
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.
SGVector< float64_t > get_energies() const
virtual float64_t inference(SGVector< int32_t > assignment)
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.
std::vector< std::set< int32_t > > m_region_intersections
std::vector< SGNDArray< float64_t > > m_theta_region
CSGObject * get_element(int32_t index) const
Matrix::Scalar max(Matrix m)
SGVector< int32_t > get_cardinalities() const
void next_index(SGVector< index_t > &curr_index) const
std::vector< SGNDArray< float64_t > > m_msgs_into_intersections
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)