Skip to content

Instantly share code, notes, and snippets.

View lewtun's full-sized avatar
🤫
LLM whispering

lewtun

🤫
LLM whispering
View GitHub Profile
@lewtun
lewtun / mapper_pipeline_example.ipynb
Created November 25, 2019 07:27
Mapper Pipeline Example
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@lewtun
lewtun / persistence_point_cloud.py
Last active January 23, 2020 14:34
Snippet to calculate persistence diagram from point cloud data
import gtda.homology as hl
# represent data as a point cloud
point_cloud = ...
# define topological features to track
homology_dimensions = [0, 1, 2]
# define simplicial complex to construct
persistence = hl.VietorisRipsPersistence(
import gtda.homology as hl
# represent data as a matrix of pairwise distances
distance_matrix = ...
# define topological features to track
homology_dimensions = [0, 1, 2]
# define simplicial complex to construct
persistence = hl.VietorisRipsPersistence(
import gtda.diagrams as diagrams
# calculate persistence diagram
persistence_diagram = ...
# define type of amplitude to calculate
amplitude = diagrams.Amplitude(metric="wasserstein")
# calculate amplitude of diagram
persistence_diagram_amplitude = amplitude.fit_transform(persistence_diagram)
import pandas as pd
# define topological features to track
homology_dimensions = [0, 1, 2]
# calculate persistence diagram
persistence_diagram = ...
# convert NumPy array of triples to DataFrame
persistence_table = pd.DataFrame(
def cv_model(X, y, features, n_fold=5, random_state=45245, params=None):
"""Evaluate a score by cross validation.
Parameters
----------
X : pandas.DataFrame
The data to fit.
y : pandas.DataFrame or pandas.Series
class TemplateTransformer(BaseEstimator, TransformerMixin):
""" An example transformer that returns the element-wise square root."""
def __init__(self, demo_param='demo'):
self.demo_param = demo_param
def fit(self, X, y=None):
"""A reference implementation of a fitting function for a transformer."""
X = check_array(X, accept_sparse=True)
self.n_features_ = X.shape[1]
sample
@lewtun
lewtun / Makefile
Last active August 13, 2020 20:17
Makefile for nbdev with linting and code formatting
# Copyight 2016 drivendata
# Copyright 2019 fast.ai
# Copyright 2020 Lewis Tunstall
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0