NAME
Statistics::SparseVector - Perl5 extension for representing and manipulating sparse binary and integer vectors
SYNOPSIS
use Statistics::SparseVector;
# methods that create new bitvectors
$vec = Statistics::SparseVector->new($n);
$vec2 = $vec1->Clone();
$vec = Statistics::SparseVector->new_Enum($n, $s);
$vec = Statistics::SparseVector->new_Bin($n, $s);
$vec = Statistics::SparseVector->new_Int($n, $s);
# miscellaneous
$vec2->Substitute_Vector($vec1, $of22, $len2, $off1, $len1);
$vec->insert_column($pos, $val);
$vec->delete_column($pos);
$vec->Size();
$vec->to_Enum();
$vec->to_Bin($sep);
$vec->Fill();
$vec->Empty();
$vec->increment();
$n = $vec->Norm();
@list = $vec->indices();
# manipulation on the bit level
$vec->Bit_Off($i);
$vec->Bit_On($i);
$vec->Inc($i);
$vec->bit_flip($i);
$vec->bit_test($i);
# overloaded operators
# increment
$vec++;
# stringify
"$vec"
DESCRIPTION
This module implements sparse bitvectors. Several methods for manipulating bitvectors are implemented.
Creation of bitvectors
new-
$vec = Statistics::BitVector->new($n);A bitvector of length
$nis created. All bits are zero. Clone-
$clone = $vec->Clone();A copy of
$vecis returned. new_Enum-
$vec = Statistics::BitVector->new_Enum($enumstring, $n);A new vector of length
$nis created from the comma-separated list of in$enumstring. new_Bin-
$vec = Statistics::BitVector->new_Bin($n, $string);A new vector of length
$nis created from bitstring$string. new_Int-
$vec = Statistics::BitVector->new_Int($n, $intlist);A new vector of length
$nis created from whitespace-separated list of integers$intlist.
Vector-wide manipulation of vector elements
Substitute_Vector-
$vec2->Substitute_Vector($vec1, $off2, $len2, $off1, $len1);$len2contiguous bits in target vector$vec2starting from$off2are replaced by$len1contiguous bits from source vector$vec1starting at bit$off1. If$off2equals the length of$vec2the bits from$vec1are appended. If$len1is zero the$len2bits from$vec2are deleted. delete_column-
$vec->delete_column($i);Delete position
$i, the other elements are shifted as necessary. insert_column-
$vec->insert_column($i, $val);Insert a vector element at position
$iwith value$val. Fill-
$vec->Fill();All bits of
$vecare set to one. Empty-
$vec->Empty();All bits of
$vecare set to zero. increment-
$vec->increment(); $vec++;The integer value of the bitvector is increased by one.
Bit_Off-
$vec->Bit_Off($i);Bit
$iis set to zero. Bit_On-
$vec->Bit_On($i);Bit
$iis set to one. Inc-
$vec->Inc($i);The integer at position
$iis increased by one. bit_flip-
$vec->bit_flip($i);Bit
$iis flipped. bit_test-
$vec->bit_test($i);Returns
1if bit$iis one,0otherwise.
Miscellany
Size-
$n = $vec->Size();Returns the size of the vector.
to_Enum-
$enumstring = $vec->to_Enum();Returns a comma-separated list of bits that are set.
indices-
Returns an array of indices of bits that are set.
to_Bin-
$bitstring = $vec->to_Bin($sep);Returns a string of bits separated by
$sep; bits should be read from left to right Norm-
Returns the number of set bits.
Overloaded operators
++-
$vec++;Same as method
increment. - Double quotes
-
$string = "$vec";Data::Dumperwants to stringify vectors. Probably becauseStatistics::SparseVectoris an overloaded package it expects double quotes to be overloaded as well.
REMARKS ABOUT THE IMPLEMENTATION
Internally sparse vectors are represented by hashes.
Only a few methods from Bit::Vector are implemented. Maybe new ones will follow in the future.
Method
Substitute_Vectoris not thorougly debugged.
VERSION
Version 0.2.
AUTHOR
SEE ALSO
perl(1), Statistics::MaxEntropy(3), Statistics::ME.wrapper.pl(3), Statistics::Candidates(3).
COPYRIGHT
Statistics::MaxEntropy comes with ABSOLUTELY NO WARRANTY and may be copied only under the terms of the GNU Library General Public License (version 2, or later), which may be found in the distribution.