icub-client
|
Utility class for functions required by both interactionSAMModel.py and trainSAMModel.py. More...
Classes | |
class | SAM.SAM_Core.SAM_utils.TimeoutError |
Custom TimeoutError Exception. More... | |
class | SAM.SAM_Core.SAM_utils.InterruptableThread |
Class to launch a function inside of a separate thread. More... | |
class | SAM.SAM_Core.SAM_utils.timeout |
Class to terminate a function running inside of a separate thread. More... | |
Functions | |
def | SAM.SAM_Core.SAM_utils.initialiseModels (argv, update, initMode='training') |
Initialise SAM Model data structure, training parameters and user parameters. More... | |
def | SAM.SAM_Core.SAM_utils.varianceClass (varianceDirection, x, thresh) |
Utility function to perform threshold or range checking. More... | |
def | SAM.SAM_Core.SAM_utils.plotKnownAndUnknown (varDict, colour, axlist, width=[0.2, factor=[(0, 0.6), plotRange=False) |
Utility function to plot variances of known and unknown as gaussian distributions. More... | |
def | SAM.SAM_Core.SAM_utils.bhattacharyya_distance (mu1, mu2, var1, var2) |
Calculates a measure for the separability of two univariate gaussians. More... | |
def | SAM.SAM_Core.SAM_utils.plot_confusion_matrix (cm, targetNames, title='Confusion matrix', cmap=plt.cm.inferno) |
Generate and display a confusion matrix. More... | |
def | SAM.SAM_Core.SAM_utils.plotGaussFromList (mlist, vlist, rlist, colour, label, width, factor, axlist, plotRange=False) |
Plot multiple Gaussians from a list on the same plot. More... | |
def | SAM.SAM_Core.SAM_utils.solve_intersections (m1, m2, std1, std2) |
Solve for the intersection/s of two Gaussian distributions. More... | |
def | SAM.SAM_Core.SAM_utils.PfromHist (sample, hist, binWidth) |
Calulates the probability of a sample from a histogram. More... | |
def | SAM.SAM_Core.SAM_utils.meanVar_varianceDistribution (dataList) |
Calculate list of means, variances and ranges for the data in the dataList. More... | |
def | SAM.SAM_Core.SAM_utils.bhattacharyya_dict (m, v) |
Calculate bhattacharyya distances for each item in the dictionaries. More... | |
def | SAM.SAM_Core.SAM_utils.smooth1D (x, window_len=11, window='hanning') |
Smooth the data using a window with a requested size. More... | |
def | SAM.SAM_Core.SAM_utils.transformTimeSeriesToSeq (Y, timeWindow, offset=1, normalised=False, reduced=False, noY=False, doOffset=False) |
Utility function to convert a time series into multiple time windows with additional functionality. More... | |
Utility class for functions required by both interactionSAMModel.py and trainSAMModel.py.
class SAM::SAM_Core::SAM_utils::TimeoutError |
Custom TimeoutError Exception.
Definition at line 414 of file SAM_utils.py.
class SAM::SAM_Core::SAM_utils::InterruptableThread |
Class to launch a function inside of a separate thread.
Definition at line 420 of file SAM_utils.py.
Public Member Functions | |
def | __init__ (self, func, args, kwargs) |
Initialise the interruptible thread. More... | |
def | run (self) |
Run the function. More... | |
def | result (self) |
def SAM.SAM_Core.SAM_utils.InterruptableThread.__init__ | ( | self, | |
func, | |||
args, | |||
kwargs | |||
) |
Initialise the interruptible thread.
Definition at line 424 of file SAM_utils.py.
def SAM.SAM_Core.SAM_utils.InterruptableThread.result | ( | self | ) |
Definition at line 442 of file SAM_utils.py.
def SAM.SAM_Core.SAM_utils.InterruptableThread.run | ( | self | ) |
Run the function.
Definition at line 434 of file SAM_utils.py.
class SAM::SAM_Core::SAM_utils::timeout |
Class to terminate a function running inside of a separate thread.
Definition at line 449 of file SAM_utils.py.
Public Member Functions | |
def | __init__ (self, sec) |
Initialise the timeout function. More... | |
def | __call__ (self, f) |
Initialise an interruptible thread and start the thread. More... | |
def SAM.SAM_Core.SAM_utils.timeout.__init__ | ( | self, | |
sec | |||
) |
Initialise the timeout function.
Definition at line 453 of file SAM_utils.py.
def SAM.SAM_Core.SAM_utils.timeout.__call__ | ( | self, | |
f | |||
) |
Initialise an interruptible thread and start the thread.
Definition at line 459 of file SAM_utils.py.
def SAM.SAM_Core.SAM_utils.bhattacharyya_dict | ( | m, | |
v | |||
) |
Calculate bhattacharyya distances for each item in the dictionaries.
m | Dictionary of means. |
v | Dictionary of variances. |
Definition at line 677 of file SAM_utils.py.
def SAM.SAM_Core.SAM_utils.bhattacharyya_distance | ( | mu1, | |
mu2, | |||
var1, | |||
var2 | |||
) |
Calculates a measure for the separability of two univariate gaussians.
Returns the bhattacharyya distance that is used to optimise for separability between known and unknown classes when these are modelled as univariate gaussians.
mu1 | Float with mean of distribution 1. |
mu2 | Float with mean of distribution 2. |
var1 | Float with variance of distribution 1. |
var2 | Float with variance of distribution 2. |
Definition at line 509 of file SAM_utils.py.
def SAM.SAM_Core.SAM_utils.initialiseModels | ( | argv, | |
update, | |||
initMode = 'training' |
|||
) |
Initialise SAM Model data structure, training parameters and user parameters.
This method starts by initialising the required Driver from the driver name in argv[3] if it exists in SAM_Drivers folder. The standard model parameters and the specific user parameters are then initialised and the data is read in by the SAMDriver.readData method to complete the model data structure. This method then replicates the model data structure for training with multiple models if it is required in the config file loaded by the Driver.
argv_0 | dataPath containing the data that is to be trained on. |
argv_1 | modelPath containing the path of where the model is to be stored. |
argv_2 | driverName containing the name of the driver class that is to be loaded from SAM_Drivers folder. |
update | String having either a value of 'update' or 'new'. 'new' will load the parameters as set in the config file of the driver being loaded present in the dataPath directory. This is used to train a new model from scratch. 'update' will check for an existing model in the modelPath directory and load the parameters from this model if it exists. This is used for retraining a model when new data becomes available. |
initMode | String having either a value of 'training' or 'interaction'. 'training' takes into consideration the value of update in loading the parameters. (Used by trainSAMModel.py) 'interaction' loads the parameters directly from the model if the model exists. (Used by interactionSAMModel.py) |
Definition at line 59 of file SAM_utils.py.
def SAM.SAM_Core.SAM_utils.meanVar_varianceDistribution | ( | dataList | ) |
Calculate list of means, variances and ranges for the data in the dataList.
dataList | List of numpy arrays containing the data to check. |
Definition at line 639 of file SAM_utils.py.
def SAM.SAM_Core.SAM_utils.PfromHist | ( | sample, | |
hist, | |||
binWidth | |||
) |
Calulates the probability of a sample from a histogram.
sample | Float with sample to be tested. |
hist | Numpy array with normalised histogram probability values. |
binWidth | Float indicating the width for each probability bin. |
Definition at line 621 of file SAM_utils.py.
def SAM.SAM_Core.SAM_utils.plot_confusion_matrix | ( | cm, | |
targetNames, | |||
title = 'Confusion matrix' , |
|||
cmap = plt.cm.inferno |
|||
) |
Generate and display a confusion matrix.
This method plots a formatted confusion matrix from the provided array and target names.
cm | Square numpy array containing the values for the confusion matrix. |
targetNames | labels for the different classes. |
title | Title of the plot. |
cmap | Matplotlib colourmap for the plot. |
Definition at line 531 of file SAM_utils.py.
def SAM.SAM_Core.SAM_utils.plotGaussFromList | ( | mlist, | |
vlist, | |||
rlist, | |||
colour, | |||
label, | |||
width, | |||
factor, | |||
axlist, | |||
plotRange = False |
|||
) |
Plot multiple Gaussians from a list on the same plot.
mlist | List of float means. |
vlist | List of float variances. |
rlist | List of float data ranges. |
colour | Colour for the plots. |
label | Label for the plot. |
width | Width of line in the plot. |
factor | Factor for the height of the ranges to make them more aesthetic. |
axlist | List of axes. |
plotRange | Boolean to plot ranges or not. |
Definition at line 562 of file SAM_utils.py.
def SAM.SAM_Core.SAM_utils.plotKnownAndUnknown | ( | varDict, | |
colour, | |||
axlist, | |||
width = [0.2 , |
|||
factor = [(0, 0.6) , |
|||
plotRange = False |
|||
) |
Utility function to plot variances of known and unknown as gaussian distributions.
varDict | Dictionary containing the mean and variances of known and unknown for different sections of data. |
colour | List of strings with the colours to be used for each plot. |
axlist | Plot object to pass in and update. |
width | List of floats with the linewidth for the plots. |
factor | List of tuples with factors for the plotting of ranges. |
plotRange | Boolean to plot a range together with gaussian distributions or not. |
Definition at line 484 of file SAM_utils.py.
def SAM.SAM_Core.SAM_utils.smooth1D | ( | x, | |
window_len = 11 , |
|||
window = 'hanning' |
|||
) |
Smooth the data using a window with a requested size.
This method is based on the convolution of a scaled window with the signal. The signal is prepared by introducing reflected copies of the signal (with the window size) in both ends so that transient parts are minimized in the beginning and end part of the output signal.
input: x The input signal. window_len The dimension of the smoothing window; should be an odd integer. window The type of window from 'flat', 'hanning', 'hamming', 'bartlett', 'blackman' flat window will produce a moving average smoothing.
output: The smoothed signal.
Definition at line 710 of file SAM_utils.py.
def SAM.SAM_Core.SAM_utils.solve_intersections | ( | m1, | |
m2, | |||
std1, | |||
std2 | |||
) |
Solve for the intersection/s of two Gaussian distributions.
m1 | Float Mean of Gaussian 1. |
m2 | Float Mean of Gaussian 2. |
std1 | Float Standard Deviation of Gaussian 1. |
std2 | Float Standard Deviation of Gaussian 2. |
Definition at line 603 of file SAM_utils.py.
def SAM.SAM_Core.SAM_utils.transformTimeSeriesToSeq | ( | Y, | |
timeWindow, | |||
offset = 1 , |
|||
normalised = False , |
|||
reduced = False , |
|||
noY = False , |
|||
doOffset = False |
|||
) |
Utility function to convert a time series into multiple time windows with additional functionality.
Y | Time series data. |
timeWindow | Length of the time window. |
offset | Number of non-overlapping frames between successive time windows. |
normalised | Boolean to normalise time windows with respect to the starting frame. |
reduced | Boolean to remove the starting frame if normalisation is enabled since this frame contains 0. |
noY | Boolean to return time windows of labels together. |
doOffset | In future versions this parameter will enable skipping data points between sampled windows. |
Definition at line 755 of file SAM_utils.py.
def SAM.SAM_Core.SAM_utils.varianceClass | ( | varianceDirection, | |
x, | |||
thresh | |||
) |
Utility function to perform threshold or range checking.
varianceDirection | List of strings with the conditions to check. |
x | The value to be checked. |
thresh | The threshold against which x is to be checked given the checks in varianceDirection. |
Definition at line 398 of file SAM_utils.py.