Skip to content

PySRF

PySRF implements SRF (Similarity-Based Representation Factorization), a method for revealing low-dimensional, non-negative, interpretable embeddings from similarity matrices. Given a symmetric, non-negative similarity matrix \(S\), SRF reveals a small set of sparse, non-negative dimensions \(W\) with \(S \approx WW^\top\). It learns from observed entries without imputing missing values and selects the number of dimensions by cross-validation.

New here? See What is SRF? for how the method works and when to use it, or jump straight to Installation and the Quick start.

Quick example

import numpy as np
from pysrf import SRF, cross_val_score

# Your similarity matrix (e.g. from behavioral judgments or neural data)
s = np.random.rand(100, 100)
s = (s + s.T) / 2

# Select the model rank, then fit
cv = cross_val_score(s, range(1, 21), random_state=42)
model = SRF(rank=cv.model_rank, random_state=42)
w = model.fit_transform(s)

# Reconstruct the similarity matrix from the learned dimensions
s_reconstructed = model.reconstruct()

Next steps