%% Weight distribution of Hebbian synapses in rate model
 clear; clf; %clear workspace and figure
 nn=500; npat=1000; %number of nodes and patterns
%% Random pattern; firing rates are exponential distributed
 ar=40; %average firing rate of pattern
 rPre =-ar.*log(rand(nn,npat)); %exponential distr. pre rates
 rPost=-ar.*log(rand(1,npat));  %exponential distr. post rate
%% Weight matrix
 w=(rPost-ar)*(rPre-ar)'; %Hebbian covariance rule
 w=w/sqrt(npat); %standard scaling to keep variance constant
%% Histogram plotting
 x=-10:1:10; 
 [n,x]=hist(w/nn,x); %calculate histogram
 n=n/sum(n); %normalizaton to get probability distribution 
 h=bar(x,n); set(h,'facecolor','none');
%% Fit normal ditribution to data
 a0=[0 5];
 [tmp,a]=leasqr(x',n',a0','normalOctave');
 n2=normalOctave(-15:0.1:15,a);
 hold on; plot(-15:0.1:15,n2,'r')
