Skip to content

Instantly share code, notes, and snippets.

View Kautenja's full-sized avatar
:octocat:
$(git status)

Christian Kauten Kautenja

:octocat:
$(git status)
View GitHub Profile
@Kautenja
Kautenja / Distance Functions.ipynb
Created September 25, 2017 23:41
Implementations of different distance functions in Python
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@Kautenja
Kautenja / count_words.py
Last active January 5, 2018 19:51
A Python3 script to count the words in a Markdown document with inline LaTeX.
"""This Python script counts words in a Markdown / LaTeX document(s).
Usage:
python3 count_words.py <filename or directory>
It will ignore ATX headers, LaTeX & Markdown comments, and LaTeX markup tags.
TODO: inline HTML, Markdown images & tables
"""
@Kautenja
Kautenja / array.py
Created February 19, 2018 20:23
A simple conversion of a Python list to an array indexed from 1 for algorithm analysis
class Array(object):
"""A list that indexes like an array [1...n] (for algorithm analysis)."""
def __init__(self, items: list) -> None:
"""Create a new array from a list."""
self.items = items
def __repr__(self) -> str:
"""Return an executable string represention of `self`."""
return '{}({})'.format(self.__class__.__name__, self.items)
@Kautenja
Kautenja / tpfp.py
Last active November 16, 2022 09:23
A Python method for calculating accuracy, true positives/negatives, and false positives/negatives from prediction and ground truth arrays.
"""A method to calculate the number of True/False Positive/Negative guesses."""
import numpy as np
def tpfp(predictions: np.ndarray,
ground_truth: np.ndarray,
negative: int=0.0,
positive: int=1.0,
normalize: bool=True) -> dict:
"""
@Kautenja
Kautenja / confusion_dataframe.py
Created March 9, 2018 02:36
a pandas wrapper for the sklearn confusion_matrix method
"""A simple method wrapping around `confusion_matrix`."""
def confusion_dataframe(*args, **kwargs):
"""
Generate an sklearn confusion matrix as a DataFrame.
Args:
*args: positional args for `confusion_matrix`
**kwargs: keyword args for `confusion_matrix`
@Kautenja
Kautenja / heatmap.py
Last active December 2, 2020 21:55
A quick method to generate a matplotlib heatmap from a pandas.DataFrame
import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
def heatmap(data,
size_scale:int = 100,
figsize: tuple = (15, 12),
x_rotation: int = 270,
@Kautenja
Kautenja / realtime_plot.py
Last active June 9, 2018 01:17
A class for plotting a single discrete line in realtime using Matplotlib
"""An object to show a realtime plot of the value of a discrete line."""
from matplotlib import pyplot as plt
from matplotlib.ticker import MaxNLocator
class RealtimePlot(object):
"""A simple realtime plot to show the value of a discrete line."""
def __init__(self, figsize: tuple=(4, 4)) -> None:
"""
@Kautenja
Kautenja / iou.py
Last active June 1, 2021 12:10
An implementation of the Intersection over Union (IoU) metric for Keras.
"""An implementation of the Intersection over Union (IoU) metric for Keras."""
from keras import backend as K
def iou(y_true, y_pred, label: int):
"""
Return the Intersection over Union (IoU) for a given label.
Args:
y_true: the expected y values as a one-hot
@Kautenja
Kautenja / get_tf_gpu_models.py
Last active October 27, 2018 21:28
Methods to get the model name of GPUs used by TensorFlow.
"""Methods to get the model name of GPUs used by TensorFlow."""
from tensorflow.python.client import device_lib
def get_device_model(device) -> str:
"""
Return the model of a TensorFlow device.
Args:
device: the device to get the model name of
@Kautenja
Kautenja / tar-progress.md
Last active November 12, 2024 22:00
one-liners for using tar with gzip and pv for a progress bar

Compress

tar cf - <files> -P | pv -s $(du -sb <files> | awk '{print $1}') | gzip > <some .tar.gz file>

where:

  • `` is the root-mounted (i.e. starts with /) path to the files