8 #include <vnl/vnl_matrix.h> 15 template <
class VectorType,
class ScalarType>
double ComputeVMFPdf(
const VectorType &v,
const VectorType &meanDirection,
const ScalarType &kappa)
19 std::cout <<
"Norm of mean direction: " <<
anima::ComputeNorm(meanDirection) << std::endl;
21 throw itk::ExceptionObject(__FILE__, __LINE__,
"Von Mises & Fisher distribution requires unitary vectors.",ITK_LOCATION);
35 resVal = std::exp(tmpVal);
37 tmpVal = 1.0 - std::exp(-2.0 * kappa);
38 resVal /= (2.0 * M_PI * tmpVal);
44 template <
class ScalarType,
unsigned int Dimension>
46 VMFDistance(
const itk::Point <ScalarType, Dimension> &muFirst,
const double &kappaFirst,
47 const itk::Point <ScalarType, Dimension> &muSec,
const double &kappaSec)
51 double scalarProduct = 0;
52 for (
unsigned int i = 0;i < Dimension;++i)
53 scalarProduct += muFirst[i] * muSec[i];
55 if (scalarProduct < -1.0)
58 if (scalarProduct > 1.0)
61 double acosValue = std::acos(scalarProduct);
63 dist =
anima::safe_log(std::max(1.0e-16,kappaSec) / std::max(1.0e-16,kappaFirst));
65 dist += acosValue * acosValue;
70 template <
class ScalarType>
81 double rbarSq = rbar * rbar;
82 kappa = rbar * (12.0 + 6.0 * rbarSq + 5.0 * rbarSq * rbarSq) / 6.0;
84 else if (rbar < 0.48070)
85 kappa = 0.1 * (rbar - 0.44639) / (0.48070 - 0.44639) + 1.0;
86 else if (rbar < 0.51278)
87 kappa = 0.1 * (rbar - 0.48070) / (0.51278 - 0.48070) + 1.1;
88 else if (rbar < 0.54267)
89 kappa = 0.1 * (rbar - 0.51278) / (0.54267 - 0.51278) + 1.2;
90 else if (rbar < 0.57042)
91 kappa = 0.1 * (rbar - 0.54267) / (0.57042 - 0.54267) + 1.3;
92 else if (rbar < 0.59613)
93 kappa = 0.1 * (rbar - 0.57042) / (0.59613 - 0.57042) + 1.4;
94 else if (rbar < 0.61990)
95 kappa = 0.1 * (rbar - 0.59613) / (0.61990 - 0.59613) + 1.5;
96 else if (rbar < 0.64183)
97 kappa = 0.1 * (rbar - 0.61990) / (0.64183 - 0.61990) + 1.6;
98 else if (rbar < 0.66204)
99 kappa = 0.1 * (rbar - 0.64183) / (0.66204 - 0.64183) + 1.7;
100 else if (rbar < 0.68065)
101 kappa = 0.1 * (rbar - 0.66204) / (0.68065 - 0.66204) + 1.8;
102 else if (rbar < 0.69777)
103 kappa = 0.1 * (rbar - 0.68065) / (0.69777 - 0.68065) + 1.9;
104 else if (rbar < 0.71353)
105 kappa = 0.1 * (rbar - 0.69777) / (0.71353 - 0.69777) + 2.0;
106 else if (rbar < 0.72803)
107 kappa = 0.1 * (rbar - 0.71353) / (0.72803 - 0.71353) + 2.1;
108 else if (rbar < 0.74138)
109 kappa = 0.1 * (rbar - 0.72803) / (0.74138 - 0.72803) + 2.2;
110 else if (rbar < 0.75367)
111 kappa = 0.1 * (rbar - 0.74138) / (0.75367 - 0.74138) + 2.3;
112 else if (rbar < 0.76500)
113 kappa = 0.1 * (rbar - 0.75367) / (0.76500 - 0.75367) + 2.4;
114 else if (rbar < 0.77545)
115 kappa = 0.1 * (rbar - 0.76500) / (0.77545 - 0.76500) + 2.5;
116 else if (rbar < 0.78511)
117 kappa = 0.1 * (rbar - 0.77545) / (0.78511 - 0.77545) + 2.6;
118 else if (rbar < 0.79404)
119 kappa = 0.1 * (rbar - 0.78511) / (0.79404 - 0.78511) + 2.7;
120 else if (rbar < 0.80231)
121 kappa = 0.1 * (rbar - 0.79404) / (0.80231 - 0.79404) + 2.8;
125 double irbar = 1.0 - rbar;
126 double irbarSq = irbar * irbar;
127 kappa = 1.0 / (2.0 * irbar - irbarSq - irbar * irbarSq);
double GetVonMisesConcentrationMLE(const ScalarType rbar)
Maximum likelihood estimation of the concentration parameter of the 2D von Mises distribution accordi...
double ComputeNorm(const VectorType &v)
double VMFDistance(const itk::Point< ScalarType, Dimension > &muFirst, const double &kappaFirst, const itk::Point< ScalarType, Dimension > &muSec, const double &kappaSec)
double ComputeScalarProduct(const VectorType &v1, const VectorType &v2, const unsigned int NDimension)
double safe_log(const ScalarType x)
double ComputeVMFPdf(const VectorType &v, const VectorType &meanDirection, const ScalarType &kappa)