https://github.com/tensorly/tensorly
Revision aaae58cc70f03ac357af64aa1300ab00eaf9bb6d authored by JeanKossaifi on 23 October 2016, 18:50:41 UTC, committed by JeanKossaifi on 23 October 2016, 18:50:41 UTC
1 parent 1e94ea4
Tip revision: aaae58cc70f03ac357af64aa1300ab00eaf9bb6d authored by JeanKossaifi on 23 October 2016, 18:50:41 UTC
Cosmetic changes
Cosmetic changes
Tip revision: aaae58c
_higher_order_moment.py
from ._khatri_rao import khatri_rao
def higher_order_moment(matrix, order=3):
"""Higher order moment of a matrix of observations
Computes the `order`-order moment of `matrix``
Each row of `matrix` represents a samples
(i.e. an observation)
Parameters
----------
matrix : 2D-array
array of shape (n_samples, n_features)
i.e. each row is a sample
order : int, optional
order of the moment to compute
"""
matrix = matrix - matrix.mean(axis=0)
n_features = matrix.shape[-1]
t = khatri_rao([matrix.T] * order).mean(axis=1)
return t.reshape([n_features] * order)
Computing file changes ...