Did you know ... | Search Documentation: |
Pack mtx -- prolog/mtx.pl |
This is a library for working with data matrices, taking off from where library(csv) ends.
The library will hopefully grow to become useful tool for logic programming based data science.
In theory the library supports polymorphic representations of matrices, but in its
current form is best to assume that the canonical form (see mtx/1) is the only one supported.
The library should be considered as still in developmental flux.
License: MIT.
At the very least library(mtx)
can be viewed as an addition/enhancement io of matrices to files via mtx/2.
The library can interrogate the data/ subdirectory of all installed packs for csv files using alias data.<br>
?- mtx( data(mtcars), Mtcars ). Mtcars = [row(mpg, cyl, disp, hp, ....
Where mtcars.csv
is in some pack's data directory.
?- mtx_data( mtcars, Mtcars ). Mtx = [row(mpg, cyl, disp, hp, ....
Where mtcars.csv is in pack(mtx)
data subdirectory.
mtx/2 works both as input and output.<br>
If 2nd argument is ground, mtx/2 with output the 2nd argument to the file pointed by the 1st.
Else, the 1st argument is inputed to the 2nd argument in standard form.
?- tmp_file( mtc, TmpF ), mtx( pack('mtx/data/mtcars'), Mtc ), mtx( TmpF, Mtc ). TmpF = '/tmp/pl_mtc_14092_0', Mtc = [row(mpg, cyl,
The first call to mtx/2 above, inputs the test csv mtcars.csv, to Mtc (instantiated to list of rows).
The second call, outputs Mtc to the temporary file TmpF.
mtx/3 provides a couple of options on top of csv_read_file/3 and csv_write_file/3.
sep(Sep)
is short for separator, that also understands comma, tab and space (see mtx_sep/2).
match(Match)
is short for match_arity(Match)
?- mtx( data(mtcars), Mtcars, sep(comma) ). Mtcars = [row(mpg, cyl, disp, hp, ....)|...]
If a predicate definition has both Cnm and Cps define them in that order.
Good starting points are the documentation for mtx/1, mtx/2 and mtx/3.
pack(mtx/data)
.
Data is in canonical Mtx format.
SetName
?- mtx( pack(mtx/data/mtcars), Mtcars ), mtx_data(mtcars, Mtcars). Mtcars = [row(mpg, cyl, disp, hp, drat, wt, qsec, vs, am, gear, carb), row(21.0, 6.0, 160.0, 110.0, 3.9, 2.62, 16.46, 0.0, 1.0, 4.0, 4.0), row(21.0, 6.0, 160.0, 110.0, 3.9, 2.875, 17.02, 0.0, 1.0, 4.0, 4.0), row(22.8, 4.0, 108.0, 93.0, 3.85, 2.32, 18.61, 1.0, 1.0, 4.0, 1.0), row(21.4, 6.0, 258.0, 110.0, 3.08, 3.215, 19.44, 1.0, 0.0, 3.0, 1.0), row(18.7, 8.0, 360.0, 175.0, 3.15, 3.44, 17.02, 0.0, 0.0, 3.0, 2.0), row(18.1, 6.0, 225.0, 105.0, 2.76, 3.46, 20.22, 1.0, 0.0, 3.0, 1.0), row(14.3, 8.0, nle.360.0, 245.0, 3.21, 3.57, 15.84, 0.0, 0.0, 3.0, 4.0), row(..., ..., ..., ..., ..., ..., ..., ..., ..., ..., ...)|...]
Sep can be a code, or one of:
mtx
.
The pack is distributed under the MIT license.
?- mtx_version( Ver, Date ). Ver = 0:6:0, Date = date(2021, 6, 17).
The following predicates are exported, but not or incorrectly documented.