% three4.m % NEUR 1680, Spring 2008 % It is easy to show that in order to get equality % (rather than mere proportionality) % in the equation appearing in this exercise % we need to put a coefficient of 2/N in front of the summation sign, % N being the number of unit vectors, i.e., "neurons". % This can be seen after a little algebra, and using the facts that % if theta_i, i=1,...,N are N independent uniformly distributed angles on [0,2*pi] % then % (1/N) * SUM (cos(theta_i))^2 is approximately .5, and % (1/N) * SUM (cos(theta_i))*(sin(theta_i)) is approximately 0. % These two facts can be proven by realizing that the above sums are % discrete-sum approximations of the definite integrals of the functions cos(x) % and cos(x) * sin(x), respectively, over the interval [0,2*pi]. clear V = [2.034 -5.45]; % pick any "stimulus" N = 100000; % number of "neurons" theta = 2*pi*rand(1,N); % preferred orientations of the N neurons C = [cos(theta); sin(theta)]; % these are the N unit vectors arranged as column vectors responses = V*C; % "responses" of the N neurons to stimulus V population_vector = (2/N) * C*(responses'); error = sqrt(norm(V - population_vector')); % error, i.e. Euclidean distance between stimulus and population vector display(['ERROR: ', num2str(error)])