Skip to content
Tom SF Haines edited this page Mar 30, 2016 · 1 revision

Miscellaneous Algorithms

Overview

Misc

A selection of miscellaneous algorithms:

philox.h/.c - The random number generator from the paper "Parallel Random Numbers: As Easy as 1, 2, 3" by J. K. Salmon et al. This algorithm was designed for GPU use, but after using it for my background subtraction paper I started using it on the CPU as well. Its a great approach as it can go from any number to a random value, so you can easily do the normal thing, of requesting numbers in sequence, but also assign random numbers to, e.g. locations in a grid, and evaluate them efficiently without needing a cache. Has a reasonable selection of samplers for various PDFs. I use this to make my code deterministic, and it also means that if I ever write a GPU version of the code I should be able to obtain bit-identical behaviour. Has no Python interface - its for use by other C/C++ modules that may have a Python interface.

tps.py - A straight forward pure-Python thin plate spline implementation.


Classes

TPS()

A n-dimensional thin plate spline implimentation. Nothing fancy - just a basic implimentation, so don't go throwing large data sets at it. Implimentation based on a snipet of a pdf found on the internet written by David Eberly. Includes smoothing, just by the addition of an identity matrix to the Green kernal matrix.

get_a(self) Returns a, the vector of kernel weights for each point in the spline.

get_b(self) Returns the vector b, the parameters of the base plane. The last entry is the constant.

get_n(self) Returns the number of dimensions of the thin plate spline.

get_x(self) Returns the set of points that locate the basis functions.

learn(self, x, y, a, b) Allows you to learn a model, partially if you so choose. x is the data matrix of points to fit the spline through - a numpy array of shape [d,n], where d is the number of points (d>=n) and n the number of dimensions. y is the answer for each point, a vector aligned with x. If a and b are provided it can be set to None instead. b is the parameters of the plane, a (n+1) vector with the first n entries aligned with the dimensions and the final one the constant to offset it. a is the kernel weights, a size d matrix that indicates the weight associated with each kernel evalatuon of a point with the green function kernel.

Clone this wiki locally