How to use

C��sar Souza edited this page Mar 21, 2015 · 8 revisions
  1. Accord.NET Framework
  2. Getting started
  3. Published books
  4. How to use
  5. Sample applications

Help improve this wiki! Those pages can be edited by anyone that would like to contribute examples and documentation to the framework.

Have you found this software useful? Consider donating only U$10 so it can get even better! This software is completely free and will always stay free. Enjoy!

Donate

Clone this wiki locally

How to use

Loading data

If you plan to load data into your application (which is most likely the case), then you should consider adding a reference to the Accord.IO library into your project. This library provides data readers for formats like Excel, comma-separated values, matlab matrix files, LibSVM and LibLinear's data formats, and others. If you are interested in loading sounds into your application, consider adding a reference to the Accord.Audio.Formats library.

Tables

Excel and Excel compatible files (such as .csv)

To import a table from Excel or .CSV files, you can use the ExcelReader class class. To load the contents of "Sheet1" located in "worksheet.xlsx", use:

DataTable table = new ExcelReader("worksheet.xlsx").GetWorksheet("Sheet1");

In order to convert a DataTable to a framework matrix, we can use

double[,] matrix = table.ToMatrix();

Note: If you plan to read files from the latest versions of Microsoft Excel in .xls or .xlsx formats, please be sure to have the Microsoft Access Database Engine 2010 Redistributable, available here. In order to use ACE in both 32-bit and 64-bit applications, you need to install both redistributables from the Microsoft website. To install them both, you need to use the /passive command line switch to prevent the installation from failing once it detects another component version already installed. After downloading the executables, run the following two commands:

C:\Users\You\Downloads\AccessDatabaseEngine.exe /passive
C:\Users\You\Downloads\AccessDatabaseEngine_x64.exe /passive

Matrices

The framework can load any MATLAB-compatible .mat file using the MatReader class. It can also parse matrices written in MATLAB, Octave, Mathematica and C#/NET formats directly from text. Examples are shown below.

// From free-text format
double[,] a = Matrix.Parse(@"1 2
                             3 4");

// From MATLAB/Octave format
matrix[,] b = Matrix.Parse("[1 2; 3 4]", OctaveMatrixFormatProvider.InvariantCulture);

// From C# multi-dimensional array format
string str = @"double[,] matrix = 
               {
                  { 1, 2 },
                  { 3, 4 },
                  { 5, 6 },
               }";

double[,] c = Matrix.Parse(str, CSharpMatrixFormatProvider.InvariantCulture);

Images

Images can be loaded in the standard .NET Framework way. However, one might be interested into converting images from matrices and vice-versa; in this case, the classes in the Accord.Imaging.Converters namespace.

Sounds

Sounds can be loaded from files or recorded on-the-fly using a capture device.

Video

Video capturing is done using AForge.NET.

Manipulating matrices

The framework provides matrix manipulation routines through extension methods. Just import the Accord.Math namespace into your source file and all common .NET datatypes will be extended with several extension methods related to mathematics. Please see the Mathematics page for more examples and details.

Matrix operations in the Accord.NET Framework through extension methods.

One common task in matrix manipulation is to decompose a matrix into various forms. Some examples of the decompositions supported by the framework are listed below. Those decompositions can be used to solve linear systems, compute matrix inverses and pseudo-inverses and extract other useful information about data.

Decompositions Multidimensional Jagged
Cholesky (double)(float)(decimal) (double)(float)(decimal)
Eigenvalue (EVD) (double)(float)
Generalized Eigenvalue [1] (double)
Nonnegative Factorization (double)
LU (double)(float)(decimal) (double)(float)(decimal)
QR (double)(float)(decimal)
Singular value (SVD) (double)(float)

Data preprocessing

Before attempting to learn a machine learning model, a good practice is to preprocess, normalize and clean your data. One of the simplest ways to normalize data is by transforming them to Z-scores. In order to transform your data to Z-Scores, you can use the following method:

double[][] scores = Accord.Statistics.Tools.ZScores(inputs);

In case you would like to subtract the mean from your data, you can use the Center method

double[][] centered = Accord.Statistics.Tools.Center(inputs);

And to divide by the standard deviation you can use the Standardize method

double[][] standard = Accord.Statistics.Tools.Standardize(inputs);

Learning from input and output pairs

Finding similarity groups in data

Visualizing your results

Chart controls

Data-binding

Some framework objects can be data-bound to WPF or Windows Forms controls. Examples are all the statistical analysis classes (PCA, LDA, PLS, KPCA, ...), statistical distributions and hypothesis tests.

Specifying statistical distributions

Testing your hypothesis

Persisting models to disk