Question: Matlab Question please copy and paste the code in Matlab, it has the explanation for each code. Q2:we looked at population vector encoding and decoding
Matlab Question please copy and paste the code in Matlab, it has the explanation for each code.
Q2:we looked at population vector encoding and decoding based on 8 neurons with sinusoidal response. Replicate the finding from the class using 64 instead of 8 neurons, without changing other parameters, namely time resolution of 1ms, 50 trials for encoding, and the width of tuning curves is still 2000 data points. Describe your observations about the differences of the effect of increasing the number of neurons, in 4 lines.
this is the code:
clear all
%We are going to run MATLAB simulation of the Population vector encoding
%and decoding(non-parametric only) as covered in the class
% we start by simulating 8 neuronal cells,
%----------------------------PART 1
CellCount=8;
Discretization=10000;
Angles=linspace(-pi,pi,Discretization);%Divide the angular space into 10000 points
dt=1/1000;
%1. Create the firing rate profile for these 8 neurons in a loop
% The paper uses Gaussian profiles, but for this tutorial we will instead
% use a sinusoidal curve, for simplicity.
wave=2+2*cos(linspace(-pi,pi,2000));%This is the basic sin curve scaled up with 1500 data points
TuningCurves(1:CellCount,1:10000)=0;%Initialize firing rate to Nans
centerPoints=round(linspace(1001,9001,CellCount));
%The centerPoints are the indices where each of our 8 neurons will have
%maximum firing rate. So we will have their centers at 1000,2000... upto 9000
for n=1:CellCount
TuningCurves(n,centerPoints(n)-1000:centerPoints(n)+999)=wave;
end
%Here we have created sinusoidal waveforms of total width 1500 data points
%Note that the gap between 2 centers of sinusoids is 1000 and their widths
%are 1500 so they overlap for around 30% In the assignment we will
%investigate how this overlap affects decoding.
figure;plot(Angles,TuningCurves(:,:)');
xlabel('Angle in Radians')
ylabel('Firing Rate in Hz')
xlim([-pi pi])
%To get a better idea, plot just 1 FRProfile, using plot(Angles,FRProfiles(3,:)')
%You will see a neuron which has sinusoidal firing rate at the start, and
%then it stays at 1.
%-----------------------------------PART 2
%Create spikes for each of the neurons now and add them over 50 trials
N=50;
for n=1:CellCount
RandVector=rand(Discretization,N);
Spikes(:,:,n)=double(RandVector<(repmat(TuningCurves(n,:)',1,N))*dt);
end
%Now lets find the number of spikes at 0 degrees for each of the neuron.
%Which means around index of 5000
InputAngleInd=5000;
for n=1:CellCount
PopulationVector(n)=sum(sum(Spikes((InputAngleInd-50):(InputAngleInd+50),:,n)));
end
%For each neuron, we found how many total spikes did this neuron fire, over
%the 50 trials for 100 datapoints around the Stimulus index
%This is the population vector, the response of this population of 4
%neurons to the presented stimulus
figure;plot(Angles(centerPoints),PopulationVector,'.','MarkerSize',40)
xlabel('Angle in Radians')
xlim([-pi pi])
ylabel('Total spikes in 50 trials')
%So, in the plot created, there is 1 dot created for each neuron, and this
%corresponds to how many spikes this neuron would create, based on the
%stimulus presented.
%-------------------PART 3
% Now to decode this using non-parametric fitting
%The idea for decoding is the following: We consider stimuli at different
%places(angles in our case) and consider the response of all 8 cells based
%on their Firing Rate profiles for each of these
%loctions of stimuli which we are considering.
StimulusSpace=100:100:10000;%We will use 100 points
% Now we will write a double for loop, to compute the response of each of
% the 8 neurons to the 100 stimulus testing points as above
for m=1:length(StimulusSpace) %And each of the angle we are testing
for n=1:CellCount %For each neuron
TestingVectors(n,m)=TuningCurves(n,StimulusSpace(m));
%Find the value of tuningcurve of the nth cell at the location specified
%by the value in StimulusSpace's "m"th index
end
TestingVectors(:,m)=TestingVectors(:,m)/sum(TestingVectors(:,m));
%For each location where we test, normalize the TestingVector over
%All neurons
end
%Now to find the best fit, we will take the dot product between the
%response curve which we have, and these TestingVectors for each of the
%Angles in the stimulus space
for m=1:length(StimulusSpace)
Decoding(m)=dot(PopulationVector,TestingVectors(:,m));
end
%Finally plot the decoding curve, and your Population curve.
figure;plot(Angles(StimulusSpace),Decoding,'r');
hold on
plot(Angles(centerPoints),PopulationVector,'.','MarkerSize',40)
ylabel('Total spikes in 50 trials')
xlabel('Angle in Radians')
xlim([-pi pi])
[value,Index]=max(Decoding);
%The Index above will be the index in StimulusSpace where maximum dot
%product, or overlap existed between the observed PopulationVector, and the
%testingVectors which we had created.
%Hence the angle corresponding to this StimulusSpace index will be the decoded angle.
%For the plot, we create a line at this value of maximum dot product
line([Angles(StimulusSpace(Index)),Angles(StimulusSpace(Index))],ylim,'Color','k');
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
