radialBirth.m
上传用户:fsbooksir
上传日期:2013-10-19
资源大小:14k
文件大小:2k
源码类别:

matlab例程

开发平台:

Matlab

  1. function [k,mu,M,match,aBirth,rBirth] = radialBirth(match,aBirth,rBirth,k,mu,M,delta,x,y,hyper,t,bFunction,walkInt,walk);
  2. if nargin < 14, error('Not enough input arguments.'); end
  3. [N,d] = size(x);      % N = number of data, d = dimension of x.
  4. [N,c] = size(y);      % c = dimension of y, i.e. number of outputs.
  5. insideBirth=1;
  6. uB=rand(1);
  7. % INITIALISE H AND P MATRICES:
  8. % ===========================
  9. invH=zeros(k(t)+1+d,k(t)+1+d,c);
  10. P=zeros(N,N,c);
  11. invHproposal=zeros(k(t)+2+d,k(t)+2+d,c);
  12. Pproposal=zeros(N,N,c);
  13. for i=1:c,
  14.   invH(:,:,i) = (M'*M + (1/delta(t,i))*eye(k(t)+1+d));
  15.   P(:,:,i) = eye(N) - M*inv(invH(:,:,i))*M';
  16. end;
  17. % PROPOSE A NEW BASIS FUNCTION:
  18. % ============================
  19. proposal=zeros(1,d);
  20. for i=1:d,
  21.   proposal(1,i)= (min(x(:,i))-walk(i)) + ((max(x(:,i))+walk(i))-(min(x(:,i))-walk(i)))*rand(1,1);
  22. end;
  23. % CHECK IF THE PROPOSED CENTRE ALREADY EXISTS:
  24. % =========================================== 
  25. match1=0;
  26. notEnded=1;
  27. i=1;
  28. if k(t)>0
  29.   while ((match1==0)&(notEnded==1)),
  30.     if k(t)>0
  31.       if (mu{t}(i,:)==proposal),
  32.         match1=1;
  33.       elseif (i<k(t)),
  34.         i=i+1;
  35.       else
  36.         notEnded=0;
  37.       end;
  38.     else
  39.       notEnded=0;
  40.     end;
  41.   end;
  42. end;
  43. if (match1>0),
  44.   match=match+1;
  45.   mu{t+1} = mu{t};
  46.   k(t+1) = k(t);
  47.   M=M;
  48. else
  49.   % IF IT DOESN'T EXIST, PERFORM A BIRTH MOVE:
  50.   % =========================================
  51.   Mproposal = [M feval(bFunction,proposal,x)];
  52.   for i=1:c,
  53.     invHproposal(:,:,i) = (Mproposal'*Mproposal + inv(delta(t,i))*eye(k(t)+2+d));
  54.     Pproposal(:,:,i) = eye(N) - Mproposal*inv(invHproposal(:,:,i))*Mproposal'; 
  55.   end;
  56.   ratio= inv(k(t)+1) * inv(sqrt(delta(t,1))) * sqrt((det(invH(:,:,1)))/(det(invHproposal(:,:,1)))) * ((hyper.gamma+y(:,1)'*P(:,:,1)*y(:,1))/(hyper.gamma+y(:,1)'*Pproposal(:,:,1)*y(:,1)))^((hyper.v+N)/2);      
  57.   for i=2:c,
  58.     ratio= ratio * inv(sqrt(delta(t,i))) * sqrt((det(invH(:,:,i)))/(det(invHproposal(:,:,i)))) * ((hyper.gamma+y(:,i)'*P(:,:,i)*y(:,i))/(hyper.gamma+y(:,i)'*Pproposal(:,:,i)*y(:,i)))^((hyper.v+N)/2); 
  59.   end;
  60.   acceptance = min(1,ratio);   
  61.   if (uB<acceptance),
  62.     mu{t+1} = [mu{t}; proposal];
  63.     k(t+1) = k(t)+1;
  64.     M=Mproposal;
  65.     aBirth=aBirth+1;
  66.   else
  67.     mu{t+1} = mu{t};
  68.     k(t+1) = k(t);
  69.     rBirth=rBirth+1;
  70.     M=M;
  71.   end;
  72. end;