Template Function brille::munkres_permutation¶
Defined in File permutation.hpp
Function Documentation¶
-
template<class
T, classR, classI, typename = typename std::enable_if<std::is_same<typename CostTraits<T>::type, R>::value>::type>
boolbrille::munkres_permutation(const T *centre, const T *neighbour, const std::array<I, 3> &Nel, const R Wscl, const R Wvec, const R Wmat, const size_t span, const size_t Nobj, bArray<size_t> &permutations, const size_t centre_idx, const size_t neighbour_idx, const int vec_cost_func = 0)¶ Use Munkres’ Assignment algorithm to determine a permutation.
For two arrays of data, located in memory at
centreandneighbour, and each representingNobjsets ofNel[0]scalars,Nel[1]vector elements, andNel[2]matrix elements, determine the sorting permutation that maps the elements atcentreonto the same global mapping as the sorting permutation already stored atpermutations[neighbour_idx]. The resultant global permutation is stored atpermutations[centre_idx].Each array of data to be compared must be formatted as:
[ 0{(0…Nel[0]-1)(0…Nel[1]-1)(0…Nel[2]-1)} 1{(0…Nel[0]-1)(0…Nel[1]-1)(0…Nel[2]-1)} ⋮ Nobj-1{(0…Nel[0]-1)(0…Nel[1]-1)(0…Nel[2]-1)} ]The function constructs an
Nobj×Nobjcost matrix, where each element is given byCᵢⱼ = Wscl×∑ₖ₋₀ᴺˢᶜˡ√(centre[i,k]-neighbour[j,k]) + Wvec×𝔣ᵥ(centre_vec[i],neighbour_vec[j]) + Wmat×𝔣ₘ(centre_mat[i],neighbour_mat[j])where
Wscl,Wvec, andWmatare weight factors for adjusting the relative cost of the scalar, vector, and matrix differences, respectively; 𝔣ᵥ is the vector cost function; and 𝔣ₘ is the matrix cost function.The vector cost function is selected by
vec_cost_functo be one of: the angle between the vectors, the length of the difference between the vectors, or one minus the inner product of the vectors.The matrix cost function is the Frobenius norm of the difference between the two matrices.
- Return
trueif the permutation was assigned successfully, otherwisefalse- Parameters
centre: The values to be sorted by the determined permutationneighbour: The values against which thecentrevalues are comparedNel: The number of scalars, vector elements, and matrix elements per objectWscl: The cost weight for scalar elementsWvec: The cost weight for vectorsWmat: The cost weight for matricesspan: The number of elements per object,Nel[0]+Nel[1]+Nel[2]Nobj: The number of objects at each ofcentreandneighbour[out] permutations: Contains the global permutation sorting for the neighbour and is where the centre permutation is storedcentre_idx: The index intopermutationswhere the output is storedneighbour_idx: The index intopermutationsto find the neighbour permutationvec_cost_func: Used to select the eigenvector cost function: 0 –>vector_angle1 –>vector_distance2 –>1-brille::utils::vector_product3 –>abs(sin(brille::utils::hermitian_angle))