Skip to content

Commit

Permalink
Fixed unitary tests
Browse files Browse the repository at this point in the history
  • Loading branch information
qferre committed Oct 13, 2020
1 parent 15ed84c commit 654a5a5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
5 changes: 5 additions & 0 deletions pygtftk/stats/intersect/modl/apriori.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ def __init__(self, min_support):
To run apriori, use the following steps, if X is a matrix with one line per transaction, one column per item and a '1' if the item is presnet in the transaction :
>>> X = [[1,1,0],[1,0,1]]
>>> names = ['A','B','C']
>>> from pygtftk.stats.intersect.modl.apriori import Apriori, matrix_to_list_of_transactions, apriori_results_to_matrix
>>> transactions = matrix_to_list_of_transactions(X, names)
>>> myminer = Apriori(min_support = 0)
>>> myminer.run_apriori(transactions)
Expand Down Expand Up @@ -153,7 +156,9 @@ def matrix_to_list_of_transactions(x, names):
From a matrix with one line per transaction and one column per element with 1 if present and 0 if absent,
returns a list of transaction
"""
# Enforce type
names = np.array(names)
x = np.array(x)

# Get the list of all nonzero elements in each row
result = []
Expand Down
10 changes: 2 additions & 8 deletions pygtftk/stats/intersect/modl/subroutines.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,8 @@ def normalize_and_jitter_matrix_rows(X, normalize = True, jitter = True):
>>> from pygtftk.stats.intersect.modl.subroutines import normalize_and_jitter_matrix_rows
>>> D = np.array([[1,1,0],[0,1,0],[0,1,1]])
>>> Dc = normalize_and_jitter_matrix_rows(D)
>>> Dc_theory = [[0, 1, 0], [3.534E-4, 7.071E-1, 7.071E-1], [7.071E-1, 7.071E-1, 5E-4]]
>>> npt.assert_almost_equal(Dc, Dc_theory, decimal = 4)
>>> Dc_theory = [[0, 1, 0], [7.0736E-5, 7.07107E-1, 7.07107E-1], [7.07107E-1, 7.07107E-1, 9.99859E-05]]
>>> npt.assert_almost_equal(Dc, Dc_theory, decimal = 5)
"""

X = np.array(X) # Enforce NumPy array
Expand Down Expand Up @@ -449,10 +449,4 @@ def manhattan_dist_with_sparsity(X_true, X_rebuilt, code):
best_words = list(set(dictionary))
best_words.remove(tuple([0] * nb_features))

# If the words had been normalized, un-normalize them.
if normalize_words:
best_words = np.array(best_words).astype(bool).astype(int)



return best_words

0 comments on commit 654a5a5

Please sign in to comment.