Package parsimony :: Package functions :: Package multiblock :: Module losses :: Class LatentVariableCovariance
[hide private]
[frames] | no frames]

Class LatentVariableCovariance

source code

                              object --+            
                                       |            
                     properties.Function --+        
                                           |        
                properties.CompositeFunction --+    
                                               |    
                   properties.MultiblockFunction --+
                                                   |
                                      object --+   |
                                               |   |
                   properties.MultiblockGradient --+
                                                   |
                                      object --+   |
                                               |   |
properties.MultiblockLipschitzContinuousGradient --+
                                                   |
                                                  LatentVariableCovariance

Represents

    Cov(X.w, Y.c) = (1 / (n - 1)) * w'.X'.Y.c,

where X.w and Y.c are latent variables.

Parameters
----------
X : List with two numpy arrays. The two blocks.

unbiased : Boolean. Whether or not to use biased or unbiased sample
        covariance. Default is True, the unbiased sample covariance is
        used.

Instance Methods [hide private]
 
__init__(self, X, unbiased=True)
x.__init__(...) initializes x; see help(type(x)) for signature
source code
 
reset(self)
Free any cached computations from previous use of this Function.
source code
 
f(self, w)
Function value.
source code
 
grad(self, w, index)
Gradient of the function.
source code
 
L(self, w, index)
Lipschitz constant of the gradient with given index.
source code

Inherited from properties.MultiblockFunction: add_constraint, get_constraints

Inherited from properties.Function: get_params, set_params

Inherited from properties.MultiblockGradient: approx_grad

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Class Variables [hide private]
  __abstractmethods__ = frozenset([])
  _abc_negative_cache_version = 14

Inherited from properties.MultiblockFunction: __metaclass__, constraints

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, X, unbiased=True)
(Constructor)

source code 

x.__init__(...) initializes x; see help(type(x)) for signature

Overrides: object.__init__
(inherited documentation)

reset(self)

source code 

Free any cached computations from previous use of this Function.

Overrides: properties.Function.reset
(inherited documentation)

f(self, w)

source code 

Function value.

From the interface "Function".

Overrides: properties.Function.f

grad(self, w, index)

source code 
Gradient of the function.

From the interface "MultiblockGradient".

Parameters
----------
w : List of numpy arrays. The weight vectors, w[index] is the point at
        which to evaluate the gradient.

index : Non-negative integer. Which variable the gradient is for.

Examples
--------
>>> import numpy as np
>>> from parsimony.functions.multiblock.losses import LatentVariableCovariance
>>>
>>> np.random.seed(42)
>>> X = np.random.rand(100, 150)
>>> Y = np.random.rand(100, 50)
>>> w = np.random.rand(150, 1)
>>> c = np.random.rand(50, 1)
>>> cov = LatentVariableCovariance([X, Y])
>>> grad = cov.grad([w, c], 0)
>>> approx_grad = cov.approx_grad([w, c], 0)
>>> np.allclose(grad, approx_grad)
True

Overrides: properties.MultiblockGradient.grad

L(self, w, index)

source code 

Lipschitz constant of the gradient with given index.

From the interface "MultiblockLipschitzContinuousGradient".

Overrides: properties.MultiblockLipschitzContinuousGradient.L