Home > learn_constraint > ccl_learna_alpha.m

ccl_learna_alpha

PURPOSE ^

[optimal] = ccl_learna_alpha (Un, X, options)

SYNOPSIS ^

function [optimal] = ccl_learna_alpha (Un, X, options)

DESCRIPTION ^

 [optimal] = ccl_learna_alpha (Un, X, options)

 Learning state dependent projection matrix N(q) for problem with the form
 Un = N(q) * F(q) where N is a state dependent projection matrix
                        F is some policy

 Input:

   X                                State of the system
   Un                               Control of the system generated with the form Un(q) = N(q) * F(q)
                                    where N(q)=I-pinv(A(q))'A(q) is the projection matrix that projects
                                    F(q) unto the nullspace of A(q). N(q) can be state dependent, but
                                    it should be generated in a consistent way.

 Output:
   optimal                          A model for the projection matrix
   optimal.f_proj(q)                A function that predicts N(q) given q

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [optimal] = ccl_learna_alpha (Un, X, options)
0002 % [optimal] = ccl_learna_alpha (Un, X, options)
0003 %
0004 % Learning state dependent projection matrix N(q) for problem with the form
0005 % Un = N(q) * F(q) where N is a state dependent projection matrix
0006 %                        F is some policy
0007 %
0008 % Input:
0009 %
0010 %   X                                State of the system
0011 %   Un                               Control of the system generated with the form Un(q) = N(q) * F(q)
0012 %                                    where N(q)=I-pinv(A(q))'A(q) is the projection matrix that projects
0013 %                                    F(q) unto the nullspace of A(q). N(q) can be state dependent, but
0014 %                                    it should be generated in a consistent way.
0015 %
0016 % Output:
0017 %   optimal                          A model for the projection matrix
0018 %   optimal.f_proj(q)                A function that predicts N(q) given q
0019 
0020 
0021 
0022 
0023 % CCL: A MATLAB library for Constraint Consistent Learning
0024 % Copyright (C) 2007  Matthew Howard
0025 % Contact: matthew.j.howard@kcl.ac.uk
0026 %
0027 % This library is free software; you can redistribute it and/or
0028 % modify it under the terms of the GNU Lesser General Public
0029 % License as published by the Free Software Foundation; either
0030 % version 2.1 of the License, or (at your option) any later version.
0031 %
0032 % This library is distributed in the hope that it will be useful,
0033 % but WITHOUT ANY WARRANTY; without even the implied warranty of
0034 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0035 % Lesser General Public License for more details.
0036 %
0037 % You should have received a copy of the GNU Library General Public
0038 % License along with this library; if not, write to the Free
0039 % Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
0040 
0041 % essential parameters
0042 model.dim_b     = options.dim_b ;   % dimensionality of the gaussian kernel basis
0043 model.dim_r     = options.dim_r ;   % dimensionality of the end effector
0044 model.dim_x     = size(X, 1) ;      % dimensionality of input
0045 model.dim_u     = size(Un,1) ;      % dimensionality of output Un = N(X) * F(X) where X
0046 model.dim_t     = model.dim_u - 1 ; % dimensionality of each constraint parameters
0047 dim_n           = size(X,2) ;       % number of training points
0048 
0049 % choose a method for generating the centres for gaussian kernel. A
0050 % grid centre is usually adequate for a 2D problem. For higher
0051 % dimensionality, kmeans centre normally performs better
0052 if model.dim_x < 3
0053     model.dim_b = floor(sqrt(model.dim_b))^2 ;
0054     centres     = ccl_math_gc (X, model.dim_b) ;          % generate centres based on grid
0055 else
0056     centres     = ccl_math_kc (X, model.dim_b) ;        % generate centres based on K-means
0057 end
0058 variance        = mean(mean(sqrt(ccl_math_distances(centres, centres))))^2 ; % set the variance as the mean distance between centres
0059 model.phi       = @(x) ccl_basis_rbf ( x, centres, variance );   % gaussian kernel basis function
0060 BX              = model.phi(X) ;                                    % K(X)
0061 
0062 optimal.nmse    = 10000000 ;        % initialise the first model
0063 model.var       = sum(var(Un,0,2)) ;% variance of Un
0064 
0065 % The constraint matrix consists of K mutually orthogonal constraint vectors.
0066 % At the k^{th} each iteration, candidate constraint vectors are
0067 % rotated to the space orthogonal to the all ( i < k ) constraint
0068 % vectors. At the first iteration, Rn = identity matrix
0069 Rn = cell(1,dim_n) ;
0070 for n = 1 : dim_n
0071     Rn{n} = eye(model.dim_u) ;
0072 end
0073 
0074 % The objective functions is E(Xn) = A(Xn) * Rn(Xn) * Un. For faster
0075 % computation, RnUn(Xn) = Rn(Xn)*Un(Xn) is pre-caldulated to avoid
0076 % repeated calculation during non-linear optimisation. At the first iteration, the rotation matrix is the identity matrix, so RnUn = Un
0077 RnUn    = Un ;
0078 
0079 Iu      = eye(model.dim_u) ;
0080 for alpha_id = 1:model.dim_r
0081     model.dim_k = alpha_id ;
0082     model       = ccl_learna_sa (BX, RnUn, model ) ;                                 % search the optimal k^(th) constraint vector
0083     theta       = [pi/2*ones(dim_n, (alpha_id-1)), (model.w{alpha_id}* BX)' ] ;     % predict constraint parameters
0084     for n = 1: dim_n
0085         Rn{n}       = ccl_math_rotmat (theta(n,:), Rn{n}, model, alpha_id) ;    % update rotation matrix for the next iteration
0086         RnUn(:,n)   = Rn{n} * Un(:,n) ;                                             % rotate Un ahead for faster computation
0087     end
0088     % if the k^(th) constraint vector reduce the fitness, then the
0089     % previously found vectors are enough to describe the constraint
0090     if (model.nmse > optimal.nmse) && (model.nmse > 1e-3)
0091         break ;
0092     else
0093         optimal   = model ;
0094     end
0095 end
0096 optimal.f_proj  =  @(q) ccl_learna_pred_proj_alpha (optimal, q, Iu) ;  % a function to predict the projection matrix
0097 fprintf('\t Found %d constraint vectors with residual error = %4.2e\n', optimal.dim_k, optimal.nmse) ;
0098 end

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