Reference
Setup
ViewDesc
tuple[Hashable, Hashable, Unpack[tuple[Hashable, ...]]]
Main method
solrcmf.SolrCMF
Sparse Orthogonal Low-rank Collective Matrix Factorization (SolrCMF).
Jointly factorises a collection of data matrices X[k], one per view pair k = (i, j, ...), as
X[k] ≈ V[i] diag(d[k]) V[j]^T
where V[i] and V[j] are column-orthonormal factor matrices shared across all data matrices that involve view i or j, and d[k] is a vector of per-factor signal strengths for the view pair k.
Structure sparsity is imposed on d[k] via an L1 penalty (controlled
by structure_penalty), causing factors that carry no signal for a
given view pair to be zeroed out. Optionally, factor-level sparsity
in the loadings can be imposed on a sparse auxiliary variable U via a
second L1 penalty (factor_penalty). Globally inactive factors
(zero in every d[k]) can be pruned during fitting when
factor_pruning=True.
The problem is solved by multi-block ADMM. The algorithm alternates between closed-form updates for Z (data fidelity), D (soft- thresholding), V (Procrustes / SVD), and optionally U and V' (factor sparsity), followed by dual ascent steps for the multipliers.
Attributes:
| Name | Type | Description |
|---|---|---|
vs_ |
dict[Entity, NDArray[float64]]
|
Fitted orthonormal factor matrices, one per view. |
ds_ |
dict[ViewDesc, NDArray[float64]]
|
Fitted scaling vectors, one per view pair. |
us_ |
dict[Entity, NDArray[float64]]
|
Fitted sparse loading matrices,
one per view. Only present when |
est_max_rank_ |
int
|
Effective rank after fitting (number of globally active factors). |
Methods:
| Name | Description |
|---|---|
__init__ |
Initialize SolrCMF. |
factor_pattern |
Return the factor pattern of the fitted solution. |
structure_pattern |
Return the structure pattern of the fitted solution. |
Source code in src/solrcmf/solrcmf.py
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 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 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 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 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 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 | |
__init__(*, structure_penalty=None, max_rank=None, factor_penalty=None, factor_pruning=True, init='random', init_kwargs=None, rho=None, alpha=None, mu=None, max_iter=1000, abs_tol=1e-06, rel_tol=1e-06, save_ctx=False)
Initialize SolrCMF.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
structure_penalty
|
float | None
|
L1 penalty weight on the scaling vectors d[k].
Larger values produce sparser structure patterns. Mutually
exclusive with providing |
None
|
max_rank
|
int | None
|
Maximum number of factors. Mutually exclusive with
providing |
None
|
factor_penalty
|
float | None
|
L1 penalty weight on the sparse factor loadings U.
If None, no factor sparsity is imposed. Mutually exclusive with
providing |
None
|
factor_pruning
|
bool
|
If True, globally inactive factors (zero in all d[k]) are removed from all blocks during fitting, reducing the effective rank over time. |
True
|
init
|
str
|
Initialisation strategy. "random" draws V from the Stiefel
manifold; "custom" uses factor matrices provided via the |
'random'
|
init_kwargs
|
dict[str, Any] | None
|
Additional keyword arguments for the initialiser. For "random" init, supports "rng" (int or Generator) for reproducibility and "repetitions" (int) for multiple restarts. |
None
|
rho
|
float | None
|
ADMM penalty parameter. If None, a lower bound derived from the problem structure is used. |
None
|
alpha
|
float | None
|
Ridge regularisation weight on V. Defaults to 1e-3 * rho. |
None
|
mu
|
float | None
|
Weight for the V' slack penalty. Defaults to 10.0 when factor sparsity or a fixed factor pattern is used. |
None
|
max_iter
|
int
|
Maximum number of ADMM iterations. |
1000
|
abs_tol
|
float
|
Absolute convergence tolerance on the objective change. |
1e-06
|
rel_tol
|
float
|
Relative convergence tolerance on the objective change. |
1e-06
|
save_ctx
|
bool
|
If True, the full ADMM context is stored as |
False
|
Source code in src/solrcmf/solrcmf.py
factor_pattern()
Return the factor pattern of the fitted solution.
Returns None if factor sparsity was not computed.
Source code in src/solrcmf/solrcmf.py
Hyperparameter selection
solrcmf.ElementwiseFolds
Element-wise k-fold splitter for collections of data matrices.
Observed entries (non-NaN) across all data matrices are independently
partitioned into k roughly equal folds. Each call to split yields k
(train_indices, test_indices) pairs, where indices are flat into the
corresponding data matrix.
Methods:
| Name | Description |
|---|---|
__init__ |
Initialize ElementwiseFolds. |
get_n_splits |
Return the number of splits. |
Source code in src/solrcmf/splits.py
__init__(n_splits, *, shuffle=True, rng=None)
Initialize ElementwiseFolds.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_splits
|
int
|
Number of folds. Must be at least 2. |
required |
shuffle
|
bool
|
Whether to shuffle observed entries before assigning them to folds. |
True
|
rng
|
Generator | None
|
Random number generator used for shuffling. Must be |
None
|
Source code in src/solrcmf/splits.py
solrcmf.SolrCMFCV
Cross-validated hyperparameter selection for SolrCMF.
Fits SolrCMF over a grid of structure_penalty, max_rank, and
factor_penalty values, selects the best combination by
cross-validation, and refits on the full data.
Two cross-validation strategies are supported. "structure_first_debiased_cv" first estimates the structure pattern on the full data for each parameter combination, then cross-validates a debiased (unpenalized) refit using that fixed pattern. "penalized_cv" cross-validates the full penalized estimation directly on held-out entries.
Attributes:
| Name | Type | Description |
|---|---|---|
cv_results_ |
dict[str, list]
|
Per-parameter-combination diagnostics. Each list has one entry per parameter combination. Keys:
Additional keys for cv_strategy="structure_first_debiased_cv":
Additional keys for cv_strategy="penalized_cv":
|
best_index_ |
int
|
Index into cv_results_ of the selected parameter combination. |
best_estimator_ |
SolrCMF
|
Estimator refit on all data with the selected parameters. |
best_max_rank_ |
int
|
Effective rank of the best estimator after fitting. |
Methods:
| Name | Description |
|---|---|
__init__ |
Initialize SolrCMFCV. |
fit |
Cross-validate the parameter grid and refit on the best combination. |
Source code in src/solrcmf/crossval.py
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 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 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 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 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 653 654 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 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 | |
__init__(*, structure_penalty=1.0, max_rank=10, factor_penalty=None, factor_pruning=True, cv=10, cv_strategy='structure_first_debiased_cv', score='neg_mean_squared_error', refit='1se_debiased', init='random', init_kwargs=None, rho=None, alpha=None, mu=None, max_iter=1000, abs_tol=1e-06, rel_tol=1e-06, verbose=False, n_jobs=None)
Initialize SolrCMFCV.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
structure_penalty
|
float | ArrayLike
|
L1 penalty weight on d[k], or an array-like of values to search over. |
1.0
|
max_rank
|
int | ArrayLike
|
Maximum number of factors, or an array-like of values to search over. |
10
|
factor_penalty
|
float | ArrayLike | None
|
L1 penalty weight on sparse factor loadings U, or
an array-like of values to search over. |
None
|
factor_pruning
|
bool
|
Whether to prune globally inactive factors during fitting. |
True
|
cv
|
int | BaseSplitter
|
Number of cross-validation folds, or a BaseSplitter instance. |
10
|
cv_strategy
|
str
|
Cross-validation strategy. See class docstring. |
'structure_first_debiased_cv'
|
score
|
str
|
Scoring function used to evaluate held-out predictions. |
'neg_mean_squared_error'
|
refit
|
str
|
Strategy for selecting and refitting the final estimator. Prefix "mean" selects by mean CV score; "1se" applies the one-standard-error rule. Suffix "debiased" refits without penalty using the estimated structure pattern; "penalized" refits with the full penalty. |
'1se_debiased'
|
init
|
str
|
Initialisation strategy passed to each SolrCMF fit. |
'random'
|
init_kwargs
|
dict | None
|
Additional keyword arguments for the initialiser. |
None
|
rho
|
float | None
|
ADMM penalty parameter passed to each SolrCMF fit. |
None
|
alpha
|
float | None
|
Ridge regularisation weight on V passed to each SolrCMF fit. |
None
|
mu
|
float | None
|
V'-slack penalty weight passed to each SolrCMF fit. |
None
|
max_iter
|
int
|
Maximum number of ADMM iterations per fit. |
1000
|
abs_tol
|
float
|
Absolute convergence tolerance per fit. |
1e-06
|
rel_tol
|
float
|
Relative convergence tolerance per fit. |
1e-06
|
verbose
|
bool
|
Whether to print progress messages during fitting. |
False
|
n_jobs
|
int | None
|
Number of parallel jobs. Passed to joblib.Parallel. |
None
|
Source code in src/solrcmf/crossval.py
fit(X, y=None, *, structure_weights=None, factor_weights=None, vs=None, ds=None, us=None)
Cross-validate the parameter grid and refit on the best combination.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
dict[ViewDesc, NDArray[float64]]
|
Data matrices, one per view pair. |
required |
y
|
Ignored. |
None
|
|
structure_weights
|
dict[ViewDesc, NDArray[float64] | float64] | None
|
Per-element L1 weights on d[k], one array per view pair. Passed through to each SolrCMF fit. |
None
|
factor_weights
|
dict[Entity, NDArray[float64] | float64] | None
|
Per-element L1 weights on U, one array per view. Passed through to each SolrCMF fit. |
None
|
vs
|
list[dict[Entity, NDArray[float64]]] | None
|
List of initial factor matrices, one dict per repetition. Required when init="custom". |
None
|
ds
|
list[dict[ViewDesc, NDArray[float64]]] | None
|
List of initial scaling vectors, one dict per repetition. Required when init="custom". |
None
|
us
|
list[dict[Entity, NDArray[float64]]] | None
|
List of initial sparse loading matrices, one dict per repetition. Required when init="custom" and factor sparsity is used. |
None
|
Returns:
| Type | Description |
|---|---|
SolrCMFCV
|
self |
Source code in src/solrcmf/crossval.py
267 268 269 270 271 272 273 274 275 276 277 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 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 653 654 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 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 | |
Initialization
solrcmf.multiview_init(xs, max_rank)
Compute a decomposition using the SVD of the concatenated matrices.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
xs
|
dict[ViewDesc, NDArray[float64]]
|
Input data |
required |
max_rank
|
int
|
Maximum rank of the decomposition |
required |
Returns:
| Type | Description |
|---|---|
dict[Entity, NDArray[float64]]
|
A tuple (vs, ds) containing the factor matrices in vs and the |
dict[ViewDesc, NDArray[float64]]
|
singular values in ds. |
Source code in src/solrcmf/initstrategies.py
solrcmf.best_random_init(xs, max_rank, *, n_inits=1, n_jobs=-1, rng=None, **kwargs)
Generate best unpenalized solution from random starting points.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
xs
|
dict[ViewDesc, NDArray[float64]]
|
Input data |
required |
max_rank
|
int
|
Maximum rank |
required |
n_inits
|
int
|
Number of random starting points to test |
1
|
n_jobs
|
int
|
Number of jobs to run concurrently, use as in joblib.Parallel |
-1
|
rng
|
Generator | int | None
|
Random number generator (numpy.random.Generator),
random seed, or |
None
|
**kwargs
|
Additional arguments passed to the SolrCMF estimator. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
fit |
SolrCMF
|
The solution found with minimal objective value among
all solutions obtained from the |
Source code in src/solrcmf/initstrategies.py
Synthetic data generation
solrcmf.simulate
Functions to simulate synthetic data.
This module provides functions to simulate synthetic data.
Classes:
| Name | Description |
|---|---|
SimulationResult |
Return type of simulate. |
Functions:
| Name | Description |
|---|---|
simulate |
Simulate synthetic data confirming to the SolrCMF model. |
SimulationResult
simulate(*, viewdims, factor_scales, scales=None, snr=1.0, factor_sparsity=None, rng=None)
Simulate synthetic data confirming to the SolrCMF model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
viewdims
|
Mapping[Entity, int]
|
A mapping of views to view dimensions. |
required |
factor_scales
|
Mapping[ViewDesc, ArrayLike]
|
A mapping of view descriptors to scalars or 1D arrays describing the strength of each factor. |
required |
scales
|
Mapping[ViewDesc, float] | None
|
A mapping of view descriptors to positive scalars which scale the factor_scales of the corresponding view descriptor. |
None
|
snr
|
Mapping[ViewDesc, float] | float
|
A mapping of view descriptors to signal-to-noise ratios. |
1.0
|
factor_sparsity
|
Mapping[Entity, float] | None
|
|
None
|
rng
|
Generator | None
|
A random number generator or |
None
|
Returns:
| Type | Description |
|---|---|
SimulationResult
|
A dictionary containing the following keys
|
Source code in src/solrcmf/simulate.py
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 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 | |
Auxiliary methods
solrcmf.LowRankImputation
Low-rank matrix imputation via alternating ridge regression.
Factorises an incomplete matrix X as U @ V.T, where U and V are estimated by alternating ridge regression on the observed entries. Missing values (NaN) are excluded from all computations and can be recovered from the fitted factors via U_ @ V_.T.
Attributes:
| Name | Type | Description |
|---|---|---|
U_ |
NDArray[float64]
|
Left factor matrix of shape (n_samples, max_rank). |
V_ |
NDArray[float64]
|
Right factor matrix of shape (n_features, max_rank). |
converged_ |
bool
|
Whether the convergence criterion was met. |
n_iter_ |
int
|
Number of iterations performed. |
loss_ |
float
|
Final objective value. |
Methods:
| Name | Description |
|---|---|
__init__ |
Initialize LowRankImputation. |
fit |
Fit the low-rank factorisation to X. |
Source code in src/solrcmf/lrimpute.py
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 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 165 166 167 168 169 170 171 172 173 174 175 176 177 178 | |
__init__(*, penalty=1.0, max_rank=10, init='random', warm_start=False, max_iter=1000, tol=1e-06, random_state=None)
Initialize LowRankImputation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
penalty
|
float
|
Ridge regularisation weight applied to both U and V. |
1.0
|
max_rank
|
int
|
Number of latent factors. |
10
|
init
|
str
|
Initialisation strategy. "random" draws U and V from a standard normal distribution; "custom" uses the U and V provided to fit. |
'random'
|
warm_start
|
bool
|
If True, reuse U_ and V_ from a previous fit as the starting point instead of reinitialising. |
False
|
max_iter
|
int
|
Maximum number of alternating update iterations. |
1000
|
tol
|
float
|
Convergence tolerance; stops when the relative decrease in loss falls below tol. |
1e-06
|
random_state
|
int | RandomState | None
|
Seed or RandomState instance for reproducible random initialisation. |
None
|
Source code in src/solrcmf/lrimpute.py
fit(X, y=None, *, U=None, V=None)
Fit the low-rank factorisation to X.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
Input matrix of shape (n_samples, n_features), possibly containing NaN for missing entries. |
required | |
y
|
Ignored. |
None
|
|
U
|
Initial left factor matrix of shape (n_samples, max_rank). Used when init='custom' or warm_start=True. |
None
|
|
V
|
Initial right factor matrix of shape (n_features, max_rank). Used when init='custom' or warm_start=True. |
None
|
Returns:
| Type | Description |
|---|---|
LowRankImputation
|
self |
Source code in src/solrcmf/lrimpute.py
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 165 166 167 168 169 170 171 172 173 174 175 176 177 178 | |
solrcmf.bicenter(X, tol=1e-16, max_iter=10)
Bicenter the input matrix allowing for missing values.
Instead of simply centering all elements around a total mean value, this
function models the data as X = m + rm + cm + Y, where m is the total
mean (shape ()), rm are row means (shape (n, 1)), cm are column means
(shape (1, m)), and Y are residuals (shape (n, m)).
Implements the centering algorithm described in
Hastie et al. (2015) Matrix completion and low-rank SVD via fast alternating least squares. Journal of Machine Learning Research, 16(104):3367--3402, 2015.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
NDArray[floating[Any]]
|
The input matrix |
required |
tol
|
float
|
Convergence tolerance |
1e-16
|
max_iter
|
int
|
Maximum number of iterations to perform. |
10
|
Returns:
| Type | Description |
|---|---|
tuple[NDArray[floating[Any]], floating[Any], NDArray[floating[Any]], NDArray[floating[Any]]]
|
A tuple (Y, m, rm, cm) containing the bi-centered matrix Y, the overall mean m, as well as row-means rm and column-means cm. |
Source code in src/solrcmf/preprocess.py
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 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 | |
solrcmf.nanscale(X, scale)
Scale all non-nan values in an array.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
NDArray[floating[Any]]
|
Input array to be scaled, possibly containing numpy.nan values. |
required |
scale
|
float
|
Positive scale parameter. |
required |
Returns:
| Type | Description |
|---|---|
NDArray[floating[Any]]
|
A scaled version of the input array. |