Added transformer and separation NMF with documentation and demo.
MODIFY
demos/demo_transformer_nmf.py
demos/demo_transformer_nmf.py
@@ -24,51 +24,9 @@ def simple_example():
nussl_nmf.max_num_iterations = n_iter
nussl_nmf.distance_measure = nussl.DistanceType.DIVERGENCE
- # set up nimfa NMF
- V = mixture
- nimfa_nmf = nimfa.Nmf(V, max_iter=n_iter, rank=n_bases, update='divergence')
-
- # calculate errors
- errors = []
- num_iterations = 100
- for i in range(num_iterations):
# run NU NMF
nussl_nmf.run()
signals = nussl_nmf.recombine_calculated_matrices()
- #run nimfa NMF
- nmf_fit = nimfa_nmf()
- W = nmf_fit.basis()
- H = nmf_fit.coef()
-
- nimfa_est = np.dot(W, H)
- nussl_est = np.dot(nussl_nmf.templates, nussl_nmf.activation_matrix)
- error = np.abs(nussl_est - nimfa_est) / nimfa_est * 100
- errors.append(error.flatten())
-
- errors = np.array(errors).flatten()
- mean_error = np.mean(errors)
- std_dev_error = np.std(errors)
- print "mean", mean_error
- print "std", std_dev_error
- std_check = True
- num_over_std_dev = 0
- for error in errors:
- if error > (mean_error + (5 * std_dev_error)):
- num_over_std_dev += 1
- print num_over_std_dev
- if (num_over_std_dev/float(num_iterations)) > .05:
- std_check = False
- print (num_over_std_dev / float(num_iterations))
- print std_check
- # error statistics
-
-
- # print('nimfa estimate:\n%s\n\n' % nimfa_est)
- # print('nussl estimate:\n%s\n\n' % nussl_est)
- # print('Errors:\n%s' % error)
-
-
-
if __name__ == '__main__':
simple_example()
\ No newline at end of file

MODIFY
nussl/Nmf.py
nussl/Nmf.py
@@ -21,6 +21,18 @@ class NMF(separation_base.SeparationBase):
References:
[1] Lee, Daniel D., and H. Sebastian Seung. "Algorithms for non-negative matrix factorization."
Advances in neural information processing systems. 2001.
+
+ Parameters:
+ input_matrix (np.array): The audio signal matrix to factor into template and activation matrices
+ num_templates (int): The rank of the templates matrix
+ activation_matrix (np.array): An optional seed for the activation matrix
+ templates(np.array): An optional seed for the templates matrix
+ distance_measure(str): Specifies to use euclidean or divergence distance metrics
+ should_update_template(bool): Whether the template matrix should be updated for another iteration
+ should_update_activation (bool): Whether the activation matrix should be updated for another iteration
+
+ Examples:
+ :ref:'The Transformer NMF Demo Example <transformer_nmf_demo>'
"""
def __str__(self):

MODIFY
nussl/transformer_nmf.py
nussl/transformer_nmf.py
@@ -19,26 +19,17 @@ class TransformerNMF(object):
[1] Lee, Daniel D., and H. Sebastian Seung. "Algorithms for non-negative matrix factorization."
Advances in neural information processing systems. 2001.
- :param: input_matrix: The matrix to factor into template and activation matrices
- :type: input_matrix: 2D numpy array
-
- :param: num_templates: The rank of the templates matrix
- :type: num_templates: int
-
- :param: activation_matrix: An optional seed for the activation matrix
- :type: activation_matrix: 2D numpy array
-
- :param: templates: An optional seed for the templates matrix
- :type: templates: 2D numpy array
-
- :param: distance_measure: Specifies to use euclidean or divergence distance metrics
- :type: distance_measure: str
-
- :param: should_update_template: Whether the template matrix should be updated for another iteration
- :type: should_update_template: bool
-
- :param: should_update_activation: Whether the activation matrix should be updated for another iteration
- :type: should_update_activation: bool
+ Parameters:
+ input_matrix (np.array): The matrix to factor into template and activation matrices
+ num_templates (int): The rank of the templates matrix
+ activation_matrix (np.array): An optional seed for the activation matrix
+ templates(np.array): An optional seed for the templates matrix
+ distance_measure(str): Specifies to use euclidean or divergence distance metrics
+ should_update_template(bool): Whether the template matrix should be updated for another iteration
+ should_update_activation (bool): Whether the activation matrix should be updated for another iteration
+
+ Examples:
+ :ref:'The Transformer NMF Demo Example <transformer_nmf_demo>'
"""
def __init__(self, input_matrix, num_templates,
@@ -91,8 +82,20 @@ class TransformerNMF(object):
No inputs. N must be set prior to calling this function.
- Returns an activation matrix (in a 2d numpy array)
- and a set of template vectors (also 2d numpy array).
+ Returns:
+ * **activation_matrix** (*np.array*) - a 2D numpy matrix containing the estimated activation matrix
+ * **templates** (*np.array*) - a 2D numpy matrix containing the estimated templates
+
+ Example:
+ ::
+ input_matrix = np.random.rand(10, 10)
+ nussl_nmf = nussl.TransformerNMF(input_matrix, num_templates=2,
+ activation_matrix=None, templates=None, distance_measure="euclidean",
+ should_update_template=None, should_update_activation=None)
+
+ nussl_nmf.run()
+ signals = nussl_nmf.recombine_calculated_matrices()
+
"""
if self.input_matrix is None or self.input_matrix.size == 0:

Added transformer and separation NMF with documentation and demo.