Skip to content
Snippets Groups Projects
Commit 19d66887 authored by vkarve2's avatar vkarve2
Browse files

Changed Sparsity Metric.

parent 3e082f8b
No related branches found
No related tags found
No related merge requests found
......@@ -55,9 +55,9 @@ def sort_WH(W0, H0):
def sparsity_metric(H):
def sparsity_column(column):
column = (column - column.max())/column.max()
column = column**2
return np.sum(column)
return sum([sparsity_column(i) for i in H.T])/np.product(H.shape)
sparse = np.linalg.norm(column)
return sparse/len(column)
return sum([sparsity_column(i) for i in H.T])/len(H.T)
def calculate_error(D, W, H):
......@@ -160,9 +160,7 @@ def factorize(data_array, rank, beta = None, threshold = 0.20, max_iter = 400, s
results = results.append(dict(zip(column_names, column_values)), ignore_index = True)
## Comment out the impose_L1_constraint for SPEEDS data
W, H = impose_L1_constraint(W, H)
error = calculate_error(D, W, H)
sparsity = sparsity_metric(H)
log.info('Error= %s, Sparsity= %s', error, sparsity)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment