class menpofit.modelinstance.PDM(data, max_n_components=None)[source]

Bases: ModelInstance

Class for building a Point Distribution Model. It is a specialised version of ModelInstance for use with spatial data.

  • data (list of menpo.shape.PointCloud or menpo.model.PCAModel instance) – If a list of menpo.shape.PointCloud, then a menpo.model.PCAModel will be trained from those training shapes. Otherwise, a trained menpo.model.PCAModel instance can be provided.

  • max_n_components (int or None, optional) – The maximum number of components that the model will keep. If None, then all the components will be kept.


Returns a flattened representation of the object as a single vector.


vector ((N,) ndarray) – The core representation of the object, flattened into a single vector. Note that this is always a view back on to the original object, but is not writable.


Generate an efficient copy of this object.

Note that Numpy arrays and other Copyable objects on self will be deeply copied. Dictionaries and sets will be shallow copied, and everything else will be assigned (no copy will be made).

Classes that store state other than numpy arrays and immutable types should overwrite this method to ensure all state is copied.


type(self) – A copy of this object


Returns the Jacobian of the similarity model reshaped in order to have the standard Jacobian shape, i.e. (n_points, n_weights, n_dims) which maps to (n_features, n_components, n_dims) on the linear model.


jacobian ((n_features, n_components, n_dims) ndarray) – The Jacobian of the model in the standard Jacobian shape.


Build a new instance of the object from it’s vectorized state.

self is used to fill out the missing state required to rebuild a full object from it’s standardized flattened state. This is the default implementation, which is which is a deepcopy of the object followed by a call to from_vector_inplace(). This method can be overridden for a performance benefit if desired.


vector ((n_parameters,) ndarray) – Flattened representation of the object.


object (type(self)) – An new instance of this class.


Deprecated. Use the non-mutating API, from_vector.

For internal usage in performance-sensitive spots, see _from_vector_inplace()


vector ((n_parameters,) ndarray) – Flattened representation of this object


Tests if the vectorized form of the object contains nan values or not. This is particularly useful for objects with unknown values that have been mapped to nan values.


has_nan_values (bool) – If the vectorized object contains nan values.

increment(shapes, n_shapes=None, forgetting_factor=1.0, max_n_components=None, verbose=False)[source]

Update the eigenvectors, eigenvalues and mean vector of this model by performing incremental PCA on the given samples.

  • shapes (list of menpo.shape.PointCloud) – List of new shapes to update the model from.

  • n_shapes (int or None, optional) – If int, then shapes must be an iterator that yields n_shapes. If None, then shapes has to be a list (so we know how large the data matrix needs to be).

  • forgetting_factor ([0.0, 1.0] float, optional) – Forgetting factor that weights the relative contribution of new samples vs old samples. If 1.0, all samples are weighted equally and, hence, the results is the exact same as performing batch PCA on the concatenated list of old and new simples. If <1.0, more emphasis is put on the new samples. See [1] for details.

  • max_n_components (int or None, optional) – The maximum number of components that the model will keep. If None, then all the components will be kept.

  • verbose (bool, optional) – If True, then information about the progress will be printed.



D. Ross, J. Lim, R.S. Lin, M.H. Yang. “Incremental Learning for Robust Visual Tracking”. International Journal on Computer Vision, 2007.


Update this object so that it attempts to recreate the new_target.


new_target (PointCloud) – The new target that this object should try and regenerate.

property n_active_components

The number of components currently in use on this model.



property n_dims

The number of dimensions of the spatial instance of the model



property n_parameters

The length of the vector that this object produces.



property n_points

The number of points on the target.



property n_weights

The number of parameters in the linear model.



property target

The current menpo.shape.PointCloud that this object produces.



property weights

The weights of the model.


(n_weights,) ndarray