basis
GPBasis
Bases: SpatialBasis
Gaussian-process basis with an RBF kernel (Nystrom).
Regularizes the landmark kernel with eps * I before SVD.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
length_scale
|
float
|
RBF length scale :math: .. math::
Smaller values allow more rapidly varying functions. If |
None
|
length_fraction
|
float
|
Fraction :math: .. math::
taken over the fitted coordinates :math: |
0.17
|
**kwargs
|
Forwarded to :class: |
{}
|
Attributes:
| Name | Type | Description |
|---|---|---|
length_scale_ |
float
|
Length scale of the fitted basis. Set by :meth: |
Source code in scdesigner/src/scdesigner/data/basis.py
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 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 | |
SpatialBasis
Bases: ABC
Low-rank 2D spatial basis with stateful fit / transform.
Subclasses define _kernel and _regularize (applied to the
landmark kernel before SVD). fit picks landmarks, stores the
projection U_m[:, :df] / s_m[:df], training column std (if
standardize), and the penalty diagonal s_0 / s_j (capped).
transform reuses that state on new coordinates. fit evaluates the
kernel on at most chunk_size coordinates at a time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
int
|
Basis columns to retain. |
15
|
n_landmarks
|
int
|
Landmark count for the Nystrom approximation. |
200
|
eps
|
float
|
Numerical floor for kernel and column-std. |
1e-06
|
max_penalty_ratio
|
float
|
Cap on |
1000.0
|
standardize
|
bool
|
Divide columns by training std. |
False
|
Attributes:
| Name | Type | Description |
|---|---|---|
landmarks_, projection_, col_sd_, penalty_diag |
Set by :meth: |
Source code in scdesigner/src/scdesigner/data/basis.py
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 86 87 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 133 134 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 | |
fit(coords, chunk_size=None)
Fit on coords; chunk_size=None evaluates all rows at once.
Source code in scdesigner/src/scdesigner/data/basis.py
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | |
TPSBasis
Bases: SpatialBasis
Thin-plate spline basis (Nystrom).
Projects out the TPS penalty null space (intercept + linear terms over
landmarks) before SVD; drops singular values below eps.
Source code in scdesigner/src/scdesigner/data/basis.py
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 | |
rbf_kernel(A, B, length_scale)
Radial basis function kernel: K[i,j] = exp(-||A_i - B_j||^2 / (2 * length_scale^2)).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
A
|
ndarray of shape (n, d)
|
First set of points. |
required |
B
|
ndarray of shape (m, d)
|
Second set of points. |
required |
length_scale
|
float
|
Controls the spatial range of correlation; larger values give smoother functions. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
K |
ndarray of shape (n, m)
|
|
Examples:
>>> K = rbf_kernel(np.array([[0.0, 0.0]]), np.array([[1.0, 0.0]]), length_scale=1.0)
>>> float(K[0, 0])
Source code in scdesigner/src/scdesigner/data/basis.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | |
tps_kernel(A, B, eps)
Thin-plate spline kernel: K[i,j] = ||A_i - B_j||^2 log ||A_i - B_j||.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
A
|
ndarray of shape (n, d)
|
First set of points. |
required |
B
|
ndarray of shape (m, d)
|
Second set of points. |
required |
eps
|
float
|
Epsilon parameter, preventing log(0). |
required |
Returns:
| Name | Type | Description |
|---|---|---|
K |
ndarray of shape (n, m)
|
|
Examples:
>>> K = tps_kernel(np.array([[0.0, 0.0]]), np.array([[1.0, 0.0]]), eps=1e-6)
>>> K
Source code in scdesigner/src/scdesigner/data/basis.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | |