447days since
    site established.

    Visitors

    Contact Information

    The SimpleMatrix C++ Library

    About


    SimpleMatrix is an extremely lightweight matrix library, containing a single header file. 
    • It uses the namespace smat
    • The Matrix class is a template class. 
    • It implements basic matrix representations and operations, such as multiplication, transpose, and submatrix.  
    • It does not implement complicated operations such as inverse, determinant, eigenvector, or decompositions. 
    • It implements the Multidimensional Scaling (MDS) algorithm. 

    Download


    The code package can be downloaded here

    Current version is v4.1. 


    Related Publication


    • Quan Wang, Kim L. Boyer. Feature Learning by Multidimensional Scaling and its Applications in Object Recognition. 2013 26th SIBGRAPI Conference on Graphics, Patterns and Images (Sibgrapi). IEEE, 2013. [preprint]  [website]

    File Descriptions


      
     File name Instructions
     SimpleMatrix.h
    •  The single header file of the SimpleMatrix library. 
     demo_Matrix.cpp
    •  A demo showing how to use this library, including reading matrix from txt file, matrix multiplication, and MDS. 
    •  A Makefile is provided to compile this demo with g++.
     visualize_MDS_results.m
    •  This is a MATLAB script for showing the MDS results of running demo_Matrix.exe
    •  The demo_Matrix.exe performs MDS on the matrix in swissD.txt, which is the geodesic distance matrix of a Swiss roll surface. 
    •  The MDS results are saved in swissX.txt
    •  swissroll.mat stores data for the visualization.
     ReadMe.txt
    •  This file contains the instructions of this package. 
     Makefile
    •  This is the makefile to compile demo_Matrix.cpp
     X.txt
    •  A txt file storing a matrix for the use of demo_Matrix.exe.
     swissD.txt
    •  A txt file storing a matrix for the use of demo_Matrix.exe. The 561*561 matrix is the geodesic distance matrix of a Swiss roll surface. 
     swissroll.mat
    •  MATLAB data for the visualization.

    Tutorial


     Create a 3*4 matrix A where each entry equals to 1.0:
    • smat::Matrix<double> *A=new smat::Matrix<double>(3,4,1.0);
     Create a 5*4 matrix B where each entry is a random value between 0 and 1:
    • smat::Matrix<double> *B=new smat::Matrix<double>(5,4,"rand");
     Read a matrix C from the text file "X.txt", where each line is a row, and entries are separated by comma, or space, or tab:
    • smat::Matrix<double> *C=new smat::Matrix<double>("X.txt");
     Create a 4*4 Identity matrix I:
    • smat::Matrix<double> *I=new smat::Matrix<double>(4,4,"I");
     Create a 9*3 matrix RP where each column is a random permutation of integers from 1 to 9:
    • smat::Matrix<double> *RP=new smat::Matrix<double>(9,3,"randperm");
     Create a 3*4 matrix RI where each entry is a random integral number in the range between 0 and RAND_MAX:
    • smat::Matrix<double> *RI=new smat::Matrix<double>(3,4,"rand_int");
     Display the contents of matrix A:
    • A->print();
     Create a matrix A1 which is a copy of matrix A:
    • smat::Matrix<double> *A1=A->copy();
     Create a matrix A2 which is the transpose of matrix A:
    • smat::Matrix<double> *A2=A->transpose();
     Create a matrix A3 which is the submatrix of matrix A, containing rows 0 to 3, and columns 2 to 4 of A:
    • smat::Matrix<double> *A3=A->sub(0,3,2,4);
    Both row index and column index start from 0.
     Create a matrix A4 which contains the absolute values of matrix A:
    • smat::Matrix<double> *A4=A->abs();
     Get the number of rows and number of columns of matrix A:
    • A->rows();
    • A->columns();
     Get the value of an entry of matrix A, and add 1 to it:
    • value=A->get(row,column);
    • A->set(row,column,value+1);
    These two methods are used to access the matrix elements.
     Save matrix A to text file "Y.txt":
    • A->saveTxt("Y.txt");
     Get the trace of matrix A:
    • A->trace();
     Get the Frobenius norm of matrix A:
    • A->fnorm();
     Get the p-norm of matrix A:
    • A->pnorm(p);
     Get the maximal element and its location of matrix A:
    • maxValue=A->maxEl(row,column);
     Get the minimal element and its location of matrix A:
    • minValue=A->minEl(row,column);
     Get the mean value of matrix A:
    • A->mean();
     Get the sum of all entries of matrix A:
    • A->sum();
     Get the standard deviation of all entries of matrix A:
    • A->std();
     Add value 1.0 to all entries of matrix A in space:
    • A->addNumberSelf(1.0);
     Multiply value 2.0 to all entries of matrix A in space:
    • A->multiplyNumberSelf(2.0);
      Add matrix B to matrix A in space:
    • A->addMatrixSelf(B);
     Dot multiply matrix B to matrix A in space:
    • A->dotMultiplyMatrixSelf(B);
     Create a matrix S which is the sum of matrix A and B:
    • smat::Matrix<double> * S=A->addMatrixNew(B);
     Create a matrix P which is the dot product of matrix A and B:
    • smat::Matrix<double> * P=A->dotMultiplyMatrixNew(B);
     Create a matrix P which is the matrix product of matrix A and B:
    • smat::Matrix<double> * P=A->multiplyMatrixNew(B);
     Perform Multidimensional Scaling (MDS) on the square distance matrix D without initialization, and save the results in matrix X:
    • smat::Matrix<double> * X=MDS_UCF(D,NULL, dim, iter);
    • smat::Matrix<double> * X=MDS_SMACOF(D,NULL, dim, iter);
    Here dim is the number of dimensions, iter is the number of iterations. Recommended value of iter is 30. UCF and SMACOF are two different algorithms. We recommend UCF.
     Perform Multidimensional Scaling (MDS) on the square distance matrix D with initialization X0, and save the results in matrix X:
    • smat::Matrix<double> * X=MDS_UCF(D,X0, dim, iter);
    • smat::Matrix<double> * X=MDS_SMACOF(D,X0, dim, iter);
    Here dim is the number of dimensions, iter is the number of iterations. Recommended value of iter is 30. UCF and SMACOF are two different algorithms. We recommend UCF.





    Č
    ċ
    Quan Wang,
    Jun 17, 2013, 10:29 PM
    Comments