help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Speedup/Refaktoring loop? Extended...


From: Andreas Romeyke
Subject: Re: Speedup/Refaktoring loop? Extended...
Date: Wed, 27 Aug 2008 17:56:29 +0200

Hello,

Am Wed, 27 Aug 2008 16:58:01 +0200
schrieb David Bateman <address@hidden>:

> Could you give a complete example to test against? Three possible 
> reasons are that the above explicitly transposes U and Octave in

Sure, this is the code of (my test-) function nmf3.m:
--------------- snip --------------
%%%
%%% NMF nach Lee & Seung
%%%
%%% copyright 2008
%%% Andreas Romeyke (address@hidden)
%%%
%%% computes the NMF decomposition of given matrix X with
%%% compression-parameter and returns 2 matrices
%%% U and V with X_approx=U*V ~ X
%%%
function [U,V] = nmf3(X, compression)
maxit=10000;
epsilon=0.00000000001;
lasterr=1000000000000000000000000000;
[rows,columns]=size(X);
if compression > rows || compression > columns
    display ('compression should not be larger than rows or columns in
given matrix'); abort;
end
U=(rand(rows,compression));
V=(rand(compression,columns));
X=X / max(max(X));
for n = 1:maxit
    a=U.' * X;
    b=U.' * U * V;
    V=V .* a ./ b;
    a=X * V.';
    b=U * V * V.';
    U=U .* a ./ b;
    % calc error/residue
    Xapprox=U*V;
    err=(sum (sum( abs(X-Xapprox) )));
    if (lasterr - err < epsilon)
        break;
    end
    if (mod(n,200) == 0)
        printf('n:%i err:%f\n', n, err);
    end
    lasterr=err;
end
--------------- snap --------------
 
> then Octave 3.1.51+, and presumably Matlab, will never explicitly
> form the transpose matrix but call the underlying lapack code with
> the transpose flagged. A final reason might be that the matlab solver

Thanks for your explanation. But I did not see the reason, why the
transpose-operator and the transpose function will be evaluated
differently? Should it not be the same in internal representation of
Octaves's interpreter? I thought Octave uses an AST to walk on it?

> for over/under determined matrices uses a QR decomposition rather
> than the xGELSD function as Octave does. The reason Octave doesn't
> want to change is discussed in the thread
> 
>  
> http://www.nabble.com/Behavior-of-mldivide-in-Octave-relative-to-Matlab-to16561235.html
> 
> Matlab gets a significant speed increase for their solution at the
> cost of a solution that is not invariant with column permutations. I
> suspect this third issue is the reason for the speed difference Marco
> pointed out how to duplicate Matlab's behavior for this, and
> presumably their speed, with 4 lines of code.

Thanks.

Bye Andreas

-- 
Software Developer / Dipl. Inform. (FH)
Max Planck Institute for Human Cognitive and Brain Sciences
Department of Psychology
Stephanstr. 1a, 04103 Leipzig, Germany

Attachment: signature.asc
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]