Estimate Neural Manifold Curvature#

Set-up + Imports#

 In [1]:
import setup

setup.main()
%load_ext autoreload
%autoreload 2
%load_ext jupyter_black

import os

import matplotlib.pyplot as plt
import numpy as np
import torch

os.environ["GEOMSTATS_BACKEND"] = "pytorch"
import geomstats.backend as gs
Working directory:  /home/facosta/neurometry/neurometry
Directory added to path:  /home/facosta/neurometry
Directory added to path:  /home/facosta/neurometry/neurometry

Load config & model#

 In [89]:
run_name = "run_6rixqmzt_t2_synthetic_noise_var_1e-05_embedding_dim_3"
 In [92]:
results_dir = os.path.join(os.getcwd(), "curvature/results")
models_dir = os.path.join(results_dir, "trained_models")
configs_dir = os.path.join(results_dir, "configs")


import json

model_file = os.path.join(models_dir, f"{run_name}_model.pt")
config_file = os.path.join(configs_dir, f"{run_name}.json")

with open(config_file, "r") as file:
    config_dict = json.load(file)


class Config:
    def __init__(self, config_dict):
        self.__dict__.update(config_dict)

    def __getattr__(self, name):
        if name in self:
            return self[name]
        else:
            raise AttributeError(
                f"'{self.__class__.__name__}' object has no attribute '{name}'"
            )


config = Config(config_dict)
 In [94]:
import neurometry.curvature.models.toroidal_vae as toroidal_vae


model = toroidal_vae.ToroidalVAE(
    data_dim=config.data_dim,
    latent_dim=config.latent_dim,
    sftbeta=config.sftbeta,
    encoder_width=config.encoder_width,
    encoder_depth=config.encoder_depth,
    decoder_width=config.decoder_width,
    decoder_depth=config.decoder_depth,
    posterior_type=config.posterior_type,
).to(config.device)


# model.load_state_dict(torch.load(model_file))
# model.eval();

model = torch.load(model_file)
model.eval();

Compute extrinsic curvature#

 In [95]:
import neurometry.curvature.evaluate as evaluate

z_grid, geodesic_dist, _, curv_norms_learned = evaluate.compute_curvature_learned(
    model=model,
    config=config,
    embedding_dim=config.embedding_dim,
    n_grid_points=config.n_grid_points,
)
torch.Size([100, 2])
An error occurred for i=0: linalg.inv: The diagonal element 2 is zero, the inversion could not be completed because the input matrix is singular.
tensor([[3.5656, 0.0000],
        [0.0000, 0.0000]])
An error occurred for i=1: linalg.inv: The diagonal element 2 is zero, the inversion could not be completed because the input matrix is singular.
tensor([[3.5656, 0.0000],
        [0.0000, 0.0000]])
An error occurred for i=2: linalg.inv: The diagonal element 2 is zero, the inversion could not be completed because the input matrix is singular.
tensor([[3.5656, 0.0000],
        [0.0000, 0.0000]])
An error occurred for i=3: linalg.inv: The diagonal element 2 is zero, the inversion could not be completed because the input matrix is singular.
tensor([[3.5656, 0.0000],
        [0.0000, 0.0000]])
An error occurred for i=4: linalg.inv: The diagonal element 2 is zero, the inversion could not be completed because the input matrix is singular.
tensor([[3.5656, 0.0000],
        [0.0000, 0.0000]])
An error occurred for i=5: linalg.inv: The diagonal element 2 is zero, the inversion could not be completed because the input matrix is singular.
tensor([[3.5656, 0.0000],
        [0.0000, 0.0000]])
An error occurred for i=6: linalg.inv: The diagonal element 2 is zero, the inversion could not be completed because the input matrix is singular.
tensor([[3.5656, 0.0000],
        [0.0000, 0.0000]])
An error occurred for i=7: linalg.inv: The diagonal element 2 is zero, the inversion could not be completed because the input matrix is singular.
tensor([[3.5656, 0.0000],
        [0.0000, 0.0000]])
An error occurred for i=8: linalg.inv: The diagonal element 2 is zero, the inversion could not be completed because the input matrix is singular.
tensor([[3.5656, 0.0000],
        [0.0000, 0.0000]])
An error occurred for i=9: linalg.inv: The diagonal element 2 is zero, the inversion could not be completed because the input matrix is singular.
tensor([[3.5656, 0.0000],
        [0.0000, 0.0000]])
An error occurred for i=10: linalg.inv: The diagonal element 2 is zero, the inversion could not be completed because the input matrix is singular.
tensor([[3.3398, 0.0000],
        [0.0000, 0.0000]])
An error occurred for i=11: linalg.inv: The diagonal element 2 is zero, the inversion could not be completed because the input matrix is singular.
tensor([[3.3398, 0.0000],
        [0.0000, 0.0000]])
An error occurred for i=12: linalg.inv: The diagonal element 2 is zero, the inversion could not be completed because the input matrix is singular.
tensor([[3.3398, 0.0000],
        [0.0000, 0.0000]])
An error occurred for i=13: linalg.inv: The diagonal element 2 is zero, the inversion could not be completed because the input matrix is singular.
tensor([[3.3398, 0.0000],
        [0.0000, 0.0000]])
An error occurred for i=14: linalg.inv: The diagonal element 2 is zero, the inversion could not be completed because the input matrix is singular.
tensor([[3.3398, 0.0000],
        [0.0000, 0.0000]])
An error occurred for i=15: linalg.inv: The diagonal element 2 is zero, the inversion could not be completed because the input matrix is singular.
tensor([[3.3398, 0.0000],
        [0.0000, 0.0000]])
An error occurred for i=16: linalg.inv: The diagonal element 2 is zero, the inversion could not be completed because the input matrix is singular.
tensor([[3.3398, 0.0000],
        [0.0000, 0.0000]])
An error occurred for i=17: linalg.inv: The diagonal element 2 is zero, the inversion could not be completed because the input matrix is singular.
tensor([[3.3398, 0.0000],
        [0.0000, 0.0000]])
An error occurred for i=18: linalg.inv: The diagonal element 2 is zero, the inversion could not be completed because the input matrix is singular.
tensor([[3.3398, 0.0000],
        [0.0000, 0.0000]])
An error occurred for i=19: linalg.inv: The diagonal element 2 is zero, the inversion could not be completed because the input matrix is singular.
tensor([[3.3398, 0.0000],
        [0.0000, 0.0000]])
An error occurred for i=20: linalg.inv: The diagonal element 2 is zero, the inversion could not be completed because the input matrix is singular.
tensor([[2.8585, 0.0000],
        [0.0000, 0.0000]])
An error occurred for i=21: linalg.inv: The diagonal element 2 is zero, the inversion could not be completed because the input matrix is singular.
tensor([[2.8585, 0.0000],
        [0.0000, 0.0000]])
An error occurred for i=22: linalg.inv: The diagonal element 2 is zero, the inversion could not be completed because the input matrix is singular.
tensor([[2.8585, 0.0000],
        [0.0000, 0.0000]])
An error occurred for i=23: linalg.inv: The diagonal element 2 is zero, the inversion could not be completed because the input matrix is singular.
tensor([[2.8585, 0.0000],
        [0.0000, 0.0000]])
An error occurred for i=24: linalg.inv: The diagonal element 2 is zero, the inversion could not be completed because the input matrix is singular.
tensor([[2.8585, 0.0000],
        [0.0000, 0.0000]])
An error occurred for i=25: linalg.inv: The diagonal element 2 is zero, the inversion could not be completed because the input matrix is singular.
tensor([[2.8585, 0.0000],
        [0.0000, 0.0000]])
An error occurred for i=26: linalg.inv: The diagonal element 2 is zero, the inversion could not be completed because the input matrix is singular.
tensor([[2.8585, 0.0000],
        [0.0000, 0.0000]])
An error occurred for i=27: linalg.inv: The diagonal element 2 is zero, the inversion could not be completed because the input matrix is singular.
tensor([[2.8585, 0.0000],
        [0.0000, 0.0000]])
An error occurred for i=28: linalg.inv: The diagonal element 2 is zero, the inversion could not be completed because the input matrix is singular.
tensor([[2.8585, 0.0000],
        [0.0000, 0.0000]])
An error occurred for i=29: linalg.inv: The diagonal element 2 is zero, the inversion could not be completed because the input matrix is singular.
tensor([[2.8585, 0.0000],
        [0.0000, 0.0000]])
An error occurred for i=30: linalg.inv: The diagonal element 2 is zero, the inversion could not be completed because the input matrix is singular.
tensor([[9.6676, 0.0000],
        [0.0000, 0.0000]])
An error occurred for i=31: linalg.inv: The diagonal element 2 is zero, the inversion could not be completed because the input matrix is singular.
tensor([[9.6676, 0.0000],
        [0.0000, 0.0000]])
An error occurred for i=32: linalg.inv: The diagonal element 2 is zero, the inversion could not be completed because the input matrix is singular.
tensor([[9.6676, 0.0000],
        [0.0000, 0.0000]])
An error occurred for i=33: linalg.inv: The diagonal element 2 is zero, the inversion could not be completed because the input matrix is singular.
tensor([[9.6676, 0.0000],
        [0.0000, 0.0000]])
An error occurred for i=34: linalg.inv: The diagonal element 2 is zero, the inversion could not be completed because the input matrix is singular.
tensor([[9.6676, 0.0000],
        [0.0000, 0.0000]])
An error occurred for i=35: linalg.inv: The diagonal element 2 is zero, the inversion could not be completed because the input matrix is singular.
tensor([[9.6676, 0.0000],
        [0.0000, 0.0000]])
An error occurred for i=36: linalg.inv: The diagonal element 2 is zero, the inversion could not be completed because the input matrix is singular.
tensor([[9.6676, 0.0000],
        [0.0000, 0.0000]])
An error occurred for i=37: linalg.inv: The diagonal element 2 is zero, the inversion could not be completed because the input matrix is singular.
tensor([[9.6676, 0.0000],
        [0.0000, 0.0000]])
An error occurred for i=38: linalg.inv: The diagonal element 2 is zero, the inversion could not be completed because the input matrix is singular.
tensor([[9.6676, 0.0000],
        [0.0000, 0.0000]])
An error occurred for i=39: linalg.inv: The diagonal element 2 is zero, the inversion could not be completed because the input matrix is singular.
tensor([[9.6676, 0.0000],
        [0.0000, 0.0000]])
An error occurred for i=40: linalg.inv: The diagonal element 2 is zero, the inversion could not be completed because the input matrix is singular.
tensor([[10.4394,  0.0000],
        [ 0.0000,  0.0000]])
An error occurred for i=41: linalg.inv: The diagonal element 2 is zero, the inversion could not be completed because the input matrix is singular.
tensor([[10.4394,  0.0000],
        [ 0.0000,  0.0000]])
An error occurred for i=42: linalg.inv: The diagonal element 2 is zero, the inversion could not be completed because the input matrix is singular.
tensor([[10.4394,  0.0000],
        [ 0.0000,  0.0000]])
An error occurred for i=43: linalg.inv: The diagonal element 2 is zero, the inversion could not be completed because the input matrix is singular.
tensor([[10.4394,  0.0000],
        [ 0.0000,  0.0000]])
An error occurred for i=44: linalg.inv: The diagonal element 2 is zero, the inversion could not be completed because the input matrix is singular.
tensor([[10.4394,  0.0000],
        [ 0.0000,  0.0000]])
An error occurred for i=45: linalg.inv: The diagonal element 2 is zero, the inversion could not be completed because the input matrix is singular.
tensor([[10.4394,  0.0000],
        [ 0.0000,  0.0000]])
An error occurred for i=46: linalg.inv: The diagonal element 2 is zero, the inversion could not be completed because the input matrix is singular.
tensor([[10.4394,  0.0000],
        [ 0.0000,  0.0000]])
An error occurred for i=47: linalg.inv: The diagonal element 2 is zero, the inversion could not be completed because the input matrix is singular.
tensor([[10.4394,  0.0000],
        [ 0.0000,  0.0000]])
An error occurred for i=48: linalg.inv: The diagonal element 2 is zero, the inversion could not be completed because the input matrix is singular.
tensor([[10.4394,  0.0000],
        [ 0.0000,  0.0000]])
An error occurred for i=49: linalg.inv: The diagonal element 2 is zero, the inversion could not be completed because the input matrix is singular.
tensor([[10.4394,  0.0000],
        [ 0.0000,  0.0000]])
An error occurred for i=50: linalg.inv: The diagonal element 2 is zero, the inversion could not be completed because the input matrix is singular.
tensor([[24.1509,  0.0000],
        [ 0.0000,  0.0000]])
An error occurred for i=51: linalg.inv: The diagonal element 2 is zero, the inversion could not be completed because the input matrix is singular.
tensor([[24.1509,  0.0000],
        [ 0.0000,  0.0000]])
An error occurred for i=52: linalg.inv: The diagonal element 2 is zero, the inversion could not be completed because the input matrix is singular.
tensor([[24.1509,  0.0000],
        [ 0.0000,  0.0000]])
An error occurred for i=53: linalg.inv: The diagonal element 2 is zero, the inversion could not be completed because the input matrix is singular.
tensor([[24.1509,  0.0000],
        [ 0.0000,  0.0000]])
An error occurred for i=54: linalg.inv: The diagonal element 2 is zero, the inversion could not be completed because the input matrix is singular.
tensor([[24.1509,  0.0000],
        [ 0.0000,  0.0000]])
An error occurred for i=55: linalg.inv: The diagonal element 2 is zero, the inversion could not be completed because the input matrix is singular.
tensor([[24.1509,  0.0000],
        [ 0.0000,  0.0000]])
An error occurred for i=56: linalg.inv: The diagonal element 2 is zero, the inversion could not be completed because the input matrix is singular.
tensor([[24.1509,  0.0000],
        [ 0.0000,  0.0000]])
An error occurred for i=57: linalg.inv: The diagonal element 2 is zero, the inversion could not be completed because the input matrix is singular.
tensor([[24.1509,  0.0000],
        [ 0.0000,  0.0000]])
An error occurred for i=58: linalg.inv: The diagonal element 2 is zero, the inversion could not be completed because the input matrix is singular.
tensor([[24.1509,  0.0000],
        [ 0.0000,  0.0000]])
An error occurred for i=59: linalg.inv: The diagonal element 2 is zero, the inversion could not be completed because the input matrix is singular.
tensor([[24.1509,  0.0000],
        [ 0.0000,  0.0000]])
An error occurred for i=60: linalg.inv: The diagonal element 2 is zero, the inversion could not be completed because the input matrix is singular.
tensor([[14.2595,  0.0000],
        [ 0.0000,  0.0000]])
An error occurred for i=61: linalg.inv: The diagonal element 2 is zero, the inversion could not be completed because the input matrix is singular.
tensor([[14.2595,  0.0000],
        [ 0.0000,  0.0000]])
An error occurred for i=62: linalg.inv: The diagonal element 2 is zero, the inversion could not be completed because the input matrix is singular.
tensor([[14.2595,  0.0000],
        [ 0.0000,  0.0000]])
An error occurred for i=63: linalg.inv: The diagonal element 2 is zero, the inversion could not be completed because the input matrix is singular.
tensor([[14.2595,  0.0000],
        [ 0.0000,  0.0000]])
An error occurred for i=64: linalg.inv: The diagonal element 2 is zero, the inversion could not be completed because the input matrix is singular.
tensor([[14.2595,  0.0000],
        [ 0.0000,  0.0000]])
An error occurred for i=65: linalg.inv: The diagonal element 2 is zero, the inversion could not be completed because the input matrix is singular.
tensor([[14.2595,  0.0000],
        [ 0.0000,  0.0000]])
An error occurred for i=66: linalg.inv: The diagonal element 2 is zero, the inversion could not be completed because the input matrix is singular.
tensor([[14.2595,  0.0000],
        [ 0.0000,  0.0000]])
An error occurred for i=67: linalg.inv: The diagonal element 2 is zero, the inversion could not be completed because the input matrix is singular.
tensor([[14.2595,  0.0000],
        [ 0.0000,  0.0000]])
An error occurred for i=68: linalg.inv: The diagonal element 2 is zero, the inversion could not be completed because the input matrix is singular.
tensor([[14.2595,  0.0000],
        [ 0.0000,  0.0000]])
An error occurred for i=69: linalg.inv: The diagonal element 2 is zero, the inversion could not be completed because the input matrix is singular.
tensor([[14.2595,  0.0000],
        [ 0.0000,  0.0000]])
An error occurred for i=70: linalg.inv: The diagonal element 2 is zero, the inversion could not be completed because the input matrix is singular.
tensor([[6.6733, 0.0000],
        [0.0000, 0.0000]])
An error occurred for i=71: linalg.inv: The diagonal element 2 is zero, the inversion could not be completed because the input matrix is singular.
tensor([[6.6733, 0.0000],
        [0.0000, 0.0000]])
An error occurred for i=72: linalg.inv: The diagonal element 2 is zero, the inversion could not be completed because the input matrix is singular.
tensor([[6.6733, 0.0000],
        [0.0000, 0.0000]])
An error occurred for i=73: linalg.inv: The diagonal element 2 is zero, the inversion could not be completed because the input matrix is singular.
tensor([[6.6733, 0.0000],
        [0.0000, 0.0000]])
An error occurred for i=74: linalg.inv: The diagonal element 2 is zero, the inversion could not be completed because the input matrix is singular.
tensor([[6.6733, 0.0000],
        [0.0000, 0.0000]])
An error occurred for i=75: linalg.inv: The diagonal element 2 is zero, the inversion could not be completed because the input matrix is singular.
tensor([[6.6733, 0.0000],
        [0.0000, 0.0000]])
An error occurred for i=76: linalg.inv: The diagonal element 2 is zero, the inversion could not be completed because the input matrix is singular.
tensor([[6.6733, 0.0000],
        [0.0000, 0.0000]])
An error occurred for i=77: linalg.inv: The diagonal element 2 is zero, the inversion could not be completed because the input matrix is singular.
tensor([[6.6733, 0.0000],
        [0.0000, 0.0000]])
An error occurred for i=78: linalg.inv: The diagonal element 2 is zero, the inversion could not be completed because the input matrix is singular.
tensor([[6.6733, 0.0000],
        [0.0000, 0.0000]])
An error occurred for i=79: linalg.inv: The diagonal element 2 is zero, the inversion could not be completed because the input matrix is singular.
tensor([[6.6733, 0.0000],
        [0.0000, 0.0000]])
An error occurred for i=80: linalg.inv: The diagonal element 2 is zero, the inversion could not be completed because the input matrix is singular.
tensor([[6.9866, 0.0000],
        [0.0000, 0.0000]])
An error occurred for i=81: linalg.inv: The diagonal element 2 is zero, the inversion could not be completed because the input matrix is singular.
tensor([[6.9866, 0.0000],
        [0.0000, 0.0000]])
An error occurred for i=82: linalg.inv: The diagonal element 2 is zero, the inversion could not be completed because the input matrix is singular.
tensor([[6.9866, 0.0000],
        [0.0000, 0.0000]])
An error occurred for i=83: linalg.inv: The diagonal element 2 is zero, the inversion could not be completed because the input matrix is singular.
tensor([[6.9866, 0.0000],
        [0.0000, 0.0000]])
An error occurred for i=84: linalg.inv: The diagonal element 2 is zero, the inversion could not be completed because the input matrix is singular.
tensor([[6.9866, 0.0000],
        [0.0000, 0.0000]])
An error occurred for i=85: linalg.inv: The diagonal element 2 is zero, the inversion could not be completed because the input matrix is singular.
tensor([[6.9866, 0.0000],
        [0.0000, 0.0000]])
An error occurred for i=86: linalg.inv: The diagonal element 2 is zero, the inversion could not be completed because the input matrix is singular.
tensor([[6.9866, 0.0000],
        [0.0000, 0.0000]])
An error occurred for i=87: linalg.inv: The diagonal element 2 is zero, the inversion could not be completed because the input matrix is singular.
tensor([[6.9866, 0.0000],
        [0.0000, 0.0000]])
An error occurred for i=88: linalg.inv: The diagonal element 2 is zero, the inversion could not be completed because the input matrix is singular.
tensor([[6.9866, 0.0000],
        [0.0000, 0.0000]])
An error occurred for i=89: linalg.inv: The diagonal element 2 is zero, the inversion could not be completed because the input matrix is singular.
tensor([[6.9866, 0.0000],
        [0.0000, 0.0000]])
An error occurred for i=90: linalg.inv: The diagonal element 2 is zero, the inversion could not be completed because the input matrix is singular.
tensor([[3.5656, 0.0000],
        [0.0000, 0.0000]])
An error occurred for i=91: linalg.inv: The diagonal element 2 is zero, the inversion could not be completed because the input matrix is singular.
tensor([[3.5656, 0.0000],
        [0.0000, 0.0000]])
An error occurred for i=92: linalg.inv: The diagonal element 2 is zero, the inversion could not be completed because the input matrix is singular.
tensor([[3.5656, 0.0000],
        [0.0000, 0.0000]])
An error occurred for i=93: linalg.inv: The diagonal element 2 is zero, the inversion could not be completed because the input matrix is singular.
tensor([[3.5656, 0.0000],
        [0.0000, 0.0000]])
An error occurred for i=94: linalg.inv: The diagonal element 2 is zero, the inversion could not be completed because the input matrix is singular.
tensor([[3.5656, 0.0000],
        [0.0000, 0.0000]])
An error occurred for i=95: linalg.inv: The diagonal element 2 is zero, the inversion could not be completed because the input matrix is singular.
tensor([[3.5656, 0.0000],
        [0.0000, 0.0000]])
An error occurred for i=96: linalg.inv: The diagonal element 2 is zero, the inversion could not be completed because the input matrix is singular.
tensor([[3.5656, 0.0000],
        [0.0000, 0.0000]])
An error occurred for i=97: linalg.inv: The diagonal element 2 is zero, the inversion could not be completed because the input matrix is singular.
tensor([[3.5656, 0.0000],
        [0.0000, 0.0000]])
An error occurred for i=98: linalg.inv: The diagonal element 2 is zero, the inversion could not be completed because the input matrix is singular.
tensor([[3.5656, 0.0000],
        [0.0000, 0.0000]])
An error occurred for i=99: linalg.inv: The diagonal element 2 is zero, the inversion could not be completed because the input matrix is singular.
tensor([[3.5656, 0.0000],
        [0.0000, 0.0000]])
Computation time: 1.080 seconds.
 In [ ]: