modeling package¶
modeling.graphing module¶
The module graphing.py contains classes for building graphical structures of learned skills for Keyframe-based LfD.
-
class
modeling.graphing.
KeyframeGraph
[source]¶ NetworkX MultiDiGraph extended graph class for containing keyframes and their corresponding models.
-
cull_node
(node)[source]¶ Takes received node and removes it from the task graph
Parameters: - node: hashable networkx node name (usually int)
the node to be removed from network x graph
-
fit_models
(observation_vectorizor)[source]¶ Fits all models in graph. Expects that each keyframe node in graph has populated “observation” key as a list of Observation objects.
Parameters: - observation_vectorizor : function
Function that takes observations stored in graph and converts their data into vector form for use by model fitting function.
-
-
class
modeling.graphing.
ObservationClusterer
[source]¶ Clusters together observations by keyframe ID and gathers pertinent information regarding each keyframe. This will be used by a KeyframeGraph object.
-
assign_applied_constraints
(cluster)[source]¶ Assigns the applied constraints for the given keyframe cluster.
Parameters: - cluster : dict
Dictionary to assign the applied constraints..
-
assign_keyframe_type
(cluster)[source]¶ Assigns the keyframe type for the given keyframe cluster.
Parameters: - cluster : dict
Dictionary to assign the keyframe type.
-
cluster_observations_by_id
(observations)[source]¶ Takes in a the entirety of observations from all Demosntrations and groups them together by keyframe ID.
Parameters: - observations : list
List of the Observation objects to cluster.
Returns: - clusters : dict
Dictionary of clusters with top level keys the keyframe IDs and values another dictionary populated with ‘observations’ key with list of Observations.
-
generate_clusters
(demonstrations)[source]¶ Generates the clustered Observations from a list of Demonstrations.
Parameters: - demonstrations : list
List of the Demonstration objects from which labeled Observations.
Returns: - clusters : dict
Dictionary of clusters with top level keys the keyframe IDs and values another dictionary populated with pertinent information associated with each keyframe (i.e. keyframe type, applied constraints etc,.)
-
modeling.models module¶
Wrappers around various models
-
class
modeling.models.
GaussianMixtureModel
(n_components=5, means_init=None)[source]¶ Wrapper class for Scikit Learn’s Gaussian Mixture Model.
Attributes: - n_components : int
Number of clusters for KMeans
- model : GaussianMixture
Wrapped class model.
-
fit
(train_X)[source]¶ Wrapper method for fit() method of GMM model.
Parameters: - train_X : {array-like, sparse matrix}, shape = [n_samples, n_features]
-
class
modeling.models.
KDEModel
(kernel='gaussian', bandwidth=0.001)[source]¶ Wrapper class for Scikit Learn’s Kernel Density Estsimation model.
Attributes: - model : KernelDensity
Wrapped class model.
-
fit
(train_X)[source]¶ Wrapper method for fit() method of Kernel Density model.
Parameters: - train_X : {array-like, sparse matrix}, shape = [n_samples, n_features]
-
class
modeling.models.
KMeansModel
(n_clusters=5)[source]¶ Wrapper class for Scikit Learn’s KMeans clustering.
Attributes: - n_clusters : int
Number of clusters for KMeans
- model : KMeans
Wrapped class model.
modeling.sampling module¶
The module sampling.py contains classes for sampling and ranking points from Keyframe models.
-
class
modeling.sampling.
KeyframeSampler
(analyzer, data_converter)[source]¶ Sampling class that uses model representing a keyframe to sample points.
Attributes: - analyzer : object
Analysis object that evaluates sampled points for their validity (constraint satisfcation).
- data_converter : func
Function to convert a raw sample into an Observation object for use by the analyzer.
-
generate_n_valid_samples
(model, constraint_ids, n=100)[source]¶ Parameters: - model : object
Model object used to generate raw samples.
- constraint_ids : list
List of constraint IDs required for validity.
- n : int
Number of valid samples to generate.
Returns: - raw_samples : list
List of valid raw samples generated from the model.
-
generate_raw_samples
(model, num_of_samples)[source]¶ Parameters: - model : object
Model object used to generate raw samples.
- num_of_samples : int
Number of samples to generate.
Returns: - raw_samples : list
List of raw samples generated from the model.
-
rank_samples
(model, samples)[source]¶ Parameters: - model : object
Model object used to generate raw samples.
- samples : list
List of samples to rank according to their score as measured by the model.
Returns: - rank_sorted_sampled : list
List of rank (according to model scoring function) sorted samples (descending order).
modeling.visualization module¶
The visualization.py module constains classes for viewing sample poitns and models used in Cairo LfD.
-
class
modeling.visualization.
GaussianMixtureModelViewer
(gmm, observation_vectors)[source]¶ Class for viewing observation vector representaions within Gaussian Mixture Model.
Attributes: - kmm : KMeansModel
Model to visualize.
- observation_vectors : list
List of vectorized Observations.
-
class
modeling.visualization.
KMeansModelViewer
(kmm, observation_vectors)[source]¶ Class for viewing observation vector representation with KMeansModel.
Attributes: - kmm : KMeansModel
Model to visualize.
- observation_vectors : list
List of vectorized Observations.
-
view_3D_clusters
(x_index, y_index, z_index)[source]¶ Generates 3D graph of the clusters of KMeans model
Parameters: - x_index : int
Index of sample point to represent the x-axis value.
- y_index : int
Index of sample point to represent the y-axis value.
- z_index : int
Index of sample point to represent the z-axis value.
-
class
modeling.visualization.
SamplePointViewer
[source]¶ Class for viewing samples points via Matplotlib’s pyplot.
-
view_3D_scatter
(sample_points, x_index, y_index, z_index)[source]¶ Generates 3D graph according of the passed in sample points.
Parameters: - sample_points : list
List of numpy arrays (usually observations)
- x_index : int
Index of sample point to represent the x-axis value.
- y_index : int
Index of sample point to represent the y-axis value.
- z_index : int
Index of sample point to represent the z-axis value.
-