-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3ae4807
commit f8f4046
Showing
4 changed files
with
950 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 3, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# code from google/CCA: https://github.com/google/svcca\n", | ||
"\n", | ||
"import os, sys\n", | ||
"from matplotlib import pyplot as plt\n", | ||
"%matplotlib inline\n", | ||
"import numpy as np\n", | ||
"import pickle\n", | ||
"import pandas\n", | ||
"import gzip\n", | ||
"\n", | ||
"sys.path.append(\"..\")\n", | ||
"import cca_core" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"def _plot_helper(arr, xlabel, ylabel):\n", | ||
" plt.plot(arr, lw=2.0)\n", | ||
" plt.xlabel(xlabel)\n", | ||
" plt.ylabel(ylabel)\n", | ||
" plt.grid()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 4, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"adding eps to diagonal and taking inverse\n", | ||
"taking square root\n", | ||
"dot products...\n", | ||
"trying to take final svd\n", | ||
"computed everything!\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"# Toy Example of CCA in action\n", | ||
"\n", | ||
"# assume X_fake has 100 neurons and we have their activations on 1000 datapoints\n", | ||
"A_fake = np.random.randn(100, 2000)\n", | ||
"# Y_fake has 50 neurons with activations on the same 1000 datapoints\n", | ||
"# Note X and Y do *not* have to have the same number of neurons\n", | ||
"B_fake = np.random.randn(50, 2000)\n", | ||
"\n", | ||
"# computing CCA simliarty between X_fake, Y_fake\n", | ||
"# We expect similarity should be very low, because the fake activations are not correlated\n", | ||
"results = cca_core.get_cca_similarity(A_fake, B_fake, verbose=True)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.5.6" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
Oops, something went wrong.