Algorithm-RandomMatrixGeneration
view release on metacpan or search on metacpan
lib/Algorithm/RandomMatrixGeneration.pm view on Meta::CPAN
package Algorithm::RandomMatrixGeneration;
use 5.006;
use strict;
use warnings;
use Math::BigFloat;
require Exporter;
our @ISA = qw(Exporter);
our @EXPORT = qw( generateMatrix );
our $VERSION = '0.06';
# add check for type of marginal values
# modify output format to sparse.
sub generateMatrix
{
my $ref_rmar = shift;
my $ref_cmar = shift;
my $precision = shift;
my $seed = shift;
my @tmp_rmar = @$ref_rmar;
my @tmp_cmar = @$ref_cmar;
my $n = $#tmp_rmar;
my $m = $#tmp_cmar;
# error checks
if(!$n)
{
print STDERR "No row marginals provided.\n";
exit 1;
}
if(!$m)
{
print STDERR "No column marginals provided.\n";
exit 1;
}
if(!$precision)
{
print STDERR "Precision not provided.\n";
exit 1;
}
if(defined $seed)
{
srand($seed);
}
# find the type of marginals values: integers/real
# assume integer and loop through row and col marginals.
# check each value for decimal values.
# break on first occurrence of real number.
my $format = "integer";
# also find if any of the marginal is negative
# assume positive and then loop through to find a contradiction
my $signValues = "positive";
# for each row (0..n)
for(my $i=0; $i<=$n; $i++)
{
if($tmp_rmar[$i] =~ /\.0*[1-9]+/)
{
$format = "real";
if($signValues eq "negative")
{
last;
}
}
if($tmp_rmar[$i] =~ /^-/)
{
$signValues = "negative";
if($format eq "real")
{
last;
}
}
}
if($format eq "integer" || $signValues eq "positive")
{
# for each col (0..m)
for(my $j=0; $j<=$m; $j++)
{
if($tmp_cmar[$j] =~ /\.0*[1-9]+/)
( run in 0.894 second using v1.01-cache-2.11-cpan-0bd6704ced7 )