Skip to content

Instantly share code, notes, and snippets.

View rmsander's full-sized avatar

Ryan Sander rmsander

View GitHub Profile
@rmsander
rmsander / composite_prod_norm_sklearn.py
Created September 6, 2021 19:02
Function for implementing custom distance metrics for use in sklearn neighbor search algorithms.
"""Function for implementing custom distance metrics for use in sklearn neighbor
search algorithms.
Here, we will use a composite product norm composed of a product of norms over
given (contiguous) subsets of states. The norms over these subsets are taken
to be L2 norms.
If x = [s a]^T, where s and a are the contiguous subsets of x that this
product norm is decomposed into, then this product norm can be written as:
@rmsander
rmsander / covariance_stability_metrics.py
Created September 6, 2021 19:11
Function to compute stability metrics for covariance matrices, namely log determinants and condition numbers.
"""Function to compute stability metrics for covariance matrices,
namely log determinants and condition numbers."""
# Use torch
import torch
def compute_covariance_metrics(Kxx, x_train, writer):
"""Helper function to compute covariance metrics.
Parameters:
Kxx (torch.Tensor): Tensor object corresponding to a covariance matrix.