Hi
I am doing SVD in sparse matrix
How can I optimize the code for better performance

Dims [5000,5000]
------------------------------------------

# For Sparse Input
my $mat_pdl = new PDL::Sparse($total_col,$total_rows);
$mat_pdl->set(a,b => value);
$mat_pdl->bake;
$mat_pdl->normalize;
return $mat_pdl->as_pdl;

#For SVD
 my $bigpdl = $mat->pdl->as_pdl;
my ($n,$m) = $bigpdl->dims;
 my $d = $m;

    $d = $n if($n < $m);
    my ($ut,$s,$vt) = svdlas2ad($bigpdl,$d);  # Calculating Truncated SVD
    transpose($ut);
 $s = stretcher($s);

// Suppose I have 100 singular values and I want to retain top k_values =>
75% Energy
Say The total energy is (12.4)2 + (9.5)2 +(1.3)2 = 245.70, while the
retained energy is (12.4)2 + (9.5)2 = 244.01.
Thus, we have retained over 99% of the energy with $k_values = 1;
for(my $i=$k_values+1; $i<$s->getdim(1); $i++){
set  $s,$i,$i,0 ;
}
 my $new_matrix = $transpose($ut) x $s x $vt;

-----------------------------------------
For Maximum Elements & Too Long to PRINT

$PDL::BIGPDL=1                                           ;
my $max_elem = 1000000000000000000000

sub PDL::Core::string {
    my ( $self, $format ) = @_;
    if ( $PDL::_STRINGIZING ) {
        return "ALREADY_STRINGIZING_NO_LOOPS";
    }
    local $PDL::_STRINGIZING = 1;
    my $ndims = $self->getndims;
    if ( $self->nelem > $max_elem ) {
        return "TOO LONG TO PRINT";
    }
    if ( $ndims == 0 ) {
        if ( $self->badflag() and $self->isbad() ) { =>
            return "BAD";
        }
        else {
            my @x = $self->at();
            return ( $format ? sprintf( $format, $x[ 0 ] ) : "$x[0]" );
        }
    }
    return "Null"  if $self->isnull;
    return "Empty" if $self->isempty;    # Empty piddle



    local $PDL::Core::sep  = $PDL::use_commas ? "," : " ";
    local $PDL::Core::sep2 = $PDL::use_commas ? "," : "";
    if ( $ndims == 1 ) {
        return PDL::Core::str1D( $self, $format );
    }
    else {
        return PDL::Core::strND( $self, $format, 0 );
    }
}
_______________________________________________
Perldl mailing list
Perldl@jach.hawaii.edu
http://mailman.jach.hawaii.edu/mailman/listinfo/perldl

Reply via email to