tor, 20 05 2010 kl. 18:12 -0400, skrev Kyle Winfree:
> I would like to submit a new function for consideration of
> inclusion.
Sorry about the late reply.
> This function, gramian.m, is different from gram.m in that it computes the
> general
> Gramian for a set of vectors. This does not necessarily pertain to
> control of systems.
I don't know the use of this function, so I cannot comment much on it. I
do have a few code-related questions:
+function [G, M] = gramian(varargin)
+ switch(length(varargin))
+ case 1
+ % a matrix has been given such that each column is a vector
+ M = varargin{1};
Do you really need this case? Isn't it already handled by the
'otherwise' branch?
Also, you should ensure that the number of input arguments is larger
than zero and raise an error if not.
+ otherwise
+ % separate vectors have been given, first check to ensure they
all have the same dimension.
+ sz = size(varargin{1});
+ M = zeros(sz(1),length(varargin));
+ for(n=1:length(varargin))
+ if(size(varargin{n},1) ~= sz(1) || size(varargin{n},2) ~=
1)
+ fprintf('Sorry, there was an error with your input
(vector %i). Please ensure the vectors all have the same number of
rows.\n', n);
Please don't apologize; just say something like 'gramian: input vectors
must have same size'.
Also, use the 'error' function for reporting errors.
Can you use the 'size_equal' function for determining if the input sizes
are correct?
+ n = size(M,2);
+ for(i=1:n)
+ for(j=i:n)
+ G(i,j) = dot(M(:,i), M(:,j));
+ end
+ end
Can you somehow vectorise this loop? I guess it should be possible...
In many machine learning tasks you are interested in computing the Gram
matrix using a different inner product. Could your function be
generalised to support an optional alternative inner product?
Søren
------------------------------------------------------------------------------
_______________________________________________
Octave-dev mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/octave-dev