API Reference¶
cvxball
¶
Core package for minimum enclosing ball utilities and solvers.
Exposes the version and both solvers, so the whole public surface is reachable as
from cvxball import min_circle_active_set, min_circle_fgk. The submodule paths
cvxball.solver and cvxball.fischer_gaertner_kutz keep working, so this is
additive -- but the short form is the documented one, which leaves the module
layout free to change without breaking callers.
The two solvers answer the same question and agree on the answer, arriving from
opposite sides: :func:cvxball.min_circle_active_set ascends the dual and holds
no enclosing ball until it terminates, while :func:cvxball.min_circle_fgk
deflates an enclosing ball and is feasible throughout. The first is the default --
faster on every row of experiments/bench_seb.py, and it returns the dual
weights as a certificate; :func:cvxball.fischer_gaertner_kutz.ball_with_counts
is the second one's fuller signature, reporting the support set and the pivot
counts alongside the ball.
The dependencies are NumPy and SciPy, which the re-exports pull in on import.
That is the intended trade: they are the package's only reason to exist, so an
import cvxball that did not pull them in would be deferring work every caller
is about to need. Nothing else is imported, because nothing else is needed -- the
Clarabel cone program and Welzl's recursion, which the two solvers are measured
against, live in experiments/ and are references rather than solvers this
ships.
Ball
¶
Bases: NamedTuple
A ball, plus the work that went into finding it.
Attributes:
| Name | Type | Description |
|---|---|---|
radius |
float
|
The radius of the enclosing ball. |
centre |
ndarray
|
The centre, of shape |
support |
ndarray
|
Indices into the input of the final support set |
iterations |
int
|
How many turns of the main loop ran. |
drops |
int
|
How many points left the support set. |
insertions |
int
|
How many points entered it. |
Source code in src/cvxball/fischer_gaertner_kutz.py
ball_with_counts(points, pivot_rule='heuristic', dynamic_qr=True, verbose=False)
¶
Solve the smallest enclosing ball by the pivoting method, reporting the work done.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
points
|
ndarray
|
A |
required |
pivot_rule
|
PivotRule
|
|
'heuristic'
|
dynamic_qr
|
bool
|
Carry the factorisation across pivots, repairing it in
|
True
|
verbose
|
bool
|
If |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
The |
Ball
|
class: |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in src/cvxball/fischer_gaertner_kutz.py
470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 | |
min_circle_active_set(points, verbose=False, maintain=None)
¶
Compute the smallest enclosing circle with an active-set method.
An active-set QP method on the dual of the enclosing-ball problem, in place of handing a cone program to a conic solver. It maintains a support set of points held on the ball's boundary and repeatedly
- centres the ball on that support set by solving one small linear system
(:func:
_face_weights), - shrinks the support when it cannot hold — either because a weight would turn
negative, or because the set has become affinely dependent
(:func:
_affine_null_space) — moving as far as non-negativity allows, and - adds the farthest point that is still outside the ball.
Each subproblem is a k x k solve with k <= d, so the cost per iteration
is driven by the dimension rather than by the number of points, and the method
stops at an exact vertex of the dual feasible set instead of at an
interior-point tolerance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
points
|
ndarray
|
A numpy array of shape |
required |
verbose
|
bool
|
If |
False
|
maintain
|
bool | None
|
Whether to carry the support's factorisation across iterations
and repair it, rather than rebuilding it each time. |
None
|
Returns:
| Type | Description |
|---|---|
float
|
A tuple |
ndarray
|
radius (float) and center is a numpy array of shape |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Example
Three points forming a right triangle, whose smallest enclosing circle is
the one on its hypotenuse. Both values are pinned to full precision here,
where the cone program in experiments/clarabel_ball.py can only pin its
centre to three decimals — this method stops at an exact vertex of the
dual feasible set, so on an input whose answer is exactly representable it
returns that answer bit-for-bit.
import numpy as np from cvxball import min_circle_active_set points = np.array([[0, 0], [1, 0], [0, 1]]) radius, center = min_circle_active_set(points) radius == 2**0.5 / 2 True center array([0.5, 0.5])
Source code in src/cvxball/solver.py
278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 | |
min_circle_fgk(points, verbose=False)
¶
Compute the smallest enclosing ball, in this package's solver signature.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
points
|
ndarray
|
A numpy array of shape |
required |
verbose
|
bool
|
If |
False
|
Returns:
| Type | Description |
|---|---|
tuple[float, ndarray]
|
A tuple |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Example
The right triangle whose smallest enclosing circle is the one on its hypotenuse.
The values are rounded here, as they are for the cone program, and the
reason is worth stating because it is easy to assume otherwise: this
method terminates at an exact combinatorial configuration -- the
support set {(1, 0), (0, 1)} -- but the centre it reports is not the
exact circumcentre of that set. It is the running sum of the walks that
got there, so it lands a few ulp out (four, on this input). The shipped
active-set method solves afresh for the centre of its final support and
so returns sqrt(2) / 2 bit-for-bit; the difference is one of
arithmetic, not of which ball the two methods identify.
import numpy as np from cvxball import min_circle_fgk radius, center = min_circle_fgk(np.array([[0, 0], [1, 0], [0, 1]])) round(radius, 12) 0.707106781187 np.round(center, 12) array([0.5, 0.5])