Skip to content

Commit

Permalink
Updated data_path.py and added documentation to analyze_similarity.py
Browse files Browse the repository at this point in the history
  • Loading branch information
yingtluo committed Dec 13, 2015
1 parent ac9060d commit aa6229f
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 3 deletions.
52 changes: 49 additions & 3 deletions code/stat159lambda/reproduction/analyze_similarity.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,58 @@


def get_pairwise_correlations():
"""
Finds and returns the paths to the correlations of all possible pairs of
subjects (if the paths exist)
Parameters
----------
None
Returns
-------
paths : string array
"""
subject_pairs = itertools.combinations(SUBJECTS, 2)
return [np.load(dp.get_correlation_path(subj_a, subj_b))
for subj_a, subj_b in subject_pairs]


def get_correlations(aggregation='pooled'):
"""
Calculates correlations either using means or the pooled data, depending
on specification
Parameters
----------
aggregation : string (optional)
Returns
-------
correlations : array
"""
correlations = np.concatenate(tuple(get_pairwise_correlations()))
if aggregation == 'mean':
correlations = get_pairwise_correlations()
correlations = np.mean(np.matrix(correlations).T, axis=1)
correlations = correlations[~np.isnan(correlations)]
return np.squeeze(np.asarray(correlations))
if aggregation == 'pooled':
correlations = np.concatenate(tuple(get_pairwise_correlations()))
return correlations[~np.isnan(correlations)]
return correlations[~np.isnan(correlations)]


def save_correlation_histogram(aggregation):
"""
Plots and saves the histogram of all correlations calculated by the
specified aggregation into figures folder
Parameters
----------
aggregation : string
Returns
-------
None
"""
plt.hist(get_correlations(aggregation), bins=40)
output_file_name = '{0}/figures/{1}_correlation_histogram.png'.format(
REPO_HOME_PATH, aggregation)
Expand All @@ -40,6 +74,18 @@ def save_correlation_histogram(aggregation):


def save_correlation_percentiles(aggregation):
"""
Calculates and saves the correlation percentiles calculated by the
specified aggregation into figures folder
Parameters
----------
aggregation : string
Returns
-------
None
"""
correlations = get_correlations(aggregation)
results = [[p, np.percentile(correlations, p)] for p in PERCENTILES]
output_file_name = '{0}/figures/{1}_correlation_percentiles.txt'.format(
Expand Down
16 changes: 16 additions & 0 deletions code/stat159lambda/utils/data_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,19 @@ def get_2d_path(subj_num):
"""
return '{0}/data/processed/sub{1}_rcds_2d.npy'.format(REPO_HOME_PATH,
subj_num)

def get_correlation_hist_path(aggregation):
"""
Derives the absolute path to the correlations calculated by using either
the means or pooled data
Parameters
----------
aggregation : string
Returns
-------
path : string
"""
return '{0}/figures/{1}_correlation_histogram.png'.format(REPO_HOME_PATH,
aggregation)

0 comments on commit aa6229f

Please sign in to comment.