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

Return the input distance matrix whose columns are sorted in ascending order on output, optionally only up to the kth row of each column, such that the kth row in the ith column is the kth nearest neighbor to the \(i^{th}\) reference point.
More...

Detailed Description

Return the input distance matrix whose columns are sorted in ascending order on output, optionally only up to the kth row of each column, such that the kth row in the ith column is the kth nearest neighbor to the \(i^{th}\) reference point.

The input matrix of shape (1:npnt, 1:nref) represents the distances of nref reference points from npnt neighbor points.
The matrix entries can be any measure of distance as long they are non-negative.

Parameters
[in,out]distance: The input or input/output contiguous array of rank 2 of shape (1:npnt, 1:nref) of
  1. type real of kind any supported by the processor (e.g., RK, RK32, RK64, or RK128).
each column i of which contains the distances of npnt neighbor points stored by the column rows from the ith reference point.
For example, such distance matrix can be obtained via:
  1. getDisMatEuclid or setDisMatEuclid
or any other distance metric module of the library.
  1. If the input argument rank is missing, then distance has intent(inout).
    On output, the rows of each column of distance are sorted separately in ascending order such that the kth row in column i contains the distance of the kth nearest neighbor of reference(1:ndim, i) represented by column distance(1:npnt, i).
  2. If the input argument rank is present, then distance has intent(in).
    On output, the rows of each column of rank are filled with the rank of the corresponding element of distance ranked by its nearness to the reference represented by column distance(1:npnt, i).
[out]rank: The output contiguous array of the same rank and shape as distance of type integer of default kind IK each element of which contains the nearest neighbor rank of the corresponding element of distance.
The neighborhood ranking is with respect to the point represented by the column of the element.
(optional. It can be present if and only if the input argument k is missing.)
[in]k: The output scalar integer of default kind IK, representing the row in each column of distance up to which the distances in each column will be sorted in ascending order.
The rest of the rows beyond the kth row remain unsorted.
This argument is useful when sorting the entire distance matrix or computing the entire rank matrix is unnecessary.
(optional, default = size(distance, 1). It can be present if and only if the input argument rank is missing.)


Possible calling interfaces

use pm_knn, only: setKnnSorted
call setKnnSorted(distance(1:npnt, 1:nref))
call setKnnSorted(distance(1:npnt, 1:nref), k)
call setKnnSorted(distance(1:npnt, 1:nref), rank(1:npnt, 1:nref))
Return the input distance matrix whose columns are sorted in ascending order on output,...
Definition: pm_knn.F90:181
This module contains procedures and generic interfaces for computing the nearest neighbor statistics ...
Definition: pm_knn.F90:82
Warning
The condition all(shape(distance) == shape(rank)) must hold for the corresponding input arguments.
The condition 0 < k .and. k <= size(distance, 1) must hold for the corresponding 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.
Note
To sort the neighbors of an individual point (corresponding to a single column vector), use the generic interfaces of pm_arrayRank or pm_arraySort.
See also
getDisEuclid
setDisEuclid
getDisMatEuclid
setDisMatEuclid


Example usage

1program example
2
3 use pm_kind, only: SK, IK, LK, RKH
4 use pm_io, only: display_type
5 use pm_distanceEuclid, only: getDisMatEuclid, rdpack, uppLow, uppLowDia, euclid, euclidu, euclidsq
7 use pm_distUnif, only: getUnifRand
8 use pm_knn, only: setKnnSorted
9
10 implicit none
11
12 integer(IK) :: npnt, nref, itry, ntry = 5
13 type(display_type) :: disp
14 disp = display_type(file = "main.out.F90")
15
16 call disp%skip()
17 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
18 call disp%show("! Sort a precomputed distance matrix according to the nearest neighbors.")
19 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
20 call disp%skip()
21
22 block
23 use pm_kind, only: RKG => RKS ! all processor kinds are supported.
24 integer(IK), allocatable :: rank(:,:)
25 real(RKG), allocatable :: dismat(:,:), point(:,:)
26 do itry = 1, ntry
27 call disp%skip()
28 call disp%show("npnt = getUnifRand(1, 3); nref = getUnifRand(5, 7)")
29 npnt = getUnifRand(1, 3); nref = getUnifRand(5, 7)
30 call disp%show("[npnt, nref]")
31 call disp%show( [npnt, nref] )
32 call disp%show("point = getUnifRand(1._RKG, 2._RKG, npnt, nref)")
33 point = getUnifRand(1._RKG, 2._RKG, npnt, nref)
34 call disp%show("point")
35 call disp%show( point )
36 call disp%show("dismat = getDisMatEuclid(point)")
37 dismat = getDisMatEuclid(point)
38 call disp%show("dismat")
39 call disp%show( dismat )
40 call disp%show("call setKnnSorted(dismat, k = 1)")
41 call setKnnSorted(dismat, k = 1)
42 call disp%show("dismat")
43 call disp%show( dismat )
44 call disp%show("call setKnnSorted(dismat, k = 2)")
45 call setKnnSorted(dismat, k = 2)
46 call disp%show("dismat")
47 call disp%show( dismat )
48 call disp%show("dismat = getDisMatEuclid(point)")
49 dismat = getDisMatEuclid(point)
50 call disp%show("dismat")
51 call disp%show( dismat )
52 call disp%show("call setResized(rank, shape(dismat))")
53 call setResized(rank, shape(dismat))
54 call disp%show("call setKnnSorted(dismat, rank)")
55 call setKnnSorted(dismat, rank)
56 call disp%show("dismat")
57 call disp%show( dismat )
58 call disp%show("rank")
59 call disp%show( rank )
60 call disp%skip()
61 call disp%show("dismat = getDisMatEuclid(rdpack, uppLow, point) ! drop the zero-valued diagonal elements of the dismat matrix.")
62 dismat = getDisMatEuclid(rdpack, uppLow, point) ! drop the zero-valued diagonal elements of the dismat matrix.
63 call disp%show("dismat")
64 call disp%show( dismat )
65 call disp%show("call setKnnSorted(dismat, k = 1)")
66 call setKnnSorted(dismat, k = 1)
67 call disp%show("dismat")
68 call disp%show( dismat )
69 call disp%show("dismat = getDisMatEuclid(rdpack, uppLow, point) ! drop the zero-valued diagonal elements of the dismat matrix.")
70 dismat = getDisMatEuclid(rdpack, uppLow, point) ! drop the zero-valued diagonal elements of the dismat matrix.
71 call disp%show("dismat")
72 call disp%show( dismat )
73 call disp%show("call setResized(rank, shape(dismat))")
74 call setResized(rank, shape(dismat))
75 call disp%show("call setKnnSorted(dismat, rank)")
76 call setKnnSorted(dismat, rank)
77 call disp%show("dismat")
78 call disp%show( dismat )
79 call disp%show("rank")
80 call disp%show( rank )
81 call disp%skip()
82 end do
83 end block
84
85end program example
Allocate or resize (shrink or expand) an input allocatable scalar string or array of rank 1....
Generate and return a scalar or a contiguous array of rank 1 of length s1 of randomly uniformly distr...
Return the full or a subset of the Euclidean (squared) distance matrix of the input set of npnt point...
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
This module contains procedures and generic interfaces for resizing allocatable arrays of various typ...
This module contains classes and procedures for computing various statistical quantities related to t...
This module contains procedures and generic interfaces for computing the Euclidean norm of a single p...
type(euclidu_type), parameter euclidu
This is a scalar parameter object of type euclidu_typethat is exclusively used to request unsafe meth...
type(euclid_type), parameter euclid
This is a scalar parameter object of type euclid_type that is exclusively used to request safe method...
type(euclidsq_type), parameter euclidsq
This is a scalar parameter object of type euclidsq_typethat is exclusively used to request computing ...
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 LK
The default logical kind in the ParaMonte library: kind(.true.) in Fortran, kind(....
Definition: pm_kind.F90:541
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 RKH
The scalar integer constant of intrinsic default kind, representing the highest-precision real kind t...
Definition: pm_kind.F90:858
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
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! Sort a precomputed distance matrix according to the nearest neighbors.
4!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5
6
7npnt = getUnifRand(1, 3); nref = getUnifRand(5, 7)
8[npnt, nref]
9+3, +6
10point = getUnifRand(1._RKG, 2._RKG, npnt, nref)
11point
12+1.43204689, +1.19008255, +1.64724052, +1.49888933, +1.93696427, +1.82989347
13+1.70187974, +1.72265720, +1.75669837, +1.55251837, +1.23169208, +1.58536541
14+1.50525379, +1.56958437, +1.14748597, +1.61878192, +1.40994740, +1.14204204
15dismat = getDisMatEuclid(point)
16dismat
17+0.00000000, +0.251230717, +0.421083361, +0.199161664, +0.696492136, +0.551162660
18+0.251230717, +0.00000000, +0.623152733, +0.355990529, +0.907944441, +0.781664550
19+0.421083361, +0.623152733, +0.00000000, +0.534618974, +0.654566646, +0.250492930
20+0.199161664, +0.355990529, +0.534618974, +0.00000000, +0.581765413, +0.581312001
21+0.696492136, +0.907944441, +0.654566646, +0.581765413, +0.00000000, +0.456423342
22+0.551162660, +0.781664550, +0.250492930, +0.581312001, +0.456423342, +0.00000000
23call setKnnSorted(dismat, k = 1)
24dismat
25+0.00000000, +0.00000000, +0.00000000, +0.00000000, +0.00000000, +0.00000000
26+0.199161664, +0.251230717, +0.250492930, +0.199161664, +0.456423342, +0.250492930
27+0.251230717, +0.355990529, +0.623152733, +0.355990529, +0.581765413, +0.781664550
28+0.421083361, +0.623152733, +0.534618974, +0.534618974, +0.654566646, +0.581312001
29+0.696492136, +0.907944441, +0.654566646, +0.581765413, +0.907944441, +0.456423342
30+0.551162660, +0.781664550, +0.421083361, +0.581312001, +0.696492136, +0.551162660
31call setKnnSorted(dismat, k = 2)
32dismat
33+0.00000000, +0.00000000, +0.00000000, +0.00000000, +0.00000000, +0.00000000
34+0.199161664, +0.251230717, +0.250492930, +0.199161664, +0.456423342, +0.250492930
35+0.251230717, +0.355990529, +0.421083361, +0.355990529, +0.581765413, +0.456423342
36+0.421083361, +0.623152733, +0.534618974, +0.534618974, +0.654566646, +0.551162660
37+0.696492136, +0.907944441, +0.654566646, +0.581765413, +0.907944441, +0.581312001
38+0.551162660, +0.781664550, +0.623152733, +0.581312001, +0.696492136, +0.781664550
39dismat = getDisMatEuclid(point)
40dismat
41+0.00000000, +0.251230717, +0.421083361, +0.199161664, +0.696492136, +0.551162660
42+0.251230717, +0.00000000, +0.623152733, +0.355990529, +0.907944441, +0.781664550
43+0.421083361, +0.623152733, +0.00000000, +0.534618974, +0.654566646, +0.250492930
44+0.199161664, +0.355990529, +0.534618974, +0.00000000, +0.581765413, +0.581312001
45+0.696492136, +0.907944441, +0.654566646, +0.581765413, +0.00000000, +0.456423342
46+0.551162660, +0.781664550, +0.250492930, +0.581312001, +0.456423342, +0.00000000
47call setResized(rank, shape(dismat))
48call setKnnSorted(dismat, rank)
49dismat
50+0.00000000, +0.251230717, +0.421083361, +0.199161664, +0.696492136, +0.551162660
51+0.251230717, +0.00000000, +0.623152733, +0.355990529, +0.907944441, +0.781664550
52+0.421083361, +0.623152733, +0.00000000, +0.534618974, +0.654566646, +0.250492930
53+0.199161664, +0.355990529, +0.534618974, +0.00000000, +0.581765413, +0.581312001
54+0.696492136, +0.907944441, +0.654566646, +0.581765413, +0.00000000, +0.456423342
55+0.551162660, +0.781664550, +0.250492930, +0.581312001, +0.456423342, +0.00000000
56rank
57+1, +2, +3, +4, +5, +6
58+4, +1, +6, +1, +6, +3
59+2, +4, +1, +2, +4, +5
60+3, +3, +4, +3, +3, +1
61+6, +6, +2, +6, +1, +4
62+5, +5, +5, +5, +2, +2
63
64dismat = getDisMatEuclid(rdpack, uppLow, point) ! drop the zero-valued diagonal elements of the dismat matrix.
65dismat
66+0.251230717, +0.251230717, +0.421083361, +0.199161664, +0.696492136, +0.551162660
67+0.421083361, +0.623152733, +0.623152733, +0.355990529, +0.907944441, +0.781664550
68+0.199161664, +0.355990529, +0.534618974, +0.534618974, +0.654566646, +0.250492930
69+0.696492136, +0.907944441, +0.654566646, +0.581765413, +0.581765413, +0.581312001
70+0.551162660, +0.781664550, +0.250492930, +0.581312001, +0.456423342, +0.456423342
71call setKnnSorted(dismat, k = 1)
72dismat
73+0.199161664, +0.251230717, +0.250492930, +0.199161664, +0.456423342, +0.250492930
74+0.251230717, +0.355990529, +0.421083361, +0.355990529, +0.581765413, +0.456423342
75+0.421083361, +0.623152733, +0.623152733, +0.534618974, +0.654566646, +0.781664550
76+0.696492136, +0.907944441, +0.654566646, +0.581765413, +0.907944441, +0.581312001
77+0.551162660, +0.781664550, +0.534618974, +0.581312001, +0.696492136, +0.551162660
78dismat = getDisMatEuclid(rdpack, uppLow, point) ! drop the zero-valued diagonal elements of the dismat matrix.
79dismat
80+0.251230717, +0.251230717, +0.421083361, +0.199161664, +0.696492136, +0.551162660
81+0.421083361, +0.623152733, +0.623152733, +0.355990529, +0.907944441, +0.781664550
82+0.199161664, +0.355990529, +0.534618974, +0.534618974, +0.654566646, +0.250492930
83+0.696492136, +0.907944441, +0.654566646, +0.581765413, +0.581765413, +0.581312001
84+0.551162660, +0.781664550, +0.250492930, +0.581312001, +0.456423342, +0.456423342
85call setResized(rank, shape(dismat))
86call setKnnSorted(dismat, rank)
87dismat
88+0.251230717, +0.251230717, +0.421083361, +0.199161664, +0.696492136, +0.551162660
89+0.421083361, +0.623152733, +0.623152733, +0.355990529, +0.907944441, +0.781664550
90+0.199161664, +0.355990529, +0.534618974, +0.534618974, +0.654566646, +0.250492930
91+0.696492136, +0.907944441, +0.654566646, +0.581765413, +0.581765413, +0.581312001
92+0.551162660, +0.781664550, +0.250492930, +0.581312001, +0.456423342, +0.456423342
93rank
94+3, +1, +5, +1, +5, +3
95+1, +3, +1, +2, +4, +5
96+2, +2, +3, +3, +3, +1
97+5, +5, +2, +5, +1, +4
98+4, +4, +4, +4, +2, +2
99
100
101npnt = getUnifRand(1, 3); nref = getUnifRand(5, 7)
102[npnt, nref]
103+3, +6
104point = getUnifRand(1._RKG, 2._RKG, npnt, nref)
105point
106+1.32560205, +1.02266192, +1.25533628, +1.73648643, +1.64236033, +1.55406213
107+1.65914297, +1.47304463, +1.90322745, +1.04094779, +1.04590237, +1.83482695
108+1.45213532, +1.32187223, +1.68931150, +1.16542017, +1.04012775, +1.63469553
109dismat = getDisMatEuclid(point)
110dismat
111+0.00000000, +0.378647327, +0.347515553, +0.795736670, +0.803834558, +0.341155529
112+0.378647327, +0.00000000, +0.611723959, +0.848958313, +0.803651989, +0.714934289
113+0.347515553, +0.611723959, +0.00000000, +1.11780763, +1.14290559, +0.311285526
114+0.795736670, +0.848958313, +1.11780763, +0.00000000, +0.156787947, +0.940075576
115+0.803834558, +0.803651989, +1.14290559, +0.156787947, +0.00000000, +0.991821289
116+0.341155529, +0.714934289, +0.311285526, +0.940075576, +0.991821289, +0.00000000
117call setKnnSorted(dismat, k = 1)
118dismat
119+0.00000000, +0.00000000, +0.00000000, +0.00000000, +0.00000000, +0.00000000
120+0.341155529, +0.378647327, +0.311285526, +0.156787947, +0.156787947, +0.311285526
121+0.378647327, +0.611723959, +0.611723959, +0.848958313, +0.803651989, +0.714934289
122+0.795736670, +0.848958313, +1.11780763, +0.795736670, +0.803834558, +0.940075576
123+0.803834558, +0.803651989, +1.14290559, +0.940075576, +0.991821289, +0.991821289
124+0.347515553, +0.714934289, +0.347515553, +1.11780763, +1.14290559, +0.341155529
125call setKnnSorted(dismat, k = 2)
126dismat
127+0.00000000, +0.00000000, +0.00000000, +0.00000000, +0.00000000, +0.00000000
128+0.341155529, +0.378647327, +0.311285526, +0.156787947, +0.156787947, +0.311285526
129+0.347515553, +0.611723959, +0.347515553, +0.795736670, +0.803651989, +0.341155529
130+0.795736670, +0.848958313, +1.11780763, +0.848958313, +0.803834558, +0.940075576
131+0.803834558, +0.803651989, +1.14290559, +0.940075576, +0.991821289, +0.991821289
132+0.378647327, +0.714934289, +0.611723959, +1.11780763, +1.14290559, +0.714934289
133dismat = getDisMatEuclid(point)
134dismat
135+0.00000000, +0.378647327, +0.347515553, +0.795736670, +0.803834558, +0.341155529
136+0.378647327, +0.00000000, +0.611723959, +0.848958313, +0.803651989, +0.714934289
137+0.347515553, +0.611723959, +0.00000000, +1.11780763, +1.14290559, +0.311285526
138+0.795736670, +0.848958313, +1.11780763, +0.00000000, +0.156787947, +0.940075576
139+0.803834558, +0.803651989, +1.14290559, +0.156787947, +0.00000000, +0.991821289
140+0.341155529, +0.714934289, +0.311285526, +0.940075576, +0.991821289, +0.00000000
141call setResized(rank, shape(dismat))
142call setKnnSorted(dismat, rank)
143dismat
144+0.00000000, +0.378647327, +0.347515553, +0.795736670, +0.803834558, +0.341155529
145+0.378647327, +0.00000000, +0.611723959, +0.848958313, +0.803651989, +0.714934289
146+0.347515553, +0.611723959, +0.00000000, +1.11780763, +1.14290559, +0.311285526
147+0.795736670, +0.848958313, +1.11780763, +0.00000000, +0.156787947, +0.940075576
148+0.803834558, +0.803651989, +1.14290559, +0.156787947, +0.00000000, +0.991821289
149+0.341155529, +0.714934289, +0.311285526, +0.940075576, +0.991821289, +0.00000000
150rank
151+1, +2, +3, +4, +5, +6
152+6, +1, +6, +5, +4, +3
153+3, +3, +1, +1, +2, +1
154+2, +6, +2, +2, +1, +2
155+4, +5, +4, +6, +6, +4
156+5, +4, +5, +3, +3, +5
157
158dismat = getDisMatEuclid(rdpack, uppLow, point) ! drop the zero-valued diagonal elements of the dismat matrix.
159dismat
160+0.378647327, +0.378647327, +0.347515553, +0.795736670, +0.803834558, +0.341155529
161+0.347515553, +0.611723959, +0.611723959, +0.848958313, +0.803651989, +0.714934289
162+0.795736670, +0.848958313, +1.11780763, +1.11780763, +1.14290559, +0.311285526
163+0.803834558, +0.803651989, +1.14290559, +0.156787947, +0.156787947, +0.940075576
164+0.341155529, +0.714934289, +0.311285526, +0.940075576, +0.991821289, +0.991821289
165call setKnnSorted(dismat, k = 1)
166dismat
167+0.341155529, +0.378647327, +0.311285526, +0.156787947, +0.156787947, +0.311285526
168+0.347515553, +0.611723959, +0.347515553, +0.795736670, +0.803651989, +0.341155529
169+0.378647327, +0.714934289, +0.611723959, +0.848958313, +0.803834558, +0.714934289
170+0.803834558, +0.803651989, +1.14290559, +0.940075576, +0.991821289, +0.940075576
171+0.795736670, +0.848958313, +1.11780763, +1.11780763, +1.14290559, +0.991821289
172dismat = getDisMatEuclid(rdpack, uppLow, point) ! drop the zero-valued diagonal elements of the dismat matrix.
173dismat
174+0.378647327, +0.378647327, +0.347515553, +0.795736670, +0.803834558, +0.341155529
175+0.347515553, +0.611723959, +0.611723959, +0.848958313, +0.803651989, +0.714934289
176+0.795736670, +0.848958313, +1.11780763, +1.11780763, +1.14290559, +0.311285526
177+0.803834558, +0.803651989, +1.14290559, +0.156787947, +0.156787947, +0.940075576
178+0.341155529, +0.714934289, +0.311285526, +0.940075576, +0.991821289, +0.991821289
179call setResized(rank, shape(dismat))
180call setKnnSorted(dismat, rank)
181dismat
182+0.378647327, +0.378647327, +0.347515553, +0.795736670, +0.803834558, +0.341155529
183+0.347515553, +0.611723959, +0.611723959, +0.848958313, +0.803651989, +0.714934289
184+0.795736670, +0.848958313, +1.11780763, +1.11780763, +1.14290559, +0.311285526
185+0.803834558, +0.803651989, +1.14290559, +0.156787947, +0.156787947, +0.940075576
186+0.341155529, +0.714934289, +0.311285526, +0.940075576, +0.991821289, +0.991821289
187rank
188+5, +1, +5, +4, +4, +3
189+2, +2, +1, +1, +2, +1
190+1, +5, +2, +2, +1, +2
191+3, +4, +3, +5, +5, +4
192+4, +3, +4, +3, +3, +5
193
194
195npnt = getUnifRand(1, 3); nref = getUnifRand(5, 7)
196[npnt, nref]
197+1, +5
198point = getUnifRand(1._RKG, 2._RKG, npnt, nref)
199point
200+1.75428414, +1.35725904, +1.14576936, +1.67224753, +1.56387782
201dismat = getDisMatEuclid(point)
202dismat
203+0.00000000, +0.397025079, +0.608514786, +0.820366144E-1, +0.190406322
204+0.397025079, +0.00000000, +0.211489677, +0.314988494, +0.206618786
205+0.608514786, +0.211489677, +0.00000000, +0.526478171, +0.418108463
206+0.820366144E-1, +0.314988494, +0.526478171, +0.00000000, +0.108369708
207+0.190406322, +0.206618786, +0.418108463, +0.108369708, +0.00000000
208call setKnnSorted(dismat, k = 1)
209dismat
210+0.00000000, +0.00000000, +0.00000000, +0.00000000, +0.00000000
211+0.820366144E-1, +0.206618786, +0.211489677, +0.820366144E-1, +0.108369708
212+0.190406322, +0.211489677, +0.418108463, +0.108369708, +0.190406322
213+0.397025079, +0.314988494, +0.526478171, +0.314988494, +0.206618786
214+0.608514786, +0.397025079, +0.608514786, +0.526478171, +0.418108463
215call setKnnSorted(dismat, k = 2)
216dismat
217+0.00000000, +0.00000000, +0.00000000, +0.00000000, +0.00000000
218+0.820366144E-1, +0.206618786, +0.211489677, +0.820366144E-1, +0.108369708
219+0.190406322, +0.211489677, +0.418108463, +0.108369708, +0.190406322
220+0.397025079, +0.314988494, +0.526478171, +0.314988494, +0.206618786
221+0.608514786, +0.397025079, +0.608514786, +0.526478171, +0.418108463
222dismat = getDisMatEuclid(point)
223dismat
224+0.00000000, +0.397025079, +0.608514786, +0.820366144E-1, +0.190406322
225+0.397025079, +0.00000000, +0.211489677, +0.314988494, +0.206618786
226+0.608514786, +0.211489677, +0.00000000, +0.526478171, +0.418108463
227+0.820366144E-1, +0.314988494, +0.526478171, +0.00000000, +0.108369708
228+0.190406322, +0.206618786, +0.418108463, +0.108369708, +0.00000000
229call setResized(rank, shape(dismat))
230call setKnnSorted(dismat, rank)
231dismat
232+0.00000000, +0.397025079, +0.608514786, +0.820366144E-1, +0.190406322
233+0.397025079, +0.00000000, +0.211489677, +0.314988494, +0.206618786
234+0.608514786, +0.211489677, +0.00000000, +0.526478171, +0.418108463
235+0.820366144E-1, +0.314988494, +0.526478171, +0.00000000, +0.108369708
236+0.190406322, +0.206618786, +0.418108463, +0.108369708, +0.00000000
237rank
238+1, +2, +3, +4, +5
239+4, +5, +2, +1, +4
240+5, +3, +5, +5, +1
241+2, +4, +4, +2, +2
242+3, +1, +1, +3, +3
243
244dismat = getDisMatEuclid(rdpack, uppLow, point) ! drop the zero-valued diagonal elements of the dismat matrix.
245dismat
246+0.397025079, +0.397025079, +0.608514786, +0.820366144E-1, +0.190406322
247+0.608514786, +0.211489677, +0.211489677, +0.314988494, +0.206618786
248+0.820366144E-1, +0.314988494, +0.526478171, +0.526478171, +0.418108463
249+0.190406322, +0.206618786, +0.418108463, +0.108369708, +0.108369708
250call setKnnSorted(dismat, k = 1)
251dismat
252+0.820366144E-1, +0.206618786, +0.211489677, +0.820366144E-1, +0.108369708
253+0.190406322, +0.211489677, +0.418108463, +0.108369708, +0.190406322
254+0.397025079, +0.314988494, +0.526478171, +0.526478171, +0.418108463
255+0.608514786, +0.397025079, +0.608514786, +0.314988494, +0.206618786
256dismat = getDisMatEuclid(rdpack, uppLow, point) ! drop the zero-valued diagonal elements of the dismat matrix.
257dismat
258+0.397025079, +0.397025079, +0.608514786, +0.820366144E-1, +0.190406322
259+0.608514786, +0.211489677, +0.211489677, +0.314988494, +0.206618786
260+0.820366144E-1, +0.314988494, +0.526478171, +0.526478171, +0.418108463
261+0.190406322, +0.206618786, +0.418108463, +0.108369708, +0.108369708
262call setResized(rank, shape(dismat))
263call setKnnSorted(dismat, rank)
264dismat
265+0.397025079, +0.397025079, +0.608514786, +0.820366144E-1, +0.190406322
266+0.608514786, +0.211489677, +0.211489677, +0.314988494, +0.206618786
267+0.820366144E-1, +0.314988494, +0.526478171, +0.526478171, +0.418108463
268+0.190406322, +0.206618786, +0.418108463, +0.108369708, +0.108369708
269rank
270+3, +4, +2, +1, +4
271+4, +2, +4, +4, +1
272+1, +3, +3, +2, +2
273+2, +1, +1, +3, +3
274
275
276npnt = getUnifRand(1, 3); nref = getUnifRand(5, 7)
277[npnt, nref]
278+3, +7
279point = getUnifRand(1._RKG, 2._RKG, npnt, nref)
280point
281+1.32593203, +1.78545368, +1.99960399, +1.02113891, +1.43536305, +1.13885760, +1.77757585
282+1.82568300, +1.88241410, +1.23005056, +1.62767661, +1.98310626, +1.18339515, +1.23146415
283+1.72075176, +1.16353393, +1.17418659, +1.66540480, +1.49088717, +1.56189442, +1.69307745
284dismat = getDisMatEuclid(point)
285dismat
286+0.00000000, +0.724479258, +1.05230474, +0.367652893, +0.299324185, +0.687579930, +0.746889532
287+0.724479258, +0.00000000, +0.686696410, +0.949180007, +0.489757597, +1.03218460, +0.839174747
288+1.05230474, +0.686696410, +0.00000000, +1.16481566, +0.992854416, +0.945186973, +0.564398944
289+0.367652893, +0.949180007, +1.16481566, +0.00000000, +0.573034286, +0.471124321, +0.854369402
290+0.299324185, +0.489757597, +0.992854416, +0.573034286, +0.00000000, +0.855859458, +0.850268364
291+0.687579930, +1.03218460, +0.945186973, +0.471124321, +0.855859458, +0.00000000, +0.653819978
292+0.746889532, +0.839174747, +0.564398944, +0.854369402, +0.850268364, +0.653819978, +0.00000000
293call setKnnSorted(dismat, k = 1)
294dismat
295+0.00000000, +0.00000000, +0.00000000, +0.00000000, +0.00000000, +0.00000000, +0.00000000
296+0.299324185, +0.489757597, +0.564398944, +0.367652893, +0.299324185, +0.471124321, +0.564398944
297+0.367652893, +0.686696410, +0.945186973, +1.16481566, +0.489757597, +0.653819978, +0.653819978
298+0.724479258, +0.724479258, +0.686696410, +0.949180007, +0.573034286, +1.03218460, +0.746889532
299+1.05230474, +0.839174747, +0.992854416, +0.573034286, +0.992854416, +0.855859458, +0.850268364
300+0.687579930, +1.03218460, +1.05230474, +0.471124321, +0.855859458, +0.945186973, +0.839174747
301+0.746889532, +0.949180007, +1.16481566, +0.854369402, +0.850268364, +0.687579930, +0.854369402
302call setKnnSorted(dismat, k = 2)
303dismat
304+0.00000000, +0.00000000, +0.00000000, +0.00000000, +0.00000000, +0.00000000, +0.00000000
305+0.299324185, +0.489757597, +0.564398944, +0.367652893, +0.299324185, +0.471124321, +0.564398944
306+0.367652893, +0.686696410, +0.686696410, +0.471124321, +0.489757597, +0.653819978, +0.653819978
307+0.687579930, +0.724479258, +0.945186973, +0.573034286, +0.573034286, +0.687579930, +0.746889532
308+0.724479258, +0.839174747, +0.992854416, +0.854369402, +0.992854416, +0.855859458, +0.850268364
309+1.05230474, +1.03218460, +1.05230474, +1.16481566, +0.855859458, +0.945186973, +0.839174747
310+0.746889532, +0.949180007, +1.16481566, +0.949180007, +0.850268364, +1.03218460, +0.854369402
311dismat = getDisMatEuclid(point)
312dismat
313+0.00000000, +0.724479258, +1.05230474, +0.367652893, +0.299324185, +0.687579930, +0.746889532
314+0.724479258, +0.00000000, +0.686696410, +0.949180007, +0.489757597, +1.03218460, +0.839174747
315+1.05230474, +0.686696410, +0.00000000, +1.16481566, +0.992854416, +0.945186973, +0.564398944
316+0.367652893, +0.949180007, +1.16481566, +0.00000000, +0.573034286, +0.471124321, +0.854369402
317+0.299324185, +0.489757597, +0.992854416, +0.573034286, +0.00000000, +0.855859458, +0.850268364
318+0.687579930, +1.03218460, +0.945186973, +0.471124321, +0.855859458, +0.00000000, +0.653819978
319+0.746889532, +0.839174747, +0.564398944, +0.854369402, +0.850268364, +0.653819978, +0.00000000
320call setResized(rank, shape(dismat))
321call setKnnSorted(dismat, rank)
322dismat
323+0.00000000, +0.724479258, +1.05230474, +0.367652893, +0.299324185, +0.687579930, +0.746889532
324+0.724479258, +0.00000000, +0.686696410, +0.949180007, +0.489757597, +1.03218460, +0.839174747
325+1.05230474, +0.686696410, +0.00000000, +1.16481566, +0.992854416, +0.945186973, +0.564398944
326+0.367652893, +0.949180007, +1.16481566, +0.00000000, +0.573034286, +0.471124321, +0.854369402
327+0.299324185, +0.489757597, +0.992854416, +0.573034286, +0.00000000, +0.855859458, +0.850268364
328+0.687579930, +1.03218460, +0.945186973, +0.471124321, +0.855859458, +0.00000000, +0.653819978
329+0.746889532, +0.839174747, +0.564398944, +0.854369402, +0.850268364, +0.653819978, +0.00000000
330rank
331+1, +2, +3, +4, +5, +6, +7
332+5, +5, +7, +1, +1, +4, +3
333+4, +3, +2, +6, +2, +7, +6
334+6, +1, +6, +5, +4, +1, +1
335+2, +7, +5, +7, +7, +5, +2
336+7, +4, +1, +2, +6, +3, +5
337+3, +6, +4, +3, +3, +2, +4
338
339dismat = getDisMatEuclid(rdpack, uppLow, point) ! drop the zero-valued diagonal elements of the dismat matrix.
340dismat
341+0.724479258, +0.724479258, +1.05230474, +0.367652893, +0.299324185, +0.687579930, +0.746889532
342+1.05230474, +0.686696410, +0.686696410, +0.949180007, +0.489757597, +1.03218460, +0.839174747
343+0.367652893, +0.949180007, +1.16481566, +1.16481566, +0.992854416, +0.945186973, +0.564398944
344+0.299324185, +0.489757597, +0.992854416, +0.573034286, +0.573034286, +0.471124321, +0.854369402
345+0.687579930, +1.03218460, +0.945186973, +0.471124321, +0.855859458, +0.855859458, +0.850268364
346+0.746889532, +0.839174747, +0.564398944, +0.854369402, +0.850268364, +0.653819978, +0.653819978
347call setKnnSorted(dismat, k = 1)
348dismat
349+0.299324185, +0.489757597, +0.564398944, +0.367652893, +0.299324185, +0.471124321, +0.564398944
350+0.367652893, +0.686696410, +0.686696410, +0.471124321, +0.489757597, +0.653819978, +0.653819978
351+0.687579930, +0.724479258, +0.945186973, +0.573034286, +0.573034286, +0.687579930, +0.839174747
352+0.724479258, +0.839174747, +0.992854416, +0.854369402, +0.850268364, +1.03218460, +0.854369402
353+1.05230474, +1.03218460, +1.05230474, +0.949180007, +0.855859458, +0.855859458, +0.850268364
354+0.746889532, +0.949180007, +1.16481566, +1.16481566, +0.992854416, +0.945186973, +0.746889532
355dismat = getDisMatEuclid(rdpack, uppLow, point) ! drop the zero-valued diagonal elements of the dismat matrix.
356dismat
357+0.724479258, +0.724479258, +1.05230474, +0.367652893, +0.299324185, +0.687579930, +0.746889532
358+1.05230474, +0.686696410, +0.686696410, +0.949180007, +0.489757597, +1.03218460, +0.839174747
359+0.367652893, +0.949180007, +1.16481566, +1.16481566, +0.992854416, +0.945186973, +0.564398944
360+0.299324185, +0.489757597, +0.992854416, +0.573034286, +0.573034286, +0.471124321, +0.854369402
361+0.687579930, +1.03218460, +0.945186973, +0.471124321, +0.855859458, +0.855859458, +0.850268364
362+0.746889532, +0.839174747, +0.564398944, +0.854369402, +0.850268364, +0.653819978, +0.653819978
363call setResized(rank, shape(dismat))
364call setKnnSorted(dismat, rank)
365dismat
366+0.724479258, +0.724479258, +1.05230474, +0.367652893, +0.299324185, +0.687579930, +0.746889532
367+1.05230474, +0.686696410, +0.686696410, +0.949180007, +0.489757597, +1.03218460, +0.839174747
368+0.367652893, +0.949180007, +1.16481566, +1.16481566, +0.992854416, +0.945186973, +0.564398944
369+0.299324185, +0.489757597, +0.992854416, +0.573034286, +0.573034286, +0.471124321, +0.854369402
370+0.687579930, +1.03218460, +0.945186973, +0.471124321, +0.855859458, +0.855859458, +0.850268364
371+0.746889532, +0.839174747, +0.564398944, +0.854369402, +0.850268364, +0.653819978, +0.653819978
372rank
373+4, +4, +6, +1, +1, +4, +3
374+3, +2, +2, +5, +2, +6, +6
375+5, +1, +5, +4, +4, +1, +1
376+1, +6, +4, +6, +6, +5, +2
377+6, +3, +1, +2, +5, +3, +5
378+2, +5, +3, +3, +3, +2, +4
379
380
381npnt = getUnifRand(1, 3); nref = getUnifRand(5, 7)
382[npnt, nref]
383+3, +6
384point = getUnifRand(1._RKG, 2._RKG, npnt, nref)
385point
386+1.65123200, +1.43651414, +1.55307031, +1.31862080, +1.36870277, +1.23046422
387+1.02029622, +1.29206896, +1.64531732, +1.76901364, +1.02533531, +1.55754352
388+1.73548675, +1.33284187, +1.59259069, +1.09936333, +1.62710953, +1.17945600
389dismat = getDisMatEuclid(point)
390dismat
391+0.00000000, +0.531118751, +0.648618877, +1.03723729, +0.302644640, +0.880255878
392+0.531118751, +0.00000000, +0.453695059, +0.543955266, +0.402912736, +0.369405657
393+0.648618877, +0.453695059, +0.00000000, +0.559946954, +0.647735000, +0.531468928
394+1.03723729, +0.543955266, +0.559946954, +0.00000000, +0.913280845, +0.242705643
395+0.302644640, +0.402912736, +0.647735000, +0.913280845, +0.00000000, +0.709048092
396+0.880255878, +0.369405657, +0.531468928, +0.242705643, +0.709048092, +0.00000000
397call setKnnSorted(dismat, k = 1)
398dismat
399+0.00000000, +0.00000000, +0.00000000, +0.00000000, +0.00000000, +0.00000000
400+0.302644640, +0.369405657, +0.453695059, +0.242705643, +0.302644640, +0.242705643
401+0.531118751, +0.402912736, +0.531468928, +0.543955266, +0.402912736, +0.369405657
402+0.648618877, +0.453695059, +0.559946954, +0.559946954, +0.647735000, +0.531468928
403+1.03723729, +0.543955266, +0.647735000, +0.913280845, +0.913280845, +0.709048092
404+0.880255878, +0.531118751, +0.648618877, +1.03723729, +0.709048092, +0.880255878
405call setKnnSorted(dismat, k = 2)
406dismat
407+0.00000000, +0.00000000, +0.00000000, +0.00000000, +0.00000000, +0.00000000
408+0.302644640, +0.369405657, +0.453695059, +0.242705643, +0.302644640, +0.242705643
409+0.531118751, +0.402912736, +0.531468928, +0.543955266, +0.402912736, +0.369405657
410+0.648618877, +0.453695059, +0.559946954, +0.559946954, +0.647735000, +0.531468928
411+1.03723729, +0.543955266, +0.647735000, +0.913280845, +0.913280845, +0.709048092
412+0.880255878, +0.531118751, +0.648618877, +1.03723729, +0.709048092, +0.880255878
413dismat = getDisMatEuclid(point)
414dismat
415+0.00000000, +0.531118751, +0.648618877, +1.03723729, +0.302644640, +0.880255878
416+0.531118751, +0.00000000, +0.453695059, +0.543955266, +0.402912736, +0.369405657
417+0.648618877, +0.453695059, +0.00000000, +0.559946954, +0.647735000, +0.531468928
418+1.03723729, +0.543955266, +0.559946954, +0.00000000, +0.913280845, +0.242705643
419+0.302644640, +0.402912736, +0.647735000, +0.913280845, +0.00000000, +0.709048092
420+0.880255878, +0.369405657, +0.531468928, +0.242705643, +0.709048092, +0.00000000
421call setResized(rank, shape(dismat))
422call setKnnSorted(dismat, rank)
423dismat
424+0.00000000, +0.531118751, +0.648618877, +1.03723729, +0.302644640, +0.880255878
425+0.531118751, +0.00000000, +0.453695059, +0.543955266, +0.402912736, +0.369405657
426+0.648618877, +0.453695059, +0.00000000, +0.559946954, +0.647735000, +0.531468928
427+1.03723729, +0.543955266, +0.559946954, +0.00000000, +0.913280845, +0.242705643
428+0.302644640, +0.402912736, +0.647735000, +0.913280845, +0.00000000, +0.709048092
429+0.880255878, +0.369405657, +0.531468928, +0.242705643, +0.709048092, +0.00000000
430rank
431+1, +2, +3, +4, +5, +6
432+5, +6, +2, +6, +1, +4
433+2, +5, +6, +2, +2, +2
434+3, +3, +4, +3, +3, +3
435+6, +1, +5, +5, +6, +5
436+4, +4, +1, +1, +4, +1
437
438dismat = getDisMatEuclid(rdpack, uppLow, point) ! drop the zero-valued diagonal elements of the dismat matrix.
439dismat
440+0.531118751, +0.531118751, +0.648618877, +1.03723729, +0.302644640, +0.880255878
441+0.648618877, +0.453695059, +0.453695059, +0.543955266, +0.402912736, +0.369405657
442+1.03723729, +0.543955266, +0.559946954, +0.559946954, +0.647735000, +0.531468928
443+0.302644640, +0.402912736, +0.647735000, +0.913280845, +0.913280845, +0.242705643
444+0.880255878, +0.369405657, +0.531468928, +0.242705643, +0.709048092, +0.709048092
445call setKnnSorted(dismat, k = 1)
446dismat
447+0.302644640, +0.369405657, +0.453695059, +0.242705643, +0.302644640, +0.242705643
448+0.531118751, +0.402912736, +0.531468928, +0.543955266, +0.402912736, +0.369405657
449+0.648618877, +0.453695059, +0.559946954, +0.559946954, +0.647735000, +0.531468928
450+0.880255878, +0.531118751, +0.647735000, +0.913280845, +0.913280845, +0.709048092
451+1.03723729, +0.543955266, +0.648618877, +1.03723729, +0.709048092, +0.880255878
452dismat = getDisMatEuclid(rdpack, uppLow, point) ! drop the zero-valued diagonal elements of the dismat matrix.
453dismat
454+0.531118751, +0.531118751, +0.648618877, +1.03723729, +0.302644640, +0.880255878
455+0.648618877, +0.453695059, +0.453695059, +0.543955266, +0.402912736, +0.369405657
456+1.03723729, +0.543955266, +0.559946954, +0.559946954, +0.647735000, +0.531468928
457+0.302644640, +0.402912736, +0.647735000, +0.913280845, +0.913280845, +0.242705643
458+0.880255878, +0.369405657, +0.531468928, +0.242705643, +0.709048092, +0.709048092
459call setResized(rank, shape(dismat))
460call setKnnSorted(dismat, rank)
461dismat
462+0.531118751, +0.531118751, +0.648618877, +1.03723729, +0.302644640, +0.880255878
463+0.648618877, +0.453695059, +0.453695059, +0.543955266, +0.402912736, +0.369405657
464+1.03723729, +0.543955266, +0.559946954, +0.559946954, +0.647735000, +0.531468928
465+0.302644640, +0.402912736, +0.647735000, +0.913280845, +0.913280845, +0.242705643
466+0.880255878, +0.369405657, +0.531468928, +0.242705643, +0.709048092, +0.709048092
467rank
468+4, +5, +2, +5, +1, +4
469+1, +4, +5, +2, +2, +2
470+2, +2, +3, +3, +3, +3
471+5, +1, +4, +4, +5, +5
472+3, +3, +1, +1, +4, +1
473
474
Test:
test_pm_knn
Todo:
High Priority: This generic interface should be extended to support discrete distance matrices.


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:
Fatemeh Bagheri, Thursday 8:40 PM, July 20, 2023, Dallas, TX Amir Shahmoradi, Saturday 1:00 AM, September, 1, 2018, Dallas, TX

Definition at line 181 of file pm_knn.F90.


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