Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
jbreffle authored Aug 26, 2017
1 parent 8543d27 commit 7856edb
Show file tree
Hide file tree
Showing 44 changed files with 235 additions and 0 deletions.
Binary file added exercises/c1/c1.pdf
Binary file not shown.
Binary file added exercises/c1/c1.ps.gz
Binary file not shown.
Binary file added exercises/c1/c1cd.tar.gz
Binary file not shown.
100 changes: 100 additions & 0 deletions exercises/c1/data/c10p1.mat
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
1.2610673e+00 8.7850842e-02
9.4870162e-01 -1.8085079e-02
8.6185491e-01 1.6224918e-01
9.5081336e-01 -4.3257720e-01
1.3874176e+00 -7.7076637e-02
1.4257554e+00 -2.1140316e-01
1.0510257e+00 -2.3929085e-01
8.6430210e-01 2.0747363e-01
1.0557558e+00 -4.4090904e-02
9.8515345e-01 -4.5922628e-01
1.2154257e+00 1.3510720e-01
1.2889587e+00 2.2091317e-01
1.3419986e+00 -1.2473362e-01
6.6064156e-01 2.8451805e-01
1.2035246e+00 8.0300324e-01
8.7489386e-01 4.1143334e-01
1.3307248e+00 -2.2338402e-01
9.9965170e-01 -2.7229713e-01
8.0970832e-01 -1.8176388e-01
1.1561395e+00 3.1659399e-01
9.6945682e-01 -1.8446872e-02
1.1501202e+00 1.1455769e-01
8.9451168e-01 3.9948466e-01
7.4866926e-01 6.2512980e-03
1.4240451e+00 -5.1108909e-02
9.5394331e-01 3.5143469e-01
8.5480809e-01 -1.4734469e-01
9.3359112e-01 -9.1376048e-02
9.3737253e-01 9.2936169e-02
7.7042668e-01 -7.7022002e-02
1.0234778e+00 -2.9261726e-01
1.3611381e+00 2.0925376e-01
6.5553227e-01 -4.0112295e-01
9.1105658e-01 -4.8095323e-01
1.1521568e+00 -2.3549257e-01
8.6928331e-01 4.8344866e-02
1.1996496e+00 5.3552165e-01
8.5463939e-01 9.0363593e-02
1.0673105e+00 -2.2429837e-02
1.3079029e+00 6.1442130e-01
1.1532697e+00 2.4437677e-01
5.1063739e-01 5.5802326e-02
1.1043312e+00 1.0781936e-01
1.2285890e+00 -4.1432114e-02
6.3112986e-01 6.9896014e-02
9.1630523e-01 -2.2843712e-01
9.3854954e-01 3.8855984e-02
1.1032298e+00 -1.4304489e-01
1.0082623e+00 8.2076036e-02
1.3657724e+00 -9.5120396e-02
1.6112417e-01 9.3146135e-01
1.2744314e-02 7.1172188e-01
-1.0664676e-01 1.3752386e+00
-8.9814343e-02 6.2681146e-01
-4.4419760e-01 6.8385513e-01
-2.0725695e-01 7.0481888e-01
2.3524013e-02 1.0151033e+00
1.3890694e-01 8.7296951e-01
-3.1440981e-01 1.0613184e+00
-1.3083182e-01 1.3129298e+00
1.3539111e-01 1.1399145e+00
-9.8466091e-02 1.3231128e+00
-4.4501379e-01 8.2839910e-01
5.9267664e-01 3.5780148e-01
2.5489893e-01 6.6979484e-01
-2.0199882e-01 1.0335235e+00
-4.2885576e-01 1.0911313e+00
1.0322712e-01 5.9400205e-01
-1.9723433e-01 1.3403960e+00
-1.1353115e-01 6.7319187e-01
4.0688787e-01 9.8696848e-01
-4.6796045e-02 6.6406917e-01
3.2124189e-01 1.3173497e+00
5.1243938e-03 9.1821940e-01
2.8407226e-01 1.0560155e+00
9.4868475e-02 9.3456735e-01
-9.5926837e-02 1.0247360e+00
4.0200412e-01 1.2523789e+00
2.4620030e-01 1.0425304e+00
2.0865607e-01 1.5049251e+00
-2.8119147e-01 1.2229519e+00
1.1669107e-01 1.2967161e+00
1.2690337e-01 9.1158256e-01
2.2537798e-01 1.1935403e+00
-9.9160040e-02 1.1949584e+00
-1.6107908e-01 8.4973897e-01
2.6860421e-01 9.4216399e-01
3.0917642e-01 9.6035139e-01
1.9981889e-03 1.1045532e+00
-1.7998092e-01 6.0799009e-01
4.0607064e-01 1.1784296e+00
2.2849174e-01 1.3944892e+00
-2.7332032e-01 1.3102919e+00
-4.0823356e-01 1.1200681e+00
-2.0742396e-01 1.3783053e+00
-1.6515944e-01 1.0489970e+00
-4.4035092e-01 1.6121930e+00
3.0303782e-01 1.0023180e+00
1.1252761e-02 5.4663902e-01
-4.0678274e-01 1.0435023e+00
Binary file added exercises/c1/data/c1p8.mat
Binary file not shown.
Binary file added exercises/c10/c10.pdf
Binary file not shown.
Binary file added exercises/c10/c10.ps.gz
Binary file not shown.
Binary file added exercises/c10/c10cd.tar.gz
Binary file not shown.
Binary file added exercises/c10/c10code.tar.gz
Binary file not shown.
1 change: 1 addition & 0 deletions exercises/c10/code/c10p10.m
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
% c10p10.m%% demonstration of the Helmholtz machine using the wake-sleep% algorithm. rand('state',105);ndim=4; % dimension of the square of barsndimsq=ndim^2;nu=400; % number of examplespbar=0.4; % probability that a given bar is onpout=0.9; % extra noise added at the endii=ones(1,ndim);oo=zeros(1,ndim);conv=zeros(ndimsq,ndim);for i=1:ndim conv((i-1)*ndim+(1:ndim),i)=ones(ndim,1);end bars=conv*(rand(ndim,nu)<pbar); % which bars are on in which examplesu=bars.*(rand(ndimsq,nu)<pout) + (1-bars).*(rand(ndimsq,nu)>pout); % generate output noisenhid=ndim+1; % number of hidden unitsW=zeros(nhid,ndimsq);G=zeros(ndimsq,nhid);g=zeros(nhid,1); % generative biases for vh=zeros(ndimsq,1); % generative biases for uw=zeros(nhid,1); % recognition biases for vsig=inline('1./(1+exp(-x))'); % sigmoid function mini=20; % mini-batches of 20 input cases at a timenits=100000;eta=0.1/mini; % learning ratefor it=1:nits %wake phase rp=randperm(nu); au=u(:,rp(1:mini)); % choose a random set of mini patterns v = rand(nhid,mini) < sig(W*au + repmat(w,1,mini)); % propagate u->v and sample gv = sig(g); % top down prediction of v g = g + eta*(v - repmat(gv,1,mini))*ones(mini,1); % delta rule for g gpu = sig(G*v + repmat(h,1,mini)); % top down prediction of u h = h + eta*(au - gpu)*ones(mini,1); % delta rule for h G = G + eta*(au - gpu)*v'; % delta rule for G sv = v; % for plotting %sleep phase gv = sig(g); % top down prediction of v v = rand(nhid,mini)<repmat(gv,1,mini); % top down sample of v gu = rand(ndimsq,mini) < sig(G*v + repmat(h,1,mini)); % top down sample of u rv = sig(W*gu + repmat(w,1,mini)); w = w + eta*(v - rv)*ones(mini,1); % delta rule for w W = W + eta*(v - rv)*gu'; % delta rule for W if (mod(it,200)==0) disp(sprintf('%d',it)); clf; colormap(gray); for i=1:nhid subplot(4,nhid,i); imagesc(reshape(G(:,i),ndim,ndim),[min(G(:)) max(G(:))]); set(gca,'xtick',[],'ytick',[]); title(num2str(sig(g(i)))); % title is gen prob colorbar; subplot(4,nhid,i+nhid); imagesc(reshape(W(i,:),ndim,ndim),[min(W(:)) max(W(:))]); set(gca,'xtick',[],'ytick',[]); colorbar; subplot(4,nhid,i+2*nhid); imagesc(reshape(u(:,rp(i)),ndim,ndim),[0 1]); set(gca,'xtick',[],'ytick',[]); title(rp(i)); % title is pattern number colorbar; subplot(4,nhid,i+3*nhid); imagesc(reshape(gpu(:,i),ndim,ndim),[0 1]); set(gca,'xtick',[],'ytick',[]); title(sprintf('%1d',sv(:,i))); % title is hidden unit state colorbar; end drawnow; endend
Expand Down
1 change: 1 addition & 0 deletions exercises/c10/code/c10p11.m
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
% c10p11.m%% demonstration of the Helmholtz machine using the wake-sleep% algorithm. rand('state',105);ndim=4; % dimension of the square of barsndimsq=ndim^2;nu=400; % number of examplespbar=0.5; % probability that a given bar is onpout=0.05; % extra noise added at the endii=ones(1,ndim);oo=zeros(1,ndim);conv=zeros(ndimsq,ndim);for i=1:ndim conv((i-1)*ndim+(1:ndim),i)=ones(ndim,1);end bars=conv*([rand(ndim/2,nu/2)<pbar zeros(ndim/2,nu/2); ... zeros(ndim/2,nu/2) rand(ndim/2,nu/2)<pbar]); % which bars are on in which examplesu=bars.*(rand(ndimsq,nu)>pout) + (1-bars).*(rand(ndimsq,nu)<pout); % generate output noise
Expand Down
1 change: 1 addition & 0 deletions exercises/c10/code/c10p6.m
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
% c10p6.m%% factor analysis exercisenu=500; % number of data pointsrandn('state',100); % to make the same as in the textgtrue=[1 ; 1 ; 1]; % since the underlying factor is identical in % each observable componentvtrue=randn(1,nu); u1=gtrue*vtrue + 0.5*randn(3,nu); % data for 10.4A and Bu2=u1;u2(2,:)=vtrue+3*randn(1,nu); % corrupt u_2 by more noiseC1=cov(u1'); % covariance matrix for u1C2=cov(u2'); % covariance matrix for u2 % the means are not very important since there % are so many data points.rot=[cos(pi/3) sin(pi/3) 0 ; -sin(pi/3) cos(pi/3) 0 ; 0 0 1] * ... [cos(pi/6) 0 sin(pi/6) ; 0 1 0 ; -sin(pi/6) 0 cos(pi/6)];
Expand Down
100 changes: 100 additions & 0 deletions exercises/c10/data/c10p1.mat
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
1.2610673e+00 8.7850842e-02
9.4870162e-01 -1.8085079e-02
8.6185491e-01 1.6224918e-01
9.5081336e-01 -4.3257720e-01
1.3874176e+00 -7.7076637e-02
1.4257554e+00 -2.1140316e-01
1.0510257e+00 -2.3929085e-01
8.6430210e-01 2.0747363e-01
1.0557558e+00 -4.4090904e-02
9.8515345e-01 -4.5922628e-01
1.2154257e+00 1.3510720e-01
1.2889587e+00 2.2091317e-01
1.3419986e+00 -1.2473362e-01
6.6064156e-01 2.8451805e-01
1.2035246e+00 8.0300324e-01
8.7489386e-01 4.1143334e-01
1.3307248e+00 -2.2338402e-01
9.9965170e-01 -2.7229713e-01
8.0970832e-01 -1.8176388e-01
1.1561395e+00 3.1659399e-01
9.6945682e-01 -1.8446872e-02
1.1501202e+00 1.1455769e-01
8.9451168e-01 3.9948466e-01
7.4866926e-01 6.2512980e-03
1.4240451e+00 -5.1108909e-02
9.5394331e-01 3.5143469e-01
8.5480809e-01 -1.4734469e-01
9.3359112e-01 -9.1376048e-02
9.3737253e-01 9.2936169e-02
7.7042668e-01 -7.7022002e-02
1.0234778e+00 -2.9261726e-01
1.3611381e+00 2.0925376e-01
6.5553227e-01 -4.0112295e-01
9.1105658e-01 -4.8095323e-01
1.1521568e+00 -2.3549257e-01
8.6928331e-01 4.8344866e-02
1.1996496e+00 5.3552165e-01
8.5463939e-01 9.0363593e-02
1.0673105e+00 -2.2429837e-02
1.3079029e+00 6.1442130e-01
1.1532697e+00 2.4437677e-01
5.1063739e-01 5.5802326e-02
1.1043312e+00 1.0781936e-01
1.2285890e+00 -4.1432114e-02
6.3112986e-01 6.9896014e-02
9.1630523e-01 -2.2843712e-01
9.3854954e-01 3.8855984e-02
1.1032298e+00 -1.4304489e-01
1.0082623e+00 8.2076036e-02
1.3657724e+00 -9.5120396e-02
1.6112417e-01 9.3146135e-01
1.2744314e-02 7.1172188e-01
-1.0664676e-01 1.3752386e+00
-8.9814343e-02 6.2681146e-01
-4.4419760e-01 6.8385513e-01
-2.0725695e-01 7.0481888e-01
2.3524013e-02 1.0151033e+00
1.3890694e-01 8.7296951e-01
-3.1440981e-01 1.0613184e+00
-1.3083182e-01 1.3129298e+00
1.3539111e-01 1.1399145e+00
-9.8466091e-02 1.3231128e+00
-4.4501379e-01 8.2839910e-01
5.9267664e-01 3.5780148e-01
2.5489893e-01 6.6979484e-01
-2.0199882e-01 1.0335235e+00
-4.2885576e-01 1.0911313e+00
1.0322712e-01 5.9400205e-01
-1.9723433e-01 1.3403960e+00
-1.1353115e-01 6.7319187e-01
4.0688787e-01 9.8696848e-01
-4.6796045e-02 6.6406917e-01
3.2124189e-01 1.3173497e+00
5.1243938e-03 9.1821940e-01
2.8407226e-01 1.0560155e+00
9.4868475e-02 9.3456735e-01
-9.5926837e-02 1.0247360e+00
4.0200412e-01 1.2523789e+00
2.4620030e-01 1.0425304e+00
2.0865607e-01 1.5049251e+00
-2.8119147e-01 1.2229519e+00
1.1669107e-01 1.2967161e+00
1.2690337e-01 9.1158256e-01
2.2537798e-01 1.1935403e+00
-9.9160040e-02 1.1949584e+00
-1.6107908e-01 8.4973897e-01
2.6860421e-01 9.4216399e-01
3.0917642e-01 9.6035139e-01
1.9981889e-03 1.1045532e+00
-1.7998092e-01 6.0799009e-01
4.0607064e-01 1.1784296e+00
2.2849174e-01 1.3944892e+00
-2.7332032e-01 1.3102919e+00
-4.0823356e-01 1.1200681e+00
-2.0742396e-01 1.3783053e+00
-1.6515944e-01 1.0489970e+00
-4.4035092e-01 1.6121930e+00
3.0303782e-01 1.0023180e+00
1.1252761e-02 5.4663902e-01
-4.0678274e-01 1.0435023e+00
Binary file added exercises/c2/c2.pdf
Binary file not shown.
Binary file added exercises/c2/c2.ps.gz
Binary file not shown.
Binary file added exercises/c2/c2cd.tar.gz
Binary file not shown.
Binary file added exercises/c2/c2code.tar.gz
Binary file not shown.
1 change: 1 addition & 0 deletions exercises/c2/code/c2p5.m
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
% mapping from cortex into the retinalam=1.2 % constants for the mapep0=1.0;[X,Y]=meshgrid(0.05:.01:3,-2:.01:2); % global coordinates for the cortexep=ep0*(exp(X/lam)-1); % eccentricitya=-(180*(ep0+ep).*Y)./(lam*ep*pi); % azimuthin=abs(a)<90; a=a.*(abs(a)<90)+90*(a>=90) - 90*(a<=-90); % take care of absurditiesclf;K=8;Theta=pi/6;Phi=0;s=cos(K*X*cos(Theta)+K*Y*sin(Theta)-Phi);subplot(2,2,1);imagesc(X(1,:),Y(:,1),s.*in);set(gca,'fontsize',18,'fontname','palatino');title('visual cortex');xlabel('X (cm)');ylabel('Y (cm)');daspect([1 1.5 1]);subplot(2,2,2);contourf(ep.*cos(a*2*pi/360),ep.*sin(a*2*pi/360),s,'w:');set(gca,'xlim',[0 12],'ylim',[-12 12]);set(gca,'fontsize',18,'fontname','palatino');title('visual space');daspect([1 1 1]);xlabel('degrees');ylabel('degrees');
Expand Down
Binary file added exercises/c2/data/c1p8.mat
Binary file not shown.
Binary file added exercises/c2/data/c2p3.mat
Binary file not shown.
Binary file added exercises/c3/c3.pdf
Binary file not shown.
Binary file added exercises/c3/c3.ps.gz
Binary file not shown.
Binary file added exercises/c3/c3cd.tar.gz
Binary file not shown.
Binary file added exercises/c3/c3code.tar.gz
Binary file not shown.
1 change: 1 addition & 0 deletions exercises/c3/code/c3p10.m
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
function [est,K,ind]=c3p10(stim,spk,nfft)%[est,K,sstim]=wf(stim,spk,nfft)%Finds the optimal decoding filter K to predict stim from spk using %matlab function spectrum with nfft frequencies%est is the resulting stimulus estimate%K is the filter%ind is the indices such that est approximmates stim(ind).spk=spk-mean(spk); % remove the mean of the spikesmstim=mean(stim); stim=stim-mstim; % remove the mean of the stimulusP=spectrum(spk,stim,nfft); % work out the various self- and % cross-spectral termsTxy=P(:,4); % the complex transfer function from X to Y -- % ie the FFT of the decoding filterT=[Txy ; conj(Txy((end-1):-1:2))]; % want the real-valued versionK=fftshift(real(ifft(T)));% shift to make it centeredest=fftfilt(K,spk); % use the fast filter algorithmest=est(nfft+1:end)+mstim; % get rid of the transientind=(nfft/2+1):(length(stim)-nfft/2); % the indices of stim that % match those of est
Expand Down
Binary file added exercises/c4/c4.pdf
Binary file not shown.
Binary file added exercises/c4/c4.ps.gz
Binary file not shown.
Binary file added exercises/c5/c5.pdf
Binary file not shown.
Binary file added exercises/c5/c5.ps.gz
Binary file not shown.
Binary file added exercises/c6/c6.pdf
Binary file not shown.
Binary file added exercises/c6/c6.ps.gz
Binary file not shown.
Binary file added exercises/c7/c7.pdf
Binary file not shown.
Binary file added exercises/c7/c7.ps.gz
Binary file not shown.
Binary file added exercises/c7/c7cd.tar.gz
Binary file not shown.
Binary file added exercises/c7/c7code.tar.gz
Binary file not shown.
1 change: 1 addition & 0 deletions exercises/c7/code/c7p5.m
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
% c7p5.m % % symmetric recurrent nonlinear networkM=[0 -1 ; -1 0]; % connection matrixh=[1 ; 1]; % inputiters=100; % maximum number of iterationseta=0.1; % Euler stepclf;subplot(1,2,1);hold on;beta=2.0; % high gain for the activation function % now step the starting conditions around the outside % of a grid v1=0;for v2=0:.25:3 c7p5sub(M,beta,h,[v1 ; v2],eta,iters); drawnow;endv2=0;for v1=0:.25:3 c7p5sub(M,beta,h,[v1 ; v2],eta,iters); drawnow;endv1=3;for v2=0:.25:3 c7p5sub(M,beta,h,[v1 ; v2],eta,iters); drawnow;endv2=3;for v1=0:.25:3 c7p5sub(M,beta,h,[v1 ; v2],eta,iters); drawnow;end % now label the graphaxis('square'); grid;title(sprintf('beta=%f',beta),'FontSize',20);xlabel('v_1','FontSize',16); ylabel('v_2','FontSize',16);subplot(1,2,2);hold on;beta=0.5; % low gain for the activation function % now step the starting conditions around the outside % of a grid v1=0;for v2=0:.25:3 c7p5sub(M,beta,h,[v1 ; v2],eta,iters); drawnow;endv2=0;for v1=0:.25:3 c7p5sub(M,beta,h,[v1 ; v2],eta,iters); drawnow;endv1=3;for v2=0:.25:3 c7p5sub(M,beta,h,[v1 ; v2],eta,iters); drawnow;endv2=3;for v1=0:.25:3 c7p5sub(M,beta,h,[v1 ; v2],eta,iters); drawnow;endaxis('square'); grid;title(sprintf('beta=%f',beta),'FontSize',20);xlabel('v_1','FontSize',16); ylabel('v_2','FontSize',16);
Expand Down
28 changes: 28 additions & 0 deletions exercises/c7/code/c7p5sub.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
function vtrace = c7p1sub(M,beta,h,vinit,eta,iters)
%vtrace = c7p1sub(M,beta,h,vinit,eta,iters)
%
%This function simulates a Hopfield network using simple Euler integration.
%
% M is the connection matrix (should be symmetric)
% beta is the gain of the activation function (tanh by befault)
% h is the bias
% vinit is the initial condition vector for the v's
% eta is the timestep for the Euler integration
% iters is the number of iterations to simulate
%
% vtrace is the v vector state of the network over time,
% one column per timestep in the simulation

N = size(M,1);
vtrace = zeros(N,iters);

vtrace(:,1) = vinit(:);

for i=2:iters
vtrace(:,i)=vtrace(:,i-1) + eta*(-vtrace(:,i-1) + ...
beta*max(M*vtrace(:,i-1) + h,0));
end

plot(vtrace(1,:),vtrace(2,:),'o',vtrace(1,:),vtrace(2,:));


Binary file added exercises/c8/c8.pdf
Binary file not shown.
Binary file added exercises/c8/c8.ps.gz
Binary file not shown.
Binary file added exercises/c9/c9.pdf
Binary file not shown.
Binary file added exercises/c9/c9.ps.gz
Binary file not shown.
Binary file added exercises/call.pdf
Binary file not shown.
Binary file added exercises/call.ps.gz
Binary file not shown.
Loading

0 comments on commit 7856edb

Please sign in to comment.