fps
¶
fps(
x: array,
batch: Optional[array] = None,
ratio: float = 0.5,
random_start: bool = True,
batch_size: Optional[int] = None,
) -> array
Farthest point sampling, from the "PointNet++: Deep Hierarchical Feature Learning on Point Sets in a Metric Space" paper.
Iteratively samples the point that is the most distant from the points already sampled. Each graph (point cloud) of the batch keeps \(\lceil \text{ratio} \cdot N_b \rceil\) of its \(N_b\) points.
On the GPU, every graph is sampled by one threadgroup of a Metal kernel; otherwise the graphs are sampled together with array operations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
array
|
Point coordinates (or features), of shape |
required |
batch
|
Optional[array]
|
Graph of each point, of shape |
None
|
ratio
|
float
|
Sampling ratio, in \((0, 1]\). Default: |
0.5
|
random_start
|
bool
|
If |
True
|
batch_size
|
Optional[int]
|
The number of graphs. Default: |
None
|
Returns:
| Type | Description |
|---|---|
array
|
The indices of the sampled points, of shape |
array
|
by graph and in sampling order. |
Example:
import mlx.core as mx
from mlx_graphs.utils import fps
x = mx.array([[-1.0, -1.0], [-1.0, 1.0], [1.0, -1.0], [1.0, 1.0]])
batch = mx.array([0, 0, 0, 0])
index = fps(x, batch, ratio=0.5, random_start=False)
>>> index
array([0, 3], dtype=int32)
Source code in mlx_graphs/utils/clustering.py
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 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 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 | |
from mlx_graphs.utils import fps · mlx_graphs/utils/clustering.py