Skip to content

Instantly share code, notes, and snippets.

View radarsat1's full-sized avatar

Stephen Sinclair radarsat1

View GitHub Profile
@radarsat1
radarsat1 / veegan_normal_mixture_keras.py
Last active March 11, 2020 16:28
Translation of VEEGAN normal mixture example to TensorFlow 2 + Keras
# Steve's adaptation of VEEGAN example:
# https://github.com/akashgit/VEEGAN/blob/master/VEEGAN_2D_RING.ipynb
# to TensorFlow 2 + Keras, with the TensorFlow Probabilities library:
# https://blog.tensorflow.org/2019/03/variational-autoencoders-with.html
#
# Stephen Sinclair <radarsat1@gmail.com>
# Google Colab version here:
# https://colab.research.google.com/drive/1dSW7Yn8okef-ng-Inkev205L2Gy6_MIx
@radarsat1
radarsat1 / collision_points_object_order.cpp
Created February 16, 2018 14:03
collision_points_object_order.cpp
/* Test for collision points locations generated by purterbation rotations in Bullet Physics */
#define BT_USE_DOUBLE_PRECISION
#include <BulletCollision/CollisionDispatch/btCollisionObject.h>
#include <BulletCollision/CollisionDispatch/btCollisionWorld.h>
#include <BulletCollision/CollisionDispatch/btCollisionDispatcher.h>
#include <BulletCollision/CollisionDispatch/btDefaultCollisionConfiguration.h>
#include <BulletCollision/CollisionShapes/btBoxShape.h>
#include <BulletCollision/CollisionShapes/btConvexHullShape.h>
@radarsat1
radarsat1 / brownian_surface.py
Last active January 23, 2024 23:47
brownian surface translation to Python
# A Python translation of the Brownian Surface function from
# http://www.mathworks.com/matlabcentral/fileexchange/38945-fractional-brownian-field-or-surface-generator
#
# More info, check https://en.wikipedia.org/wiki/Brownian_surface
#
# Example output: http://i.imgur.com/MKHxA6N.png
import numpy as np
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@radarsat1
radarsat1 / tile4_ffmpeg.sh
Created August 26, 2016 19:01
ffmpeg video tiling
#!/bin/bash
# tile four videos using ffmpeg
VID1="$1"
VID2="$2"
VID3="$3"
VID4="$4"
OUT="$5"
# ffmpeg's complex filter graph is powerful!
@radarsat1
radarsat1 / parbrute.py
Created January 2, 2012 18:33
Parallelized scipy.optimize.brute
#!/usr/bin/env python
"""Provide a parallelized version of scipy.optimize.brute for 1-, 2-, or 3-dimensional arguments.
Needed to parallelize the steps of a grid-based global optimization, so I copied the "brute" code, replaced "vectorize" with nested maps for specific numbers of arguments, and replaced the outer-most map() with a ThreadPool.map(). Likely this could be generalized to any number of arguments (e.g. by zipping the grid and iterating in parallel over the tuples) but I didn't feel like figuring that out just now.
This should perform help for routines that spend a lot of time in numpy code, but I imagine that a pure Python routine might get caught-up by the GIL. Possibly using a process pool instead of a thread pool would fix it. Currently I'm using it for a routine that spends all its time in fftconvolve() so it wasn't a problem for me.
parbrute() takes the same arguments as scipy.optimize.brute(), with the addition of thread=N for the number of threads you want in the pool. Defaults to 4