Equations

Friday 20 November 2015

POX Controller fixes

It seems that POX controller has some bugs in its source code, which appears as errors in the output window like these lines:
INFO:packet:(ipv6) warning IP packet data incomplete (114 of 316)
INFO:packet:(dns) parsing questions: incomplete name
INFO:packet:(dhcp parse) warning DHCP packet data too short to parse header: data len 86

Following POX mailing list this can be fixed by editing the POX source code:


  • add at line 244 in packet.dns:

    elif r.qtype == 28:
      assert isinstance(r.rddata, IPAddr6)
      return s + r.rddata.toRaw()


  • change at line 435 in packet.dns:

  return IPAddr6.from_raw(l[beg_index : beg_index + dlen])


  • add at line 521 in addresses.py:

  def toRaw (self):
    return self.raw


  • change at line 4431 in openflow.libopenflow_01.py the value of OFP_DEFAULT_MISS_SEND_LEN to a bigger value (default is 128). This error happens because DHCP packets are truncated.

Saturday 13 December 2014

Fixing SLiM login manager goes blank in Gentoo with XFCE

As soon as X was compiled and successfully started, I've emerged XFCE and SLiM display manager. After setting slim to auto start after boot and instead of the standard xdm, I've stumbled upon the following issue: login screen is presented asking for username and password, but as soon as those entered the screen turns blank and desktop loading is stopped.
According to the SLiM wiki it's a dbus issue and it is solved pretty easily. One should just add dbus to the default init level, by writing in terminal as root:

rc-update add dbus default

restart afterwards.

Monday 11 April 2011

Simulating Poisson Neuron With Refractory Period

In this post, I will again simulate homogeneous Poisson neuron, but with refractory period.
T = 60000;
rate = 40;
refractoryPeriod = 3;
dt = 1;
spikeTimes = [];
isRefractory = false;
restRate = 0;
r = rate;

for t = 1 : dt : 60000,
    if r * dt / 1000 < rand(1),
        spikeTimes(i) = t;
        isRefractory = true;
        r = restRate;
    end
    
    if spikeTimes(end) - t = refractoryPeriod,
        r = rate;
        isRefractory = false;
    end
end



now lets make TIH, Survivor and Hazard functions:
isi = diff(spikeTimes);
maxIsi = ceil(max(isi) / 100) * 100;
bins = -0.5 : maxIsi - 0.5;
isiHist = hist(isi, bins);
isiHist = isiHist / sum(isiHist);

%we need the cumultative sum for the survivor function
cumTih = cumsum(isiHist);
survivorFunc = 1 - cumTih;

%hazard functions is the ISI divided by the survivor function
hazard = isiHist ./ survivorFunc;

Finding Spike Rate Using Convolution

In the previous post, we found spike rate using non overlapping window. In this post,
I will show how to obtain spike rate using convolution with rectangular and Gaussian window.
I will also use the same variables.
%size of the window 100ms
windowSize = 100;

%the area must be 1
kernel = ones(1, windowSize ) ./ windowSize ;

output = conv(spikeTrain, kernel);


you should get something like this:

now if we want the kernel to be Gaussian window:
%width 600ms and variance 2
windowSize = 600;
windowVar = 2;

kernel = gausswin(windowSize, windowVar);

output = conv(spikeTrain, kernel);


you should get something like this:

Spikes Firing Rate

Continuing the last post, say, we would like to plot the firing rate of the spikes using non overlapping window.
I'll use the same variables as in previous post.
%window size 300ms
dt = 300;

%edges for bins
edges = 0 : dt : max(spikeTimes);
r = zeros(1, length(edges));

%we basically count the number of spikes in every bin
for i = 1 : length(spikeTimes),
   for j = 1 : length(edges) - 1,
       if edges(j) <= spikeTimes(i) && 
           spikeTimes(i) <= edges(j + 1),
          r(j) = r(j) + 1;
       end
   end
   
   if spikeTimes(i) == edges(end),
      r(end) = r(end) + 1;
   end
end

%normalizing the firing rate
r = r ./ dt;

%plot the firing rate
stairs(edges, r);


the result should be something like this:






We can now calculate the fano factor:
ff = var(r) / mean(r);

Sunday 10 April 2011

Poisson Spike Train Simulation

Recently I had to simulate spike trains of neuron which fires as a Poisson processes. Since code in neuroscience is mostly written in Matlab, I will stick to this.

%rate of firing
rate = 50;

%dt in milliseconds
dt = 1;

%total time of simulation 60 seconds
totalTime = 60000;

%declaration of variables
spikeTimes = [];
spikeTrain = [];

%loop throough whole time
for t = 1 : dt : totalTime,
    %r*dt is the poisson distribution
    %of firing in dt. if the distribution is 
    %greater the uniform sampling,
    %a spike is fired and its time
    %is kept.
    if rate * dt / 1000 >= rand(1),
        spikeTimes(end + 1) = t;
    end
end

%convert the vector of spike times
%to vector of spike trains.
spikeTrain(spikeTimes) = 1;


now lets plot the interspike interval histogram and see
if the neuron is indeed poissonian.

isi = diff(sp_times);
maxi = ceil(max(isi) / 100) * 100;
bins = 0.5 : maxi - 0.5;
isiHist = hist(isi, bins);
bar(bins, isiHist / max(isiHist), 1);

we've got:

















as you can see, the TIH follows exponential distribution,
hence the neuron is indeed Poisonnian.

We can also calculate the coefficient of variation:
%for calculating the Cv we need the interspike intervals
cv = std(isi) / mean(isi);


Friday 23 October 2009

install g77 in Ubuntu 9.04 (Jaunty Jackalope)

Recently i needed to compile some programs with g77, ubuntu 9.04 repositories has gcc 4.3 and gfortran. Unfortunately, gfortran is not compatible with many g77 dependent programs.
There's an easy way to install gcc 3.4 and g77:
add to /etc/sources.list the ubuntu 8.04 hardy repositories:

deb http://hu.archive.ubuntu.com/ubuntu/ hardy universe
deb-src http://hu.archive.ubuntu.com/ubuntu/ hardy universe
deb http://hu.archive.ubuntu.com/ubuntu/ hardy-updates universe
deb-src http://hu.archive.ubuntu.com/ubuntu/ hardy-updates universe

then in the terminal:

sudo aptitude update
sudo aptitude isntall g77

remove or comment the ubuntu 8.04 repositories in sources.list
that's it