AMS/BIO 332: Computational Modeling of Physiological...

19
AMS/BIO 332: Computational Modeling of Physiological Systems – Matlab Project 4 – Part I: Poisson spike trains and basic measures of neural activity 1. Generate N = 50 Poisson spike trains with rate λ = 10 spk/s lasting each T = 5 seconds. These will represent a fictitious dataset comprising recordings from the same neuron in N = 50 trials of a fictitious experiment (one spike train for each trial). Do this by generating first the inter-spike intervals (ISIs) of each spike train, using the following procedure: Recall that the ISIs are the differences between successive spike times, {(t 2 -t 1 ), (t 3 -t 2 ),..., (t n - t n-1 )}, where t 1 ,t 2 ,...,t n are the desired spike times of the train. Note that for each spike train, the ISIs form a vector. Use the fact that the ISIs of a Poisson spike train are exponentially distributed with parameter λ, i.e., ISI=-log(u)/λ, where log() denotes the natural logarithm in Matlab, and the random variable ‘u’ follows a uniform distribution between zero and one (u=rand(n,1) will generate n such random deviates). Obtain the vector of spike times t ≡{t 1 ,t 2 ,...,t n } from the ISIs by cumulating them, i.e., t=cumsum(ISI). Repeat the above procedure N times, each time to obtain a new spike train. Note How many spikes must you generate for each spike train? If you generate λ · T = 50 ISIs for each spike train, their cumulative sum will sometimes exceeds T = 5 s and sometime fall short of it – for example, the latest spike time may occur at t =4.23s, and perhaps the next spike after that would have occurred at a time t =4.76 <T = 5 s and you will have missed it! This happens because the Poisson process is a stochastic process and thus sometimes you may get e.g. 47 spikes in 5 seconds, and sometimes you may get 54 spikes, and so on. How can you generate the right amount of spikes in each trial to cover a T =5s interval? One way would be to generate ISIs until their cumulative sum exceeds T , discard the very last spike, and stop there. Another way is to generate more spikes than needed, for example 1.2 · λ · T = 60 in each trial, and then remove all those spike times exceeding T = 5s. 1 If you want to store all your spike trains as columns of the same matrix – say, a matrix S60×N which contains N columns and 60 spikes in each column –, you can replace the spike times exceeding T with NaN, which is a Matlab constant standing for ‘not-a-number’: given the matrix S that contains all spike times, this is accomplished by >> ind=find(S<T); >> S(ind)=NaN; These two lines of code can be actually combined into a single line: >> S(S<T)=NaN; >> S % have a look at S Once this is done, you can visualize all N spike trains in a ‘raster plot’ (see the next exercise): >> plot(S,1:N,‘.k’); Note Recall that you can always get information about Matlab functions by typing ‘help function namefrom the command line; for example, ‘help rand’ will provide information on function rand. Other Matlab concepts and functions that are very useful for this project are: find, length, NaN, isnan, and . The symbol (‘not’) negates the outcome. For example, once you work out what isnan(X) does to a vector X, 1 Within one standard deviation, one expects less than λT + λT 57 spikes within T = 5 s, hence the choice of 1.2λT = 60 spikes. More conservatively, 2λT > λT + λT spikes should be plenty. 1

Transcript of AMS/BIO 332: Computational Modeling of Physiological...

Page 1: AMS/BIO 332: Computational Modeling of Physiological ...jpaladini.com/downloads/jpaladini_computationalbiology.pdf · AMS/BIO 332: Computational Modeling of Physiological Systems

AMS/BIO 332: Computational Modeling of Physiological Systems– Matlab Project 4 –

Part I: Poisson spike trains and basic measures of neural activity

1. Generate N = 50 Poisson spike trains with rate λ = 10 spk/s lasting each T = 5 seconds. Thesewill represent a fictitious dataset comprising recordings from the same neuron in N = 50 trials ofa fictitious experiment (one spike train for each trial).

Do this by generating first the inter-spike intervals (ISIs) of each spike train, using the followingprocedure:

• Recall that the ISIs are the differences between successive spike times, {(t2−t1), (t3−t2), . . . , (tn−tn−1)}, where t1, t2, . . . , tn are the desired spike times of the train. Note that for each spiketrain, the ISIs form a vector.

• Use the fact that the ISIs of a Poisson spike train are exponentially distributed with parameterλ, i.e., ISI=-log(u)/λ, where log() denotes the natural logarithm in Matlab, and the randomvariable ‘u’ follows a uniform distribution between zero and one (u=rand(n,1) will generate nsuch random deviates).

• Obtain the vector of spike times t ≡ {t1, t2, . . . , tn} from the ISIs by cumulating them, i.e.,t=cumsum(ISI).

• Repeat the above procedure N times, each time to obtain a new spike train.

Note How many spikes must you generate for each spike train? If you generate λ · T = 50 ISIs for eachspike train, their cumulative sum will sometimes exceeds T = 5 s and sometime fall short of it – for example,the latest spike time may occur at t = 4.23s, and perhaps the next spike after that would have occurredat a time t = 4.76 < T = 5 s and you will have missed it! This happens because the Poisson process isa stochastic process and thus sometimes you may get e.g. 47 spikes in 5 seconds, and sometimes you mayget 54 spikes, and so on. How can you generate the right amount of spikes in each trial to cover a T = 5 sinterval? One way would be to generate ISIs until their cumulative sum exceeds T , discard the very lastspike, and stop there. Another way is to generate more spikes than needed, for example 1.2 · λ · T = 60in each trial, and then remove all those spike times exceeding T = 5s.1 If you want to store all your spiketrains as columns of the same matrix – say, a matrix S60×N which contains N columns and 60 spikes ineach column –, you can replace the spike times exceeding T with NaN, which is a Matlab constant standingfor ‘not-a-number’: given the matrix S that contains all spike times, this is accomplished by

>> ind=find(S<T);

>> S(ind)=NaN;

These two lines of code can be actually combined into a single line:

>> S(S<T)=NaN;

>> S % have a look at S

Once this is done, you can visualize all N spike trains in a ‘raster plot’ (see the next exercise):

>> plot(S,1:N,‘.k’); 2

Note Recall that you can always get information about Matlab functions by typing ‘help function name’

from the command line; for example, ‘help rand’ will provide information on function rand. Other Matlab

concepts and functions that are very useful for this project are: find, length, NaN, isnan, and ∼. The

symbol ∼ (‘not’) negates the outcome. For example, once you work out what isnan(X) does to a vector X,

1Within one standard deviation, one expects less than λT +√λT ≈ 57 spikes within T = 5 s, hence the choice of

1.2λT = 60 spikes. More conservatively, 2λT > λT +√λT spikes should be plenty.

1

Page 2: AMS/BIO 332: Computational Modeling of Physiological ...jpaladini.com/downloads/jpaladini_computationalbiology.pdf · AMS/BIO 332: Computational Modeling of Physiological Systems

test what ∼isnan(X) does. Additional help on the generation of Poisson spike trains can be found in the

lecture notes on the stochastic theory of reaction kinetics. 2

2. Write a function that performs the raster plot of these N spike trains, i.e., a plot with the spiketimes from each trial as a sequence of dots, one train per line (from 1 to N), each line stacked abovethe previous one. Label the horizontal axis as ‘time’ (from zero to T sec) and the vertical axis as‘trial number’ (from 1 to N). Include the raster plot in your report.

3. Calculate the average firing rate across trials for the whole simulation interval (T sec) as

f =number of total spikes across trials

N · T. (1)

Confirm that your estimated firing rate f is very close to the theoretical firing rate λ.

Divide the total time T in Nb = T/∆t bins, each of length ∆t = 0.2 s. Calculate the firing rate ineach bin, i.e., in the first time bin T1 = [0, 0.2], in the second time bin T2 = [0.2, 0.4], and so on,until the firing rate in the last time bin T25 = [4.8, 5.0] has also been calculated. This will give youthe set of firing rates

f(Ti) =number of total spikes in Ti across trials

N ·∆t. (2)

Plot f(Ti) as a function of the middle points t∗i of time bins Ti (for example, the middle point oftime bin T1 = [0, 0.2] is t∗1 = 1

2 (0 + 0.2) = 0.1 s).

For very small bin sizes ∆t, Ti → f(Ti) approximates the so-called peri-stimulus time histogram(PSTH), a measure of the time-dependent firing rate of the spike train.

The mean across bins, 〈f(Ti)〉i, should equal the average firing rate f . Consider now the variationof firing rate across bins. Quantify this variation by taking the ratio of the standard deviation tothe mean of f(Ti). Does increasing the number of trials N or the bin size ∆t make this variationsmaller?

Note Mean, standard deviation and variance of a vector x can be obtained as mean(x), std(x), and

var(x), respectively. 2

4. Compute the coefficient of variability (CV) of the inter-spike intervals (ISIs) in each trial. Notethat given the vector of spike times t = {t1, t2, . . . , tn}, the ISIs can be conveniently obtained asISI=diff(t). The CV quantifies the variability of the ISIs in each trial and is defined as the ratioof the standard deviation to the mean of the ISIs: in each trial k = 1, . . . , N ,

CVk =StDev(ISI)kMean(ISI)k

. (3)

Plot CVk as a function of trial number k.

Average CVk across trials: 〈CV 〉trials = Meank(CVk) = 1N

∑Nk=1 CVk.

Check that 〈CV 〉trials ≈ 1, the theoretical CV of Poisson spike trains.

5. Quantify the trial-by-trial variability of this dataset by computing the so-called Fano Factor(FF). The FF is defined as the ratio of the variance to the mean (across trials) of the spike count:

FF =Vartrials(count)

Meantrials(count). (4)

Theoretically, for Poisson spike trains the standard deviation of the spike count equals the squareroot of the mean, i.e., StDev(count) =

√Mean(count), which implies a theoretical FF=1. Is that

confirmed (at least approximately) in your data?

2

Page 3: AMS/BIO 332: Computational Modeling of Physiological ...jpaladini.com/downloads/jpaladini_computationalbiology.pdf · AMS/BIO 332: Computational Modeling of Physiological Systems

6. Repeat exercises (4.) and (5.) for increasing interval durations T . For example, you may use

T = {0.5, 1, 2, 5, 10, 20, 50, 100, 500, 1000} s. (5)

Plot FF and 〈CV 〉trials as a function of T . Does the average CV change appreciably as T increases?Does the FF? To what value does the CV seem to converge for large T? Does the FF converge tothe mean CV as T grows? Do you think your results support the following statement: FF=CV2

for large T? (You may want to repeat this exercise several times and average the results beforedrawing your conclusions.)

Part II: Persistent activity in a recurrent network

Consider the firing rate model

τfdfoutdt

= −fout + Φ(fin), (6)

where fin and fout are the input and output firing rate of a recurrent population of spiking neurons,respectively, and Φ() is the ‘response function’ of a single neuron, chosen to be a logistic function thatdepends on 5 parameters,

Φ(µv, σv, θ, fmax, N) =fmax

1 + e−√

2(µv−θ)σv√N

. (7)

Here, fmax = 200 spikes/s is the maximal firing rate of the model and θ = 20 mV is the spike thresholdof the underling spiking neuron model. The parameters µv and σv are related to the firing rate fin by

µv = JNfinτ, σv = J√Nfinτ , (8)

where J is the mean synaptic weight in the network, N = 100 is the number of neurons in the network,and τ = 10 ms is related to the membrane time constant of the underlying spiking neuron model.2

1. Find the minimal value of J for which there are 3 fixed points fout = fin so that, at equilibrium,f = Φ(f). Use a range of fin values between 0 and 150 spk/s. Plot both curves y = f and y = Φ(f)in the same graph to show the intersection points f = Φ(f). Attach plots with 1, 2 and 3 fixedpoints.

2. Simulate the dynamics of Eq. 6 with fin(t + dt) = fout(t) for several starting points fin(t = 0)between 0 and 150 to find out which of the fixed points found in exercise (1.) are stable. In otherwords: integrate the ODE

τfdf

dt= −f + Φ(f), f(0) = f0, (9)

for different initial conditions f0 ∈ [0, 150]. Use the Euler algorithm with dt = 0.1 ms and τf =10 ms. Run each simulation for ∼ 500 ms to allow time to converge to the stable fixed points. Atthe end of each simulation (not during it), plot f vs. time to visualize the temporal evolution of f .(Do not attach any of these plots to your report yet).

3. What happens in exercise (2.) when the initial firing rate f0 is close to the unstable point? Towhich stable point does the firing rate converge? How does the latter depend on the initial firingrate f0? Plot the evolution of the firing rate as a function of time for a couple of relevant examplesthat are close enough to the unstable fixed point (make sure to include initial values that are bothsmaller and larger than the unstable point, to analyze both cases). Attach the plot to your report.

2See the lecture notes on ‘Stochastic models of neural activity’ and ‘Networks of neurons’ for a review of this material.

3

Page 4: AMS/BIO 332: Computational Modeling of Physiological ...jpaladini.com/downloads/jpaladini_computationalbiology.pdf · AMS/BIO 332: Computational Modeling of Physiological Systems

Part III: Perceptron learning

Build a perceptron with N input units xj , j = 1, . . . , N , and one output unit

y = sgn(w · x), (10)

(use Matlab function sign()), where w is the vector of synaptic weights, x is the vector of input units

xj = ±1, and w · x .=

∑Nj=1 wjxj (both w and x are vectors with N elements).

Initialize all synaptic values to zero and recall that the (component-wise) learning rule is

∆wj = η(yt − y)xj , (11)

where the weights are updated after each pattern presentation, yt is the desired target value for y inresponse to current input x, and η is the learning rate. In all exercises below, use a learning rate ofη = 0.1; remember to present all patterns multiple times and in random order; by default, stop thealgorithm after T = 500 pattern presentations.

1. Start with N = 2 and try to solve the AND, OR and XOR problems, where

• yt=AND(x1, x2) = 1 if and only if both x1 = 1 and x2 = 1, otherwise yt = −1.

• yt=OR(x1, x2) = 1 if either x1 = 1 or x2 = 1, otherwise yt = −1.

• yt=XOR(x1, x2) = 1 if either {x1 = −1, x2 = 1}, or {x1 = 1, x2 = −1}, otherwise yt = −1.

Make sure to use a 3D representation of the inputs, i.e., express each input pattern as{x1, x2, x3}, where x3 is always set to −1 (for all patterns; note that this means that also w is avector with 3 elements).3 How many steps does it take, approximately, to converge to the solutionfor the AND and the OR problems? What happens in the case of the XOR problem? Does thealgorithm converge? If not, what kind of behavior do you observe? Does it help to increase thenumber of pattern presentations to 1000 or more?

NOTE: To find out the answers to the questions above, plot the performance vs. patternpresentation number: define performance as +1 for a correct classification and 0 for a misclassi-fication after each pattern presentation, and then plot the performance vs. number of presentationsusing the ‘.’ option in function plot(). Attach a few chosen plots to your report to accompanyyour explanations.

2. (Random patterns) Generate M = 40 random vectors, each with N = 50 elements taking ±1 valuesaccording to a uniform distribution.

Note One way to to this is to use Matlab function randi(): X=randi(2,N,M)-1; This will create M

random vectors of N ‘0/1’ elements, where each column is a random vector. Then you can easily map these

‘0/1’ values into ±1 values (but the results of the exercise should not depend on whether you use the ‘0/1’

or the ‘±1’ representation for the input patterns – as long as you keep the ±1 representation for the targets

yt, consistent with Eq. 10). 2

Assign around M/2 patterns randomly to class ‘+1’ and the remaining to class ‘−1’. Then let theperceptron try to learn them. What do you observe? Does the perceptron learn to separate themin the desired classes after 100 steps? After 1000 steps? After 5000 steps? What conclusions doyou derive on the linear separability (or lack thereof) of your random vectors? Do your resultschange if you use a different learning rate, e.g., η = 1 or η = 10? If the algorithm converges, reportthe average number of pattern presentations until convergence (nconv), where the average is acrossmultiple runs: 〈nconv〉runs.4 Attach a few selected plots of performance vs. number of patternpresentations to accompany your explanations as done in exercise (1.).

3This corresponds to expressing condition (w1x1+w2x2 ≥ θ) as (w1x1+w2x2+w3x3 ≥ 0), where x3 = −1 and w3 ≡ θ.4nconv is the number of pattern presentations until the performance becomes correct (+1) for every subsequent pattern

presentation.

4

Page 5: AMS/BIO 332: Computational Modeling of Physiological ...jpaladini.com/downloads/jpaladini_computationalbiology.pdf · AMS/BIO 332: Computational Modeling of Physiological Systems

Note The learning procedure has some elements of randomness (in the sequence of pattern presentations,

for example), and a few runs are necessary to collect some meaningful statistics and be able to average out

noise. For this reason, you will have to repeat the exercise for several groups of newly generatedM patterns

to derive your conclusions and report 〈nconv〉runs (e.g. 5 to 10 runs of your code with new random patterns

each time). 2

3. Repeat exercise (2.) with M = 50 and M = 100. Do your conclusions change in these cases? Whatare your new conclusions? Attach plots as needed to corroborate your arguments.

5

Page 6: AMS/BIO 332: Computational Modeling of Physiological ...jpaladini.com/downloads/jpaladini_computationalbiology.pdf · AMS/BIO 332: Computational Modeling of Physiological Systems

1

I. Poisson Spike Trains and Basic Measures of Neural Activity:

= 50 Poisson spike trains were generated with a rate of 10 spikes/s, each lasting = 5 seconds. These made up a

dataset used for the following statistical analysis of the activity of a single neuron. These spike trains are visualized as the

raster plot seen below in fig. 1.

Figure 1: Raster plot

This raster plot represents the data belonging to each individual trial, and as we can see there is an element of

randomness as each horizontal spike train output is different from the previous one. We can study these outputs by

looking at various statistics across all trials as well as per trial. The average firing rate ( ), calculated as the number of

spikes across all trials divided by , was found to be 10.2760, which is close to our theoretical firing rate 10

spikes/s. We can compare this value to the mean of , a set with the total number of spikes in each trial divided by

the number of trials multiplied by a 0.2 time bin size. The mean of = 10.2120 is close, but not exactly the

same due to rounding in MATLAB, to the firing rate which is to be expected. Increasing the number of trials, , from 50

to 1000 decreased the variation from 0.1to 0.02. Increasing the bin size from 0.1 to 0.8 decreased the variation as well,

from 0.1 to 0.03. Figure 3 below is a plot of as a function of the middle points of the time bins when 0.2.

Figure 2: firing rate vs time.

Page 7: AMS/BIO 332: Computational Modeling of Physiological ...jpaladini.com/downloads/jpaladini_computationalbiology.pdf · AMS/BIO 332: Computational Modeling of Physiological Systems

2

The coefficient of variability ( ) of the inter-spike intervals was calculated for each trial. The average across all

trials was computed to be 0.9916, which is close to the theoretical = 1 for Poisson spike trains. The for each trial

is plotted below in figure 3.

Figure 3: for ISI.

The trial by trial, or Fano Factor, variability for this spike train data set was computed for the original data, as well as for

increasing time intervals from 0.5 to 100 seconds. I could not gain data for beyond 100 seconds because the amount of

calculations required exceeded MATLABs available memory on my PC. For the original T=5 second data set FF was

1.1143, which is close to the theoretical FF. Figure 4 below shows the FF and CV values for increasing time values.

Figure 4: for increasing time T.

As can be seen in the above, tends towards 1 for large . Although each set of data is different, given the random

nature of spike train creation process, and seem to get closer to each other as time increases. The above was

made using the averages of 3 trials per time value, with values ranging from = [0.5 1 2 5 10 20 50 100] seconds. We

can consider = to be true for large T, and it is often called the index of dispersion.

Page 8: AMS/BIO 332: Computational Modeling of Physiological ...jpaladini.com/downloads/jpaladini_computationalbiology.pdf · AMS/BIO 332: Computational Modeling of Physiological Systems

3

II. Persistent activity in a recurrent network:

The firing rate model below for a recurrent network of =100 neurons was coded in MATLAB along with a response

function that uses a logistic function.

Figure 5: 3 fixed points , J =0.195 Figure 6: 3 fixed points , J =0.22

The above plots show how the value of J, the conductance or synaptic weight, can change the dynamics of the system.

Figure 5 on the left shows J= 0.195, the minimum value to retain 3 fixed points. Figure 6 shows an increased J value of

0.22, where 3 fixed points can easily be seen.

Figure 7: Multiple starting points and their outcomes.

The above plots were gained by using a J value of 0.22, and they correspond to the dynamics of figure 6 where the 3 fixed

points can more easily be ascertained. We can see in the above plot that near the unstable initial firing rate of 22 we have

behavior leading to one of the stable points, 0 and 116. If we start with values below 22, the dynamics of the system

tends toward 0, where there is no persistent firing rate. Conversely if we start at values above 22, we attain persistent

activity at 116 spikes/s.

Page 9: AMS/BIO 332: Computational Modeling of Physiological ...jpaladini.com/downloads/jpaladini_computationalbiology.pdf · AMS/BIO 332: Computational Modeling of Physiological Systems

4

III. Persistent activity in a recurrent network:

Figure 8: AND Boolean problem 500 presentations Figure 9: AND Boolean problem 50 presentations

The two plots above are the performance vs presentation outcomes for the AND Boolean target assignment for . We

can see that after approximately 17 presentations the perceptron has learned the pattern and classifies the target

correctly all the way to 500 presentations.

Figure 10: OR Boolean problem 500 presentations Figure 11: OR Boolean problem 50 presentations

Again we can see similar outcomes for the OR Boolean target assignment for . The perceptron has learned the pattern

after approximately 7 presentations, and continues to classifiy them correctly all the way out to 500 presentations

Page 10: AMS/BIO 332: Computational Modeling of Physiological ...jpaladini.com/downloads/jpaladini_computationalbiology.pdf · AMS/BIO 332: Computational Modeling of Physiological Systems

5

Figure 12: XOR Boolean problem 500 presentations

Finally we can see from the above plot the outcome of the XOR Boolean target assignment. The perceptron cannot learn

this pattern because it is not linearly separable. We can see that the perceptron incorrectly classifies the pattern all the

way out to 500 presentations, and it will remain this way even past 1000 presentations.

Figure 13: 1000 presentations for 50x40 random presentation matrix.

Above is the plot for a random 50,40 matrix with random presentation patterns. As we can see, the perceptron learns the

pattern after approximately = 600 presentations, and then continues to classify them correctly all the way out to

1000 presentations. Increasing the learning rate did not seem to have a big effect on the outcome of the perceptron

performance. Because the perceptron was able to learn the patterns, I can say the random vectors are linearly seperable

(if solvable).

Page 11: AMS/BIO 332: Computational Modeling of Physiological ...jpaladini.com/downloads/jpaladini_computationalbiology.pdf · AMS/BIO 332: Computational Modeling of Physiological Systems

6

Figure 14: M=50

Finally, above is the outcome when the number of M (columns) vectors are changed. The most interesting difference is

that it seems to take somewhat less presentations for the perceptron to learn when M = 50. However, there are no

results for M=100 because when there are more random vectors than the size of the pattern (N=50), the outcome is not

linearly separable and therefore not solvable by the perceptron.

I completed this project entirely on my own, with some help from Professor La Camera during office hours. All scripts are original

works produced by myself with input from the professor.

-Jason Paladini

Page 12: AMS/BIO 332: Computational Modeling of Physiological ...jpaladini.com/downloads/jpaladini_computationalbiology.pdf · AMS/BIO 332: Computational Modeling of Physiological Systems

7

IV. Appendix of Scripts Used:

Exercise 1:

**********************************************ex_1.m**********************************************

% This function outputs the spike times for ONE spike train into "t" function[t, totalTime]= ex_1(t,totalTime) % lambda, firing rate lambda = 10;

%total time of simulation 5 seconds (s) totalTime = 1000; % milliseconds (ms)

%declaration of variables spikeTimes = []; spikeTrain = []; %loop throough whole time

for T = 1 : totalTime*1.2 if lambda / 1000 >= -log(rand()); spikeTimes(end + 1) = T; end isi = diff(spikeTimes); % for possible later use t = cumsum(isi)/1000; % Convert ms to s t = t'; end

Page 13: AMS/BIO 332: Computational Modeling of Physiological ...jpaladini.com/downloads/jpaladini_computationalbiology.pdf · AMS/BIO 332: Computational Modeling of Physiological Systems

8

**********************************************callt.m**********************************************

% This script calls ex_1.m and assigns each spike train to a cell inside S clear all

N = 50; total_time = 1; % seconds

S = cell(1,N); S(:) = {NaN(100,N)}; for trial = 1:N

S{trial} = ex_1; % hold on % plot(ex_1,trial,'.k') % xlabel('time(s)') % ylabel('trial number') % hold off end

% Find and change all values >5 to NaN S = cellfun(@(x) x + (sign(inf * (x <= 5)) - 1), S,'un',0);

for trial = 1:N sumtrials(trial) = sum(~isnan(S{1,trial})); end

% Calculations total_spikes = sum(sumtrials); f=(total_spikes/(N*total_time));

f

Page 14: AMS/BIO 332: Computational Modeling of Physiological ...jpaladini.com/downloads/jpaladini_computationalbiology.pdf · AMS/BIO 332: Computational Modeling of Physiological Systems

9

**********************************************bins.m**********************************************

%% Find and assign Ti vectors, find midpoints

% Assign variable values callt;

N=50; T = 1; dt=0.2; i(1) = 0.0; fti = cell(1,T/dt); totalspikes_i = zeros(1,N);

for bin = 1:T/dt X = cellfun(@(x) find(x(:,1)>i(bin) & x(:,1)<i(bin)+dt),S,'Un',0); for ii = 1:N totalspikes_i(ii) = numel(X{1,ii}); end fTi(bin) = sum(totalspikes_i)/(N*dt); tmi(bin) = 0.5*(i(bin) + i(bin)+dt); i(bin+1) = i(bin)+dt; end

% Calculate Variation, mean and standard deviation of f(Ti) uf = mean(fTi); sf = std(fTi); Variation = sf/uf;

% Display variation, mean & std dev of firing rate Variation

uf sf

%% Find CV for each individual trial

ISI = cellfun(@diff,S,'Un',0);

ISImean = cellfun(@nanmean,ISI,'Un',0); ISImean = cell2mat(ISImean); ISIstd = cellfun(@nanstd,ISI,'Un',0); ISIstd = cell2mat(ISIstd);

for trial = 1:N CV(trial) = ISIstd(trial)/ISImean(trial); end

k = 1:length(CV);

CVm = nanmean(CV);

Page 15: AMS/BIO 332: Computational Modeling of Physiological ...jpaladini.com/downloads/jpaladini_computationalbiology.pdf · AMS/BIO 332: Computational Modeling of Physiological Systems

10

************************************CONTINUED bins.m CONTINUED*************************************

% Display mean of CV trials over length k

CVm

%% Fano Factor nspikes = cellfun(@numel,ISI,'Un',0); nspikes = cell2mat(nspikes); mspikes = mean(nspikes); sspikes = std(nspikes); vspikes = var(nspikes); FF = vspikes/mspikes; % Display Fano Factor FF

FFt = [1.1196 0.7164 0.9410 0.9725 0.9856 0.9819 0.9957 0.9916]; CVt = [0.7015 1.0704 1.1847 0.9036 1.0329 0.9092 1.0585 1.029]; t = [0.5 1.0 2.0 5.0 10.0 20.0 50.0 100.0];

%% plots

% figure(2) % plot(tmi,fTi) % xlabel('time (s)') % ylabel('firing rate') % figure(3) % hold on % L1 = sprintf('Average CV = %g',CVm); % plot(k,CV) % plot(k,CVm,'.r') % hold off % legend(L1) % xlabel('k^t^h trial') % ylabel('Coefficient of Variation') figure(4) % for T = [0.5 1 2 5 10 20 50 100] seconds L2 = sprintf('Fano Factor'); L3 = sprintf('Cv'); hold on plot(t,FFt,'r') plot(t,CVt,'b') legend(L2,L3) hold off xlabel('time (s)') ylabel('FF / CV')

Page 16: AMS/BIO 332: Computational Modeling of Physiological ...jpaladini.com/downloads/jpaladini_computationalbiology.pdf · AMS/BIO 332: Computational Modeling of Physiological Systems

11

Exercise 2:

**********************************************ex2_1.m**********************************************

%% Example 2-1

% simulation variables clear all J = 0.22; % Vary to get different # of fixed points fmax = 200; % maximal firing rate, spikes/s tau = 0.010; % membrane time constant, ms N = 100; % Number neurons in network theta = 20; % spike threshold, mv %fout = zeros(1,150);

%% Loop

% starting conditions fin(1) = 0; fout(1) = 0; uv(1) = 0; tv(1) = 0; fn(1) = 0;

for i = 1:150 uv(i+1) = J*N*fin(i)*tau; tv(i+1) = J*sqrt(N*fin(i)*tau); phi(i+1) = ((fmax)/(1+exp(-((sqrt(2)*(uv(i)-theta))/(tv(i)*sqrt(N)))))); fin(i+1) = fin(i)+1; %fout(i+1) = (phi(i)-fout(i))/tau; end

%% plot clf figure(1) hold on plot(fin,phi,'r') plot(fin,fin,'b') plot(115,115,'ok') plot(27,27,'ok') plot(0,0,'ok') hold off ylabel('fout') xlabel('fin') %title('') %axis([-5 225 -5 220])

Page 17: AMS/BIO 332: Computational Modeling of Physiological ...jpaladini.com/downloads/jpaladini_computationalbiology.pdf · AMS/BIO 332: Computational Modeling of Physiological Systems

12

**********************************************ex2_3.m**********************************************

%% Example 2-2 and 2-3

% simulation variables clear all J = 0.22; % Vary to get different # of fixed points fmax = 200; % maximal firing rate, spikes/s tau = 0.010; % membrane time constant, seconds tauf = 10; % (ms) time constant of the firing rate dynamics (ms) N = 100; % Number neurons in network theta = 20; % spike threshold, mv dt = 0.1; %fout = zeros(1,150);

%% Loop

% starting conditions fout(1) = 0; uv(1) = 0; tv(1) = 0; ti=0:dt:500; % ms fin=1:150; % spk/s i=0; for j = 114 fout=fin(j); for t=ti i=i+1; uv(i+1) = J*N*fout(i)*tau; tv(i+1) = J*sqrt(N*fout(i)*tau); phi(i+1) = ((fmax)/(1+exp(-((sqrt(2)*(uv(i)-theta))/(tv(i)*sqrt(N)))))); fout(i+1) = fout(i)+ dt*((phi(i) - fout(i))/tauf); end end fout=fout(1:end-1); clf figure(2); hold on plot(ti,fout,'b'); ylabel('fout') xlabel('time') hold off %title('') %axis([-5 220 -5 220])

Page 18: AMS/BIO 332: Computational Modeling of Physiological ...jpaladini.com/downloads/jpaladini_computationalbiology.pdf · AMS/BIO 332: Computational Modeling of Physiological Systems

13

Exercise 3:

**********************************************ex3_1.m**********************************************

clear all

x = [-1 -1 -1; -1 1 -1; 1 -1 -1; 1 1 -1]';%presentations with 3 elements (0 = -1) yt = [-1 -1 -1 1]; % AND yt = [-1 1 1 1]; % OR %yt = [-1 1 1 -1]; % X-OR

w = [0 0 0]; % Assign initial weights with 3 elements n = 0.1; % learning rate T = 1:500; % *********Number of presentations******** R = zeros(1,length(T)); % Initialization of output vector

for i = 1 : length(T)

ind=randi(4); % find random integer from 1 to 4 y = sign(w*x(:,ind)); % This is the output R(i)=0; if yt(ind)==y R(i)=1; end w=w+n*(yt(ind)-y)*x(:,ind)';

end

% Plots figure(1) plot(T,R,'.k') xlabel('presentation number') ylabel('performance') axis([0 500 -1 2]);

Page 19: AMS/BIO 332: Computational Modeling of Physiological ...jpaladini.com/downloads/jpaladini_computationalbiology.pdf · AMS/BIO 332: Computational Modeling of Physiological Systems

14

**********************************************ex3_2.m**********************************************

clear all N = 50; M = 50; x = randi(2,N,M)-1; x(x==0)= -1; x = x'; yt1 = ones(N,M/2); yt2 = zeros(N,M/2); yt = horzcat(yt1,yt2);

w = zeros(1,M); % Assign initial weights with 3 elements n = 10; % learning rate T = 1:1000; % *********Number of presentations******** R = zeros(1,length(T)); % Initialization of output vector

for i = 1 : length(T) ind=randi(M); % find random integer from 1 to 4 y = sign(w*x(:,ind)); % This is the output R(i)=0; if yt(ind)==y R(i)=1; end w=w+n*(yt(ind)-y)*x(:,ind)'; end

% Plots figure(1) plot(T,R,'.k') xlabel('presentation number') ylabel('performance') axis([0 1000 -1 2]); %figure(2) %plot(length(T),P,'.k')