Re: Random number help
- From: "Nishant" <nishantxl@xxxxxxxxxxxxxx>
- Date: 13 Sep 2005 07:20:08 -0700
Hello friends,
At your request I am posting the code which
is used to generate cooccurance matrix for each iteration of for loop.
The problem here is that it generates same cooccurance matrix for each
iiteration in for loop.The cooccurance matrix depends on the sequence
of random no generated during one iteration of the for loop.Now what I
am unable to follow is that when I enter large value for PP and CC then
the random no generator does not work and it produces the same sequence
of random no for each single iteration in for loop - meaning I get the
same cooccurance matrix for each iteration of for loop. This implies I
get the sum cooccuranc e matrix with only two elements 0 and the no of
iterations of for loop say - 4 . But instead my actual result sum
cooccuracne matrix should have all the numbers between 0 and 4 for this
case viz 0,1,2 , 3 4,.
And what surprises me most is that the code works fine if the no
PP and CC is less than 3 or for say(a small no), but it fails to work
if PP and CC are larger nos say 10.
Please let me know if you find any flaw in my code or the method of
using random generator.
Awaiting ur reply
Thanks for your support
Nishant
PLz see code below
clc ;
close all;
clear all;
M = input('Enter the number of rows/columns for the square matrix =
');
r = input('Enter the number for the power r greater than zero in the
probability formula= ');
PP=input('Enter the number for the no of people N= ');
CC=input('Enter the number of samples n=');
CCM=0;
% rand('state',0);
% rand('state',sum(1*clock));
% s = rand('state');
% u1 = rand(M^2*M^2);
% rand('state',s);
% u2 = rand(M^2*M^2);
abc=1;dendfigno=PP+1;
for dd=1 : PP
disp('The information about person no.');
disp(dd);
% INPUT the number M, this serves as input argument for function call
%generate_M(M);
% rand('state',0);
% abc=1;
s='r.';
X = [];Y = [];Z=[];A=[];B=[];G=[];AR=[]; JJ=[];%G is used to store
group/cluster assignment information
for i=0 :M-1
for k= 0 : M-1
X = [X i];
Y = [Y k];
% XA(i+1,:)=
end
end
figure(dd);
axis equal;
t=(M-1)/2;
for m=0 : M-1
for l=0 : M-1
Z=[Z 0];
end
end
A=[X-t];
B=[Y-t];
AA=reshape(A,M,M);
BA=reshape(B,M,M);
% l = 1
% for j = 1: sqrt(length(A))
% for k = 1:sqrt(length(A))
% Asq(j,k) = A(1,l)
% l= l+1
% end
% end
% l=1
% for j = 1: sqrt(length(B))
% for k = 1:sqrt(length(B))
% Bsq(j,k) = B(1,l)
% l= l+1
% end
% end
plot(A,B,s,A,Z,'b-',Z,B,'g-');
% AA= Asq';
% BA= Bsq';
disp('X Coordinates MATRIX AA IS')
disp(AA)
disp('Y Coordinates MATRIX BA IS')
disp(BA)
temp=0;
for i=1 : M
for k=1 : M
x1=AA(M,M)-AA(i,k);
y1=BA(M,M)-BA(i,k);
x2=AA(M,1)-AA(i,k);
y2=BA(M,1)-BA(i,k);
x3=AA(1,1)-AA(i,k);
y3=BA(1,1)-BA(i,k);
x4=AA(1,M)-AA(i,k);
y4=BA(1,M)-BA(i,k);
d1=sqrt(x1^2+y1^2);
d2=sqrt(x2^2+y2^2);
d3=sqrt(x3^2+y3^2);
d4=sqrt(x4^2+y4^2);
D=[d1 d2 d3 d4];
%k=1;
disp('probabilities for point ')
disp(i);disp(','); disp(k);
s=0;
% if min(D)== 0
% SPL=i;
% rand('state',0);
% rand('state',sum(0.001*clock));
Y = rand(abc);
disp('The Random no is');
disp(Y);
jb=0;
dd=[];
if ((d1>0)&( d2>0)&(d3>0)&(d4>0))
jb=1;
expe=0;
for kk=1: 4
PN(kk)=(1/D(kk)^r)/(1/d1^r + 1/d2^r + 1/d3^r + 1/d4^r);
disp('INFORMATION ABOUT PROB DATA');
disp('FOR ASSIGNING A POINT TO GROUP/CLUSTER NO.');
disp(kk);
disp('THE THEORITICAL PROBABILITY IS');
disp(PN(kk));
s=s+ PN(kk);
dd=[dd s];
if (Y<=dd(kk))
expe=expe+1;
while expe==1
prob=Y;
disp('the point is assigned to cluster/group no.');
G(i,k)=kk;
disp(kk);
disp(' the randomly assigned probability of clustering to
the group is');
disp(prob);
expe=expe+1;
end
end
end
end
disp('the sum of probability to be assigned to either of groups is');
disp(s);
if jb==0
disp('special case');
n=[];
for m=1 : 4
% disp('Probability of going to group no');
% disp(k);
if D(m) == 0
temp=temp+1;
n=[n 1]; break,end;
P(m)=(1/D(m)^r)/(1/d1^r + 1/d2^r + 1/d3^r + 1/d4^r);
if P(m)== 0
n=[n 0];
continue
end
% Y = rand(size(t));
n(m)=abs(minus(P(m),Y));
s=s+ P(m);
% disp(P(k))
end
[C,I]=min(n); % not able to
assign proper group in case of case failure ie 0 case type
if C ==0
[C,I]=max(n);
% C=C+1;
% I=temp;
end
disp('the point is assigned to cluster/group no.');
G(i,k)=I;
disp(I);
disp('the probability of assigned to that group is');
disp(C);
end % end of bigger for loop
% % for m=1 : 4
% % % disp('Probability of going to group no');
% % % disp(k);
% % if D(m) == 0
% % P(m)=1, break,end
% % P(m)=(1/D(m)^r)/(1/d1^r + 1/d2^r + 1/d3^r + 1/d4^r);
% % s=s+ P(m);
% % % disp(P(k))
% % end
% % [C,I]=max(P)
% % disp('the point is assigned to cluster/group no.');
% % disp(I);
% % disp('the probability of assigned to that group is');
% % disp(C);
%
% disp(s)
end
end
AAAA= reshape(G',1,M^2);
KKK=eye(M^2);
for i = 1 : M^2
for j=1 : M^2
if AAAA(i)==AAAA(j)
KKK(i,j)=1;
KKK(j,i)=1;
end
end
end
JJ=KKK;
% return
disp('the sample co-occurance matrix is as follows');% GIVING SAME
RESULT FOR EACH ITERATION
disp(KKK)
disp('check-the M X M matrix containing group info is ');
disp(G)
disp('check-the 1 X M matrix containing group info is ');
disp(AAAA)
X= KKK;
Y= pdist(X,'cityblock');
Z= linkage(Y,'average');
figure(dendfigno);
[H,T] = dendrogram(Z,'colorthreshold','default');
% H = dendrogram(Z);
CCM= CCM + JJ;
dendfigno=dendfigno+1;
end % end of main for loop
disp('The sum co-occurance matrix is=');% REPETITION OF NUMBERS SO
DEFECTIVE
disp(CCM);
X= CCM;
Y= pdist(X,'cityblock');
Z= linkage(Y,'average');
figure(99);
[H,T] = dendrogram(Z,'colorthreshold','default');
sum_ccm = sum(CCM,1);
disp(sum_ccm);
Ch = nchoosek(PP,CC);
% k=1;t=k+1;ctr=1;
% for i= 1 : Ch
% for j=1 : 2
% if j==1
% AR(i,j)=k;
% end
%
% if j==2
% AR(i,j)=t;
% t=t+1;
% end
% if t==PP+1
% t=k+2;
% k=k+1;
% end
%
% end
Op=nchoosek(1:1:PP,CC);
disp(Op);
% end
disp(AR)
Kl = randperm(Ch);
Ab=Kl(1);
Aj=Op(Ab,:);
disp('SAMPLING BEGINS for the following elements ');
disp(Aj);
ACCM=0;k2k=1;dendfigno=CC+1
% for dd=Aj(1): Aj(CC)
for dd=1:CC
% rand('state',0);
% rand('state',sum(100*clock));
disp('The information about person no.');
disp(Aj(dd));
% INPUT the number M, this serves as input argument for function call
%generate_M(M);
% rand('state',0);
% rand('state',sum(100*clock));
% abc=1;
s='r.';
X = [];Y = [];Z=[];A=[];B=[];G=[];AR=[]; JJ=[];%G is used to store
group/cluster assignment information
for i=0 :M-1
for k= 0 : M-1
X = [X i];
Y = [Y k];
% XA(i+1,:)=
end
end
figure(dd);
axis equal;
t=(M-1)/2;
for m=0 : M-1
for l=0 : M-1
Z=[Z 0];
end
end
A=[X-t];
B=[Y-t];
AA=reshape(A,M,M);
BA=reshape(B,M,M);
% l = 1
% for j = 1: sqrt(length(A))
% for k = 1:sqrt(length(A))
% Asq(j,k) = A(1,l)
% l= l+1
% end
% end
% l=1
% for j = 1: sqrt(length(B))
% for k = 1:sqrt(length(B))
% Bsq(j,k) = B(1,l)
% l= l+1
% end
% end
plot(A,B,s,A,Z,'b-',Z,B,'g-');
% AA= Asq';
% BA= Bsq';
disp('X Coordinates MATRIX AA IS')
disp(AA)
disp('Y Coordinates MATRIX BA IS')
disp(BA)
temp=0;
for i=1 : M
for k=1 : M
x1=AA(M,M)-AA(i,k);
y1=BA(M,M)-BA(i,k);
x2=AA(M,1)-AA(i,k);
y2=BA(M,1)-BA(i,k);
x3=AA(1,1)-AA(i,k);
y3=BA(1,1)-BA(i,k);
x4=AA(1,M)-AA(i,k);
y4=BA(1,M)-BA(i,k);
d1=sqrt(x1^2+y1^2);
d2=sqrt(x2^2+y2^2);
d3=sqrt(x3^2+y3^2);
d4=sqrt(x4^2+y4^2);
D=[d1 d2 d3 d4];
%k=1;
disp('probabilities for point ')
disp(i);disp(','); disp(k);
s=0;
% if min(D)== 0
% SPL=i;
% rand('state',0);
% rand('state',sum(100*clock));
Y = rand(abc);
disp('The Random no is');
disp(Y);
jb=0;
dd=[];
if ((d1>0)&&( d2>0)&&(d3>0)&&(d4>0))
jb=1;
expe=0;
for kk=1: 4
PN(kk)=(1/D(kk)^r)/(1/d1^r + 1/d2^r + 1/d3^r + 1/d4^r);
disp('INFORMATION ABOUT PROB DATA');
disp('FOR ASSIGNING A POINT TO GROUP/CLUSTER NO.');
disp(kk);
disp('THE THEORITICAL PROBABILITY IS');
disp(PN(kk));
s=s+ PN(kk);
dd=[dd s];
if (Y<=dd(kk))
expe=expe+1;
while expe==1
prob=Y;
disp('the point is assigned to cluster/group no.');
G(i,k)=kk;
disp(kk);
disp(' the randomly assigned probability of clustering to
the group is');
disp(prob);
expe=expe+1;
end
end
end
end
disp('the sum of probability to be assigned to either of groups is');
disp(s);
if jb==0
disp('special case');
n=[];
for m=1 : 4
% disp('Probability of going to group no');
% disp(k);
if D(m) == 0
temp=temp+1;
n=[n 1]; break,end;
P(m)=(1/D(m)^r)/(1/d1^r + 1/d2^r + 1/d3^r + 1/d4^r);
if P(m)== 0
n=[n 0];
continue
end
% Y = rand(size(t));
n(m)=abs(minus(P(m),Y));
s=s+ P(m);
% disp(P(k))
end
[C,I]=min(n); % not able to
assign proper group in case of case failure ie 0 case type
if C ==0
[C,I]=max(n);
% C=C+1;
% I=temp;
end
disp('the point is assigned to cluster/group no.');
G(i,k)=I;
disp(I);
disp('the probability of assigned to that group is');
disp(C);
end % end of bigger for loop
% % for m=1 : 4
% % % disp('Probability of going to group no');
% % % disp(k);
% % if D(m) == 0
% % P(m)=1, break,end
% % P(m)=(1/D(m)^r)/(1/d1^r + 1/d2^r + 1/d3^r + 1/d4^r);
% % s=s+ P(m);
% % % disp(P(k))
% % end
% % [C,I]=max(P)
% % disp('the point is assigned to cluster/group no.');
% % disp(I);
% % disp('the probability of assigned to that group is');
% % disp(C);
%
% disp(s)
end
end
AAAA= reshape(G',1,M^2);
KKK=eye(M^2);
for i = 1 : M^2
for j=1 : M^2
if AAAA(i)==AAAA(j)
KKK(i,j)=1;
KKK(j,i)=1;
end
end
end
JJ=KKK;
% return
disp('the sample co-occurance matrix is as follows');% GIVING SAME
RESULT FOR EACH ITERATION
disp(KKK)
disp('check-the M X M matrix containing group info is ');
disp(G)
disp('check-the 1 X M matrix containing group info is ');
disp(AAAA)
X= KKK;
Y= pdist(X,'cityblock');
Z= linkage(Y,'average');
figure(dendfigno);
[H,T] = dendrogram(Z,'colorthreshold','default');
ACCM= ACCM + JJ;
disp(k2k);
k2k=k2k+1;
disp('check');
disp(ACCM);
end % end of main for loop
disp('The sum co-occurance matrix for given sample is=');% REPETITION
OF NUMBERS SO DEFECTIVE
disp(ACCM);
X= ACCM;
Y= pdist(X,'cityblock');
Z= linkage(Y,'average');
figure(100);
[H,T] = dendrogram(Z,'colorthreshold','default');
disp('for the sample no');
disp(Aj);
% end % end main for loop
.
- Follow-Ups:
- Re: Random number help
- From: Nishant
- Re: Random number help
- From: Nishant
- Re: Random number help
- From: Nishant
- Re: Random number help
- From: Nishant
- Re: Random number help
- From: Nishant
- Re: Random number help
- From: Nishant
- Re: Random number help
- From: Steve Amphlett
- Re: Random number help
- References:
- Random number help
- From: Nishant
- Re: Random number help
- From: Nishant
- Re: Random number help
- From: Steve Amphlett
- Random number help
- Prev by Date: Re: mexCallMATLAB and waitbar
- Next by Date: Re: kernel smoother
- Previous by thread: Re: Random number help
- Next by thread: Re: Random number help
- Index(es):
Relevant Pages
|
Loading