Home > learn_policy > ccl_learnp_lwpi.m

ccl_learnp_lwpi

PURPOSE ^

model = ccl_learnp_lwpi(X,Y,model)

SYNOPSIS ^

function model = ccl_learnp_lwpi(X,Y,model)

DESCRIPTION ^

 model = ccl_learnp_lwpi(X,Y,model)

 Learn null space policy using locally weighted regression (LWR)

 Input:

   X                               Input state data
   Y                               Target data
   model                           Model related parameters

 Output:
   model                           learnt model

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function model = ccl_learnp_lwpi(X,Y,model)
0002 % model = ccl_learnp_lwpi(X,Y,model)
0003 %
0004 % Learn null space policy using locally weighted regression (LWR)
0005 %
0006 % Input:
0007 %
0008 %   X                               Input state data
0009 %   Y                               Target data
0010 %   model                           Model related parameters
0011 %
0012 % Output:
0013 %   model                           learnt model
0014 
0015 % CCL: A MATLAB library for Constraint Consistent Learning
0016 % Copyright (C) 2007  Matthew Howard
0017 % Contact: matthew.j.howard@kcl.ac.uk
0018 %
0019 % This library is free software; you can redistribute it and/or
0020 % modify it under the terms of the GNU Lesser General Public
0021 % License as published by the Free Software Foundation; either
0022 % version 2.1 of the License, or (at your option) any later version.
0023 %
0024 % This library is distributed in the hope that it will be useful,
0025 % but WITHOUT ANY WARRANTY; without even the implied warranty of
0026 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0027 % Lesser General Public License for more details.
0028 %
0029 % You should have received a copy of the GNU Library General Public
0030 % License along with this library; if not, write to the Free
0031 % Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
0032 
0033 [dimY N] = size(Y);
0034 
0035 % find normalised Y
0036 r = sum(Y.^2,1).^0.5;
0037 YN = Y./repmat(r,dimY,1);
0038 
0039 % find feature vectors
0040 Phi      = model.phi(X);
0041 dimPhi   = size(Phi,1); % get feature dimensionality
0042 
0043 % find weights
0044 W        = model.W(X);
0045 Nc       = size(W,1);   % get no. centres
0046 
0047 % train each local model
0048 for nc=1:Nc
0049     WPhi=repmat(W(nc,:),dimPhi,1).*Phi;
0050     
0051     % construct Jacobian
0052     YPhit = Y*WPhi';
0053     g = YPhit(:);
0054     
0055     % construct Hessian
0056     H = zeros(dimY*dimPhi);
0057     for n=1:N
0058         YNPhit = YN(:,n)*Phi(:,n)';
0059         v(:,n) = YNPhit(:);
0060         H = H + W(nc,n)*v(:,n)*v(:,n)';
0061     end
0062     
0063     % do eigendecomposition for inversion
0064     %[V,D] = eig(H+1e-6*eye(size(H)));
0065     [V,D] = eig(H);
0066     ev = diag(D);
0067     ind = find(ev>1e-6);
0068     V1=V(:,ind);
0069     pinvH1 = V1*diag(ev(ind).^-1)*V1';
0070     model.w(:,:,nc)=reshape(pinvH1*g,dimY,dimPhi)';
0071 end
0072

Generated on Mon 01-Jan-2018 15:49:39 by m2html © 2005