ParaMonte Fortran 2.0.0
Parallel Monte Carlo and Machine Learning Library
See the latest version documentation.
pm_distanceMahal::setDisMahalSq Interface Reference

Return the square of the Mahalanobis distance of a (set of npnt) point(s) from a single (or a set of nsam independent) sample(s) characterized by a (set of) Multivariate Normal (MVN) distribution(s) in ndim dimensions. More...

Detailed Description

Return the square of the Mahalanobis distance of a (set of npnt) point(s) from a single (or a set of nsam independent) sample(s) characterized by a (set of) Multivariate Normal (MVN) distribution(s) in ndim dimensions.

See pm_distanceMahal for the mathematical definition of the Mahalanobis distance.

Parameters
[out]mahalSq: The output of the same type and kind as the input point representing the square of the Mahalanobis distance of point from the MVN distribution(s) specified by the arguments center and invCov.
On output, mahalSq is,
  1. a scalar if,
    1. the input point is a scalar.
    2. the input point is of shape (1:ndim) and invCov is of shape (1:ndim, 1:ndim).
  2. a vector of size (1:nsam) if the input point is of shape (1:ndim) and invCov is of shape (1:ndim, 1:ndim, 1:nsam).
  3. a vector of size (1:npnt) if the input point is of shape (1:ndim, 1:npnt) and invCov is of shape (1:ndim, 1:ndim).
  4. a matrix of size (1:nsam, 1:npnt) if the input point is of shape (1:ndim, 1:npnt) and invCov is of shape (1:ndim, 1:ndim, 1:nsam).
[in]point: The input scalar, or vector of size ndim, or array of shape (ndim, npnt) of either
  1. type complex of kind any supported by the processor (e.g., CK, CK32, CK64, or CK128), or
  2. type real of kind any supported by the processor (e.g., RK, RK32, RK64, or RK128),
representing the ndim-dimensional coordinates of (npnt) point(s) whose distance(s) from the specified MVN distribution(s) should be computed.
[in]invCov: The input scalar or matrix of shape (ndim, ndim) or array of shape (ndim, ndim, nsam) of the same type and kind as the input point, representing the inverse covariance matrix(es) of the MVN distribution(s).
(optional, default = 1 if and only if point is a scalar, otherwise, the Identity matrix of shape (ndim, ndim)).
[in]center: The input scalar or vector size ndim or matrix of shape (ndim, nsam) of the same type and kind as the input point, representing the center of the MVN distribution(s).
(optional, default = 0).


Possible calling interfaces

call setDisMahalSq(mahalSq, point, invCov) ! elemental
call setDisMahalSq(mahalSq, point, invCov, mean) ! elemental
call setDisMahalSq(mahalSq, point(1:ndim), invCov(1:ndim, 1:ndim))
call setDisMahalSq(mahalSq, point(1:ndim), invCov(1:ndim, 1:ndim), center(1:ndim))
call setDisMahalSq(mahalSq(1:npnt), point(1:ndim, 1:npnt), invCov(1:ndim, 1:ndim))
call setDisMahalSq(mahalSq(1:npnt), point(1:ndim, 1:npnt), invCov(1:ndim, 1:ndim), center(1:ndim))
call setDisMahalSq(mahalSq(1:nsam), point(1:ndim), invCov(1:ndim, 1:ndim, 1:nsam))
call setDisMahalSq(mahalSq(1:nsam), point(1:ndim), invCov(1:ndim, 1:ndim, 1:nsam), center(1:ndim, 1:nsam))
call setDisMahalSq(mahalSq(1:nsam, 1:npnt), point(1:ndim, 1:npnt), invCov(1:ndim, 1:ndim, 1:nsam))
call setDisMahalSq(mahalSq(1:nsam, 1:npnt), point(1:ndim, 1:npnt), invCov(1:ndim, 1:ndim, 1:nsam), center(1:ndim, 1:nsam))
Return the square of the Mahalanobis distance of a (set of npnt) point(s) from a single (or a set of ...
This module contains classes and procedures for computing the Mahalanobis statistical distance.
Warning
The condition size(point, 1) == size(center, 1) must hold for the corresponding input arguments.
The condition all(size(point, 1) == [size(invCov, 1), size(invCov, 2)]) must hold for the corresponding input arguments.
The condition size(center, rank(center)) == size(invCov, rank(invCov)) must hold for the corresponding input arguments.
The condition isMatClass(invCov, posdefmat) must hold for the corresponding input arguments.
The size and shape of the input mahalSq must be consistent with other input arguments.
These conditions are verified only if the library is built with the preprocessor macro CHECK_ENABLED=1.
The pure procedure(s) documented herein become impure when the ParaMonte library is compiled with preprocessor macro CHECK_ENABLED=1.
By default, these procedures are pure in release build and impure in debug and testing builds.
Remarks
The procedures under this generic interface are elemental only when all input arguments are scalars or arrays of the same rank as other array-like arguments.
Note
The computation of the Mahalanobis distance for complex arguments follows the normal intrinsic Fortran rules for complex arithmetic.


Example usage

1program example
2
3 use pm_kind, only: SK, IK
4 use pm_arrayFill, only: getFilled
5 use pm_distUnif, only: getUnifRand
7 use pm_distCov, only: getCovRand
10 use pm_matrixInit, only: getMatInit
11 use pm_matrixInit, only: uppLowDia
12 use pm_io, only: display_type
13
14 implicit none
15
16 integer(IK) :: ndim, npnt, nsam, isam
17
18 type(display_type) :: disp
19 disp = display_type(file = "main.out.F90")
20
21 call disp%skip()
22 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
23 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
24 call disp%show("! Compute the Mahalanobis distance squared for real-valued arguments.")
25 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
26 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
27 call disp%skip()
28
29 block
30
31 use pm_kind, only: RKG => RKS ! all other real kinds are also supported.
32 real(RKG), allocatable :: point(:,:), mahalSq(:,:), mean(:,:), invCov(:,:,:)
33
34 call disp%show("ndim = 3; npnt = 5; nsam = 2")
35 ndim = 3; npnt = 5; nsam = 2
36 call disp%show("point = getUnifRand(0., 1., ndim, npnt)")
37 point = getUnifRand(0., 1., ndim, npnt)
38 call disp%show("point")
39 call disp%show( point )
40 call disp%show("call setResized(mean, [ndim, nsam])")
41 call setResized(mean, [ndim, nsam])
42 call disp%show("call setResized(invCov, [ndim, ndim, nsam])")
43 call setResized(invCov, [ndim, ndim, nsam])
44 call disp%show("do isam = 1, nsam")
45 do isam = 1, nsam
46 call disp%show("invCov(:,:,isam) = getCovRand(mold = 1., ndim = ndim)")
47 invCov(:,:,isam) = getCovRand(mold = 1., ndim = ndim)
48 call disp%show("mean(:,isam) = getFilled(isam - 1, ndim)")
49 mean(:,isam) = getFilled(isam - 1, ndim)
50 call disp%show("end do")
51 end do
52 call disp%show("invCov")
53 call disp%show( invCov )
54 call disp%show("mean")
55 call disp%show( mean )
56 call disp%show("call setResized(mahalSq, [nsam, npnt])")
57 call setResized(mahalSq, [nsam, npnt])
58
59
60 call disp%show("call setDisMahalSq(mahalSq, point, invCov) ! for a set of ndim-dimensional points against nsam independent samples centered at origin.")
61 call setDisMahalSq(mahalSq, point, invCov)
62 call disp%show("mahalSq")
63 call disp%show( mahalSq )
64 call disp%show("call setDisMahalSq(mahalSq, point, invCov, mean) ! for a set of ndim-dimensional points against nsam independent samples centered at mean.")
65 call setDisMahalSq(mahalSq, point, invCov, mean)
66 call disp%show("mahalSq")
67 call disp%show( mahalSq )
68
69 call disp%show("call setDisMahalSq(mahalSq(1:nsam, 1), point(1:ndim, 1), invCov) ! for a single ndim-dimensional point against nsam independent samples centered at origin.")
70 call setDisMahalSq(mahalSq(1:nsam, 1), point(1:ndim, 1), invCov)
71 call disp%show("mahalSq(1:nsam, 1)")
72 call disp%show( mahalSq(1:nsam, 1) )
73 call disp%show("call setDisMahalSq(mahalSq(1:nsam, 1), point(1:ndim, 1), invCov, mean) ! for a single ndim-dimensional point against nsam independent samples centered at mean.")
74 call setDisMahalSq(mahalSq(1:nsam, 1), point(1:ndim, 1), invCov, mean)
75 call disp%show("mahalSq(1:nsam, 1)")
76 call disp%show( mahalSq(1:nsam, 1) )
77
78
79 call disp%show("call setDisMahalSq(mahalSq(1, 1:npnt), point, invCov(:,:,1)) ! for a set of ndim-dimensional points against one sample centered at origin.")
80 call setDisMahalSq(mahalSq(1, 1:npnt), point, invCov(:,:,1))
81 call disp%show("mahalSq(1, 1:npnt)")
82 call disp%show( mahalSq(1, 1:npnt) )
83 call disp%show("call setDisMahalSq(mahalSq(1, 1:npnt), point, invCov(:,:,1), mean(:,1)) ! for a set of ndim-dimensional points against one sample centered at mean.")
84 call setDisMahalSq(mahalSq(1, 1:npnt), point, invCov(:,:,1), mean(:,1))
85 call disp%show("mahalSq(1, 1:npnt)")
86 call disp%show( mahalSq(1, 1:npnt) )
87
88 call disp%show("call setDisMahalSq(mahalSq(1, 1), point(1:ndim, 1), invCov(:,:,1)) ! for a single ndim-dimensional point one sample centered at origin.")
89 call setDisMahalSq(mahalSq(1, 1), point(1:ndim, 1), invCov(:,:,1))
90 call disp%show("mahalSq(1, 1)")
91 call disp%show( mahalSq(1, 1) )
92 call disp%show("call setDisMahalSq(mahalSq(1, 1), point(1:ndim, 1), invCov(:,:,1), mean(:,1)) ! for a single ndim-dimensional point one sample centered at mean.")
93 call setDisMahalSq(mahalSq(1, 1), point(1:ndim, 1), invCov(:,:,1), mean(:,1))
94 call disp%show("mahalSq(1, 1)")
95 call disp%show( mahalSq(1, 1) )
96
97
98 call disp%show("call setDisMahalSq(mahalSq(1, 1:npnt), point(1, 1:npnt), invCov(1,1,1)) ! for a set of single-dimensional points against one sample centered at origin.")
99 call setDisMahalSq(mahalSq(1, 1:npnt), point(1, 1:npnt), invCov(1,1,1))
100 call disp%show("mahalSq(1, 1:npnt)")
101 call disp%show( mahalSq(1, 1:npnt) )
102 call disp%show("call setDisMahalSq(mahalSq(1, 1:npnt), point(1, 1:npnt), invCov(1,1,1), mean(1,1)) ! for a set of single-dimensional points against one sample centered at mean.")
103 call setDisMahalSq(mahalSq(1, 1:npnt), point(1, 1:npnt), invCov(1,1,1), mean(1,1))
104 call disp%show("mahalSq(1, 1:npnt)")
105 call disp%show( mahalSq(1, 1:npnt) )
106
107 call disp%show("call setDisMahalSq(mahalSq(1, 1), point(1, 1), invCov(1,1,1)) ! for a single single-dimensional point one sample centered at origin.")
108 call setDisMahalSq(mahalSq(1, 1), point(1, 1), invCov(1,1,1))
109 call disp%show("mahalSq(1, 1)")
110 call disp%show( mahalSq(1, 1) )
111 call disp%show("call setDisMahalSq(mahalSq(1, 1), point(1, 1), invCov(1,1,1), mean(1,1)) ! for a single single-dimensional point one sample centered at mean.")
112 call setDisMahalSq(mahalSq(1, 1), point(1, 1), invCov(1,1,1), mean(1,1))
113 call disp%show("mahalSq(1, 1)")
114 call disp%show( mahalSq(1, 1) )
115
116 end block
117
118 call disp%skip()
119 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
120 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
121 call disp%show("! Compute the Mahalanobis distance squared for complex-valued arguments.")
122 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
123 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
124 call disp%skip()
125
126 block
127
128 use pm_kind, only: CKG => CKS ! all other complex kinds are also supported.
129 complex(CKG), allocatable :: point(:,:), mahalSq(:,:), mean(:,:), invCov(:,:,:)
130
131 call disp%show("ndim = 3; npnt = 5; nsam = 2")
132 ndim = 3; npnt = 5; nsam = 2
133 call disp%show("point = getUnifRand(0., 1., ndim, npnt)")
134 point = getUnifRand(0., 1., ndim, npnt)
135 call disp%show("point")
136 call disp%show( point )
137 call disp%show("call setResized(mean, [ndim, nsam])")
138 call setResized(mean, [ndim, nsam])
139 call disp%show("call setResized(invCov, [ndim, ndim, nsam])")
140 call setResized(invCov, [ndim, ndim, nsam])
141 call disp%show("do isam = 1, nsam")
142 do isam = 1, nsam
143 call disp%show("invCov(:,:,isam) = getCovRand(mold = (1., 1.), ndim = ndim)")
144 invCov(:,:,isam) = getCovRand(mold = (1., 1.), ndim = ndim)
145 call disp%show("mean(:,isam) = getFilled(isam - 1, ndim)")
146 mean(:,isam) = getFilled(isam - 1, ndim)
147 call disp%show("end do")
148 end do
149 call disp%show("invCov")
150 call disp%show( invCov )
151 call disp%show("mean")
152 call disp%show( mean )
153 call disp%show("call setResized(mahalSq, [nsam, npnt])")
154 call setResized(mahalSq, [nsam, npnt])
155
156
157 call disp%show("call setDisMahalSq(mahalSq, point, invCov) ! for a set of ndim-dimensional points against nsam independent samples centered at origin.")
158 call setDisMahalSq(mahalSq, point, invCov)
159 call disp%show("mahalSq")
160 call disp%show( mahalSq )
161 call disp%show("call setDisMahalSq(mahalSq, point, invCov, mean) ! for a set of ndim-dimensional points against nsam independent samples centered at mean.")
162 call setDisMahalSq(mahalSq, point, invCov, mean)
163 call disp%show("mahalSq")
164 call disp%show( mahalSq )
165
166 call disp%show("call setDisMahalSq(mahalSq(1:nsam, 1), point(1:ndim, 1), invCov) ! for a single ndim-dimensional point against nsam independent samples centered at origin.")
167 call setDisMahalSq(mahalSq(1:nsam, 1), point(1:ndim, 1), invCov)
168 call disp%show("mahalSq(1:nsam, 1)")
169 call disp%show( mahalSq(1:nsam, 1) )
170 call disp%show("call setDisMahalSq(mahalSq(1:nsam, 1), point(1:ndim, 1), invCov, mean) ! for a single ndim-dimensional point against nsam independent samples centered at mean.")
171 call setDisMahalSq(mahalSq(1:nsam, 1), point(1:ndim, 1), invCov, mean)
172 call disp%show("mahalSq(1:nsam, 1)")
173 call disp%show( mahalSq(1:nsam, 1) )
174
175
176 call disp%show("call setDisMahalSq(mahalSq(1, 1:npnt), point, invCov(:,:,1)) ! for a set of ndim-dimensional points against one sample centered at origin.")
177 call setDisMahalSq(mahalSq(1, 1:npnt), point, invCov(:,:,1))
178 call disp%show("mahalSq(1, 1:npnt)")
179 call disp%show( mahalSq(1, 1:npnt) )
180 call disp%show("call setDisMahalSq(mahalSq(1, 1:npnt), point, invCov(:,:,1), mean(:,1)) ! for a set of ndim-dimensional points against one sample centered at mean.")
181 call setDisMahalSq(mahalSq(1, 1:npnt), point, invCov(:,:,1), mean(:,1))
182 call disp%show("mahalSq(1, 1:npnt)")
183 call disp%show( mahalSq(1, 1:npnt) )
184
185 call disp%show("call setDisMahalSq(mahalSq(1, 1), point(1:ndim, 1), invCov(:,:,1)) ! for a single ndim-dimensional point one sample centered at origin.")
186 call setDisMahalSq(mahalSq(1, 1), point(1:ndim, 1), invCov(:,:,1))
187 call disp%show("mahalSq(1, 1)")
188 call disp%show( mahalSq(1, 1) )
189 call disp%show("call setDisMahalSq(mahalSq(1, 1), point(1:ndim, 1), invCov(:,:,1), mean(:,1)) ! for a single ndim-dimensional point one sample centered at mean.")
190 call setDisMahalSq(mahalSq(1, 1), point(1:ndim, 1), invCov(:,:,1), mean(:,1))
191 call disp%show("mahalSq(1, 1)")
192 call disp%show( mahalSq(1, 1) )
193
194
195 call disp%show("call setDisMahalSq(mahalSq(1, 1:npnt), point(1, 1:npnt), invCov(1,1,1)) ! for a set of single-dimensional points against one sample centered at origin.")
196 call setDisMahalSq(mahalSq(1, 1:npnt), point(1, 1:npnt), invCov(1,1,1))
197 call disp%show("mahalSq(1, 1:npnt)")
198 call disp%show( mahalSq(1, 1:npnt) )
199 call disp%show("call setDisMahalSq(mahalSq(1, 1:npnt), point(1, 1:npnt), invCov(1,1,1), mean(1,1)) ! for a set of single-dimensional points against one sample centered at mean.")
200 call setDisMahalSq(mahalSq(1, 1:npnt), point(1, 1:npnt), invCov(1,1,1), mean(1,1))
201 call disp%show("mahalSq(1, 1:npnt)")
202 call disp%show( mahalSq(1, 1:npnt) )
203
204 call disp%show("call setDisMahalSq(mahalSq(1, 1), point(1, 1), invCov(1,1,1)) ! for a single single-dimensional point one sample centered at origin.")
205 call setDisMahalSq(mahalSq(1, 1), point(1, 1), invCov(1,1,1))
206 call disp%show("mahalSq(1, 1)")
207 call disp%show( mahalSq(1, 1) )
208 call disp%show("call setDisMahalSq(mahalSq(1, 1), point(1, 1), invCov(1,1,1), mean(1,1)) ! for a single single-dimensional point one sample centered at mean.")
209 call setDisMahalSq(mahalSq(1, 1), point(1, 1), invCov(1,1,1), mean(1,1))
210 call disp%show("mahalSq(1, 1)")
211 call disp%show( mahalSq(1, 1) )
212
213 end block
214
215end program example
Generate and return an array of the specified rank and shape of arbitrary intrinsic type and kind wit...
Allocate or resize (shrink or expand) an input allocatable scalar string or array of rank 1....
Generate and return a random positive-definite (correlation or covariance) matrix using the Gram meth...
Definition: pm_distCov.F90:394
Generate and return a scalar or a contiguous array of rank 1 of length s1 of randomly uniformly distr...
This is a generic method of the derived type display_type with pass attribute.
Definition: pm_io.F90:11726
This is a generic method of the derived type display_type with pass attribute.
Definition: pm_io.F90:11508
Generate and return a matrix of shape (shape(1), shape(2)) with the upper/lower triangle and the diag...
Generate a sample of shape (nsam), or (ndim, nsam) or (nsam, ndim) that is shifted by the specified i...
This module contains procedures and generic interfaces for convenient allocation and filling of array...
This module contains procedures and generic interfaces for resizing allocatable arrays of various typ...
This module contains classes and procedures for generating random matrices distributed on the space o...
Definition: pm_distCov.F90:72
This module contains classes and procedures for computing various statistical quantities related to t...
This module contains classes and procedures for input/output (IO) or generic display operations on st...
Definition: pm_io.F90:252
type(display_type) disp
This is a scalar module variable an object of type display_type for general display.
Definition: pm_io.F90:11393
This module defines the relevant Fortran kind type-parameters frequently used in the ParaMonte librar...
Definition: pm_kind.F90:268
integer, parameter CKS
The single-precision complex kind in Fortran mode. On most platforms, this is a 32-bit real kind.
Definition: pm_kind.F90:570
integer, parameter IK
The default integer kind in the ParaMonte library: int32 in Fortran, c_int32_t in C-Fortran Interoper...
Definition: pm_kind.F90:540
integer, parameter SK
The default character kind in the ParaMonte library: kind("a") in Fortran, c_char in C-Fortran Intero...
Definition: pm_kind.F90:539
integer, parameter RKS
The single-precision real kind in Fortran mode. On most platforms, this is an 32-bit real kind.
Definition: pm_kind.F90:567
This module contains procedures and generic interfaces relevant to generating and initializing matric...
This module contains classes and procedures for shifting univariate or multivariate samples by arbitr...
Generate and return an object of type display_type.
Definition: pm_io.F90:10282

Example Unix compile command via Intel ifort compiler
1#!/usr/bin/env sh
2rm main.exe
3ifort -fpp -standard-semantics -O3 -Wl,-rpath,../../../lib -I../../../inc main.F90 ../../../lib/libparamonte* -o main.exe
4./main.exe

Example Windows Batch compile command via Intel ifort compiler
1del main.exe
2set PATH=..\..\..\lib;%PATH%
3ifort /fpp /standard-semantics /O3 /I:..\..\..\include main.F90 ..\..\..\lib\libparamonte*.lib /exe:main.exe
4main.exe

Example Unix / MinGW compile command via GNU gfortran compiler
1#!/usr/bin/env sh
2rm main.exe
3gfortran -cpp -ffree-line-length-none -O3 -Wl,-rpath,../../../lib -I../../../inc main.F90 ../../../lib/libparamonte* -o main.exe
4./main.exe

Example output
1
2!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4! Compute the Mahalanobis distance squared for real-valued arguments.
5!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7
8ndim = 3; npnt = 5; nsam = 2
9point = getUnifRand(0., 1., ndim, npnt)
10point
11+0.307646632, +0.974289656, +0.391958237, +0.396983445, +0.624530315
12+0.423068523, +0.806940138, +0.473271310, +0.788580537, +0.701099217
13+0.131918252, +0.445738316, +0.977225959, +0.712988198, +0.518150508
14call setResized(mean, [ndim, nsam])
15call setResized(invCov, [ndim, ndim, nsam])
16do isam = 1, nsam
17invCov(:,:,isam) = getCovRand(mold = 1., ndim = ndim)
18mean(:,isam) = getFilled(isam - 1, ndim)
19end do
20invCov(:,:,isam) = getCovRand(mold = 1., ndim = ndim)
21mean(:,isam) = getFilled(isam - 1, ndim)
22end do
23invCov
24slice(:,:,1) =
25+1.00000000, +0.557211995, +0.593074739
26+0.557211995, +1.00000000, -0.204394877
27+0.593074739, -0.204394877, +1.00000000
28slice(:,:,2) =
29+1.00000000, -0.577371418, -0.201399118
30-0.577371418, +1.00000000, +0.714399278
31-0.201399118, +0.714399278, +1.00000000
32mean
33+0.00000000, +1.00000000
34+0.00000000, +1.00000000
35+0.00000000, +1.00000000
36call setResized(mahalSq, [nsam, npnt])
37call setDisMahalSq(mahalSq, point, invCov) ! for a set of ndim-dimensional points against nsam independent samples centered at origin.
38mahalSq
39+0.461408585, +3.04331183, +1.80458665, +1.74257314, +1.87335312
40+0.204134271, +1.23021388, +1.62490463, +1.61564112, +1.03314602
41call setDisMahalSq(mahalSq, point, invCov, mean) ! for a set of ndim-dimensional points against nsam independent samples centered at mean.
42mahalSq
43+0.461408585, +3.04331183, +1.80458665, +1.74257314, +1.87335312
44+1.57800484, +0.486557007, +0.289405286, +0.360471278, +0.465812206
45call setDisMahalSq(mahalSq(1:nsam, 1), point(1:ndim, 1), invCov) ! for a single ndim-dimensional point against nsam independent samples centered at origin.
46mahalSq(1:nsam, 1)
47+0.461408585, +0.204134271
48call setDisMahalSq(mahalSq(1:nsam, 1), point(1:ndim, 1), invCov, mean) ! for a single ndim-dimensional point against nsam independent samples centered at mean.
49mahalSq(1:nsam, 1)
50+0.461408585, +1.57800484
51call setDisMahalSq(mahalSq(1, 1:npnt), point, invCov(:,:,1)) ! for a set of ndim-dimensional points against one sample centered at origin.
52mahalSq(1, 1:npnt)
53+0.461408585, +3.04331183, +1.80458665, +1.74257314, +1.87335312
54call setDisMahalSq(mahalSq(1, 1:npnt), point, invCov(:,:,1), mean(:,1)) ! for a set of ndim-dimensional points against one sample centered at mean.
55mahalSq(1, 1:npnt)
56+0.461408585, +3.04331183, +1.80458665, +1.74257314, +1.87335312
57call setDisMahalSq(mahalSq(1, 1), point(1:ndim, 1), invCov(:,:,1)) ! for a single ndim-dimensional point one sample centered at origin.
58mahalSq(1, 1)
59+0.461408585
60call setDisMahalSq(mahalSq(1, 1), point(1:ndim, 1), invCov(:,:,1), mean(:,1)) ! for a single ndim-dimensional point one sample centered at mean.
61mahalSq(1, 1)
62+0.461408585
63call setDisMahalSq(mahalSq(1, 1:npnt), point(1, 1:npnt), invCov(1,1,1)) ! for a set of single-dimensional points against one sample centered at origin.
64mahalSq(1, 1:npnt)
65+0.946464539E-1, +0.949240327, +0.153631255, +0.157595858, +0.390038103
66call setDisMahalSq(mahalSq(1, 1:npnt), point(1, 1:npnt), invCov(1,1,1), mean(1,1)) ! for a set of single-dimensional points against one sample centered at mean.
67mahalSq(1, 1:npnt)
68+0.946464539E-1, +0.949240327, +0.153631255, +0.157595858, +0.390038103
69call setDisMahalSq(mahalSq(1, 1), point(1, 1), invCov(1,1,1)) ! for a single single-dimensional point one sample centered at origin.
70mahalSq(1, 1)
71+0.946464539E-1
72call setDisMahalSq(mahalSq(1, 1), point(1, 1), invCov(1,1,1), mean(1,1)) ! for a single single-dimensional point one sample centered at mean.
73mahalSq(1, 1)
74+0.946464539E-1
75
76!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
77!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
78! Compute the Mahalanobis distance squared for complex-valued arguments.
79!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
80!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
81
82ndim = 3; npnt = 5; nsam = 2
83point = getUnifRand(0., 1., ndim, npnt)
84point
85(+0.708676577, +0.00000000), (+0.593804717, +0.00000000), (+0.210587382E-1, +0.00000000), (+0.830424309, +0.00000000), (+0.272669017, +0.00000000)
86(+0.184124112E-1, +0.00000000), (+0.179924130, +0.00000000), (+0.270422697E-1, +0.00000000), (+0.247320890, +0.00000000), (+0.857843161E-1, +0.00000000)
87(+0.594376564, +0.00000000), (+0.653220415, +0.00000000), (+0.586382091, +0.00000000), (+0.886164367, +0.00000000), (+0.433728456, +0.00000000)
88call setResized(mean, [ndim, nsam])
89call setResized(invCov, [ndim, ndim, nsam])
90do isam = 1, nsam
91invCov(:,:,isam) = getCovRand(mold = (1., 1.), ndim = ndim)
92mean(:,isam) = getFilled(isam - 1, ndim)
93end do
94invCov(:,:,isam) = getCovRand(mold = (1., 1.), ndim = ndim)
95mean(:,isam) = getFilled(isam - 1, ndim)
96end do
97invCov
98slice(:,:,1) =
99(+1.00000000, +0.00000000), (+0.486899287, -0.526288986), (+0.683605313, +0.528560102)
100(+0.486899287, +0.526288986), (+1.00000000, +0.00000000), (+0.660461247, +0.210507140E-1)
101(+0.683605313, -0.528560102), (+0.660461247, -0.210507140E-1), (+1.00000000, +0.00000000)
102slice(:,:,2) =
103(+1.00000000, +0.00000000), (+0.535826564, +0.814728439), (+0.188200295, +0.344149202)
104(+0.535826564, -0.814728439), (+1.00000000, +0.00000000), (+0.612202108, -0.434279978)
105(+0.188200295, -0.344149202), (+0.612202108, +0.434279978), (+1.00000000, +0.00000000)
106mean
107(+0.00000000, +0.00000000), (+1.00000000, +0.00000000)
108(+0.00000000, +0.00000000), (+1.00000000, +0.00000000)
109(+0.00000000, +0.00000000), (+1.00000000, +0.00000000)
110call setResized(mahalSq, [nsam, npnt])
111call setDisMahalSq(mahalSq, point, invCov) ! for a set of ndim-dimensional points against nsam independent samples centered at origin.
112mahalSq
113(+1.45890498, -0.149011612E-7), (+1.60128331, +0.149011612E-7), (+0.383402228, +0.465661287E-9), (+3.03168201, +0.00000000), (+0.503445506, +0.00000000)
114(+1.04177594, +0.00000000), (+1.21607351, +0.00000000), (+0.369692475, +0.698491931E-9), (+2.30149603, -0.149011612E-7), (+0.384965748, +0.558793545E-8)
115call setDisMahalSq(mahalSq, point, invCov, mean) ! for a set of ndim-dimensional points against nsam independent samples centered at mean.
116mahalSq
117(+1.45890498, -0.149011612E-7), (+1.60128331, +0.149011612E-7), (+0.383402228, +0.465661287E-9), (+3.03168201, +0.00000000), (+0.503445506, +0.00000000)
118(+2.05134416, +0.149011612E-7), (+1.71597731, +0.149011612E-7), (+3.74191618, +0.298023224E-7), (+0.857196867, -0.558793545E-8), (+3.18694067, -0.298023224E-7)
119call setDisMahalSq(mahalSq(1:nsam, 1), point(1:ndim, 1), invCov) ! for a single ndim-dimensional point against nsam independent samples centered at origin.
120mahalSq(1:nsam, 1)
121(+1.45890498, -0.149011612E-7), (+1.04177594, +0.00000000)
122call setDisMahalSq(mahalSq(1:nsam, 1), point(1:ndim, 1), invCov, mean) ! for a single ndim-dimensional point against nsam independent samples centered at mean.
123mahalSq(1:nsam, 1)
124(+1.45890498, -0.149011612E-7), (+2.05134416, +0.149011612E-7)
125call setDisMahalSq(mahalSq(1, 1:npnt), point, invCov(:,:,1)) ! for a set of ndim-dimensional points against one sample centered at origin.
126mahalSq(1, 1:npnt)
127(+1.45890498, -0.149011612E-7), (+1.60128331, +0.149011612E-7), (+0.383402228, +0.465661287E-9), (+3.03168201, +0.00000000), (+0.503445506, +0.00000000)
128call setDisMahalSq(mahalSq(1, 1:npnt), point, invCov(:,:,1), mean(:,1)) ! for a set of ndim-dimensional points against one sample centered at mean.
129mahalSq(1, 1:npnt)
130(+1.45890498, -0.149011612E-7), (+1.60128331, +0.149011612E-7), (+0.383402228, +0.465661287E-9), (+3.03168201, +0.00000000), (+0.503445506, +0.00000000)
131call setDisMahalSq(mahalSq(1, 1), point(1:ndim, 1), invCov(:,:,1)) ! for a single ndim-dimensional point one sample centered at origin.
132mahalSq(1, 1)
133(+1.45890498, -0.149011612E-7)
134call setDisMahalSq(mahalSq(1, 1), point(1:ndim, 1), invCov(:,:,1), mean(:,1)) ! for a single ndim-dimensional point one sample centered at mean.
135mahalSq(1, 1)
136(+1.45890498, -0.149011612E-7)
137call setDisMahalSq(mahalSq(1, 1:npnt), point(1, 1:npnt), invCov(1,1,1)) ! for a set of single-dimensional points against one sample centered at origin.
138mahalSq(1, 1:npnt)
139(+0.502222478, +0.00000000), (+0.352604032, +0.00000000), (+0.443470461E-3, +0.00000000), (+0.689604521, +0.00000000), (+0.743483901E-1, +0.00000000)
140call setDisMahalSq(mahalSq(1, 1:npnt), point(1, 1:npnt), invCov(1,1,1), mean(1,1)) ! for a set of single-dimensional points against one sample centered at mean.
141mahalSq(1, 1:npnt)
142(+0.502222478, +0.00000000), (+0.352604032, +0.00000000), (+0.443470461E-3, +0.00000000), (+0.689604521, +0.00000000), (+0.743483901E-1, +0.00000000)
143call setDisMahalSq(mahalSq(1, 1), point(1, 1), invCov(1,1,1)) ! for a single single-dimensional point one sample centered at origin.
144mahalSq(1, 1)
145(+0.502222478, +0.00000000)
146call setDisMahalSq(mahalSq(1, 1), point(1, 1), invCov(1,1,1), mean(1,1)) ! for a single single-dimensional point one sample centered at mean.
147mahalSq(1, 1)
148(+0.502222478, +0.00000000)
149
Test:
test_pm_distanceMahal
Todo:
Critical Priority: The runtime checks for the complex input invCov must be implemented.
Todo:
High Priority: The performance of the implementation for complex input can be improved by using do_product on columns of invCov instead of the current implementation working with rows of invCov in matmul.


Final Remarks


If you believe this algorithm or its documentation can be improved, we appreciate your contribution and help to edit this page's documentation and source file on GitHub.
For details on the naming abbreviations, see this page.
For details on the naming conventions, see this page.
This software is distributed under the MIT license with additional terms outlined below.

  1. If you use any parts or concepts from this library to any extent, please acknowledge the usage by citing the relevant publications of the ParaMonte library.
  2. If you regenerate any parts/ideas from this library in a programming environment other than those currently supported by this ParaMonte library (i.e., other than C, C++, Fortran, MATLAB, Python, R), please also ask the end users to cite this original ParaMonte library.

This software is available to the public under a highly permissive license.
Help us justify its continued development and maintenance by acknowledging its benefit to society, distributing it, and contributing to it.

Author:
Amir Shahmoradi, Monday March 6, 2017, 3:22 pm, Institute for Computational Engineering and Sciences (ICES), The University of Texas at Austin.

Definition at line 1533 of file pm_distanceMahal.F90.


The documentation for this interface was generated from the following file: