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

Moved Spikeyness calculation from notebook to script.

parent e2cc87a6
No related branches found
No related tags found
No related merge requests found
All of the following runs were performed with seeded W and H.
Rank= 70, Threshold= 0.5, Beta= 1000
Iteration= 195, Error= 23.756524428, Sparsity= 0.77953485637
Error= 39.4664938566, Sparsity= 0.894401055224
Spikeyness= 0.694830048546 +- 0.12206727311
Percentage of zero entries in H 0.937588432419
Rank= 60, Threshold= 0.5, Beta= 1000
Iteration= 253, Error= 24.3432298654, Sparsity= 0.774516498794
Error= 39.4669297358, Sparsity= 0.893674445982
Spikeyness= 0.674227902795 +- 0.140883303958
Percentage of zero entries in H 0.93337677382
Rank= 50, Threshold= 0.5, Beta= 1000
Iteration= 187, Error= 25.6674883138, Sparsity= 0.724677771467
Error= 41.0225841279, Sparsity= 0.866354897485
Spikeyness= 0.685480900318 +- 0.126166137491
Percentage of zero entries in H 0.911963509991
Rank= 70, Threshold= 0.5, Beta= 2000
Iteration= 213, Error= 23.6911464254, Sparsity= 0.814180095816
Error= 38.1502355669, Sparsity= 0.912728500107
Spikeyness= 0.657531392813 +- 0.146041500254
Percentage of zero entries in H 0.948082412809
Rank= 60, Threshold= 0.5, Beta= 2000
Iteration= 214, Error= 24.5724601281, Sparsity= 0.787484552586
Error= 39.4079798471, Sparsity= 0.901314398479
Spikeyness= 0.645450103119 +- 0.128935090911
Percentage of zero entries in H 0.937351578338
Rank= 50, Threshold= 0.5, Beta= 2000
Iteration= 200, Error= 25.5916664602, Sparsity= 0.755849916225
Error= 40.3973114336, Sparsity= 0.883902202696
Spikeyness= 0.641419593729 +- 0.125137174258
Percentage of zero entries in H 0.922502172024
Rank= 70, Threshold= 0.5, Beta= 3000
Iteration= 189, Error= 23.9887706962, Sparsity= 0.81944166833
Error= 38.3702421277, Sparsity= 0.915190937537
Spikeyness= 0.668213382782 +- 0.175714355264
Percentage of zero entries in H 0.949298746432
Rank= 60, Threshold= 0.5, Beta= 3000
Iteration= 207, Error= 24.7230114016, Sparsity= 0.802759260588
Error= 39.3062473432, Sparsity= 0.908879226768
Spikeyness= 0.632785720459 +- 0.136641127466
Percentage of zero entries in H 0.941854908775
Rank= 50, Threshold= 0.5, Beta= 3000
Iteration= 211, Error= 25.5975656265, Sparsity= 0.776840096576
Error= 39.4146943169, Sparsity= 0.894206457924
Spikeyness= 0.621530120579 +- 0.139374591314
Percentage of zero entries in H 0.929304952215
Rank= 70, Threshold= 0.5, Beta= 0
Iteration= 285, Error= 23.537054973, Sparsity= 0.728575444028
Error= 40.5074293533, Sparsity= 0.864803954873
Spikeyness= 0.828005264916 +- 0.136428809667
Percentage of zero entries in H 0.921720243267
Rank= 50, Threshold= 0.5, Beta= 4000
Iteration= 198, Error= 25.7266195787, Sparsity= 0.781262496776
Error= 39.495107937, Sparsity= 0.896299865922
Spikeyness= 0.624696795607 +- 0.163498585964
Percentage of zero entries in H 0.930703735882
Rank= 50, Threshold= 0.5, Beta= 5000
Iteration= 195, Error= 25.8312299543, Sparsity= 0.788515400376
Error= 39.3447715646, Sparsity= 0.899773447249
Spikeyness= 0.624040384608 +- 0.174083198217
Percentage of zero entries in H 0.932953953084
Rank= 50, Threshold= 0.5, Beta= 6000
Iteration= 187, Error= 26.0090278047, Sparsity= 0.792829846133
Error= 39.5661809934, Sparsity= 0.902259746818
Spikeyness= 0.630432913411 +- 0.189080016811
Percentage of zero entries in H 0.934396177237
Rank= 50, Threshold= 0.5, Beta= 7000
Iteration= 193, Error= 26.1319179956, Sparsity= 0.801339015376
Error= 39.1617174376, Sparsity= 0.906129528842
Spikeyness= 0.636468337606 +- 0.203281521376
Percentage of zero entries in H 0.93719374457
Rank= 50, Threshold= 0.5, Beta= 8000
Iteration= 179, Error= 26.513574437, Sparsity= 0.797863491706
Sorting is not working correctly
Error= nan, Sparsity= 0.905187922934
Spikeyness= nan +- nan
Percentage of zero entries in H 0.936785403997
Rank= 50, Threshold= 0.5, Beta= 10000
Iteration= 188, Error= 26.7450059698, Sparsity= 0.809522297734
Sorting is not working correctly
Error= nan, Sparsity= 0.910893917553
Spikeyness= nan +- nan
Percentage of zero entries in H 0.940894874023
......@@ -31,6 +31,20 @@ def calculate_error(D, W, H):
norm_D = np.linalg.norm(D)
return np.linalg.norm(D - N(W@H))/norm_D*100
def spikeyness(W):
def spikeyness_column(column):
trend = W[:52*24*7, column].reshape(52,24*7)
return np.mean(np.nanstd(trend, axis=0))/np.nanmean(W[:, column])
spikey_mean = np.mean([spikeyness_column(sig) for sig in range(config.RANK)])
spikey_std = np.std([spikeyness(sig) for sig in range(config.RANK)])
return spikey_mean, spikey_std
def zeros_in_H(H):
# Percentage of zero entries in H
# Use this on H_axed
return sum(sum(H==0))/H.size
def impose_L1_constraint(W, H):
W2 = W/sum(W)
......@@ -38,7 +52,6 @@ def impose_L1_constraint(W, H):
return W2, H2
def axe_H(H, tail_cutoff = 0.4):
H2 = H.copy()
for i, column in enumerate(H.T):
......@@ -62,7 +75,7 @@ def sort_WH(W, H):
try:
assert ( np.linalg.norm(W@H2 - W2@H3) / np.linalg.norm(W@H2) ) < 0.01
except AssertionError:
log.critical('Sorting is not working correctly')
logger.critical('Sorting is not working correctly')
return W2, H3
return W2, H3
......
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