36 #ifndef VIGRA_ACCUMULATOR_GRAMMAR_HXX
37 #define VIGRA_ACCUMULATOR_GRAMMAR_HXX
40 #pragma warning (disable: 4503)
44 #include "metaprogramming.hxx"
84 template <
unsigned NDim>
class MultiHistogram;
88 class PrincipalProjection;
96 template <
int INDEX>
class CoordArg;
135 template <
class A>
class CoordWeighted;
136 template <
class A>
class DataFromHandle;
143 template <
class A>
class Whitened;
180 typedef SumOfSquaredDifferences
SSD;
225 namespace acc_detail {
236 struct Error___Tag_modifiers_of_same_kind_must_not_be_combined;
239 template <class A, class S=typename acc_detail::ModifierRule<A>::type>
240 struct StandardizeTag
242 typedef typename StandardizeTag<S>::type type;
247 struct StandardizeTag<A, A>
253 template <
class A,
class B>
254 struct StandardizeTag<A, Error___Tag_modifiers_of_same_kind_must_not_be_combined<B> >
255 :
public Error___Tag_modifiers_of_same_kind_must_not_be_combined<B>
258 namespace acc_detail {
262 enum { MinPriority = 1,
263 AccumulatorPriority = 32,
264 PrepareDataPriority = 16,
265 NormalizePriority = 8,
266 AccessDataPriority = 4,
267 WeightingPriority = 2,
270 SubstitutionMask = PrepareDataPriority | AccessDataPriority | WeightingPriority | GlobalPriority };
273 struct ModifierPriority
275 static const int value = AccumulatorPriority;
278 #define VIGRA_MODIFIER_PRIORITY(MODIFIER, VALUE) \
280 struct ModifierPriority<MODIFIER<A> > \
282 static const int value = VALUE; \
285 VIGRA_MODIFIER_PRIORITY(Global, GlobalPriority)
287 VIGRA_MODIFIER_PRIORITY(Weighted, WeightingPriority)
289 VIGRA_MODIFIER_PRIORITY(Coord, AccessDataPriority)
290 VIGRA_MODIFIER_PRIORITY(DataFromHandle, AccessDataPriority)
292 VIGRA_MODIFIER_PRIORITY(DivideByCount, NormalizePriority)
293 VIGRA_MODIFIER_PRIORITY(RootDivideByCount, NormalizePriority)
294 VIGRA_MODIFIER_PRIORITY(DivideUnbiased, NormalizePriority)
295 VIGRA_MODIFIER_PRIORITY(RootDivideUnbiased, NormalizePriority)
297 VIGRA_MODIFIER_PRIORITY(Central, PrepareDataPriority)
298 VIGRA_MODIFIER_PRIORITY(Principal, PrepareDataPriority)
299 VIGRA_MODIFIER_PRIORITY(Whitened, PrepareDataPriority)
302 VIGRA_MODIFIER_PRIORITY(StandardQuantiles, AccumulatorPriority)
304 #undef VIGRA_MODIFIER_PRIORITY
307 template <class A, int TARGET_PRIORITY, int PRIORITY=ModifierPriority<A>::value>
308 struct HasModifierPriority
310 typedef VigraFalseType type;
311 static const bool value =
false;
314 template <
class A,
int TARGET_PRIORITY>
315 struct HasModifierPriority<A, TARGET_PRIORITY, TARGET_PRIORITY>
317 typedef VigraTrueType type;
318 static const bool value =
true;
321 template <
class A,
template <
class>
class B,
int TARGET_PRIORITY,
int PRIORITY>
322 struct HasModifierPriority<B<A>, TARGET_PRIORITY, PRIORITY>
323 :
public HasModifierPriority<A, TARGET_PRIORITY>
326 template <
class A,
template <
class>
class B,
int TARGET_PRIORITY>
327 struct HasModifierPriority<B<A>, TARGET_PRIORITY, TARGET_PRIORITY>
329 typedef VigraTrueType type;
330 static const bool value =
true;
334 template <
class A,
class B>
335 struct ModifierCompare
337 static const int p1 = ModifierPriority<A>::value;
338 static const int p2 = ModifierPriority<B>::value;
339 static const int value = p1 < p2
347 struct ModifierCompareToInner;
349 template <
class A,
template <
class>
class B>
350 struct ModifierCompareToInner<B<A> >
351 :
public ModifierCompare<B<A>, A>
355 template <class A, int compare=ModifierCompareToInner<A>::value>
356 struct ModifierOrder;
360 struct ModifierOrder<A, -1>
366 template <
class A,
template <
class>
class B,
template <
class>
class C>
367 struct ModifierOrder<C<B<A> >, 0>
369 typedef Error___Tag_modifiers_of_same_kind_must_not_be_combined<C<B<A> > > type;
373 template <
class A,
template <
class>
class B,
template <
class>
class C>
374 struct ModifierOrder<C<B<A> >, 1>
376 typedef B<C<A> > type;
379 #define VIGRA_CLEANUP_DATA_PREPARATION_MODIFIERS(OUTER, INNER, RESULT) \
381 struct ModifierOrder<OUTER<INNER<A > >, 0> \
383 typedef RESULT<A > type; \
387 VIGRA_CLEANUP_DATA_PREPARATION_MODIFIERS(Central, Central, Central)
388 VIGRA_CLEANUP_DATA_PREPARATION_MODIFIERS(Principal, Principal, Principal)
389 VIGRA_CLEANUP_DATA_PREPARATION_MODIFIERS(Whitened, Whitened, Whitened)
392 VIGRA_CLEANUP_DATA_PREPARATION_MODIFIERS(Principal, Central, Principal)
393 VIGRA_CLEANUP_DATA_PREPARATION_MODIFIERS(Whitened, Central, Whitened)
394 VIGRA_CLEANUP_DATA_PREPARATION_MODIFIERS(Whitened, Principal, Whitened)
397 VIGRA_CLEANUP_DATA_PREPARATION_MODIFIERS(DataFromHandle, Coord, Coord)
399 #undef VIGRA_CLEANUP_DATA_PREPARATION_MODIFIERS
402 template <
class A,
template <
class>
class B>
403 struct ModifierRule<B<B<A> > >
408 template <class A, int PRIORITY=ModifierPriority<A>::value>
409 struct RecurseModifier;
411 template <
class A,
template <
class>
class B,
int PRIORITY>
412 struct RecurseModifier<B<A>, PRIORITY>
414 typedef typename ModifierOrder<B<typename StandardizeTag<A>::type> >::type type;
417 template <
class A,
template <
class>
class B>
418 struct RecurseModifier<B<A>, AccumulatorPriority>
426 template <
class A,
template <
class>
class B>
427 struct ModifierRule<B<A> >
428 :
public RecurseModifier<B<A> >
434 #define VIGRA_REDUCE_MODFIER(TEMPLATE, SOURCE, TARGET) \
435 template <TEMPLATE > \
436 struct ModifierRule<SOURCE > \
438 typedef TARGET type; \
444 VIGRA_REDUCE_MODFIER(VIGRA_VOID, Central<CoordinateSystem>, CoordinateSystem)
446 VIGRA_REDUCE_MODFIER(VIGRA_VOID, Whitened<CoordinateSystem>, Principal<CoordinateSystem>)
449 VIGRA_REDUCE_MODFIER(template <class> class A, A<Count>, Count)
450 VIGRA_REDUCE_MODFIER(VIGRA_VOID, Weighted<Count>, Weighted<Count>)
451 VIGRA_REDUCE_MODFIER(VIGRA_VOID, CoordWeighted<Count>, Weighted<Count>)
452 VIGRA_REDUCE_MODFIER(VIGRA_VOID, Global<Count>, Global<Count>)
455 VIGRA_REDUCE_MODFIER(
unsigned N, Moment<N>, DivideByCount<PowerSum<N> >)
456 VIGRA_REDUCE_MODFIER(
unsigned N, CentralMoment<N>, DivideByCount<Central<PowerSum<N> > >)
457 VIGRA_REDUCE_MODFIER(class A, CoordWeighted<A>, Weighted<Coord<A> >)
460 VIGRA_REDUCE_MODFIER(VIGRA_VOID, Central<Centralize>, Centralize)
461 VIGRA_REDUCE_MODFIER(VIGRA_VOID, Central<Skewness>, Skewness)
462 VIGRA_REDUCE_MODFIER(VIGRA_VOID, Central<Kurtosis>, Kurtosis)
463 VIGRA_REDUCE_MODFIER(VIGRA_VOID, Central<FlatScatterMatrix>, FlatScatterMatrix)
464 VIGRA_REDUCE_MODFIER(VIGRA_VOID, Central<ScatterMatrixEigensystem>, ScatterMatrixEigensystem)
466 VIGRA_REDUCE_MODFIER(VIGRA_VOID, Principal<Centralize>, PrincipalProjection)
467 VIGRA_REDUCE_MODFIER(VIGRA_VOID, Whitened<Centralize>, Whiten)
468 VIGRA_REDUCE_MODFIER(VIGRA_VOID, Principal<PrincipalProjection>, PrincipalProjection)
469 VIGRA_REDUCE_MODFIER(VIGRA_VOID, Whitened<PrincipalProjection>, Whiten)
470 VIGRA_REDUCE_MODFIER(VIGRA_VOID, Whitened<Whiten>, Whiten)
473 template <
unsigned N>
474 struct ModifierRule<AbsPowerSum<N> >
476 typedef typename IfBool<(N % 2 == 0), PowerSum<N>, AbsPowerSum<N> >::type type;
480 #undef VIGRA_REDUCE_MODFIER
483 struct ShouldBeWeighted
485 typedef VigraFalseType type;
486 static const bool value =
false;
490 struct ShouldBeWeighted<ArgMinWeight>
492 typedef VigraTrueType type;
493 static const bool value =
true;
497 struct ShouldBeWeighted<ArgMaxWeight>
499 typedef VigraTrueType type;
500 static const bool value =
true;
503 template <
class A,
template <
class>
class B>
504 struct ShouldBeWeighted<B<A> >
505 :
public ShouldBeWeighted<A>
511 struct IsCoordinateFeature
513 typedef VigraFalseType type;
514 static const bool value =
false;
517 template <
class A,
template <
class>
class B>
518 struct IsCoordinateFeature<B<A> >
520 typedef typename IsCoordinateFeature<A>::type type;
521 static const bool value = IsCoordinateFeature<A>::value;
525 struct IsCoordinateFeature<Coord<A> >
527 typedef VigraTrueType type;
528 static const bool value =
true;
532 struct IsPrincipalFeature
534 typedef VigraFalseType type;
535 static const bool value =
false;
538 template <
class A,
template <
class>
class B>
539 struct IsPrincipalFeature<B<A> >
541 typedef typename IsPrincipalFeature<A>::type type;
542 static const bool value = IsPrincipalFeature<A>::value;
546 struct IsPrincipalFeature<Principal<A> >
548 typedef VigraTrueType type;
549 static const bool value =
true;
553 struct IsPrincipalFeature<Whitened<A> >
555 typedef VigraTrueType type;
556 static const bool value =
true;
565 namespace acc_detail {
568 struct DefaultModifier;
571 struct ModifierPriority<DefaultModifier<A> >
573 static const int value = ModifierPriority<A>::value << 1;
576 template <class A, int TargetPriority, int Priority=ModifierPriority<A>::value>
577 struct InsertDefaultModifier
579 typedef DefaultModifier<typename InsertDefaultModifier<A, (TargetPriority << 1)>::type> type;
582 template <
class A,
int TargetPriority>
583 struct InsertDefaultModifier<A, TargetPriority, TargetPriority>
588 template <class A, int TargetPriority, int Priority=ModifierPriority<A>::value>
591 template <
class A,
int TargetPriority>
592 struct TagLongForm<A, TargetPriority, MaxPriority>
594 typedef typename InsertDefaultModifier<A, TargetPriority>::type type;
597 template <
class A,
template <
class>
class B,
int TargetPriority>
598 struct TagLongForm<B<A>, TargetPriority, MaxPriority>
600 typedef typename InsertDefaultModifier<B<A>, TargetPriority>::type type;
603 template <
class A,
template <
class>
class B,
int TargetPriority,
int Priority>
604 struct TagLongForm<B<A>, TargetPriority, Priority>
606 typedef typename TagLongForm<A, (Priority << 1)>::type Inner;
607 typedef typename InsertDefaultModifier<B<Inner>, TargetPriority>::type type;
610 template <
class A,
template <
class>
class B,
int TargetPriority>
611 struct TagLongForm<B<A>, TargetPriority, TargetPriority>
613 typedef typename TagLongForm<A, (TargetPriority << 1)>::type Inner;
614 typedef B<Inner> type;
618 struct LongModifierRule
624 template <class A, class S=typename LongModifierRule<A>::type>
625 struct StandardizeTagLongForm
627 typedef typename StandardizeTagLongForm<S>::type type;
632 struct StandardizeTagLongForm<A, A>
637 template <
class A,
template <
class>
class B>
638 struct LongModifierRule<B<A> >
640 typedef B<typename LongModifierRule<A>::type> type;
644 struct LongModifierRule<DefaultModifier<A> >
649 #define VIGRA_DROP_DATA_PREPARATION_MODIFIERS(SOURCE, TARGET) \
651 struct LongModifierRule<SOURCE > \
653 typedef TARGET type; \
656 VIGRA_DROP_DATA_PREPARATION_MODIFIERS(Central<Sum>, Sum)
657 VIGRA_DROP_DATA_PREPARATION_MODIFIERS(Principal<Sum>, Sum)
658 VIGRA_DROP_DATA_PREPARATION_MODIFIERS(Whitened<Sum>, Sum)
659 VIGRA_DROP_DATA_PREPARATION_MODIFIERS(Principal<FlatScatterMatrix>, FlatScatterMatrix)
660 VIGRA_DROP_DATA_PREPARATION_MODIFIERS(Whitened<FlatScatterMatrix>, FlatScatterMatrix)
661 VIGRA_DROP_DATA_PREPARATION_MODIFIERS(Principal<ScatterMatrixEigensystem>, ScatterMatrixEigensystem)
662 VIGRA_DROP_DATA_PREPARATION_MODIFIERS(Whitened<ScatterMatrixEigensystem>, ScatterMatrixEigensystem)
664 #undef VIGRA_DROP_DATA_PREPARATION_MODIFIERS
667 struct CheckSubstitutionFlag
669 static const bool value = (ModifierPriority<A>::value & SubstitutionMask) != 0;
672 template <
class A,
class B,
673 bool substitute=CheckSubstitutionFlag<A>::value>
674 struct SubstituteModifiers;
676 template <
class A,
class B>
677 struct SubstituteModifiers<A, B, false>
682 template <
class A,
template <
class>
class AA,
class B,
template <
class>
class BB>
683 struct SubstituteModifiers<AA<A>, BB<B>, true>
685 typedef AA<typename SubstituteModifiers<A, B>::type> type;
688 template <
class A,
class B,
template <
class>
class BB>
689 struct SubstituteModifiers<DefaultModifier<A>, BB<B>, true>
691 typedef BB<typename SubstituteModifiers<A, B>::type> type;
694 template <
class A,
template <
class>
class AA,
class B,
template <
class>
class BB>
695 struct SubstituteModifiers<AA<A>, BB<B>, false>
697 typedef BB<typename SubstituteModifiers<A, B>::type> type;
702 template <
class A,
class B>
703 struct TransferModifiers
705 typedef typename StandardizeTag<A>::type StdA;
706 typedef typename StandardizeTag<B>::type StdB;
707 typedef typename acc_detail::TagLongForm<StdA, acc_detail::MinPriority>::type AA;
708 typedef typename acc_detail::TagLongForm<StdB, acc_detail::MinPriority>::type BB;
709 typedef typename acc_detail::SubstituteModifiers<AA, BB>::type AB;
710 typedef typename acc_detail::StandardizeTagLongForm<AB>::type StdAB;
711 typedef typename StandardizeTag<StdAB>::type type;
714 template <
class A,
class HEAD,
class TAIL>
715 struct TransferModifiers<A, TypeList<HEAD, TAIL> >
717 typedef TypeList<typename TransferModifiers<A, HEAD>::type,
718 typename TransferModifiers<A, TAIL>::type> type;
722 struct TransferModifiers<A, void>
727 template <
class TargetTag,
class A=
typename TargetTag::Dependencies>
728 struct StandardizeDependencies
730 :
public StandardizeDependencies<TargetTag, typename A::type>
734 template <
class TargetTag,
class HEAD,
class TAIL>
735 struct StandardizeDependencies<TargetTag, TypeList<HEAD, TAIL> >
737 typedef typename StandardizeTag<TargetTag>::type Target;
738 typedef typename TransferModifiers<Target, TypeList<HEAD, TAIL> >::type type;
741 template <
class TargetTag>
742 struct StandardizeDependencies<TargetTag, void>
749 #endif // VIGRA_ACCUMULATOR_GRAMMAR_HXX
Basic statistic. Data value where weight assumes its minimal value.
Definition: accumulator.hxx:5141
Histogram where user provides bounds for linear range mapping from values to indices.
Definition: accumulator-grammar.hxx:71
Basic statistic. PowerSum = .
Definition: accumulator-grammar.hxx:59
RootDivideByCount< Central< PowerSum< 2 > > > StdDev
Alias. Standard deviation.
Definition: accumulator-grammar.hxx:185
PowerSum< 0 > Count
Alias. Count.
Definition: accumulator-grammar.hxx:145
Central< PowerSum< 2 > > SumOfSquaredDifferences
Alias. Sum of squared differences.
Definition: accumulator-grammar.hxx:175
DivideByCount< Central< PowerSum< 2 > > > Variance
Alias. Variance.
Definition: accumulator-grammar.hxx:183
DivideByCount< SumOfAbsDifferences > MeanAbsoluteDeviation
Alias. Mean absolute deviation.
Definition: accumulator-grammar.hxx:203
Basic statistic. Maximum value.
Definition: accumulator.hxx:5063
AbsPowerSum< 1 > AbsSum
Alias. Absolute sum.
Definition: accumulator-grammar.hxx:199
PowerSum< 2 > SumOfSquares
Alias. Sum of squares.
Definition: accumulator-grammar.hxx:158
Modifier. Compute statistic globally rather than per region.
Definition: accumulator-grammar.hxx:145
Basic statistic. Skewness.
Definition: accumulator.hxx:4302
SumOfSquaredDifferences SSD
Alias. Sum of squared differences.
Definition: accumulator-grammar.hxx:180
Basic statistic. Identity matrix of appropriate size.
Definition: accumulator.hxx:3705
DivideByCount< ScatterMatrixEigensystem > CovarianceEigensystem
Alias. Covariance eigensystem.
Definition: accumulator-grammar.hxx:196
Basic statistic. Kurtosis.
Definition: accumulator.hxx:4374
Basic statistic. Unbiased Kurtosis.
Definition: accumulator.hxx:4410
DivideByCount< FlatScatterMatrix > Covariance
Alias. Covariance.
Definition: accumulator-grammar.hxx:192
Histogram where range mapping bounds are defined by minimum and maximum of data.
Definition: accumulator-grammar.hxx:72
Basic statistic. Flattened uppter-triangular part of scatter matrix.
Definition: accumulator.hxx:4506
Modifier. Substract mean before computing statistic.
Definition: accumulator-grammar.hxx:139
Compute weighted version of the statistic.
Definition: accumulator-grammar.hxx:134
DivideUnbiased< Central< PowerSum< 2 > > > UnbiasedVariance
Alias. Unbiased variance.
Definition: accumulator-grammar.hxx:187
Alias. CentralMoment.
Definition: accumulator-grammar.hxx:175
Weighted< RegionCenter > CenterOfMass
Alias. Center of mass.
Definition: accumulator-grammar.hxx:213
Definition: accessor.hxx:43
Weighted< Coord< Principal< Variance > > > MomentsOfInertia
Alias. Moments of inertia.
Definition: accumulator-grammar.hxx:215
DivideByCount< Sum > Mean
Alias. Mean.
Definition: accumulator-grammar.hxx:161
Basic statistic. Unbiased Skewness.
Definition: accumulator.hxx:4338
Coord< Mean > RegionCenter
Alias. Region center.
Definition: accumulator-grammar.hxx:206
Specifies index of labels in CoupledHandle.
Definition: accumulator-grammar.hxx:95
Specifies index of data in CoupledHandle.
Definition: accumulator-grammar.hxx:94
Alias. Moment.
Definition: accumulator-grammar.hxx:173
PowerSum< 1 > Sum
Alias. Sum.
Definition: accumulator-grammar.hxx:156
Definition: accumulator.hxx:4676
RootDivideByCount< SumOfSquares > RootMeanSquares
Alias. Root mean square.
Definition: accumulator-grammar.hxx:163
Modifier. Project onto PCA eigenvectors.
Definition: accumulator-grammar.hxx:140
Central< AbsSum > SumOfAbsDifferences
Alias. Sum of absolute differences.
Definition: accumulator-grammar.hxx:201
Histogram where data values are equal to bin indices.
Definition: accumulator-grammar.hxx:70
Basic statistic. Data where weight assumes its maximal value.
Definition: accumulator.hxx:5216
Modifier. RootDivideByCount = sqrt( TAG/Count )
Definition: accumulator-grammar.hxx:128
DivideUnbiased< FlatScatterMatrix > UnbiasedCovariance
Alias. Unbiased covariance.
Definition: accumulator-grammar.hxx:194
Compute (0%, 10%, 25%, 50%, 75%, 90%, 100%) quantiles from given histogram.
Definition: accumulator-grammar.hxx:77
Modifier. Divide statistic by Count: DivideByCount = TAG / Count .
Definition: accumulator-grammar.hxx:127
Basic statistic. AbsPowerSum = .
Definition: accumulator-grammar.hxx:60
Specifies index of data in CoupledHandle.
Definition: accumulator-grammar.hxx:93
Like AutoRangeHistogram, but use global min/max rather than region min/max.
Definition: accumulator-grammar.hxx:73
RootDivideUnbiased< Central< PowerSum< 2 > > > UnbiasedStdDev
Alias. Unbiased standard deviation.
Definition: accumulator-grammar.hxx:189
Coord< Principal< CoordinateSystem > > RegionAxes
Alias. Region axes.
Definition: accumulator-grammar.hxx:210
Basic statistic. Minimum value.
Definition: accumulator.hxx:4985
Weighted< RegionAxes > AxesOfInertia
Alias. Axes of inertia.
Definition: accumulator-grammar.hxx:217
Modifier. Divide statistics by Count-1: DivideUnbiased = TAG / (Count-1)
Definition: accumulator-grammar.hxx:129
Modifier. Compute statistic from pixel coordinates rather than from pixel values. ...
Definition: accumulator-grammar.hxx:133
Coord< Principal< StdDev > > RegionRadii
Alias. Region radii.
Definition: accumulator-grammar.hxx:208
Modifier. RootDivideUnbiased = sqrt( TAG / (Count-1) )
Definition: accumulator-grammar.hxx:130