% Copyright 2013 Allen Institute for Brain Science
% Licensed under the Apache License, Version 2.0 (the "License");
% you may not use this file except in compliance with the License.
% You may obtain a copy of the License at
% http://www.apache.org/licenses/LICENSE-2.0
% Unless required by applicable law or agreed to in writing, software
% distributed under the License is distributed on an "AS IS" BASIS,
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
% See the License for the specific language governing permissions and
% limitations under the License.

%------------------------------------------------------------------------------------

%Script to calculate the first ten normalized moments for all the randomly generated
%synaptic weight distributions

%NOTE: The .mat file FigS10_randdist.mat consisting of the original
%distributions used for FigS10 has also been made available and can be 
%used to reproduce the figure exactly. 

load FigS10_randdist.mat; %using FigS10_generate_randdist.m to generate distributions

mom1=[];
mom2=[];
mom3=[];
mom4=[];
mom5=[];
mom6=[];
mom7=[];
mom8=[];
mom9=[];
mom10=[];
for ii=1:length(dist(1,:))
    mom1 = [mom1;x.^1*dist(:,ii)];
    mom2 = [mom2;x.^2*dist(:,ii)];
    mom3 = [mom3;x.^3*dist(:,ii)];
    mom4 = [mom4;x.^4*dist(:,ii)];
    mom5 = [mom5;x.^5*dist(:,ii)];
    mom6 = [mom6;x.^6*dist(:,ii)];
    mom7 = [mom7;x.^7*dist(:,ii)];
    mom8 = [mom8;x.^8*dist(:,ii)];
    mom9 = [mom9;x.^9*dist(:,ii)];
    mom10 = [mom10;x.^10*dist(:,ii)];
end;

%Normalize moments between 0 and 1
norm_mom1=(mom1-min(mom1))/max(mom1-min(mom1));
norm_mom2=(mom2-min(mom2))/max(mom2-min(mom2));
norm_mom3=(mom3-min(mom3))/max(mom3-min(mom3));
norm_mom4=(mom4-min(mom4))/max(mom4-min(mom4));
norm_mom5=(mom5-min(mom5))/max(mom5-min(mom5));
norm_mom6=(mom6-min(mom6))/max(mom6-min(mom6));
norm_mom7=(mom7-min(mom7))/max(mom7-min(mom7));
norm_mom8=(mom8-min(mom8))/max(mom8-min(mom8));
norm_mom9=(mom9-min(mom9))/max(mom9-min(mom9));
norm_mom10=(mom10-min(mom10))/max(mom10-min(mom10));

norms = [norm_mom1 norm_mom2 norm_mom3 norm_mom4 norm_mom5 norm_mom6 norm_mom7 norm_mom8 norm_mom9 norm_mom10];

%Save data
save('FigS10_moms1to10.mat','mom1','mom2','mom3','mom4','mom5','mom6','mom7','mom8','mom9','mom10');
save('FigS10_norm_moms1to10.mat','norms');
