Skip to content

Instantly share code, notes, and snippets.

@atremblay
atremblay / ode_phase_plane.py
Created December 4, 2022 00:08
ode phase plane
from pylab import grid, show, savefig, subplots, tight_layout, style
import numpy as np
style.use('ggplot')
def phase_plane(A, x_min=-3, x_max=3, y_min=-3, y_max=3):
fig, ax = subplots(1,1, figsize=(5,5), dpi=500)
state_vec = np.array(
np.meshgrid(
np.linspace(x_min, x_max, 1000),
np.linspace(y_min, y_max, 1000)
#######################################################################
# copied from https://github.com/gillescastel/latex-snippets #
#######################################################################
global !p
texMathZones = ['texMathZone'+x for x in ['A', 'AS', 'B', 'BS', 'C', 'CS', 'D', 'DS', 'E', 'ES', 'F', 'FS', 'G', 'GS', 'H', 'HS', 'I', 'IS', 'J', 'JS', 'K', 'KS', 'L', 'LS', 'DS', 'V', 'W', 'X', 'Y', 'Z']]
texIgnoreMathZones = ['texMathText']
texMathZoneIds = vim.eval('map('+str(texMathZones)+", 'hlID(v:val)')")
@atremblay
atremblay / batchprofilecallback.py
Last active December 21, 2017 22:53
Keras Batch Profile Callback. Measure time to run one batch. Use mostly for monitoring.
import logging
import datetime
import tensorflow as tf
class BatchProfileCallback(tf.keras.callbacks.Callback):
"""
BatchProfileCallback
Log how long a batch takes to run. Monitor potential slow downs.
@atremblay
atremblay / mac_setup_script.sh
Last active February 23, 2024 13:44
Mac setup script
platform=$(uname -s)
arch=$(uname -m)
PYTHON_VERSION=3.10
if [[ "$platform" == 'Linux' ]]; then
sudo apt install stow tldr
curl -sS https://starship.rs/install.sh | sh
git clone --depth 1 https://github.com/wbthomason/packer.nvim\ ~/.local/share/nvim/site/pack/packer/start/packer.nvim
@atremblay
atremblay / smscallback.py
Last active March 9, 2018 01:00
Keras SMS Callback
import os
import tensorflow as tf
from twilio.rest import Client
class SMSCallback(tf.keras.callbacks.Callback):
"""
SMSCallback
Because you are not always standing in front of your computer waiting for
@atremblay
atremblay / sql_conditional_entropy.py
Last active February 4, 2016 18:04
Joint Entropy calculated with SQL for discrete values
# This is part of the implementation of this paper
# https://www.aaai.org/Papers/FLAIRS/1999/FLAIRS99-042.pdf
# This was written for MLDB (www.mldb.ai). Not tested for other databases
# Conditional entropy $H(Y|X) = -\sum_x{P(x)\sum_y{P(y|x)\log(P(y|x))}}$
from pandas import DataFrame
def conditional_entropy(Y, X, table):
df = mldb.query("""
SELECT -sum(PX.p_x*A.right)
FROM (
@atremblay
atremblay / fast_reservoir_sampling.py
Created January 13, 2016 13:40
Reservoir sampling python
import random
import numpy as np
# http://erikerlandson.github.io/blog/2015/11/20/very-fast-reservoir-sampling/
def fast_reservoir_sampling(file_handle, N=1000000, callable=None):
sample = []
if callable is None:
callable = lambda x: x
j = N