Browse Source

Data: docs

pull/248/head
Christoph Ruegg 12 years ago
parent
commit
87f1eefcf9
  1. 17
      docs/content/CSV.fsx
  2. 90
      docs/content/MatlabFiles.fsx
  3. 62
      docs/content/MatrixMarket.fsx
  4. 6
      docs/tools/templates/template.cshtml

17
docs/content/CSV.fsx

@ -32,11 +32,12 @@ Reading a matrix from a delimited file
--------------------------------------
The `DelimitedReader` class provides static functions to read a matrix from a file or string in delimited form.
It can read from:
* **Read**: read from a TextReader. If you have your delimited data already in memory in a string,
* **TextReader**: If you have your delimited data already in memory in a string,
you can use this method using a StringReader.
* **ReadStream**: read directly from a stream, e.g. a MemoryStream, FileStream or NetworkStream.
* **ReadFile**: read from a file, specified by the file system path.
* **Stream**: read directly from a stream, e.g. a MemoryStream, FileStream or NetworkStream.
* **File Path (string)**: read from a file, specified by the file system path.
All these functions expect the data type of the matrix to be generated as generic type argument.
Only Double, Single, Complex and Complex32 are supported.
@ -44,6 +45,8 @@ Only Double, Single, Complex and Complex32 are supported.
Example:
[lang=csharp]
using MathNet.Numerics.Data.Text;
Matrix<double> matrix = DelimitedReader.Read<double>("data.csv", false, ",", true);
Unfortunately the lack of standard means that the parsing logic needs to be parametrized accordingly.
@ -64,7 +67,7 @@ but for simplicity the Read functions expects those parameters explicitly as opt
Writing a matrix to a delimited file
------------------------------------
The dual to the delimiter above is the `DelimitedWriter` class that can serialize a matrix
The dual to the reader above is the `DelimitedWriter` class that can serialize a matrix
to a delimited text file, stream or TextWriter.
The static Write functions accept the following optional arguments to control the output format:
@ -82,7 +85,7 @@ The static Write functions accept the following optional arguments to control th
Example:
[lang=csharp]
DelimitedWriter.WriteFile(matrix, "data.csv", ",");
DelimitedWriter.Write("data.csv", matrix, ",");
Alternatives
@ -91,7 +94,7 @@ Alternatives
The data extension packages also offer other ways to serialize a matrix to a binary stream or file.
Among others:
* NIST MatrixMarket text files
* MATLAB mat files
* [NIST MatrixMarket text files](MatrixMarket.html)
* [MATLAB Level-5 Mat files](MatlabFiles.html)
*)

90
docs/content/MatlabFiles.fsx

@ -0,0 +1,90 @@
(*** hide ***)
#I "../../out/lib/net40"
#r "MathNet.Numerics.dll"
#r "MathNet.Numerics.FSharp.dll"
(**
MATLAB Level-5 Mat Files
========================
Level-5 MATLAB Mat files are popular as binary file container for storing one or more matrices.
Math.NET Numerics provides basic support for such Mat files with the **MathNet.Numerics.Data.Matlab** package,
which is available on NuGet as separate package and not included in the basic distribution.
Reading matrices from a MATLAB file
-----------------------------------
The `MatlabReader` class provides static functions to list all matrices stored in a MAT file or stream,
and to read them individually as Math.NET matrices:
[lang=csharp]
using MathNet.Numerics.LinearAlgebra;
using MathNet.Numerics.Data.Matlab;
// read the first matrix as double
Matrix<double> m = MatlabReader.Read<double>("collection.mat");
// read a specific matrix named "vd":
Matrix<double> m = MatlabReader.Read<double>("collection.mat", "vd");
// we can also choose to convert to a different type:
Matrix<Complex> m = MatlabReader.Read<Complex>("collection.mat");
// read all matrices of a file by name into a dictionary
Dictionary<string,Matrix<double>> ms =
MatlabReader.ReadAll<double>("collection.mat");
// read the matrices named "Ad" and "vd" into a dictionary
var ms = MatlabReader.ReadAll<double>("collection.mat", "vd", "Ad");
Alternatively the reader can list all matrices of a file into named data elements,
which can then be read into matrices individually. This is useful e.g. if we need to
read some of the matrices to a different type:
[lang=csharp]
List<MatlabMatrix> ms = MatlabReader.List("collection.mat");
Matrix<double> Ad = MatlabReader.Unpack<double>(ms.Find(m => m.Name == "Ad"));
Matrix<float> vd = MatlabReader.Unpack<float>(ms.Find(m => m.Name == "vd"));
Writing matrices to a MATLAB file
---------------------------------
The dual to the reader above is the `MatlabWriter` class that can serialize matrices
to a MATLAB file or stream. Like the reader, the writer can use `MatlabMatrix` data elements
to compose packed matrices into a file. Each matrix has a name which must not contain spaces.
[lang=csharp]
var matrices = new List<MatlabMatrix>();
m.Add(MatlabWriter.Pack(myFirstMatrix, "m1");
m.Add(MatlabWriter.Pack(mySecondMatrix, "m2");
MatlabWrier.Store("file.mat", matrices);
But there are also direct routines if only a single matrix or matrices of all the same data type
are to be stored in a file:
[lang=csharp]
// write a single matrix "myMatrix" and name it "m1".
MatlabWriter.Write("file.mat", myMatrix, "m1");
// write multiple matrices, from a list of matrices and a list of their names:
MatlabWriter.Write("file.mat", new[] { m1, m2 }, new[] { "m1", "m2" });
// write a dictionary of matrices:
var dict = new Dictionary<string, Matrix<double>>();
dict.Add("m1", m1);
dict.Add("m2", m2);
MatlabWriter.Write("file.mat", dict);
Alternatives
------------
The data extension packages also offer other ways to serialize a matrix to a text file.
Among others:
* [Delimited Text Files (CSV & TSV)](CSV.html)
* [NIST MatrixMarket text files](MatrixMarket.html)
*)

62
docs/content/MatrixMarket.fsx

@ -0,0 +1,62 @@
(*** hide ***)
#I "../../out/lib/net40"
#r "MathNet.Numerics.dll"
#r "MathNet.Numerics.FSharp.dll"
(**
NIST MatrixMarket Text Files
============================
MatrixMarket is both a [vast repository of test data](http://math.nist.gov/MatrixMarket/)
and a text-based [exchange file format](http://math.nist.gov/MatrixMarket/formats.html) provided by NIST.
Being text-based makes it convenient to deal with and program against, and also works well with versioning
tools like [Git](http://www.git-scm.com/). But other than [CSV](CSV.html) it can also store sparse matrices in a compact way.
Math.NET Numerics provides basic support for MatrixMarket files with the **MathNet.Numerics.Data.Text** package,
which is available on NuGet as separate package and not included in the basic distribution.
Reading a matrix from a MatrixMarket file
-----------------------------------------
The `MatrixMarketReader` class provides static functions to read a matrix or a vector from a file or string.
It can read from:
* **TextReader**: If you have your delimited data already in memory in a string,
you can use this method using a StringReader.
* **Stream**: read directly from a stream, e.g. a MemoryStream, FileStream or NetworkStream.
* **File Path (string)**: read from a file, specified by the file system path. Optionally GZip compressed.
All these functions expect the data type of the matrix to be generated as generic type argument.
Only Double, Single, Complex and Complex32 are supported.
Example:
[lang=csharp]
using MathNet.Numerics.Data.Text;
Matrix<double> matrix = MatrixMarketReader.ReadMatrix<double>("fidap007.mtx");
Writing a matrix to a MatrixMarket file
---------------------------------------
The dual to the reader above is the `MatrixMarketWriter` class that can serialize a matrix or vector
to a MatrixMarket text file, stream or TextWriter.
Example:
[lang=csharp]
MatrixMarketWriter.WriteMatrix("matrix.mtx", m);
Alternatives
------------
The data extension packages also offer other ways to serialize a matrix to a binary stream or file.
Among others:
* [Delimited Text Files (CSV & TSV)](CSV.html)
* [MATLAB Level-5 Mat files](MatlabFiles.html)
*)

6
docs/tools/templates/template.cshtml

@ -86,7 +86,7 @@
<li>Linear Least Squares</li>
<li>Nonlinear Optimization</li>
<li><a href="@Root/Distance.html">Distance Metrics</a></li>
<li class="nav-header">Curve Fitting</li>
<li><a href="@Root/Regression.html">Regression</a></li>
<li>Interpolation</li>
@ -97,11 +97,11 @@
<li class="nav-header">Working Together</li>
<li><a href="@Root/CSV.html">Delimited Text Files (CSV)</a></li>
<li>NIST MatrixMarket</li>
<li><a href="@Root/MatrixMarket.html">NIST MatrixMarket</a></li>
<li><a href="@Root/MatlabFiles.html">MATLAB</a></li>
<li>FsLab & Deedle</li>
<li>Microsoft Excel</li>
<li>numl.net machine learning</li>
<li>MATLAB</li>
<li>R-project</li>
</ul>

Loading…
Cancel
Save