Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
yuanli2333 committed Jun 30, 2019
1 parent 3ae4807 commit f8f4046
Show file tree
Hide file tree
Showing 4 changed files with 950 additions and 0 deletions.
96 changes: 96 additions & 0 deletions CCA.ipynb
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
}
Loading

0 comments on commit f8f4046

Please sign in to comment.