InstanceLinearModel¶
- class menpo.model.base.InstanceLinearModel(components)[source]¶
Bases: LinearModel, InstanceBackedModel
- component(index)¶
Return a particular component of the linear model.
Parameters: index : int
The component that is to be returned
:type: `type(self.template_instance)` :
- component_vector(index)¶
A particular component of the model, in vectorized form.
Parameters: index : int
The component that is to be returned
:type: (n_features,) ndarray :
- instance(weights)¶
Creates a new instance of the model using the first len(weights) components.
Parameters: weights : (n_weights,) ndarray or list
weights[i] is the linear contribution of the i’th component to the instance vector.
Returns: instance : type(self.template_instance)
An instance of the model.
Raises: ValueError: If n_weights > n_components :
- instance_vector(weights)¶
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)¶
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)¶
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()¶
Enforces that this models components are orthonormalized
s.t. component_vector(i).dot(component_vector(j) = dirac_delta
- project(instance)¶
Projects the instance onto the model, retrieving the optimal linear weightings.
Parameters: novel_instance : Vectorizable
A novel instance.
Returns: projected : (n_components,)
A vector of optimal linear weightings
- project_out(instance)¶
Returns a version of instance where all the basis of the model have been projected out.
Parameters: instance : Vectorizable
A novel instance.
Returns: projected_out : self.instance_class
A copy of instance, with all basis of the model projected out.
- project_out_vector(vector)¶
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)¶
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)¶
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)¶
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(instance)¶
Projects a instance onto the linear space and rebuilds from the weights found.
Syntactic sugar for:
>>> instance(project(instance))
but faster, as it avoids the conversion that takes place each time.
Parameters: instance : Vectorizable
A novel instance of Vectorizable
Returns: reconstructed : self.instance_class
The reconstructed object.
- reconstruct_vector(vector)¶
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)¶
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¶
The component matrix of the linear model.
type: (n_available_components, n_features) ndarray
- d_dp¶
- n_components¶
The number of bases of the model
type: int
- n_features¶
The number of elements in each linear component.
type: int