LinearModel

class menpo.model.linear.LinearModel(components)[source]

Bases: object

A Linear Model contains a matrix of vector components, each component vector being made up of features.

component_vector(index)[source]

A particular component of the model, in vectorized form.

Parameters:

index : int

The component that is to be returned

:type: (n_features,) ndarray :

instance_vector(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.

Returns:

vectors : (n_vectors, n_features) ndarray

The instance vectors for the weighting provided.

Raises:

ValueError: If n_weights > n_available_components :

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 : LinearModel

A second linear model to orthonormalize this against.

orthonormalize_inplace()[source]

Enforces that this models components are orthonormalized

s.t. component_vector(i).dot(component_vector(j) = dirac_delta

project_out_vector(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_vector(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,)

A vector of optimal linear weights

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

Returns:

weights : (n_samples, n_components) ndarray

The matrix of optimal linear weights

reconstruct_vector(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.

components[source]

The component matrix of the linear model.

type: (n_available_components, n_features) ndarray

d_dp[source]
n_components[source]

The number of bases of the model

type: int

n_features[source]

The number of elements in each linear component.

type: int