distances
covar_anisotropic(X1=None, X2=None, d=None, g=None)
¶
Calculate the separable covariance matrix between the rows of X1 and X2 with lengthscale d and nugget g.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
X1 |
ndarray
|
First input matrix. |
None
|
X2 |
ndarray
|
Second input matrix (optional). |
None
|
d |
ndarray
|
Array of lengthscale parameters. |
None
|
g |
float
|
Nugget parameter. |
None
|
Returns:
Type | Description |
---|---|
ndarray
|
np.ndarray: Covariance matrix K. |
Examples:
>>> import numpy as np
>>> from spotpython.gp.distances import covar_anisotropic
>>> X1 = np.array([[1.0, 2.0], [3.0, 4.0]])
>>> X2 = np.array([[5.0, 6.0], [7.0, 8.0]])
>>> d = np.array([1.0, 1.0])
>>> g = 0.1
>>> K_symm = covar_anisotropic(X1=X1, d=d, g=g)
>>> print(K_symm)
[[1.1 0.36787944]
[0.36787944 1.1 ]]
>>> K = covar_anisotropic(X1=X1, X2=X2, d=d, g=g)
>>> print(K)
[[0.00012341 0.00033546]
[0.00033546 0.000911
Source code in spotpython/gp/distances.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
|
dist(X1, X2=None)
¶
Calculate the distance matrix between the rows of X1 and X2, or between X1 and itself when X2 is None.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
X1 |
ndarray
|
First input matrix. |
required |
X2 |
ndarray
|
Second input matrix. |
None
|
Returns:
Type | Description |
---|---|
ndarray
|
np.ndarray: Distance matrix D. |
Examples:
>>> import numpy as np
>>> from spotpython.gp.distances import dist
>>> X1 = np.array([[1.0, 2.0], [3.0, 4.0]])
>>> X2 = np.array([[5.0, 6.0], [7.0, 8.0]])
>>> D_symm = dist(X1)
>>> print(D_symm)
[[ 0. 8.]
[ 8. 0.]]
>>> D = dist(X1, X2)
>>> print(D)
[[32. 8.]
[18. 2.]]
Source code in spotpython/gp/distances.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
|
distance(X1, n1, X2, n2, m)
¶
Calculate the distance matrix (D) between X1 and X2.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
X1 |
ndarray
|
First input matrix of shape (n1, m). |
required |
n1 |
int
|
Number of rows in X1. |
required |
X2 |
ndarray
|
Second input matrix of shape (n2, m). |
required |
n2 |
int
|
Number of rows in X2. |
required |
m |
int
|
Number of columns (features). |
required |
Returns:
Type | Description |
---|---|
ndarray
|
np.ndarray: Distance matrix D of shape (n1, n2). |
Examples:
>>> import numpy as np
>>> from spotpython.gp.distances import distance
>>> X1 = np.array([[1.0, 2.0], [3.0, 4.0]])
>>> n1 = 2
>>> X2 = np.array([[5.0, 6.0], [7.0, 8.0]])
>>> n2 = 2
>>> m = 2
>>> D_out = distance(X1, n1, X2, n2, m)
>>> print(D_out)
[[32. 8.]
[18. 2.]]
Source code in spotpython/gp/distances.py
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
|
distance_R(X1_in, n1_in, X2_in, n2_in, m_in)
¶
Calculate the distance matrix between the rows of X1 and X2.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
X1_in |
ndarray
|
First input matrix of shape (n1, m). |
required |
n1_in |
int
|
Number of rows in X1. |
required |
X2_in |
ndarray
|
Second input matrix of shape (n2, m). |
required |
n2_in |
int
|
Number of rows in X2. |
required |
m_in |
int
|
Number of columns (features). |
required |
Returns:
Type | Description |
---|---|
ndarray
|
np.ndarray: Distance matrix D of shape (n1, n2). |
Examples:
>>> import numpy as np
>>> from spotpython.gp.distances import distance_R
>>> X1_in = np.array([1.0, 2.0, 3.0, 4.0])
>>> n1_in = 2
>>> X2_in = np.array([5.0, 6.0, 7.0, 8.0])
>>> n2_in = 2
>>> m_in = 2
>>> D_out = distance_R(X1_in, n1_in, X2_in, n2_in, m_in)
>>> print(D_out)
[[32. 8.]
[18. 2.]]
Source code in spotpython/gp/distances.py
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
|
distance_symm_R(X_in, n_in, m_in)
¶
Calculate the distance matrix between the rows of X and itself, with output in the symmetric D_out matrix.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
X_in |
ndarray
|
Input matrix of shape (n, m). |
required |
n_in |
int
|
Number of rows in X. |
required |
m_in |
int
|
Number of columns (features). |
required |
Returns:
Type | Description |
---|---|
ndarray
|
np.ndarray: Symmetric distance matrix D of shape (n, n). |
Examples:
>>> import numpy as np
>>> from spotpython.gp.distances import distance_symm_R
>>> X_in = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0])
>>> n_in = 3
>>> m_in = 2
>>> D_out = distance_symm_R(X_in, n_in, m_in)
>>> print(D_out)
[[ 0. 8. 32.]
[ 8. 0. 8.]
[32. 8. 0.]]
Source code in spotpython/gp/distances.py
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 |
|
new_matrix_bones(data, rows, cols)
¶
Create a matrix view of the given data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
ndarray
|
Input data. |
required |
rows |
int
|
Number of rows. |
required |
cols |
int
|
Number of columns. |
required |
Returns:
Type | Description |
---|---|
ndarray
|
np.ndarray: Matrix view of the input data. |
Source code in spotpython/gp/distances.py
5 6 7 8 9 10 11 12 13 14 15 16 17 |
|