[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to prevent "error: A(I, J) = X: X must be a scalar..." with work
From: |
lynx . abraxas |
Subject: |
Re: How to prevent "error: A(I, J) = X: X must be a scalar..." with working matlab code |
Date: |
Thu, 2 Aug 2007 00:40:06 +0200 |
User-agent: |
Mutt/1.5.11 |
On 31/07/07 11:12:15, James Sherman Jr. wrote:
> I don't have matlab currently available, but from octave's definition of
> linspace (and I just checked, Matlab's too) it generates a row vector. So,
> it shouldn't be possible to have the assignment
> x1(:,1) = 0.5*(linspace(...))-0.5;
>
> Since you're assigning a row vector(1 by n) to a column vector (n by 1). I
> guess Matlab does some guesswork and does the transpose for you in the
> code. Two ways I can think of to get around this, either
> 1) write your own linspace function that returns a column vector
> or
> 2) just do the transpose before you assign it to the variable u
I now got stuck on translating "w(:,:,1)= repmat((linspace(-1, 1, N)),M,1)" to
octave. I use "w(1,:,:)= repmat((linspace(-1, 1, N)),M,1)" with wich octave
doesn't complain at all but w is always empty. " repmat((linspace(-1, 1,
N)),M,1)" alone gives the proper matrix for N= 20 only if M < 7. Otherwise
it's empty too. Why's that??? I can't be running out of memory here. I use GNU
Octave, version 2.1.73 (i686-pc-linux-gnu).
The whole test programme I would like to get working with octave is at the
end. It's a Kohonen net that should adjust itself to the circle. The progress
should be redrawn in intervals. It works with the newest matlab.
Thanks for any Help
Lynx
==============================================
clear all;
P= 360; %# # of degrees steps on circle
N= 20; %# # of neurons in x
M= 20; %# # of neurons in y
L= N * M; %# total # of points
u= linspace(0,2*pi,P); %# all points on circle
x(:,1)= cos(u); %#x coordinats of points
x(:,2)= sin(u); %#y coordinats of points
w= 2*rand(M,N,2)-1;
%# w(:,:,1)= repmat((linspace(-1, 1, N)),M,1)
%# w(:,:,2)= repmat((linspace(-1, 1, M)),N,1)'
r(:,:,1)= repmat((linspace(-1, 1, N)),M,1)
r(:,:,2)= repmat((linspace(-1, 1, M)),N,1)'
T= 2000; %#
ra=T/200;
t0= 1; %#starting time 1
t1= 1000; %#for si, smaller values make the net spread first but have more
dead neurons
t2= 2000; %#for et, bigger values leads to fewer dead neurons
s0= 0.5; %# below 0.5 net does not unfold, bigger values give longer wide
interactions
e0= 0.2; %#
for t=t0:1:T
p=fix(rand(1) * size(x,1)) + 1; %#choose pattern #
for n=1:1:N
for m=1:1:M
%# s(m,n)= dot(reshape(w(m,n,:),1,2),x(p,:));
s(m,n)= sum((reshape(w(m,n,:),1,2)-x(p,:)).^2);
end
end
[C1,I1]= min(s);
[C2,I2]= min(C1);
j= [I1(I2),I2];
et= e0 * exp(-t / t2);
si= s0 * exp(-t / t1);
if(si^2 == 0)
disp(sprintf('si^2 == 00))
si
t
return
end
for n=1:1:N
for m=1:1:M
dw(m,n,:)= et * exp(-sum((r(m,n,:) - r(j(1),j(2),:)).^2) / (2 *
si^2)) * (x(p,:) - reshape(w(m,n,:),1,2));
%# if(isnan(dw(m,n,1)) || isnan(dw(m,n,2))) %#abs(dw(m,n,:)) ==
inf)
%# disp(sprintf('dw(m,n,:)= NaN or Inf 0))
%# dw(m,n,:)
%# m
%# n
%# return
%# end
end
end
if (mod(t-1,ra)==0) %# just for plotting...
%plot(x(:,1),x(:,2),w(:,1),w(:,2))
for n=1:1:N
%# plot(r(:,n,1),r(:,n,2),'r'); %# draw vertical lines
plot(w(:,n,1),w(:,n,2),'g'); %#
hold on;
end
for m=1:1:M
%# plot(r(m,:,1),r(m,:,2),'r'); %# draw horizontal lines
plot(w(m,:,1),w(m,:,2),'g'); %#
hold on;
end
plot(x(:,1),x(:,2),'b'); %# draw circle
plot(x(p,1),x(p,2),'rx');%# draw sample point
plot(w(j(1),j(2),1),w(j(1),j(2),2),'ko');%# draw winner point
hold off;
axis image; %# proportional plot
drawnow;
end
w= w + dw;
end
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Re: How to prevent "error: A(I, J) = X: X must be a scalar..." with working matlab code,
lynx . abraxas <=