Log-Marginal Likelihood Landscape module
landscape
Log-marginal likelihood landscape computation and grid search.
Handles visualization of the hyperparameter space and identification of optimal kernel configurations through grid search.
compute_lml_landscape(delta_values, log_k, sigma_range=None, length_scale_range=None, n_sigma=50, n_length=50, noise_level=None, posterior_cov=None, nbins=None, k_start=None, k_end=None, auto_sigma_factor=3.0, auto_length_fallback=0.3, validate_ranges=True, kernel_type=KernelType.RBF, kernel_params=None, pre_optimize_extra_params=True, grid_config=None, binning=None, verbose=True)
Compute log-marginal likelihood landscape in \((\sigma, \ell)\) hyperparameter space.
This visualizes how well different GP models explain the data, allowing us to:
- Test whether signal variance \(\sigma\) is significantly non-zero (evidence for features)
- Infer characteristic length scale \(\ell\) of features (sharp vs smooth)
- Assess parameter uncertainty and degeneracies (ridge structures)
- Compute Bayes factors for model comparison (signal vs noise)
Supports multiple kernel types and intelligent automatic hyperparameter range selection.
| PARAMETER | DESCRIPTION |
|---|---|
delta_values
|
Observed \(\delta(k)\) values (single sample or posterior mean), shape (n,).
TYPE:
|
log_k
|
\(\log(k)\) values, shape (n, 1) or (n,).
TYPE:
|
sigma_range
|
(min, max) for signal std \(\sigma\) (None = auto-determine from data).
TYPE:
|
length_scale_range
|
(min, max) for length scale \(\ell\) (None = auto from resolution).
TYPE:
|
n_sigma
|
Number of \(\sigma\) grid points.
TYPE:
|
n_length
|
Number of length scale \(\ell\) grid points.
TYPE:
|
noise_level
|
Fixed diagonal noise \(\sigma_n^2\) (used if posterior_cov=None).
TYPE:
|
posterior_cov
|
Full posterior covariance matrix \(\Sigma_{\mathrm{post}}\) (RECOMMENDED, nbins x nbins).
TYPE:
|
nbins
|
Number of bins for automatic length scale range (recommended).
TYPE:
|
k_start
|
Start of \(k\)-range in \(\mathrm{Mpc}^{-1}\) for automatic length scale range.
TYPE:
|
k_end
|
End of \(k\)-range in \(\mathrm{Mpc}^{-1}\) for automatic length scale range.
TYPE:
|
auto_sigma_factor
|
Multiplier for empirical_std when auto-determining sigma_max.
TYPE:
|
auto_length_fallback
|
Fraction of log_k range for length scale estimation fallback.
TYPE:
|
validate_ranges
|
If True, validate user-provided ranges and warn if unreasonable.
TYPE:
|
kernel_type
|
Type of kernel to use (default: KernelType.RBF).
TYPE:
|
kernel_params
|
Fixed kernel-specific parameters (not explored in landscape).
TYPE:
|
pre_optimize_extra_params
|
If True, pre-optimize extra kernel hyperparameters.
TYPE:
|
grid_config
|
Optional GridSearchConfig object (supersedes other parameters if provided).
TYPE:
|
binning
|
Optional BinningScheme object (supersedes nbins, k_start, k_end if provided).
TYPE:
|
verbose
|
Whether to print results.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Dict
|
Dictionary containing: - sigma_grid: 1D array of \(\sigma\) values - length_scale_grid: 1D array of \(\ell\) values - lml_grid: 2D array of log-marginal likelihoods (n_sigma, n_length) - optimal_sigma: ML estimate of \(\sigma\) - optimal_length_scale: ML estimate of \(\ell\) - max_lml: Maximum log-marginal likelihood - null_lml: LML at \(\sigma \approx 0\) (null hypothesis) - bayes_factor: exp(max_lml - null_lml) - resolution_info: Bin resolution diagnostics - auto_selected_ranges: Dict with 'sigma_range', 'length_scale_range', 'method' |
Source code in src/primefeat/gp/landscape.py
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 458 459 460 461 462 463 464 465 466 467 468 469 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 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 | |
compare_kernel_likelihoods(delta_values, log_k, kernel_configs, noise_level=None, noise_cov=None, optimize_params=False, optimize_kwargs=None)
Compare log-marginal likelihoods for different kernel configurations.
This function computes the LML for each provided kernel configuration, allowing direct comparison of how well different kernels explain the data.
| PARAMETER | DESCRIPTION |
|---|---|
delta_values
|
Observed \(\delta(k)\) values, shape (n,).
TYPE:
|
log_k
|
\(\log(k)\) values, shape (n,) or (n, 1).
TYPE:
|
kernel_configs
|
Dictionary mapping names to KernelConfig objects.
TYPE:
|
noise_level
|
Diagonal noise standard deviation \(\sigma_n\) (if noise_cov not provided).
TYPE:
|
noise_cov
|
Full posterior covariance matrix \(\Sigma_{\mathrm{post}}\) (recommended).
TYPE:
|
optimize_params
|
If True, use gradient-based optimisation to refine each kernel's hyperparameters before comparing.
TYPE:
|
optimize_kwargs
|
Extra keyword arguments forwarded to optimize().
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Dict[str, Dict]
|
Dictionary with: - 'results': Dict mapping kernel name to {lml, config, opt_result (if optimised)} - 'best_kernel': Name of kernel with highest LML - 'best_lml': Highest log-marginal likelihood - 'bayes_factors': Dict of Bayes factors relative to worst model |
Source code in src/primefeat/gp/landscape.py
655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 | |