LinearVectorModel¶

class
menpo.model.
LinearVectorModel
(components)[source]¶ Bases:
Copyable
A Linear Model contains a matrix of vector components, each component vector being made up of features.
 Parameters
components (
(n_components, n_features)
ndarray) – The components array.

component
(index)[source]¶ A particular component of the model.
 Parameters
index (int) – The component that is to be returned.
 Returns
component_vector (
(n_features,)
ndarray) – The component vector.

copy
()¶ Generate an efficient copy of this object.
Note that Numpy arrays and other
Copyable
objects onself
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.
 Returns
type(self)
– A copy of this object

instance
(weights)[source]¶ Creates a new vector instance of the model by weighting together the components.
 Parameters
weights (
(n_weights,)
ndarray or list) –The weightings for the first n_weights components that should be used.
weights[j]
is the linear contribution of the j’th principal component to the instance vector. Returns
vector (
(n_features,)
ndarray) – The instance vector for the weighting provided.

instance_vectors
(weights)[source]¶ Creates new vectorized instances of the model using all the components of the linear model.
 Parameters
weights (
(n_vectors, n_weights)
ndarray or list of lists) –The weightings for all components of the linear model. All components will be used to produce the instance.
weights[i, j]
is the linear contribution of the j’th principal component to the i’th instance vector produced. Raises
ValueError – If n_weights > n_available_components
 Returns
vectors (
(n_vectors, n_features)
ndarray) – The instance vectors for the weighting provided.

orthonormalize_against_inplace
(linear_model)[source]¶ Enforces that the union of this model’s components and another are both mutually orthonormal.
Both models keep its number of components unchanged or else a value error is raised.
 Parameters
linear_model (
LinearVectorModel
) – A second linear model to orthonormalize this against. Raises
ValueError – The number of features must be greater or equal than the sum of the number of components in both linear models ({} < {})

orthonormalize_inplace
()[source]¶ Enforces that this model’s components are orthonormalized, s.t.
component_vector(i).dot(component_vector(j) = dirac_delta
.

project
(vector)[source]¶ Projects the vector onto the model, retrieving the optimal linear reconstruction weights.
 Parameters
vector (
(n_features,)
ndarray) – A vectorized novel instance. Returns
weights (
(n_components,)
ndarray) – A vector of optimal linear weights.

project_out
(vector)[source]¶ Returns a version of vector where all the basis of the model have been projected out.
 Parameters
vector (
(n_features,)
ndarray) – A novel vector. Returns
projected_out (
(n_features,)
ndarray) – A copy of vector with all basis of the model projected out.

project_out_vectors
(vectors)[source]¶ Returns a version of vectors where all the basis of the model have been projected out.
 Parameters
vectors (
(n_vectors, n_features)
ndarray) – A matrix of novel vectors. Returns
projected_out (
(n_vectors, n_features)
ndarray) – A copy of vectors with all basis of the model projected out.

project_vectors
(vectors)[source]¶ Projects each of the vectors onto the model, retrieving the optimal linear reconstruction weights for each instance.
 Parameters
vectors (
(n_samples, n_features)
ndarray) – Array of vectorized novel instances. Returns
weights (
(n_samples, n_components)
ndarray) – The matrix of optimal linear weights.

reconstruct
(vector)[source]¶ Project a vector onto the linear space and rebuild from the weights found.
 Parameters
vector (
(n_features, )
ndarray) – A vectorized novel instance to project. Returns
reconstructed (
(n_features,)
ndarray) – The reconstructed vector.

reconstruct_vectors
(vectors)[source]¶ Projects the vectors onto the linear space and rebuilds vectors from the weights found.
 Parameters
vectors (
(n_vectors, n_features)
ndarray) – A set of vectors to project. Returns
reconstructed (
(n_vectors, n_features)
ndarray) – The reconstructed vectors.

property
components
¶ The components matrix of the linear model.
 Type
(n_available_components, n_features)
ndarray

property
n_components
¶ The number of bases of the model.
 Type
int

property
n_features
¶ The number of elements in each linear component.
 Type
int