Quickstart
import matplotlib.pyplot as pltimport numpy as npfrom flodr import FloDR, audit, viz
# X: one row per point, e.g. 50 standardised principal components; labels: one per rowtrain, test = np.arange(len(X)) % 5 != 0, np.arange(len(X)) % 5 == 0
model = FloDR(random_state=0).fit(X[train])Y = model.embedding_ # the map of the training points
Y_new = model.transform(X[test]) # one pass through the flowY_opt = model.transform_opt(X[test]) # optimised against the training mapX_back = model.inverse_transform(Y[:10]) # positions back to the inputZ = model.transform_latent(X[test]) # the map, then the residualX_same = model.inverse_latent(Z) # exact up to float precision
logp = model.score_samples(X[test]) # log densitycert = model.coverage_certificate(X[test]) # is the density a law of new points?print(cert["certifies"]) # "certified", "refused" or "undecided"
res = audit(Y, X=X[train], labels=labels[train]) # what the map hides about the labelsprint(res)
fig, ax = plt.subplots(1, 2, figsize=(8, 4))viz.plot_embedding(Y, labels[train], ax=ax[0])viz.plot_ranks([cert["fibre"]["ranks"], cert["map"]["ranks"]], ax=ax[1])viz.save(fig, "flodr.pdf")Fitting uses the GPU when PyTorch sees one. examples/quickstart.ipynb runs these calls on Fashion-MNIST.