Teetool
Probabilistic modelling of trajectories
Functions
teetool.helpers Namespace Reference

Functions

def getDistinctColours (ncolours, colour=None)
 a function to obtain n distinct colours (based on the colourspace spread into hue space), inspired by https://stackoverflow.com/questions/470690/how-to-automatically-generate-n-distinct-colors More...
 
def find_nearest (original_values, target_values)
 function to find nearest values in an array, perfect for reducing the number of datapoints More...
 
def nearest_spd (A)
 nearestSPD - the nearest (in Frobenius norm) Symmetric Positive Definite matrix to A More...
 
def get_trajectories (ntype=0, ndim=3, ntraj=50, npoints=100, noise_std=.5)
 function to generate some distributed trajectories More...
 
def in_hull (p, hull)
 Test if points in p are in hull More...
 
def unique_rows (a)
 function to find unique rows More...
 
def gauss_logp (y, ndim, c, A)
 function to evaluate the Gaussian log likelihood More...
 
def gauss (y, ndim, c, A)
 function to evaluate the Gaussian (normal distribution) More...
 
def gauss_logLc (y, ndim, cc, cA)
 function to evaluate the Gaussian log likelihood in cell-form More...
 
def getMaxOutline (ndim)
 simple function to obtain infinite outline based on dimensionality More...
 
def getGridFromResolution (outline, resolution)
 function to generate a grid based on outline and resolution More...
 
def getDimension (cluster_data)
 finds dimension D based on cluster_data More...
 
def getMinMax (cluster_data)
 find minimum/maximum of the cluster data (x, Y), x-component. More...
 
def normalise_data (cluster_data)
 normalise the cluster_data in x-domain More...
 
def getNorm (x, tuple_min_max)
 returns a normalised array based on a specified minimum/maximum More...
 
def get_cluster_data_outline (cluster_data)
 returns the outline based on cluster_data More...
 
def get_cluster_data_norm (cluster_data, outline=None)
 returns a normalised cluster_data based on outline More...
 

Function Documentation

§ find_nearest()

def teetool.helpers.find_nearest (   original_values,
  target_values 
)

function to find nearest values in an array, perfect for reducing the number of datapoints

Parameters
original_valuesan array of original values
target_valuesan array of desired values
Returns
idx returns a list of indices of points that hold the nearest values

§ gauss()

def teetool.helpers.gauss (   y,
  ndim,
  c,
  A 
)

function to evaluate the Gaussian (normal distribution)

Parameters
ydata-point
ndimdimensionality of y
cmean vector
Aconvariance matrix
Returns
value value of Gaussian at point y

§ gauss_logLc()

def teetool.helpers.gauss_logLc (   y,
  ndim,
  cc,
  cA 
)

function to evaluate the Gaussian log likelihood in cell-form

Parameters
ydata-point
ndimdimensionality of y
ccmean vector cells
cAconvariance matrix cells
Returns
loglikelihood maximum log likelihood of Gaussian, based on models found in cells
returns the log likelihood of a position based on model (in cells)

§ gauss_logp()

def teetool.helpers.gauss_logp (   y,
  ndim,
  c,
  A 
)

function to evaluate the Gaussian log likelihood

Parameters
ydata-point
ndimdimensionality of y
cmean vector
Aconvariance matrix
Returns
loglikelihood log likelihood of Gaussian

§ get_cluster_data_norm()

def teetool.helpers.get_cluster_data_norm (   cluster_data,
  outline = None 
)

returns a normalised cluster_data based on outline

Parameters
cluster_datalist of (x, Y) trajectory data
outlinearray specifying an pre-set outline, otherwise the outline is calculated from the cluster_data
Returns
cluster_data_norm list of (x, Y), where all Y and x fit in [0, 1] domain

specifying an outline is useful when wanting to normalise based on multiple clusters

§ get_cluster_data_outline()

def teetool.helpers.get_cluster_data_outline (   cluster_data)

returns the outline based on cluster_data

Parameters
cluster_datalist of (x, Y) trajectory data
Returns
outline [min, max]*ndim for outline

§ get_trajectories()

def teetool.helpers.get_trajectories (   ntype = 0,
  ndim = 3,
  ntraj = 50,
  npoints = 100,
  noise_std = .5 
)

function to generate some distributed trajectories

Parameters
ntypetype of trajectory (0 or 1)
ndimdimensionality of trajectories (2 or 3)
ntrajnumber of trajectories desired
npointshow many points each trajectory has
noise_stdincludes normal distributed (Gaussian) noise to the trajectory data-points return cluster_data a list of (x, Y) trajectory data

§ getDimension()

def teetool.helpers.getDimension (   cluster_data)

finds dimension D based on cluster_data

Parameters
cluster_datalist of (x, Y) format
Returns
D dimensionality of trajectory data

§ getDistinctColours()

def teetool.helpers.getDistinctColours (   ncolours,
  colour = None 
)

a function to obtain n distinct colours (based on the colourspace spread into hue space), inspired by https://stackoverflow.com/questions/470690/how-to-automatically-generate-n-distinct-colors

Parameters
ncoloursinteger with number of distinct colours
colourwhen colour is specified, this overrides any distinct colour
Returns
rgb_tuples a list of tuples with (R, G, B) in the [0,1] domain

§ getGridFromResolution()

def teetool.helpers.getGridFromResolution (   outline,
  resolution 
)

function to generate a grid based on outline and resolution

Parameters
outline[ndim x 2], minimum and maximum values
resolutioncan be a scalar [1x1] or specified per dimension [ndim x 1]
Returns
xx x grid
yy y grid
zz (optional) z grid

§ getMaxOutline()

def teetool.helpers.getMaxOutline (   ndim)

simple function to obtain infinite outline based on dimensionality

Parameters
ndimnumber of dimensions
Returns
outline [ndim x 2], for minimum and maximum

§ getMinMax()

def teetool.helpers.getMinMax (   cluster_data)

find minimum/maximum of the cluster data (x, Y), x-component.

The tuple is used to normalise the data

Parameters
cluster_datalist of (x, Y)
Returns
xmin minimum value of x
xmax maximum value of x

§ getNorm()

def teetool.helpers.getNorm (   x,
  tuple_min_max 
)

returns a normalised array based on a specified minimum/maximum

Parameters
xinput array
tuple_min_maxa tuple with minimum and maximum specified
Returns
x_norm a normalised array x

§ in_hull()

def teetool.helpers.in_hull (   p,
  hull 
)

Test if points in p are in hull

Parameters
pan array of points
hullpoints for hull, if not hull, make a hull from points
Returns
p_bool an array with bools whether or not the points are inside the hull

p should be a NxK coordinates of N points in K dimensions hull is either a scipy.spatial.Delaunay object or the MxK array of the coordinates of M points in Kdimensions for which Delaunay triangulation will be computed

https://stackoverflow.com/questions/16750618/whats-an-efficient-way-to-find-if-a-point-lies-in-the-convex-hull-of-a-point-cl

§ nearest_spd()

def teetool.helpers.nearest_spd (   A)

nearestSPD - the nearest (in Frobenius norm) Symmetric Positive Definite matrix to A

Parameters
Ainput matrix
Returns
Ahat nearest SPD matrix to A

nearestSPD - the nearest (in Frobenius norm) Symmetric Positive Definite matrix to A usage: Ahat = nearestSPD(A)

From Higham: "The nearest symmetric positive semidefinite matrix in the Frobenius norm to an arbitrary real matrix A is shown to be (B + H)/2, where H is the symmetric polar factor of B=(A + A')/2."

http://www.sciencedirect.com/science/article/pii/0024379588902236

arguments: (input) A - square matrix, which will be converted to the nearest Symmetric Positive Definite Matrix.

Arguments: (output) Ahat - The matrix chosen as the nearest SPD matrix to A.

RE-CODED FROM MATLAB nearestSPD http://uk.mathworks.com/matlabcentral/fileexchange/42885-nearestspd

§ normalise_data()

def teetool.helpers.normalise_data (   cluster_data)

normalise the cluster_data in x-domain

Parameters
cluster_datalist of (x, Y) data
Returns
cluster_data_norm list of (x, Y) data with normalised x

§ unique_rows()

def teetool.helpers.unique_rows (   a)

function to find unique rows

Parameters
amatrix
Returns
unique_A the matrix a with only unique rows

https://stackoverflow.com/questions/16970982/find-unique-rows-in-numpy-array