Le mercredi 23 août 2006 à 21:35 +0200, Vanuxem Grégory a écrit :

[...]

I have just read the following code, you can greatly improve it :-)
(In fact it's a good thing that this code can be improved since I will
publish it one day (I don't know under which terms though)).

Greg

> =head2 stdize
> 
> =for ref
> 
> Standardization (possibly weighted) of matrix over specified axis:
> 
>                          a - mean
>         STANDARDIZED = ------------
>                         stdev(n-1)
> 
> Uses arithmetic mean and standard deviation estimation if asked.
> Can use arbitrary values (PDL vector) and compute inplace.
> 
> =for usage
> 
> PDL = stdize(PDL, SCALAR(axis), SCALAR|PDL(center), SCALAR|PDL(scale),
> SCALAR(weight))
> axis   : threading's axis, generally observation, default = 1 unless a
> vector is given
> center : center data by variable NOCENTER = 0 | CENTER = 1  | PDL,
> DEFAULT = 1
> scale  : scale data by variable NOSCALE = 0 | SCALE = 1 | PDL, DEFAULT =
> 0
> weight : PDL of weights (size(entry matrix)), DEFAULT = ones(entry
> matrix)
> 
> =for example
> 
> my $a = random(10,10);
> my $standardized = stdize($a,1,1,1);
> 
> =cut
> 
> *stdize = \&PDL::stdize;
> 
> sub PDL::stdize{
>         my($m, $obs, $center, $scale, $weight) = @_;
>         $obs = 1 unless defined($obs) ||  $m->getndims < 2;
>         $center = 1 unless defined $center;
>         my ($mean, $rms, $mm);
> 
>         $m = $m->copy unless $m->is_inplace(0);
> 
>         $mm = $m->mv($obs,0);
>         if ( !UNIVERSAL::isa($center,'PDL') || !
> UNIVERSAL::isa($scale,'PDL')) {
>                 ($mean, $rms) = $mm->statsover($weight);
>                 $center = $mean if (!UNIVERSAL::isa($center,'PDL') &&
> $center);
>                 $scale = $rms if (!UNIVERSAL::isa($scale,'PDL') &&
> $scale);
>         }
>         $mm = $mm->mv(0,$m->getndims-1);
>         if (UNIVERSAL::isa($center,'PDL')){
>                 $mm -=  $center;
>         }
>         if (UNIVERSAL::isa($scale,'PDL')){
>                 $mm /=  $scale;
>         }
>         $m;
> 
> }
> 


        
        
                
___________________________________________________________________________ 
Découvrez un nouveau moyen de poser toutes vos questions quelque soit le sujet 
! 
Yahoo! Questions/Réponses pour partager vos connaissances, vos opinions et vos 
expériences. 
http://fr.answers.yahoo.com 



_______________________________________________
Perldl mailing list
[email protected]
http://mailman.jach.hawaii.edu/mailman/listinfo/perldl

Reply via email to