]> code.communitydata.science - cdsc_reddit.git/blob - similarities/wang_similarity.py
grid sweep selection for clustering hyperparameters
[cdsc_reddit.git] / similarities / wang_similarity.py
1 from similarities_helper import similarities
2 import numpy as np
3 import fire 
4
5 def wang_similarity(mat):
6     non_zeros = (mat != 0).astype(np.float32)
7     intersection = non_zeros.T @ non_zeros
8     return intersection
9
10
11 infile="/gscratch/comdata/output/reddit_similarity/tfidf/comment_authors.parquet"; outfile="/gscratch/comdata/output/reddit_similarity/wang_similarity_10000.feather"; min_df=1; included_subreddits=None; topN=10000; exclude_phrases=False; from_date=None; to_date=None
12     
13 def wang_overlaps(infile, outfile="/gscratch/comdata/output/reddit_similarity/wang_similarity_10000.feather", min_df=1, max_df=None, included_subreddits=None, topN=10000, exclude_phrases=False, from_date=None, to_date=None):
14
15     return similarities(infile=infile, simfunc=wang_similarity, term_colname='author', outfile=outfile, min_df=min_df, max_df=max_df, included_subreddits=included_subreddits, topN=topN, exclude_phrases=exclude_phrases, from_date=from_date, to_date=to_date)
16
17 if __name__ == "__main__":
18     fire.Fire(wang_overlaps)

Community Data Science Collective || Want to submit a patch?