NAME

Math::Lapack::Matrix

VERSION

version 0.002

CONSTRUCTORS

zeros

Allow the creation of a matrix with all values equal to zero. Its arguments are the number of rows and the number of columns.

my $m = Math::Lapack::Matrix->zeros(10, 20);

ones

Allow the creation of a matrix with all values equal to one. Its arguments are the number of rows and the number of columns.

my $m = Math::Lapack::Matrix->random(5,10);

random

Allow the creation of a matrix with all values set randomly between 0 and 1. Its arguments are the number of rows and the number of columns.

my $m = Math::Lapack::Matrix->random(15,15);

identity

Allow the creation of a identity matrix. It argument is the size of the matrix.

my $m = Math::Lapack::Matrix->identity(5);

new

Allow the creation of a new matrix. It argument is a array of values to create the matrix.

$m = Math::Lapack::Matrix->new( [ [1, 2], [3, 4] ] );

DESTROY

Allow free the memory allocated by a matrix.

$m->DESTROY();

METHODS

get_element

Allow get specific element of matrix. Its arguments are the position in row and the position in column.

my $value = $m->get_element(1,2);

shape Allow get the dimension of the matrix.

($rows, $cols) = $m->shape();

set_element

Allow set element in matrix to specific position. Its arguments are the position in row, the position in column and the value to set to that position.

$m->set_element(1,0,10);

rows

Allow get the number of rows of a matrix.

$rows = $m->rows();

columns

Allow get the number of columns of a matrix.

$cols = $m->columns();

get_max

Allow get the max value of a matrix

my $max = $a->max();

get_min

Allow get the min value of a matrix

my $min = $a->min();

mean

Allow get the mean of values of a matrix

std_deviation

Allow get the standard deviation of the values of matrix

my $std = $a->std_deviation();

norm_mean

Allow normalize every column of matrix by the mean.

my $norm = $a->norm_mean();
This method will return a matrix with dimensions (a->columns, 2). This matrix have in the first row of every column the value max - min and in the second row of every column the mean that every column was normalized.

With this returned matrix you can normalize another matrix with same values of max-min and mean using the option by.

my $new = $b->norm_mean( by => $norm ); 

norm_std_deviation

Allow normalize every column of matrix by the standard deviation.

my $std = $a->norm_std_deviation();

This method will return a matrix with dimensions (a->columns, 2). This matrix have in the first row of every column the value mean and in the second row of every column the standard deviation that every column was normalized.

With this returned matrix you can normalize another matrix with same values of mean and standard deviation using the option "by".

my $new = $b->norm_mean( by => $std ); 

OPERATIONS

addition

Allow make adiction of matrix by a scalar or by another matrix. It argument is a scalar or matrix to add.

$m = $m + $b
$m = $m + 5;
$m = $m->add($b);
$m = $m->add(10);

subtraction

Allow make subtraction of matrix by a scalar or by another matrix. It argument is a scalar or matrix to subtract.

$m = $m - $b
$m = $m - 5;
$m = 5 - $m;
$m = $m->sub($b);
$m = $m->sub(10);

multiplication

Allow the multiplication of two matrices. Its arguments are the 2 matrices to multiply.

$A = Math::Lapack::Matrix->new( [ [1, 2], [3, 4] ] );
$B = Math::Lapack::Matrix->new( [ [5, 6], [7, 8] ] );

$C = $A->eval_dot($B);
$D = $A x $B;   # alternative using operator overload

multiplication element-wise

Allow multiply a matrix by a scalar or a matrix by a matrix element-wise. It argment is the scalar to multiply for every element of a matrix.

$m = $m * 5;
$m = 5 * $m;
$m = $a * $b;
$m = $m->mul(5);

division

Allow make the division of matrix by a scalar or by another matrix. It argument is a scalar or matrix to divide.

$m = $m / $b;
$m = $m / 2;
$m = 2 / $m;
$m = $m->eval_div($b);
$m = $m->eval_div(2);

transpose

Allow transpose a matrix.

$m = $m->transpose();
$m = transpose($m);
$m = $m->T;

inverse

Allow make the operation of inverse to the elements of the matrix.

$m = $m->inverse();
$m = inverse($m);

exp

Allow make the exponential operation to every element of the matrix.

$m = $m->exp();
$m = exp($m);

pow

Allow apply the power operation to every element of the matrix. It argument is the scalar to elevate every element of the matrix.

$m = $m->pow(2);
$m = pow($m,2);

log

Allow make the logarithm operation to every element of the matrix.

$m = $m->log();
$m = log($m);

concatenate

Allow the concatenation of two matrices, vertically. Its arguments are the two matrices to concatenate

	index = 0 => concatenate in horizontally
  index = 1 => concatenate in vertically
	
	If it's not used index, by default the function will concatenate horizontally
	
	my $m = Math::Lapack::Matrix::concatenate($a, $b);
	my $m = Math::Lapack::Matrix::concatenate($a, $b, 0);
	my $m = Math::Lapack::Matrix::concatenate($a, $b, 1);

append

Allow append a matrix, vertically. It argumet is the matrix to append.

	index = 0 => append in horizontally
  index = 1 => append in vertically
	
	If it's not used index, by default the function will append horizontally
	
	my $m = $a->append($b);
	my $m = $a->append($b,1);
	my $m = $a->append($b,0);

vector_to_list

Allow convert a vector with dimentions (m,1) or (1,m) to a list. where m is the number of elements and should be more than 1.

my @vector = $a->vector_to_list();

sum

Allow sum elements of a matrix in horizontally or vertically. It argument is a index that represent to sum in horizontally or vertically the elements of the matrix. If is not used index, the function sum will sum every element of the matrix.

    index = 0 => sum in horizontally
    index = 1 => sum in vertically

	$m = $m->sum(0);
	$m = sum($m,1);
	$m = sum($m);

slice

Allow slice over the elemenents of a matrix. It argument is a hash of options. The options are:

	row_range => an array with two values of row min and row max to slice
	col_range => an array with two values of col min and col max to slice
	row => specific row
	col => specific column
    
	my $A = Math::Lapack::Matrix->new( 
					[    
            [1, 2, 3, 4, 5, 6],
            [7, 8, 9, 10, 11, 12],
            [13, 14, 15, 16, 17, 18]
          ]);

	#Get Specific row, row 0
	$A->slice( row_range => [0,0] );
	$A->slice( row => 0 );
	slice($A, row => 0);
	slice($A, row_range => [0,0]);
	
	#Get rows 1,2 and columns 2,3,4,5
	slice($A, row_range => [1,2], col_range => [2,5] );
	$A->slice( row_range => [1,2], col_range => [2,5] );

	#Get column 4
	$A->slice( col_range => [4,4] );
	$A->slice( col => 4 );
	slice($A, col => 4);
	slice($A, col_range => [4,4]);

I/O

read_csv

Allow read csv to a matrix. Its arguments are the file and a hash of options. The options are:

	row_range => an array with two values of row min and row max to slice over the csv

	col_range => an array with two values of col min and col max to slice over the csv

	row => specific row
	col => specific column
    
	Math::Lapack::Matrix::read_csv($file, row_range => [1,22])

save

Allow save a matrix to disk. It argument is the path to save the matrix.

$m->save("path");

save_matlab

Allow save matrix to matlab format. It argument is the path to save.

$m->save_matlab("path.m");

read_matrix

Allow read a matrix to memory from disk. It argument is the path to the file where the matrix as saved before.

$m = Math::Lapack::matrix->read_matrix("path");

AUTHOR

Rui Meira

COPYRIGHT AND LICENSE

This software is copyright (c) 2018-2019 by Rui Meira.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.