octave-maintainers
[Top][All Lists]
Advanced

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

Re: Low hanging fruit - Accelerated random distribution functions


From: David Bateman
Subject: Re: Low hanging fruit - Accelerated random distribution functions
Date: Fri, 23 Feb 2007 11:50:50 +0100
User-agent: Thunderbird 1.5.0.7 (X11/20060921)

Paul Kienzle wrote:
>
>> lognrnd,
>
> Current code can be improved a bit from:
>
>  rnd(k) = exp(mu(k)) .* exp(sigma(k).*randn(1,length(k)));
>
> to:
>
>  rnd(k) = exp(mu(k) + sigma(k).*randn(1,length(k)));
>
This will only be a win in the case where mu or sigma are a matrix. Note
if one is a matrix the other is promoted to be a matrix as well.
However, it is not slower for the case of scalar mu and sigma so its an
overall win to do this.. Consider the attached patch.

D.


-- 
David Bateman                                address@hidden
Motorola Labs - Paris                        +33 1 69 35 48 04 (Ph) 
Parc Les Algorithmes, Commune de St Aubin    +33 6 72 01 06 33 (Mob) 
91193 Gif-Sur-Yvette FRANCE                  +33 1 69 35 77 01 (Fax) 

The information contained in this communication has been classified as: 

[x] General Business Information 
[ ] Motorola Internal Use Only 
[ ] Motorola Confidential Proprietary

*** ./scripts/statistics/distributions/lognrnd.m.orig46 2007-02-23 
11:46:17.949059912 +0100
--- ./scripts/statistics/distributions/lognrnd.m        2007-02-23 
11:49:54.808930733 +0100
***************
*** 81,87 ****
      if  (!(mu > 0) | !(mu < Inf) | !(sigma > 0) | !(sigma < Inf))
        rnd = NaN * ones (sz);
      elseif find ((mu > 0) & (mu < Inf) & (sigma > 0) & (sigma < Inf));
!       rnd = exp (mu) * exp (sigma .* randn (sz));
      else
        rnd = zeros (sz);
      endif
--- 81,87 ----
      if  (!(mu > 0) | !(mu < Inf) | !(sigma > 0) | !(sigma < Inf))
        rnd = NaN * ones (sz);
      elseif find ((mu > 0) & (mu < Inf) & (sigma > 0) & (sigma < Inf));
!       rnd(k) = exp(mu + sigma .* randn (sz)); 
      else
        rnd = zeros (sz);
      endif
***************
*** 94,100 ****
  
      k = find ((mu > 0) & (mu < Inf) & (sigma > 0) & (sigma < Inf));
      if (any (k))
!       rnd(k) = exp (mu(k)) .* exp (sigma(k) .* randn (1, length (k)));
      endif
    endif
  
--- 94,100 ----
  
      k = find ((mu > 0) & (mu < Inf) & (sigma > 0) & (sigma < Inf));
      if (any (k))
!       rnd(k) = exp(mu(k) + sigma(k) .* randn (1, length(k))); 
      endif
    endif
  

reply via email to

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