MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ weighted_sort_score()

template<typename Element>
std::optional< double > MayaFlux::Yantra::weighted_sort_score ( const Element & element,
std::span< const SortKey > keys )
nodiscard

Weighted score of one element across the sort keys.

score = sum over keys of sign(direction) * weight * f(feature), where f is tanh when normalize is set and the identity otherwise. Returns nullopt when the element lacks the feature of any key, so the caller decides how to treat it.

Definition at line 172 of file SortingHelper.hpp.

173{
174 double score = 0.0;
175 for (const auto& key : keys) {
176 const double* value = element.get(key.feature);
177 if (value == nullptr) {
178 return std::nullopt;
179 }
180 const double x = key.normalize ? std::tanh(*value) : *value;
181 const double sign = key.direction == SortingDirection::ASCENDING ? 1.0 : -1.0;
182 score += sign * key.weight * x;
183 }
184 return score;
185}

Referenced by MayaFlux::Yantra::RegionKeySorter::sort_implementation().

Here is the caller graph for this function: