icub-client
Modules | Classes | Functions

This Module implements the core functionality to create Gaussian Process Latent Feature Models. More...

+ Collaboration diagram for SAM Core:

Modules

 SAM Drivers
 Drivers folder containing driver classes that inherit from SAMDriver to implement custom functionality.
 

Classes

class  SAM.SAM_Core.interactionSAMModel.interactionSAMModel
 Generic interaction function. More...
 
class  SAM.SAM_Core.SAMCore.LFM
 SAM based on Latent Feature Models. More...
 
class  SAM.SAM_Core.samOptimiser.modelOptClass
 Class to perform optimisation of SAM Models. More...
 
class  SAM.SAM_Core.samSupervisor.SamSupervisorModule
 Model management and supervisor. More...
 
class  SAM.SAM_Core.svi_ratio.SVI_Ratio
 Inference the marginal likelihood through {p(y,y*)}{p(y)}. More...
 

Functions

def SAM.SAM_Core.SAMCore.save_model (mm, fileName='m_serialized.txt')
 Save serialised model. More...
 
def SAM.SAM_Core.SAMCore.load_model (fileName='m_serialized.txt')
 Load serialised model. More...
 
def SAM.SAM_Core.SAMCore.save_pruned_model (mm, fileName='m_pruned', economy=False, extraDict=dict())
 Save a pruned model. More...
 
def SAM.SAM_Core.SAMCore.load_pruned_model (fileName='m_pruned', economy=False, m=None)
 Load a pruned model. More...
 
def SAM.SAM_Core.SAMCore.most_significant_input_dimensions (model)
 Determine the most descriptive output dimensions. More...
 
def SAM.SAM_Core.trainSAMModel.exception_hook (exc_type, exc_value, exc_traceback)
 Generic training function. More...
 

Detailed Description

This Module implements the core functionality to create Gaussian Process Latent Feature Models.


Class Documentation

◆ SAM::SAM_Core::interactionSAMModel::interactionSAMModel

class SAM::SAM_Core::interactionSAMModel::interactionSAMModel

Generic interaction function.

Description
Generic interaction function that carries out live collection of data, classification of said data, interaction with other modules requesting the classification and generation of training outputs for recall. The parameters for the interaction function are loaded from the config file specified in the config_path parameter of the default context file for samSupervisor.py. An example of the configuration structure is shown below.

Examples

[Model Name]
dataIn = <portName/ofInputData>:i <dataType of Port>
dataOut = <portName/ofOutputData>:o <dataType of Port>
rpcBase = <portName/ofRpcPort>
call_sign = ask_<X>_label,ask_<X>_instance
collectionMethod = collectionMethod lengthOfBuffer
[Faces]
dataIn = /sam/faces/imageData:i ImageRgb
dataOut = /sam/faces/imageData:o ImageMono
rpcBase = /sam/faces/rpc
callSign = ask_face_label,ask_face_instance
collectionMethod = future_buffered 3
Parameters
dataInThe port name for the port that will received the data to be classified and the dataType to be expected.
dataOutThe port name for the port that will output generated data and the dataType to be transmitted.
rpcBaseThe rpc port that will receive external requests. This is usually controlled by samSupervisor.py.
call_signThe commands that will trigger a classify from data event or a generate from label event.
collectionMethodThe collection method to be used. Either buffered, future_buffered or continuous. Followed by an integer indicating the length of the buffer to be used. In the case of continuous the buffer length is the maximum number of classification labels to be stored in a First In Last Out (FILO) configuration. Otherwise the buffer length indicates the number of data frames that are required for a classification to take place.

Definition at line 54 of file interactionSAMModel.py.

+ Inheritance diagram for SAM.SAM_Core.interactionSAMModel.interactionSAMModel:

Public Member Functions

def __init__ (self)
 Initialisation of the interaction function. More...
 
def configure (self, rf)
 Configure interactionSAMModel yarp module. More...
 
def close (self)
 Close Yarp module. More...
 
def closePort (self, j)
 Helper function to close ports with an enforced timeout of 3 seconds so the module doesn't hang. More...
 
def respond (self, command, reply)
 Respond to external requests. More...
 
def classifyInstance (self, reply)
 Classify a live collected data instance. More...
 
def generateInstance (self, reply, instanceName)
 Responds to an ask_X_instance request. More...
 
def recallFromLabel (self, label)
 Generates instance based on label. More...
 
def interruptModule (self)
 Module interrupt logic. More...
 
def getPeriod (self)
 Module refresh rate. More...
 
def updateModule (self)
 Logic to execute every getPeriod() seconds. More...
 
def readFrame (self)
 Logic to read an available data frame. More...
 
def collectData (self)
 Collect data function. More...
 
def test (self)
 Utility function to test data collection procedures for debugging purposes. More...
 

Public Attributes

 mm
 
 dataPath
 
 configPath
 
 modelPath
 
 driverName
 
 model_type
 
 model_mode
 
 textLabels
 
 classifiers
 
 classif_thresh
 
 verbose
 
 Quser
 
 listOfModels
 
 portsList
 
 svPort
 
 labelPort
 
 instancePort
 
 callSignList
 
 inputBottle
 
 outputBottle
 
 portNameList
 
 rpcConnected
 
 dataInConnected
 
 dataOutConnected
 
 collectionMethod
 
 bufferSize
 
 falseCount
 
 noDataCount
 
 inputType
 
 outputType
 
 errorRate
 
 dataList
 
 classificationList
 
 closeFlag
 
 instancePortName
 
 labelPortName
 
 verboseSetting
 
 exitFlag
 
 recordingFile
 
 additionalInfoDict
 
 modelLoaded
 
 attentionMode
 
 baseLogFileName
 
 windowedMode
 
 modelRoot
 
 eventPort
 
 eventPortName
 
 classTimestamps
 
 probClassList
 
 recency
 
 useRecentClassTime
 
 my_mutex
 

Constructor & Destructor Documentation

◆ __init__()

def SAM.SAM_Core.interactionSAMModel.interactionSAMModel.__init__ (   self)

Initialisation of the interaction function.

Definition at line 58 of file interactionSAMModel.py.

Member Function Documentation

◆ classifyInstance()

def SAM.SAM_Core.interactionSAMModel.interactionSAMModel.classifyInstance (   self,
  reply 
)

Classify a live collected data instance.

Description
This method responds to an ask_x_label request sent via the rpc port of the module.
In the case of collectionMethod = buffered, the data currently in the buffer is sent to processLiveData() method for the current driver which returns a classification label that is embedded in reply.
In the case of collectionMethod = future_buffered, this method reads incoming frames from the dataIn port until the collection buffer is full at which point it calls processLiveData() to get a classification label.
In the case of collectionMethod = continuous, this model returns the most recent label in the FILO buffer containing classification labels.
Parameters
replyOutgoing Yarp bottle containing classification label.
Returns
None

Definition at line 435 of file interactionSAMModel.py.

◆ close()

def SAM.SAM_Core.interactionSAMModel.interactionSAMModel.close (   self)

Close Yarp module.

Parameters
None
Returns
Boolean indicating success or no success in closing the Yarp module

Definition at line 299 of file interactionSAMModel.py.

◆ closePort()

def SAM.SAM_Core.interactionSAMModel.interactionSAMModel.closePort (   self,
  j 
)

Helper function to close ports with an enforced timeout of 3 seconds so the module doesn't hang.

Parameters
jYarp Port
Returns
None

Definition at line 316 of file interactionSAMModel.py.

◆ collectData()

def SAM.SAM_Core.interactionSAMModel.interactionSAMModel.collectData (   self)

Collect data function.

Description
This function implements three types of data collection procedures:
1) buffered : Collects data in a fixed length FIFO buffer of past frames. This buffer is read by classifyInstance().
2) future_buffered : No operation.
3) continuous : Collect data until a buffer of length windowSize is full and then perform a classification on this data. The classification is then stored in a buffer with is read by classifyInstance().
Returns
None

Definition at line 731 of file interactionSAMModel.py.

◆ configure()

def SAM.SAM_Core.interactionSAMModel.interactionSAMModel.configure (   self,
  rf 
)

Configure interactionSAMModel yarp module.

Parameters
rfYarp RF context input
argv_1String containing data path.
argv_2String containing model path.
argv_3String containing config file path (from config_path parameter of samSupervisor config file).
argv_4String driver name corresponding to a valid driver present in SAM_Drivers folder.
argv_5String 'True' or 'False' to switch formatting of logging depending on whether interaction is logging to a separate window or to the stdout of another process.
Returns
Boolean indicating success or no success in initialising the yarp module

Definition at line 128 of file interactionSAMModel.py.

◆ generateInstance()

def SAM.SAM_Core.interactionSAMModel.interactionSAMModel.generateInstance (   self,
  reply,
  instanceName 
)

Responds to an ask_X_instance request.

Description
Implements the logic for responding to an ask_X_instance rpc request for instanceName. This method responds with an ack or nack on the rpc port indicating success of memory generation and outputs the generated instance returned by recallFromLabel on the dataOut port.
Parameters
replyYarp Bottle to embed the rpc response.
instanceNameName of class to generate.
Returns
None

Definition at line 584 of file interactionSAMModel.py.

◆ getPeriod()

def SAM.SAM_Core.interactionSAMModel.interactionSAMModel.getPeriod (   self)

Module refresh rate.

Returns The period of the module in seconds.

Definition at line 651 of file interactionSAMModel.py.

◆ interruptModule()

def SAM.SAM_Core.interactionSAMModel.interactionSAMModel.interruptModule (   self)

Module interrupt logic.

Returns Boolean indicating success of logic or not.

Definition at line 643 of file interactionSAMModel.py.

◆ readFrame()

def SAM.SAM_Core.interactionSAMModel.interactionSAMModel.readFrame (   self)

Logic to read an available data frame.

Description
This function first checks the required data type of the frame to be received and instantiates the required yarp data object. This function then subsequently reads in the latest frame from the dataIn port which it returns. Return is None if the data type is not recognised. This is currently a limitation because ImageRgb, ImageMono and Bottle are so far the only supported bottle types. This can be easily extended in this section by adding more cases.

Returns Boolean indicating success of logic or not.

Definition at line 700 of file interactionSAMModel.py.

◆ recallFromLabel()

def SAM.SAM_Core.interactionSAMModel.interactionSAMModel.recallFromLabel (   self,
  label 
)

Generates instance based on label.

Parameters
labelString containing the class label for the requested generated instance.
Returns
Serialised vector representing the generated instance.

Definition at line 625 of file interactionSAMModel.py.

◆ respond()

def SAM.SAM_Core.interactionSAMModel.interactionSAMModel.respond (   self,
  command,
  reply 
)

Respond to external requests.

Description
Available requests
1) heartbeat : Sanity check request to make sure module is still alive.
2) information : Utility request to pass in contextual information.
3) portNames : Request to return the name of the currently open ports for samSupervisor to keep a list of open ports.
4) reload : Request to reload model from disk.
5) toggleVerbose : Switch logging to stdout on or off.
6) EXIT : Abort and close the module.
7) ask_X_label : Request a classification from the module.
8) ask_X_instance : Request a generative output from the module.
Parameters
commandIncoming Yarp bottle containing external request.
replyOutgoing Yarp bottle containing reply to processed request.
Returns
Boolean indicating success or no success in responding to external requests.

Definition at line 342 of file interactionSAMModel.py.

◆ test()

def SAM.SAM_Core.interactionSAMModel.interactionSAMModel.test (   self)

Utility function to test data collection procedures for debugging purposes.

Definition at line 824 of file interactionSAMModel.py.

◆ updateModule()

def SAM.SAM_Core.interactionSAMModel.interactionSAMModel.updateModule (   self)

Logic to execute every getPeriod() seconds.

Description
This function makes sure important ports are connected. Priority 1 is the rpc port. Priority 2 is the data in port. If both are connected this function triggers collectData().

Returns Boolean indicating success of logic or not.

Definition at line 662 of file interactionSAMModel.py.

Member Data Documentation

◆ additionalInfoDict

SAM.SAM_Core.interactionSAMModel.interactionSAMModel.additionalInfoDict

Definition at line 101 of file interactionSAMModel.py.

◆ attentionMode

SAM.SAM_Core.interactionSAMModel.interactionSAMModel.attentionMode

Definition at line 103 of file interactionSAMModel.py.

◆ baseLogFileName

SAM.SAM_Core.interactionSAMModel.interactionSAMModel.baseLogFileName

Definition at line 104 of file interactionSAMModel.py.

◆ bufferSize

SAM.SAM_Core.interactionSAMModel.interactionSAMModel.bufferSize

Definition at line 86 of file interactionSAMModel.py.

◆ callSignList

SAM.SAM_Core.interactionSAMModel.interactionSAMModel.callSignList

Definition at line 77 of file interactionSAMModel.py.

◆ classif_thresh

SAM.SAM_Core.interactionSAMModel.interactionSAMModel.classif_thresh

Definition at line 69 of file interactionSAMModel.py.

◆ classificationList

SAM.SAM_Core.interactionSAMModel.interactionSAMModel.classificationList

Definition at line 94 of file interactionSAMModel.py.

◆ classifiers

SAM.SAM_Core.interactionSAMModel.interactionSAMModel.classifiers

Definition at line 68 of file interactionSAMModel.py.

◆ classTimestamps

SAM.SAM_Core.interactionSAMModel.interactionSAMModel.classTimestamps

Definition at line 109 of file interactionSAMModel.py.

◆ closeFlag

SAM.SAM_Core.interactionSAMModel.interactionSAMModel.closeFlag

Definition at line 95 of file interactionSAMModel.py.

◆ collectionMethod

SAM.SAM_Core.interactionSAMModel.interactionSAMModel.collectionMethod

Definition at line 85 of file interactionSAMModel.py.

◆ configPath

SAM.SAM_Core.interactionSAMModel.interactionSAMModel.configPath

Definition at line 62 of file interactionSAMModel.py.

◆ dataInConnected

SAM.SAM_Core.interactionSAMModel.interactionSAMModel.dataInConnected

Definition at line 83 of file interactionSAMModel.py.

◆ dataList

SAM.SAM_Core.interactionSAMModel.interactionSAMModel.dataList

Definition at line 93 of file interactionSAMModel.py.

◆ dataOutConnected

SAM.SAM_Core.interactionSAMModel.interactionSAMModel.dataOutConnected

Definition at line 84 of file interactionSAMModel.py.

◆ dataPath

SAM.SAM_Core.interactionSAMModel.interactionSAMModel.dataPath

Definition at line 61 of file interactionSAMModel.py.

◆ driverName

SAM.SAM_Core.interactionSAMModel.interactionSAMModel.driverName

Definition at line 64 of file interactionSAMModel.py.

◆ errorRate

SAM.SAM_Core.interactionSAMModel.interactionSAMModel.errorRate

Definition at line 92 of file interactionSAMModel.py.

◆ eventPort

SAM.SAM_Core.interactionSAMModel.interactionSAMModel.eventPort

Definition at line 107 of file interactionSAMModel.py.

◆ eventPortName

SAM.SAM_Core.interactionSAMModel.interactionSAMModel.eventPortName

Definition at line 108 of file interactionSAMModel.py.

◆ exitFlag

SAM.SAM_Core.interactionSAMModel.interactionSAMModel.exitFlag

Definition at line 99 of file interactionSAMModel.py.

◆ falseCount

SAM.SAM_Core.interactionSAMModel.interactionSAMModel.falseCount

Definition at line 88 of file interactionSAMModel.py.

◆ inputBottle

SAM.SAM_Core.interactionSAMModel.interactionSAMModel.inputBottle

Definition at line 78 of file interactionSAMModel.py.

◆ inputType

SAM.SAM_Core.interactionSAMModel.interactionSAMModel.inputType

Definition at line 90 of file interactionSAMModel.py.

◆ instancePort

SAM.SAM_Core.interactionSAMModel.interactionSAMModel.instancePort

Definition at line 76 of file interactionSAMModel.py.

◆ instancePortName

SAM.SAM_Core.interactionSAMModel.interactionSAMModel.instancePortName

Definition at line 96 of file interactionSAMModel.py.

◆ labelPort

SAM.SAM_Core.interactionSAMModel.interactionSAMModel.labelPort

Definition at line 75 of file interactionSAMModel.py.

◆ labelPortName

SAM.SAM_Core.interactionSAMModel.interactionSAMModel.labelPortName

Definition at line 97 of file interactionSAMModel.py.

◆ listOfModels

SAM.SAM_Core.interactionSAMModel.interactionSAMModel.listOfModels

Definition at line 72 of file interactionSAMModel.py.

◆ mm

SAM.SAM_Core.interactionSAMModel.interactionSAMModel.mm

Definition at line 60 of file interactionSAMModel.py.

◆ model_mode

SAM.SAM_Core.interactionSAMModel.interactionSAMModel.model_mode

Definition at line 66 of file interactionSAMModel.py.

◆ model_type

SAM.SAM_Core.interactionSAMModel.interactionSAMModel.model_type

Definition at line 65 of file interactionSAMModel.py.

◆ modelLoaded

SAM.SAM_Core.interactionSAMModel.interactionSAMModel.modelLoaded

Definition at line 102 of file interactionSAMModel.py.

◆ modelPath

SAM.SAM_Core.interactionSAMModel.interactionSAMModel.modelPath

Definition at line 63 of file interactionSAMModel.py.

◆ modelRoot

SAM.SAM_Core.interactionSAMModel.interactionSAMModel.modelRoot

Definition at line 106 of file interactionSAMModel.py.

◆ my_mutex

SAM.SAM_Core.interactionSAMModel.interactionSAMModel.my_mutex

Definition at line 113 of file interactionSAMModel.py.

◆ noDataCount

SAM.SAM_Core.interactionSAMModel.interactionSAMModel.noDataCount

Definition at line 89 of file interactionSAMModel.py.

◆ outputBottle

SAM.SAM_Core.interactionSAMModel.interactionSAMModel.outputBottle

Definition at line 79 of file interactionSAMModel.py.

◆ outputType

SAM.SAM_Core.interactionSAMModel.interactionSAMModel.outputType

Definition at line 91 of file interactionSAMModel.py.

◆ portNameList

SAM.SAM_Core.interactionSAMModel.interactionSAMModel.portNameList

Definition at line 80 of file interactionSAMModel.py.

◆ portsList

SAM.SAM_Core.interactionSAMModel.interactionSAMModel.portsList

Definition at line 73 of file interactionSAMModel.py.

◆ probClassList

SAM.SAM_Core.interactionSAMModel.interactionSAMModel.probClassList

Definition at line 110 of file interactionSAMModel.py.

◆ Quser

SAM.SAM_Core.interactionSAMModel.interactionSAMModel.Quser

Definition at line 71 of file interactionSAMModel.py.

◆ recency

SAM.SAM_Core.interactionSAMModel.interactionSAMModel.recency

Definition at line 111 of file interactionSAMModel.py.

◆ recordingFile

SAM.SAM_Core.interactionSAMModel.interactionSAMModel.recordingFile

Definition at line 100 of file interactionSAMModel.py.

◆ rpcConnected

SAM.SAM_Core.interactionSAMModel.interactionSAMModel.rpcConnected

Definition at line 82 of file interactionSAMModel.py.

◆ svPort

SAM.SAM_Core.interactionSAMModel.interactionSAMModel.svPort

Definition at line 74 of file interactionSAMModel.py.

◆ textLabels

SAM.SAM_Core.interactionSAMModel.interactionSAMModel.textLabels

Definition at line 67 of file interactionSAMModel.py.

◆ useRecentClassTime

SAM.SAM_Core.interactionSAMModel.interactionSAMModel.useRecentClassTime

Definition at line 112 of file interactionSAMModel.py.

◆ verbose

SAM.SAM_Core.interactionSAMModel.interactionSAMModel.verbose

Definition at line 70 of file interactionSAMModel.py.

◆ verboseSetting

SAM.SAM_Core.interactionSAMModel.interactionSAMModel.verboseSetting

Definition at line 98 of file interactionSAMModel.py.

◆ windowedMode

SAM.SAM_Core.interactionSAMModel.interactionSAMModel.windowedMode

Definition at line 105 of file interactionSAMModel.py.

◆ SAM::SAM_Core::SAMCore::LFM

class SAM::SAM_Core::SAMCore::LFM

SAM based on Latent Feature Models.

Definition at line 40 of file SAMCore.py.

+ Inheritance diagram for SAM.SAM_Core.SAMCore.LFM:

Public Member Functions

def __init__ (self)
 Initalise the Latent Feature Models. More...
 
def store (self, observed, inputs=None, Q=None, kernel=None, num_inducing=None, init_X='PCA')
 Store events. More...
 
def add_labels (self, labels)
 Add labels to observations. More...
 
def learn (self, optimizer='bfgs', max_iters=1000, init_iters=300, verbose=True)
 Learn the model (analogous to "forming synapses" after perceiving data). More...
 
def check_snr (self, warningEnable=True, messages=True)
 Checks the signal to noise ratio(SNR) of the trained model. More...
 
def visualise (self, which_indices=None, plot_scales=True)
 Show the internal representation of the memory. More...
 
def visualise_interactive (self, dimensions=(20, 28), transpose=True, order='F', invert=False, scale=False, colorgray=True, view=0, which_indices=(0, 1))
 Interactive plot of the model. More...
 
def recall (self, locations)
 Recall stored events. More...
 
def pattern_completion (self, test_data, view=0, verbose=False, visualiseInfo=None, optimise=100)
 Recall novel events. More...
 
def pattern_completion_inference (self, y, target_modality=-1)
 Pattern completion wrapper. More...
 
def fantasy_memory (self, X, view=0)
 Generating novel outputs. More...
 
def familiarity (self, Ytest, ytrmean=None, ytrstd=None, optimise=100)
 Familiarity testing. More...
 
def __get_latent__ (self)
 Return number of latent dimensions. More...
 

Public Attributes

 type
 
 model
 
 observed
 
 inputs
 
 Q
 
 N
 
 num_inducing
 
 namesList
 
 Ylist
 

Constructor & Destructor Documentation

◆ __init__()

def SAM.SAM_Core.SAMCore.LFM.__init__ (   self)

Initalise the Latent Feature Models.

Definition at line 44 of file SAMCore.py.

Member Function Documentation

◆ __get_latent__()

def SAM.SAM_Core.SAMCore.LFM.__get_latent__ (   self)

Return number of latent dimensions.

Description
Convenience function to return the number of latent dimensions.
Parameters
None.
Returns
Integer with the number of latent dimensions of the model.

Definition at line 472 of file SAMCore.py.

◆ add_labels()

def SAM.SAM_Core.SAMCore.LFM.add_labels (   self,
  labels 
)

Add labels to observations.

Description
If observables are associated with labels, they can be added here. Labels has to be a matrix of size N x K, where K is the total number of different labels. If e.g. the i-th row of L is [1 0 0] (or [1 -1 -1]) then this means that there are K=3 different classes and the i-th row of the observables belongs to the first class.
Parameters
labelslist of strings containing the labels for the observations
Returns
None

Definition at line 169 of file SAMCore.py.

◆ check_snr()

def SAM.SAM_Core.SAMCore.LFM.check_snr (   self,
  warningEnable = True,
  messages = True 
)

Checks the signal to noise ratio(SNR) of the trained model.

Description
Provides an indicator of successful learning by looking at the variance distribution of the model.
Parameters
warningEnableBoolean to switch warnings on or off in the case of a low SNR.
messagesBoolean to turn output to stdout on or off.
Returns
None

Definition at line 212 of file SAMCore.py.

◆ familiarity()

def SAM.SAM_Core.SAMCore.LFM.familiarity (   self,
  Ytest,
  ytrmean = None,
  ytrstd = None,
  optimise = 100 
)

Familiarity testing.

Description
This function tests the familiarity/similarity of an input with the inputs used to train the model.
Parameters
YtestA (Dx1) numpy array whose familiarity/similarity is tested with trained outputs of the model.
ytrmeanA (Dx1) numpy array with the mean of the training inputs.
ytrstdA (Dx1) numpy array with the variance of the training inputs.
optimiseInteger number of optimisation iterations when performing pattern completion.
Returns
A float with a measure of familiarity for Ytest with the current model.

Definition at line 441 of file SAMCore.py.

◆ fantasy_memory()

def SAM.SAM_Core.SAMCore.LFM.fantasy_memory (   self,
  X,
  view = 0 
)

Generating novel outputs.

Description
The opposite of pattern completion. Instead of finding a memory from an output, here we find an output from a (possibly fantasy) memory. Here, fantasy memory is a memory not existing in the training set, found by interpolating or sampling in the memory space.
Parameters
XA (Qx1) numpy array with the location of the Q dimensional model that is to be generated.
viewInteger which is the index for the view of the MRD model that will be used to generate the fantasy_memory.
Returns
A (Qx1) numpy array with the predicted mean and a (Qx1) numpy array with the predicted variance.

Definition at line 418 of file SAMCore.py.

◆ learn()

def SAM.SAM_Core.SAMCore.LFM.learn (   self,
  optimizer = 'bfgs',
  max_iters = 1000,
  init_iters = 300,
  verbose = True 
)

Learn the model (analogous to "forming synapses" after perceiving data).

Parameters
optimizerString with the requested optimiser taken from a the list of available scipy optimisers.
max_itersInteger with the maximum number of training iterations for the second phase of training the model.
init_itersInteger with the maximum number of training iterations for the first phase of training.
verboseBoolean to turn logging to stdout on or off.
Returns
None

Definition at line 188 of file SAMCore.py.

◆ pattern_completion()

def SAM.SAM_Core.SAMCore.LFM.pattern_completion (   self,
  test_data,
  view = 0,
  verbose = False,
  visualiseInfo = None,
  optimise = 100 
)

Recall novel events.

Description
In the case of supervised learning, pattern completion means that we give new inputs and infer their corresponding outputs. In the case of unsupervised learning, pattern completion means that we give new outputs and we infer their corresponding "latent" inputs, ie the internal compressed representation of the new outputs in terms of the already formed "synapses".
Parameters
test_dataA (Dx1) numpy array containing the feature vector for which you would like to obtain the closest neighbour.
viewInteger which is the index for the view of the MRD model that will be used for pattern completion.
verboseBoolean switching logging to stdout on and off.
visualiseInfoPlot object returned by visualiseInfo. If present, plot the location of the pattern completed point. If none, no plotting.
optimiseInteger number of optimisation iterations when performing pattern completion.
Returns
A (Qx1) numpy array with the predicted mean, a (Qx1) numpy array with the predicted variance, a plot object with plotted point and an inference object returned by optimiser.

Definition at line 347 of file SAMCore.py.

◆ pattern_completion_inference()

def SAM.SAM_Core.SAMCore.LFM.pattern_completion_inference (   self,
  y,
  target_modality = -1 
)

Pattern completion wrapper.

Description
1) First, we do normal pattern completion, where given an output y, out map to the memory space to get a test memory x*. 2) Now the test memory x* is compared with stored memories. This allows us to infer the label of x*. If the labels are given in another modality (by default in the last one), then we return the label from that modality (careful, The encoding might be 1-of-K, e.g. -1 1 -1 -> 2 and also noise might exist). Instead, if the labels are not given in another modality (completely unsupervised learning), then we just return the index to the most similar training memory.
Parameters
yA (Dx1) numpy array containing the feature vector for which you would like to obtain the closest neighbour.
target_modalityInteger which is the index for the view of the MRD model that will be used for pattern completion.
Returns
Inference object returned by optimiser containing multi-dimensional mean and variance of nearest neighbour.

Definition at line 390 of file SAMCore.py.

◆ recall()

def SAM.SAM_Core.SAMCore.LFM.recall (   self,
  locations 
)

Recall stored events.

Description
This is closely related to performing pattern pattern_completion but given "training" data.
Parameters
locationsInteger which is the index of the stored event.
Returns
A (Dx1) numpy array containing the data of a training point as reconstructed by the model.

Definition at line 324 of file SAMCore.py.

◆ store()

def SAM.SAM_Core.SAMCore.LFM.store (   self,
  observed,
  inputs = None,
  Q = None,
  kernel = None,
  num_inducing = None,
  init_X = 'PCA' 
)

Store events.

Description
Read in the args observed and inputs and configure the LFM model for training or recollection.
Parameters
observedAn (N x D) matrix, where N is the number of points and D the number of features needed to describe each point.
inputsA (N x Q) matrix, where Q is the number of features per input. Leave "None" for unsupervised learning.
QLeave None for supervised learning (Q will then be the dimensionality of inputs). Otherwise, specify with an integer Q the dimensionality (number of features) for the compressed space that acts as "latent" inputs.
kernelFor the GP. Can be left as "None" for the default kernel.
num_inducingInteger of how many inducing points to use. Inducing points are a fixed number of variables through which all memory is filtered, to achieve full compression. E.g. it can correspond to the number of neurons. This is not absolutely fixed, but it also doesn't grow necessarily proportionally to the data, since synapses can make more complicated combinations of the existing neurons. The GP is here playing the role of "synapses", by learning non-linear and rich combinations of the inducing points.
init_XInitialisation method for model output. String either PCA or PPCA. Default= PCA. Initialisation uses PPCA when PCA
Returns
None

Definition at line 72 of file SAMCore.py.

◆ visualise()

def SAM.SAM_Core.SAMCore.LFM.visualise (   self,
  which_indices = None,
  plot_scales = True 
)

Show the internal representation of the memory.

Description
Creates a 2D plot showing the mean and variance distribution of the model.
Parameters
which_indicesTuple of two integers that specify which indices of the Q indices that make up the model are to be plotted.
plot_scalesBoolean to switch scale labelling on or off in the plots.
Returns
None

Definition at line 245 of file SAMCore.py.

◆ visualise_interactive()

def SAM.SAM_Core.SAMCore.LFM.visualise_interactive (   self,
  dimensions = (20, 28),
  transpose = True,
  order = 'F',
  invert = False,
  scale = False,
  colorgray = True,
  view = 0,
  which_indices = (0, 1) 
)

Interactive plot of the model.

Description
Show the internal representation of the memory and allow the user to interact with it to map samples/points from the compressed space to the original output space.
Parameters
dimensionsTuple of integers describing the dimensions that the image needs to be transposed to for display.
transposeBoolean whether to transpose the image before display.
orderBoolean whether array is in Fortan ordering ('F') or Python ordering ('C').
invertBoolean whether to invert the pixels or not.
scaleBoolean whether to scale the image or not.
colorgrayBoolean whether to plot in grayscale or not.
viewInteger in the case of MRD models which describes the view to be plotted.
which_indicesTuple of two integers that specify which indices of the Q indices that make up the model are to be plotted.
Returns
None

Definition at line 286 of file SAMCore.py.

Member Data Documentation

◆ inputs

SAM.SAM_Core.SAMCore.LFM.inputs

Definition at line 48 of file SAMCore.py.

◆ model

SAM.SAM_Core.SAMCore.LFM.model

Definition at line 46 of file SAMCore.py.

◆ N

SAM.SAM_Core.SAMCore.LFM.N

Definition at line 51 of file SAMCore.py.

◆ namesList

SAM.SAM_Core.SAMCore.LFM.namesList

Definition at line 53 of file SAMCore.py.

◆ num_inducing

SAM.SAM_Core.SAMCore.LFM.num_inducing

Definition at line 52 of file SAMCore.py.

◆ observed

SAM.SAM_Core.SAMCore.LFM.observed

Definition at line 47 of file SAMCore.py.

◆ Q

SAM.SAM_Core.SAMCore.LFM.Q

Definition at line 50 of file SAMCore.py.

◆ type

SAM.SAM_Core.SAMCore.LFM.type

Definition at line 45 of file SAMCore.py.

◆ Ylist

SAM.SAM_Core.SAMCore.LFM.Ylist

Definition at line 54 of file SAMCore.py.

◆ SAM::SAM_Core::samOptimiser::modelOptClass

class SAM::SAM_Core::samOptimiser::modelOptClass

Class to perform optimisation of SAM Models.

This class reads in the parameters for optimisation from the [Optimisation] section found in the config.ini present in the data directory passed in as dataDir. Parameters are set for variables that are present in the [driver_name] section of the same config.ini in the following manner variableName = [parameterType:commaSeparatedParameterValues].
Parameters can be :
1) discreteInt : Equally spaced integers in the form of x = [discreteInt:start,interval,end].
2) discreteFloat : Equally spaced floats in the form of x = [discreteFloat:start,interval,end].
3) continuous : Continuous range in the form of x = [continuous:start,end].
4) list : Use one parameter value at a time from the comma separated list of possible parameter values in the form of x = [list:a,b,c,d] where x is set to just one of the values in the list.
5) bool : In the form of x = [bool] where x = 1 or 0. Similar to x = [list:1,0].
6) combination : Use multiple parameters at a time from the comma separated list of possible parameters values in the form of x = [combination:a,b,c,d] where x is set to a combination of parameters. Length of the values list in x ranges from 1 to number of comma separated parameter values.
Examples

Example config.ini
[model_options]
driver = driverName # driver present in SAM_Drivers folder
modelNameBase = modelName # user set model name
[modelName]
# default parameters for the training section which must always be present.
update_mode = `new` # `new` or `false`. `New` fill train a new model with the following parameters and delete the old one. `False` will check for the availbility of an already trained model and if one is available load it together with its parameters ignoring the rest of this file.
experiment_number = 0 # experiment number in case different models are required to be compared
model_type = mrd # model type can be `mrd` or `bgplvm`
model_mode = single # model_mode can be `single` or `multiple`
model_num_inducing = 170 # any integer number. Generally < 200 for performance considerations
model_num_iterations = 50 # any integer number. High numbers mean increased training time
model_init_iterations = 450 # any integer number. High numbers mean increased training time
verbose = True # `True` or `False` will turn logging to stdout on or off. Logging to file is always on.
Quser = 10 # Number of target dimensions for the output latent space. Higher numbers mean a more detailed latent space but very sparse clusters. Higher dimensionality also requires more input data for good generalisation.
ratioData = 80 # Train/Test split. 80% train, 20% test
kernelString = "GPy.kern.RBF(Q, ARD=False) + GPy.kern.Bias(Q) + GPy.kern.White(Q)" # This is the kernel used by the Gaussian Process. Keep this constant. Future releases will make this a changeable parameter
optimiseRecall = 0 # This parameter sets the number of optimisations that occur during recall. If 0 no optimisations are made and recall becames similair to nearest neighbour analysis.
calibrateUnknown = True # This parameter triggers the learning of known/unknown classification.
# start of unique model parameters. These parameters are usually parameters to modify and alter the signal processing that occurs in user defined readData function. The following are examples.
thresholdMovement = 1
components = pos,vel
joints = head
windowOffsetPercent = 12.5
thresholdPercent = 22
moveThresh = 0.01
[Optimisation]
# default parameters for the optimisation section which must always be present.
acquisitionFunction = 'EI' # Can be either 'MPI' : maximum probability of improvement, 'EI' : Expected Improvement or 'UCB' : Upper class bound
# custom optimisation parameters which must be a subset of the default and custom parameters in the previous section
model_num_inducing = [discreteInt:20,50,220]
thresholdMovement = [bool]
components = [combination:pos,vel,acc]
joints = [list:head,chest,right hand,left hand,right arm,left arm]
windowOffsetPercent = [discreteFloat:10.0,1.5,22.5]
thresholdPercent = [continuous:13.5,]

Definition at line 91 of file samOptimiser.py.

+ Inheritance diagram for SAM.SAM_Core.samOptimiser.modelOptClass:

Public Member Functions

def __init__ (self, fName, dataDir, modelDir, driverName, mode, baseName, persistence, windowed, verbose)
 Initialisation for modelOptClass. More...
 
def configOptimisation (self)
 Configure optimisation parameters from config.ini. More...
 
def f (self, x)
 Optimisation Evaluation Function. More...
 
def copyModel (self, newName, direction)
 Utility function to copy model. More...
 

Public Attributes

 fName
 
 dataDir
 
 modelDir
 
 driverName
 
 baseName
 
 persistence
 
 verbose
 
 devnull
 
 windowed
 
 numEvals
 
 penalty
 
 mode
 
 parser
 
 sectionBackup
 
 sectionOpt
 
 modelPresent
 
 bestOptions
 
 domain
 
 bestError
 
 currIterSettings
 
 acquisitionFunction
 
 trainProcess
 
 resultsList
 
 currFiles
 
 configured
 
 numPossibilities
 

Constructor & Destructor Documentation

◆ __init__()

def SAM.SAM_Core.samOptimiser.modelOptClass.__init__ (   self,
  fName,
  dataDir,
  modelDir,
  driverName,
  mode,
  baseName,
  persistence,
  windowed,
  verbose 
)

Initialisation for modelOptClass.

Parameters
fNameFile name of the model to use as a starting point for the optimisation
dataDirDirectory containing the data to be trained
modelDirDirectory where to save optimised model and temporary models created during optimisation
driverNameName of driver to use for training which must be present in SAM_Drivers folder
modeThis is a legacy parameter that changed the behaviour of saving models. This parameter is not in use anymore.
baseNameBase name of model to be trained. Model filenames take the form of baseName_driverName_modelType_modelVersion.pickle with a corresponding baseName_driverName_modelType_modelVersion_model.h5. modelVersion can be best, exp<experiment number>, or backup.
persistence'True' or 'False' indicating terminals opened by samOptimiser stay open even after process termination
windowed'True' or 'False' indicating separate terminals will be opened by samOptimiser for each training and interaction process
verbose'True' or 'False' switching on or off logging to stdout
Returns
None

Definition at line 109 of file samOptimiser.py.

Member Function Documentation

◆ configOptimisation()

def SAM.SAM_Core.samOptimiser.modelOptClass.configOptimisation (   self)

Configure optimisation parameters from config.ini.

Reads in config.ini parameters and sets up the optimisation landscape from these parameters. Also reads in the performance of a current model if one is available to set that as the performance to beat.

Returns
None

Definition at line 153 of file samOptimiser.py.

◆ copyModel()

def SAM.SAM_Core.samOptimiser.modelOptClass.copyModel (   self,
  newName,
  direction 
)

Utility function to copy model.

Parameters
newNameModel base name to copy.
directionnormal or reverse. normal makes a copy of the model with exp<experiment number> in the filename to backup in the filename. reverse makes a copy of backup into exp<experiment number>.
Returns
True of False indicating success.

Definition at line 427 of file samOptimiser.py.

◆ f()

def SAM.SAM_Core.samOptimiser.modelOptClass.f (   self,
  x 
)

Optimisation Evaluation Function.

This function evaluates the current values chosen by the optimiser in x by writing these parameter values to the respective parameters in the training parameters section of the config.ini and subsequently making a system call to trainSAMModel.

Parameters
xList of current evaluation parameters chosen by the optimiser.
Returns
Total error for the current training parameters. Error is the weighted sum total of the confusion matrix created during testing of the model as part of training.

Definition at line 304 of file samOptimiser.py.

Member Data Documentation

◆ acquisitionFunction

SAM.SAM_Core.samOptimiser.modelOptClass.acquisitionFunction

Definition at line 134 of file samOptimiser.py.

◆ baseName

SAM.SAM_Core.samOptimiser.modelOptClass.baseName

Definition at line 116 of file samOptimiser.py.

◆ bestError

SAM.SAM_Core.samOptimiser.modelOptClass.bestError

Definition at line 132 of file samOptimiser.py.

◆ bestOptions

SAM.SAM_Core.samOptimiser.modelOptClass.bestOptions

Definition at line 130 of file samOptimiser.py.

◆ configured

SAM.SAM_Core.samOptimiser.modelOptClass.configured

Definition at line 138 of file samOptimiser.py.

◆ currFiles

SAM.SAM_Core.samOptimiser.modelOptClass.currFiles

Definition at line 137 of file samOptimiser.py.

◆ currIterSettings

SAM.SAM_Core.samOptimiser.modelOptClass.currIterSettings

Definition at line 133 of file samOptimiser.py.

◆ dataDir

SAM.SAM_Core.samOptimiser.modelOptClass.dataDir

Definition at line 113 of file samOptimiser.py.

◆ devnull

SAM.SAM_Core.samOptimiser.modelOptClass.devnull

Definition at line 119 of file samOptimiser.py.

◆ domain

SAM.SAM_Core.samOptimiser.modelOptClass.domain

Definition at line 131 of file samOptimiser.py.

◆ driverName

SAM.SAM_Core.samOptimiser.modelOptClass.driverName

Definition at line 115 of file samOptimiser.py.

◆ fName

SAM.SAM_Core.samOptimiser.modelOptClass.fName

Definition at line 112 of file samOptimiser.py.

◆ mode

SAM.SAM_Core.samOptimiser.modelOptClass.mode

Definition at line 125 of file samOptimiser.py.

◆ modelDir

SAM.SAM_Core.samOptimiser.modelOptClass.modelDir

Definition at line 114 of file samOptimiser.py.

◆ modelPresent

SAM.SAM_Core.samOptimiser.modelOptClass.modelPresent

Definition at line 129 of file samOptimiser.py.

◆ numEvals

SAM.SAM_Core.samOptimiser.modelOptClass.numEvals

Definition at line 123 of file samOptimiser.py.

◆ numPossibilities

SAM.SAM_Core.samOptimiser.modelOptClass.numPossibilities

Definition at line 202 of file samOptimiser.py.

◆ parser

SAM.SAM_Core.samOptimiser.modelOptClass.parser

Definition at line 126 of file samOptimiser.py.

◆ penalty

SAM.SAM_Core.samOptimiser.modelOptClass.penalty

Definition at line 124 of file samOptimiser.py.

◆ persistence

SAM.SAM_Core.samOptimiser.modelOptClass.persistence

Definition at line 117 of file samOptimiser.py.

◆ resultsList

SAM.SAM_Core.samOptimiser.modelOptClass.resultsList

Definition at line 136 of file samOptimiser.py.

◆ sectionBackup

SAM.SAM_Core.samOptimiser.modelOptClass.sectionBackup

Definition at line 127 of file samOptimiser.py.

◆ sectionOpt

SAM.SAM_Core.samOptimiser.modelOptClass.sectionOpt

Definition at line 128 of file samOptimiser.py.

◆ trainProcess

SAM.SAM_Core.samOptimiser.modelOptClass.trainProcess

Definition at line 135 of file samOptimiser.py.

◆ verbose

SAM.SAM_Core.samOptimiser.modelOptClass.verbose

Definition at line 118 of file samOptimiser.py.

◆ windowed

SAM.SAM_Core.samOptimiser.modelOptClass.windowed

Definition at line 120 of file samOptimiser.py.

◆ SAM::SAM_Core::samSupervisor::SamSupervisorModule

class SAM::SAM_Core::samSupervisor::SamSupervisorModule

Model management and supervisor.

Description
Single point of entry for managing training and interaction with multiple models running in parallel. Parameters loaded from default.ini in samSupervisor context folder which contains the configuration details for samSupervisor as seen in the example below.

Examples

root_path /usr/local/SAM_Data_Models
config_path sensory_level_conf.ini
persistence True
windowed True
verbose True
useOPC False
startModels False
acceptableDelay "5"
controllerIP 127.0.0.1
Parameters
root_pathPath to folder containing Data and Models folders.
config_pathName of configuration file detailing parameters for different drivers.
persistence'True' or 'False' indicating terminals opened by samSupervisor stay open even after process termination.
windowed'True' or 'False' indicating separate terminals will be opened by samSupervisor for each training and interaction process.
verbose'True' or 'False' switching on or off logging to stdout.
useOPC'True' or 'False' indicating using or not using OPC for further information.
startModels'True' or 'False' indicating all models in the config_path file will be automatically loaded during samSupervisor startup.
acceptableDelayString with an integer for the number of tries before a model is declared dead, aborted and restarted.
controllerIPIP address for the ipyparallel controller. Currently not in use. Leave at 127.0.0.1.

Definition at line 55 of file samSupervisor.py.

+ Inheritance diagram for SAM.SAM_Core.samSupervisor.SamSupervisorModule:

Public Member Functions

def __init__ (self)
 
def configure (self, rf)
 Configure interactionSAMModel Yarp module. More...
 
def close (self)
 Close Yarp module. More...
 
def checkAvailabilities (self, reply)
 Check model availabilities. More...
 
def respond (self, command, reply)
 Respond to external requests. More...
 
def forwardCommand (self, command, reply)
 Helper function to forward a call sign to the respective model with an enforced timeout of 10 seconds for the reply so the module does not hang. More...
 
def interruptModule (self)
 Module interrupt logic. More...
 
def listModels (self, reply, command)
 Returns lists of models for train or interaction categpories. More...
 
def attentionModulation (self, reply, command)
 Modulate attention of all models. More...
 
def askOPC (self, reply)
 Query the OPC for additional contextual data. More...
 
def closeModel (self, reply, command, external=False)
 Close a loaded model. More...
 
def loadModel (self, reply, command)
 Load a trained model. More...
 
def checkModel (self, reply, command, allCheck=False)
 Check availability and status of a model. More...
 
def train (self, reply, command)
 Logic for training a model. More...
 
def optimise (self, reply, command)
 Logic for optimising a model. More...
 
def deleteModel (self, reply, command)
 Deletes model from hard disk. More...
 
def configModel (self, reply, command)
 Displays the model configuration file using a system call to gedit. More...
 
def dataDirModel (self, reply, command)
 Returns the chosen model. More...
 
def reportModel (self, reply, command)
 Returns the performance of the trained model. More...
 
def train_model (self, mod)
 Train a model. More...
 
def optimise_model (self, mod, modName)
 Optimise a model. More...
 
def getPeriod (self)
 Module refresh rate. More...
 
def onlineModelCheck (self)
 Check status of loaded models. More...
 
def checkOperation (self, j)
 Check heartbeat of model. More...
 
def updateModule (self)
 Logic to execute every getPeriod() seconds. More...
 

Public Attributes

 SIGNALS_TO_NAMES_DICT
 
 terminal
 
 rootPath
 
 interactionConfPath
 
 startModels
 
 persistence
 
 windowed
 
 verbose
 
 modelPath
 
 dataPath
 
 trainingFunctionsPath
 
 trainingListHandles
 
 loadedListHandles
 
 iter
 
 rpcConnections
 
 inputBottle
 
 sendingBottle
 
 responseBottle
 
 outputBottle
 
 devnull
 
 supervisorPort
 
 interactionConfFile
 
 interactionParser
 
 interactionSectionList
 
 cluster
 
 functionsList
 
 trainableModels
 
 modelsList
 
 updateModels
 
 updateModelsNames
 
 noModels
 
 noModelsNames
 
 uptodateModels
 
 uptodateModelsNames
 
 nonResponsiveDict
 
 nonResponsiveThreshold
 
 modelConnections
 
 connectionCheckCount
 
 modelPriority
 
 opcPort
 
 useOPC
 
 attentionModes
 
 opcPortName
 
 opcRPCName
 
 baseLogFileName
 

Constructor & Destructor Documentation

◆ __init__()

def SAM.SAM_Core.samSupervisor.SamSupervisorModule.__init__ (   self)

Definition at line 56 of file samSupervisor.py.

Member Function Documentation

◆ askOPC()

def SAM.SAM_Core.samSupervisor.SamSupervisorModule.askOPC (   self,
  reply 
)

Query the OPC for additional contextual data.

Description
Query name of agent from OPC and forward it to Actions model if it is loaded. This is currently the only model that uses this method. Method will be generalised in future versions.
Parameters
replyYarp bottle for the reply from OPC.
Returns
Boolean indicating success or not.

Definition at line 767 of file samSupervisor.py.

◆ attentionModulation()

def SAM.SAM_Core.samSupervisor.SamSupervisorModule.attentionModulation (   self,
  reply,
  command 
)

Modulate attention of all models.

Parameters
commandYarp bottle with command. Example valid commands below.
replyYarp bottle for the reply from the model.
Returns
Boolean indicating success or not.
Example
attentionModulation stop
attentionModulation continue

Definition at line 737 of file samSupervisor.py.

◆ checkAvailabilities()

def SAM.SAM_Core.samSupervisor.SamSupervisorModule.checkAvailabilities (   self,
  reply 
)

Check model availabilities.

Description
This function starts by compiling a list of models present in the root_path/Models. Then cross checks that the corresponding data folder exists in root_path/Data and that it contains an appropriate config.ini file. If a data folder exists but a model does not, this is added to noModels list. If the folder and the model both exist and the modification date of the data is newer than that of the model it is added to updateModels (requiring an update) if the modification date of the model is newer it is added to uptodateModels. If the model exists but not the data folder config file, the model is ignored. Each model and data folder pair is then paired with its respective driver from the SAM_Drivers folder. If a corresponding driver is not available, the data and model are ignored.
Parameters
replyYarp Bottle containing a many string formatted response to indicate the state of all the available drivers and the corresponding models.
Returns
None

Definition at line 366 of file samSupervisor.py.

◆ checkModel()

def SAM.SAM_Core.samSupervisor.SamSupervisorModule.checkModel (   self,
  reply,
  command,
  allCheck = False 
)

Check availability and status of a model.

Description
Cross check available models, data folders, config files and driver availability for a specific model.
Parameters
replyYarp bottle for the reply from the function.
commandYarp bottle with the command and the model name to check.
allCheckBoolean to check all models if True and check a single model if False.
Returns
Boolean indicating success or not.

Definition at line 1092 of file samSupervisor.py.

◆ checkOperation()

def SAM.SAM_Core.samSupervisor.SamSupervisorModule.checkOperation (   self,
  j 
)

Check heartbeat of model.

Parameters
jYarp rpc port for loaded model to check.
Returns
correctOp_check1 Check that output count for the model rpc port is > 0.
correctOp_check2 Check that the model returns ack to a hartbeat request.

Definition at line 1700 of file samSupervisor.py.

◆ close()

def SAM.SAM_Core.samSupervisor.SamSupervisorModule.close (   self)

Close Yarp module.

Description
Starts by issuing an EXIT command to all loaded interaction modules. Terminates training processes. Closes samSupervisor ports and terminates cluster if one has been started.
Parameters
None
Returns
Boolean indicating success or no success in closing the Yarp module.

Definition at line 328 of file samSupervisor.py.

◆ closeModel()

def SAM.SAM_Core.samSupervisor.SamSupervisorModule.closeModel (   self,
  reply,
  command,
  external = False 
)

Close a loaded model.

Description
Check that a model has been loaded and if it is close the loaded model.
Parameters
replyYarp bottle for the reply from the function.
commandYarp bottle with the command and the model name to close.
externalBoolean indicating model to be closed is to be closed for good if True. Else model is to be closed for restart.
Returns
Boolean indicating success or not.

Definition at line 839 of file samSupervisor.py.

◆ configModel()

def SAM.SAM_Core.samSupervisor.SamSupervisorModule.configModel (   self,
  reply,
  command 
)

Displays the model configuration file using a system call to gedit.

Parameters
replyYarp bottle for the reply from the function.
commandYarp bottle with the command and the model name to display.
Returns
Boolean indicating success or not.

Definition at line 1274 of file samSupervisor.py.

◆ configure()

def SAM.SAM_Core.samSupervisor.SamSupervisorModule.configure (   self,
  rf 
)

Configure interactionSAMModel Yarp module.

Parameters
rfYarp RF context input.
Returns
Boolean indicating success or no success in initialising the Yarp module.

Definition at line 113 of file samSupervisor.py.

◆ dataDirModel()

def SAM.SAM_Core.samSupervisor.SamSupervisorModule.dataDirModel (   self,
  reply,
  command 
)

Returns the chosen model.

Description
samOptimiser creates multiple models with different suffixes. best indicates the best performing model. exp indicates the last trained model. backup indicates the model present before optimisation started. The priority of suffixes is best, exp, backup.
Parameters
replyYarp bottle for the reply from the function.
commandYarp bottle with the command and the model name to chose.
Returns
Boolean indicating success or not.

Definition at line 1307 of file samSupervisor.py.

◆ deleteModel()

def SAM.SAM_Core.samSupervisor.SamSupervisorModule.deleteModel (   self,
  reply,
  command 
)

Deletes model from hard disk.

Parameters
replyYarp bottle for the reply from the function.
commandYarp bottle with the command and the model name to delete.
Returns
Boolean indicating success or not.

Definition at line 1202 of file samSupervisor.py.

◆ forwardCommand()

def SAM.SAM_Core.samSupervisor.SamSupervisorModule.forwardCommand (   self,
  command,
  reply 
)

Helper function to forward a call sign to the respective model with an enforced timeout of 10 seconds for the reply so the module does not hang.

Parameters
commandYarp bottle with the call sign.
replyYarp bottle for the reply from the model.
Returns
None

Definition at line 669 of file samSupervisor.py.

◆ getPeriod()

def SAM.SAM_Core.samSupervisor.SamSupervisorModule.getPeriod (   self)

Module refresh rate.

Returns The period of the module in seconds.

Definition at line 1568 of file samSupervisor.py.

◆ interruptModule()

def SAM.SAM_Core.samSupervisor.SamSupervisorModule.interruptModule (   self)

Module interrupt logic.

Returns Boolean indicating success of logic or not.

Definition at line 679 of file samSupervisor.py.

◆ listModels()

def SAM.SAM_Core.samSupervisor.SamSupervisorModule.listModels (   self,
  reply,
  command 
)

Returns lists of models for train or interaction categpories.

Parameters
commandYarp bottle with command. Example valid commands below.
replyYarp bottle for the reply from the model.
Returns
Boolean indicating success or not.
Example
listModels returns list of models that require training
listModels returns list of interaction ready models
listModels returns a list of all models

Definition at line 697 of file samSupervisor.py.

◆ loadModel()

def SAM.SAM_Core.samSupervisor.SamSupervisorModule.loadModel (   self,
  reply,
  command 
)

Load a trained model.

Description
Launches interactionSAMModel.py for the model mentioned in the command.
Parameters
replyYarp bottle for the reply from the function.
commandYarp bottle with the command and the model name to load.
Returns
None

Definition at line 886 of file samSupervisor.py.

◆ onlineModelCheck()

def SAM.SAM_Core.samSupervisor.SamSupervisorModule.onlineModelCheck (   self)

Check status of loaded models.

Description
Checks that ports for all loaded models are alive and working. If a loaded model is not working restart the model.
Parameters
None
Returns
None

Definition at line 1581 of file samSupervisor.py.

◆ optimise()

def SAM.SAM_Core.samSupervisor.SamSupervisorModule.optimise (   self,
  reply,
  command 
)

Logic for optimising a model.

Description
Checks that requested model is present and available for optimisation.
Parameters
replyYarp bottle for the reply from the function.
commandYarp bottle with the command and the model name to optimise.
Returns
Boolean indicating success or not.

Definition at line 1167 of file samSupervisor.py.

◆ optimise_model()

def SAM.SAM_Core.samSupervisor.SamSupervisorModule.optimise_model (   self,
  mod,
  modName 
)

Optimise a model.

Description
Launches samOptimiser.py to optimise the specified model.
Parameters
modModel information.
modNameModel name.
Returns
Boolean indicating success or not.

Definition at line 1502 of file samSupervisor.py.

◆ reportModel()

def SAM.SAM_Core.samSupervisor.SamSupervisorModule.reportModel (   self,
  reply,
  command 
)

Returns the performance of the trained model.

Description
Returns the confusion matrix for a trained model or returns the confusion matrix together with a plot of the matrix.
Parameters
replyYarp bottle for the reply from the function.
commandYarp bottle with the command, the model name to report and a plot parameter to switch plot on or off.

Examples

report <modelName>

report <modelName> plot
Returns
Boolean indicating success or not.

Definition at line 1363 of file samSupervisor.py.

◆ respond()

def SAM.SAM_Core.samSupervisor.SamSupervisorModule.respond (   self,
  command,
  reply 
)

Respond to external requests.

Description
Available requests
1) askOPC : Query the OPC for additional contextual data. calls askOPC()
2) attentionModulation <> : Modulate attention of all models. Enable classification if is continue. Disable classification if is stop. Calls attentionModulation()
3) check_all : Cross checks available models, data folders, config files and driver availability. Calls checkAvailabilities()
4) check <modelName> : Cross check available models, data folders, config files and driver availability for a specific <modelName>. Calls checkModel()
5) config <modelName> : Opens the data folder config file for the specific <modelName> to view or change the training parameters. Calls configModel()
6) dataDir <modelName> : Returns the model filename that will be used for the specific <modelName>. Calls dataDirModel()
7) delete <modelName> : Deletes model from hard disk. Calls deleteModel()
8) help : Returns a many formatted list of available commands
9) load <modelName> : Launches interactionSAMModel.py for the <modelName>. Calls loadModel()
10) close <modelName> : Terminates the interactionSAMModel.py process for the <modelName>. Calls closeModel()
11) optimise <modelName> : Launches samOptimiser.py to optimise the training of the specified model. Calls optimise().
12) quit : Closes all loaded models and stops samSupervisor.
13) report <modelName> <plotFlag> : Reports the confusion matrix of <modelName> if it is a trained model. Plot result if <plotFlag> is set to plot. Return a formatted confusion matrix if <plotFlag> is not plot. Calls reportModel()
14) train <modelName> : Launches trainSAMModel.py to train the specified model. Calls train()
15) list_callSigns : Returns a list of the ask_X_label and ask_X_instance call signs for all models that are currently loaded with interactionSAMModel.py
7) ask_X_label : Forwards the received ask label request to the corresponding loaded model if the callsign is present in list_callsigns. This command has an enforced timeout of 10 seconds to respond otherwise returns nack.
8) ask_X_instance : Forwards the received ask instance request to the corresponding loaded model if the callsign is present in list_callsigns. This command has an enforced timeout of 10 seconds to respond otherwise returns nack.
Parameters
commandIncoming Yarp bottle containing external request.
replyOutgoing Yarp bottle containing reply to processed request.
Returns
Boolean indicating success or no success in responding to external requests.

Definition at line 580 of file samSupervisor.py.

◆ train()

def SAM.SAM_Core.samSupervisor.SamSupervisorModule.train (   self,
  reply,
  command 
)

Logic for training a model.

Description
Checks that requested model is present and available for training.
Parameters
replyYarp bottle for the reply from the function.
commandYarp bottle with the command and the model name to train.
Returns
Boolean indicating success or not.

Definition at line 1130 of file samSupervisor.py.

◆ train_model()

def SAM.SAM_Core.samSupervisor.SamSupervisorModule.train_model (   self,
  mod 
)

Train a model.

Description
Launches trainSAMModel.py to train the specified model.
Parameters
modString with the model name to load.
Returns
Boolean indicating success or not.

Definition at line 1422 of file samSupervisor.py.

◆ updateModule()

def SAM.SAM_Core.samSupervisor.SamSupervisorModule.updateModule (   self)

Logic to execute every getPeriod() seconds.

Description
This function makes checks that all loaded modules are still alive and if OPC querying is enabled query OPC.

Returns Boolean indicating success of logic or not.

Definition at line 1718 of file samSupervisor.py.

Member Data Documentation

◆ attentionModes

SAM.SAM_Core.samSupervisor.SamSupervisorModule.attentionModes

Definition at line 99 of file samSupervisor.py.

◆ baseLogFileName

SAM.SAM_Core.samSupervisor.SamSupervisorModule.baseLogFileName

Definition at line 102 of file samSupervisor.py.

◆ cluster

SAM.SAM_Core.samSupervisor.SamSupervisorModule.cluster

Definition at line 82 of file samSupervisor.py.

◆ connectionCheckCount

SAM.SAM_Core.samSupervisor.SamSupervisorModule.connectionCheckCount

Definition at line 95 of file samSupervisor.py.

◆ dataPath

SAM.SAM_Core.samSupervisor.SamSupervisorModule.dataPath

Definition at line 67 of file samSupervisor.py.

◆ devnull

SAM.SAM_Core.samSupervisor.SamSupervisorModule.devnull

Definition at line 77 of file samSupervisor.py.

◆ functionsList

SAM.SAM_Core.samSupervisor.SamSupervisorModule.functionsList

Definition at line 83 of file samSupervisor.py.

◆ inputBottle

SAM.SAM_Core.samSupervisor.SamSupervisorModule.inputBottle

Definition at line 73 of file samSupervisor.py.

◆ interactionConfFile

SAM.SAM_Core.samSupervisor.SamSupervisorModule.interactionConfFile

Definition at line 79 of file samSupervisor.py.

◆ interactionConfPath

SAM.SAM_Core.samSupervisor.SamSupervisorModule.interactionConfPath

Definition at line 61 of file samSupervisor.py.

◆ interactionParser

SAM.SAM_Core.samSupervisor.SamSupervisorModule.interactionParser

Definition at line 80 of file samSupervisor.py.

◆ interactionSectionList

SAM.SAM_Core.samSupervisor.SamSupervisorModule.interactionSectionList

Definition at line 81 of file samSupervisor.py.

◆ iter

SAM.SAM_Core.samSupervisor.SamSupervisorModule.iter

Definition at line 71 of file samSupervisor.py.

◆ loadedListHandles

SAM.SAM_Core.samSupervisor.SamSupervisorModule.loadedListHandles

Definition at line 70 of file samSupervisor.py.

◆ modelConnections

SAM.SAM_Core.samSupervisor.SamSupervisorModule.modelConnections

Definition at line 94 of file samSupervisor.py.

◆ modelPath

SAM.SAM_Core.samSupervisor.SamSupervisorModule.modelPath

Definition at line 66 of file samSupervisor.py.

◆ modelPriority

SAM.SAM_Core.samSupervisor.SamSupervisorModule.modelPriority

Definition at line 96 of file samSupervisor.py.

◆ modelsList

SAM.SAM_Core.samSupervisor.SamSupervisorModule.modelsList

Definition at line 85 of file samSupervisor.py.

◆ noModels

SAM.SAM_Core.samSupervisor.SamSupervisorModule.noModels

Definition at line 88 of file samSupervisor.py.

◆ noModelsNames

SAM.SAM_Core.samSupervisor.SamSupervisorModule.noModelsNames

Definition at line 89 of file samSupervisor.py.

◆ nonResponsiveDict

SAM.SAM_Core.samSupervisor.SamSupervisorModule.nonResponsiveDict

Definition at line 92 of file samSupervisor.py.

◆ nonResponsiveThreshold

SAM.SAM_Core.samSupervisor.SamSupervisorModule.nonResponsiveThreshold

Definition at line 93 of file samSupervisor.py.

◆ opcPort

SAM.SAM_Core.samSupervisor.SamSupervisorModule.opcPort

Definition at line 97 of file samSupervisor.py.

◆ opcPortName

SAM.SAM_Core.samSupervisor.SamSupervisorModule.opcPortName

Definition at line 100 of file samSupervisor.py.

◆ opcRPCName

SAM.SAM_Core.samSupervisor.SamSupervisorModule.opcRPCName

Definition at line 101 of file samSupervisor.py.

◆ outputBottle

SAM.SAM_Core.samSupervisor.SamSupervisorModule.outputBottle

Definition at line 76 of file samSupervisor.py.

◆ persistence

SAM.SAM_Core.samSupervisor.SamSupervisorModule.persistence

Definition at line 63 of file samSupervisor.py.

◆ responseBottle

SAM.SAM_Core.samSupervisor.SamSupervisorModule.responseBottle

Definition at line 75 of file samSupervisor.py.

◆ rootPath

SAM.SAM_Core.samSupervisor.SamSupervisorModule.rootPath

Definition at line 60 of file samSupervisor.py.

◆ rpcConnections

SAM.SAM_Core.samSupervisor.SamSupervisorModule.rpcConnections

Definition at line 72 of file samSupervisor.py.

◆ sendingBottle

SAM.SAM_Core.samSupervisor.SamSupervisorModule.sendingBottle

Definition at line 74 of file samSupervisor.py.

◆ SIGNALS_TO_NAMES_DICT

SAM.SAM_Core.samSupervisor.SamSupervisorModule.SIGNALS_TO_NAMES_DICT

Definition at line 58 of file samSupervisor.py.

◆ startModels

SAM.SAM_Core.samSupervisor.SamSupervisorModule.startModels

Definition at line 62 of file samSupervisor.py.

◆ supervisorPort

SAM.SAM_Core.samSupervisor.SamSupervisorModule.supervisorPort

Definition at line 78 of file samSupervisor.py.

◆ terminal

SAM.SAM_Core.samSupervisor.SamSupervisorModule.terminal

Definition at line 59 of file samSupervisor.py.

◆ trainableModels

SAM.SAM_Core.samSupervisor.SamSupervisorModule.trainableModels

Definition at line 84 of file samSupervisor.py.

◆ trainingFunctionsPath

SAM.SAM_Core.samSupervisor.SamSupervisorModule.trainingFunctionsPath

Definition at line 68 of file samSupervisor.py.

◆ trainingListHandles

SAM.SAM_Core.samSupervisor.SamSupervisorModule.trainingListHandles

Definition at line 69 of file samSupervisor.py.

◆ updateModels

SAM.SAM_Core.samSupervisor.SamSupervisorModule.updateModels

Definition at line 86 of file samSupervisor.py.

◆ updateModelsNames

SAM.SAM_Core.samSupervisor.SamSupervisorModule.updateModelsNames

Definition at line 87 of file samSupervisor.py.

◆ uptodateModels

SAM.SAM_Core.samSupervisor.SamSupervisorModule.uptodateModels

Definition at line 90 of file samSupervisor.py.

◆ uptodateModelsNames

SAM.SAM_Core.samSupervisor.SamSupervisorModule.uptodateModelsNames

Definition at line 91 of file samSupervisor.py.

◆ useOPC

SAM.SAM_Core.samSupervisor.SamSupervisorModule.useOPC

Definition at line 98 of file samSupervisor.py.

◆ verbose

SAM.SAM_Core.samSupervisor.SamSupervisorModule.verbose

Definition at line 65 of file samSupervisor.py.

◆ windowed

SAM.SAM_Core.samSupervisor.SamSupervisorModule.windowed

Definition at line 64 of file samSupervisor.py.

◆ SAM::SAM_Core::svi_ratio::SVI_Ratio

class SAM::SAM_Core::svi_ratio::SVI_Ratio

Inference the marginal likelihood through {p(y,y*)}{p(y)}.

Definition at line 23 of file svi_ratio.py.

+ Inheritance diagram for SAM.SAM_Core.svi_ratio.SVI_Ratio:

Public Member Functions

def __init__ (self, mpi_comm=None)
 
def get_trYYT (self, Y)
 
def get_YYTfactor (self, Y)
 
def gatherPsiStat (self, kern, X, Z, Y, beta, uncertain_inputs, D, missing_data)
 
def inference (self, kern, X, Z, likelihood, Y, qU)
 The SVI-VarDTC inference. More...
 

Public Attributes

 mpi_comm
 

Static Public Attributes

int const_jitter = 1e-6
 

Constructor & Destructor Documentation

◆ __init__()

def SAM.SAM_Core.svi_ratio.SVI_Ratio.__init__ (   self,
  mpi_comm = None 
)

Definition at line 25 of file svi_ratio.py.

Member Function Documentation

◆ gatherPsiStat()

def SAM.SAM_Core.svi_ratio.SVI_Ratio.gatherPsiStat (   self,
  kern,
  X,
  Z,
  Y,
  beta,
  uncertain_inputs,
  D,
  missing_data 
)

Definition at line 39 of file svi_ratio.py.

◆ get_trYYT()

def SAM.SAM_Core.svi_ratio.SVI_Ratio.get_trYYT (   self,
  Y 
)

Definition at line 29 of file svi_ratio.py.

◆ get_YYTfactor()

def SAM.SAM_Core.svi_ratio.SVI_Ratio.get_YYTfactor (   self,
  Y 
)

Definition at line 32 of file svi_ratio.py.

◆ inference()

def SAM.SAM_Core.svi_ratio.SVI_Ratio.inference (   self,
  kern,
  X,
  Z,
  likelihood,
  Y,
  qU 
)

The SVI-VarDTC inference.

Definition at line 77 of file svi_ratio.py.

Member Data Documentation

◆ const_jitter

int SAM.SAM_Core.svi_ratio.SVI_Ratio.const_jitter = 1e-6
static

Definition at line 24 of file svi_ratio.py.

◆ mpi_comm

SAM.SAM_Core.svi_ratio.SVI_Ratio.mpi_comm

Definition at line 27 of file svi_ratio.py.

Function Documentation

◆ exception_hook()

def SAM.SAM_Core.trainSAMModel.exception_hook (   exc_type,
  exc_value,
  exc_traceback 
)

Generic training function.

Generic training function that carries out SAM Model training on a collection of data, The parameters for training function are loaded from the config file present in the folder containing the data to be trained. An example of the configuration structure is shown in samOptimiser.modelOptClass Callback function to record any errors that occur in the log files.

Documentation
Substitutes the standard python exception_hook with one that records the error into a log file. Can only work if trainSAMModel.py is called from python and not ipython because ipython overrides this substitution.
Parameters
exc_typeException Type.
exc_valueException Value.
exc_tracebackException Traceback.
Returns
None

Definition at line 48 of file trainSAMModel.py.

◆ load_model()

def SAM.SAM_Core.SAMCore.load_model (   fileName = 'm_serialized.txt')

Load serialised model.

Parameters
fileNameString with the filename of model to load.
Returns
SAMObject Model

Definition at line 507 of file SAMCore.py.

◆ load_pruned_model()

def SAM.SAM_Core.SAMCore.load_pruned_model (   fileName = 'm_pruned',
  economy = False,
  m = None 
)

Load a pruned model.

Description
Load a trained model. If economy is set to True, then a not-None initial model m is needed. This model needs to be created exactly as the one that was saved (so, it is demo specific!) and in this case calling the present function will set its parameters (meaning that you still need to create a model but don't need to optimize it).
Parameters
fileNameString with the filename of the model to load.
economyBoolean to indicate whether an economy object is being loaded or not.
mModel object into which the data to be loaded is to be stored in. If left at None model will be loaded into a default model initialisation.
Returns
SAMObject model

Definition at line 583 of file SAMCore.py.

◆ most_significant_input_dimensions()

def SAM.SAM_Core.SAMCore.most_significant_input_dimensions (   model)

Determine the most descriptive output dimensions.

Description
Helper function to determine which dimensions should be plotted based on the relevance weights.
Parameters
modelModel object to be assessed.
Returns
Integer indicating the most descriptive dimension and an integer indicating the second most descriptive dimension.

Definition at line 628 of file SAMCore.py.

◆ save_model()

def SAM.SAM_Core.SAMCore.save_model (   mm,
  fileName = 'm_serialized.txt' 
)

Save serialised model.

Parameters
mmModel object to save.
fileNameString with the filename of saved model.
Returns
None

Definition at line 492 of file SAMCore.py.

◆ save_pruned_model()

def SAM.SAM_Core.SAMCore.save_pruned_model (   mm,
  fileName = 'm_pruned',
  economy = False,
  extraDict = dict() 
)

Save a pruned model.

Description
Save a trained model after pruning things that are not needed to be stored. Economy set to True will trigger a storing which creates much smaller files. See the load_pruned_model discussion on what this means in terms of restrictions.
Parameters
mmModel object to save.
fileNameString with the filename of saved model.
economyBoolean to enable or disable economy saving.
extraDictDictionary with parameters that are requested to be saved which are not in the default saved parameters but are required when loading the model for interaction.
Returns
None

Definition at line 526 of file SAMCore.py.