Class MatrixFactory


  • public class MatrixFactory
    extends Object
    Cette classe permet de creer des matrices, toutes les creations de matrice doivent etre faite a travers cette classe. Cette classe permet de modifier la representation interne des matrices de facon simple.

    Created: 11 octobre 2005 20:15:20 CEST

    Version:
    $Revision$ Last update: $Date$ by : $Author$
    Author:
    Benjamin POUSSIN <poussin@codelutin.com>
    • Field Detail

      • defaultUseLazyVector

        protected static boolean defaultUseLazyVector
        If true, createVector return all time LazyVector to prevent memory allocation when not necessary. LazyVector init real vector only when necessary
      • defaultVectorClass

        protected static Class<?> defaultVectorClass
        Valeur par defaut si aucun type de Vector n'est donné
      • defaultSparseVectorClass

        protected static Class<?> defaultSparseVectorClass
      • defaultThresholdSparse

        protected static int defaultThresholdSparse
        if we try to allocate matrix with more that this threshold, sparse matrix is used
      • vectorClass

        protected Class<?> vectorClass
      • sparseVectorClass

        protected Class<?> sparseVectorClass
      • thresholdSparse

        protected int thresholdSparse
      • useLazyVector

        protected boolean useLazyVector
      • defaultSemanticMapper

        protected static SemanticMapper defaultSemanticMapper
    • Constructor Detail

      • MatrixFactory

        protected MatrixFactory​(Class<?> vectorClass,
                                Class<?> sparseVectorClass,
                                int thresholdSparse,
                                boolean useLazyVector)
    • Method Detail

      • getVectorClass

        public Class<?> getVectorClass()
      • getSparseVectorClass

        public Class<?> getSparseVectorClass()
      • getThresholdSparse

        public int getThresholdSparse()
      • isUseLazyVector

        public boolean isUseLazyVector()
      • setDefaultVectorClass

        public static void setDefaultVectorClass​(Class<?> vectorClass)
      • setDefaultSparseVectorClass

        public static void setDefaultSparseVectorClass​(Class<?> defaultSparseVectorClass)
      • setDefaultThresholdSparse

        public static void setDefaultThresholdSparse​(int defaultThresholdSparse)
      • setDefaultUseLazyVector

        public static void setDefaultUseLazyVector​(boolean useLazyVector)
      • getDefaultVectorClass

        public static Class<?> getDefaultVectorClass()
      • setSemanticMapper

        public static void setSemanticMapper​(SemanticMapper semanticMapper)
      • getSemanticMapper

        public static SemanticMapper getSemanticMapper()
      • getInstance

        public static MatrixFactory getInstance​(Class<?> vectorClass)
        Retourne une factory utilisant vectorClass comme classe de base a l'implantation des matrices, aussi bien pour les matrices dense que les matrices creuse. Par defaut on utilise les LazyVector
        Parameters:
        vectorClass - vector class implementation
        Returns:
        factory
      • getInstance

        public static MatrixFactory getInstance​(Class<?> vectorClass,
                                                Class<?> sparseVectorClass,
                                                int thresholdSparse)
        Retourne une factory utilisant, par defaut on utilise les LazyVector
        Parameters:
        vectorClass - vector class implementation for dense matrix
        sparseVectorClass - vector class implementation for sparse matrix
        thresholdSparse - threshold to determine usage of dense or sparse matrix
        Returns:
        factory
      • getInstance

        public static MatrixFactory getInstance​(Class<?> vectorClass,
                                                Class<?> sparseVectorClass,
                                                int thresholdSparse,
                                                boolean useLazyVector)
        Retourne une factory utilisant vectorClass comme classe de base a l'implantation des matrices.
        Parameters:
        vectorClass - vector class implementation for dense matrix
        sparseVectorClass - vector class implementation for sparse matrix
        thresholdSparse - threshold to determine usage of dense or sparse matrix
        useLazyVector - if true use LazyVector
        Returns:
        factory
      • getInstance

        public static MatrixFactory getInstance()
        Utilise par defaut defaultVectorClass. Si une factory a ete initialisee pour le thread local, alors celle-ci sera reutilise, sinon une nouvelle est cree avec le backend par defaut
        Returns:
        factory
      • initMatrixFactoryThreadLocal

        public static void initMatrixFactoryThreadLocal​(Class<?> vectorClass,
                                                        Class<?> sparseVectorClass,
                                                        int thresholdSparse,
                                                        boolean useLazyVector)
        Initialise une factory pour le thread courant avec le vectorClass passe en parametre.
        Parameters:
        vectorClass - vector class implementation for dense matrix
        sparseVectorClass - vector class implementation for sparse matrix
        thresholdSparse - threshold to determine usage of dense or sparse matrix
        useLazyVector - if true use LazyVector
      • removeMatrixFactoryThreadLocal

        public static void removeMatrixFactoryThreadLocal()
        Retire la factory pour le thread courant
      • create

        public MatrixND create​(File file)
                        throws IOException
        Create new Matrix from file. File contains data as describe for export/import CSV ND
        Parameters:
        file -
        Returns:
        Throws:
        IOException
        Since:
        2.5.2
      • create

        public MatrixND create​(Reader reader)
                        throws IOException
        Create new Matrix from file. File contains data as describe for export/import CSV ND
        Parameters:
        reader -
        Returns:
        Throws:
        IOException
        Since:
        2.5.2
      • create

        public MatrixND create​(int[] dim)
      • create

        public MatrixND create​(double[] values,
                               int[] dim)
        Convert a double array into matrix.
        Parameters:
        values - The values to fill the matrix
        dim - An array representing the dimensions of the matrix
        Returns:
        a 2D matrix filled with the values, null if the dimension is more than 2
      • create

        public MatrixND create​(String name,
                               int[] dim,
                               String[] dimNames,
                               Vector data)
        Create new matrix and force backend to be data.
        Parameters:
        name - matrix's name (can be null)
        dim - matrix's dimension (must be provided)
        dimNames - dimensions' name (can be null)
        data - backend used to new matrix
        Returns:
        new Matrix with specified backend
      • create

        public MatrixND create​(String name,
                               List<?>[] semantics,
                               String[] dimNames,
                               Vector data)
        Create new matrix and force backend to be data.
        Parameters:
        name - matrix's name (can be null)
        semantics - semantiques (must be provided)
        dimNames - dimensions' name (can be null)
        data - backend used to new matrix
        Returns:
        new Matrix with specified backend
      • create

        public MatrixND create​(MatrixND matrix)
        Create new matrix by copying matrix in argument
        Parameters:
        matrix -
        Returns:
      • create

        public MatrixND create​(MatrixND matrix,
                               Vector data)
        Create new matrix by copying matrix in argument, and force backend to be data.
        Parameters:
        matrix - matrix to copied
        data - backend used to new matrix
      • matrixId

        public MatrixND matrixId​(int size)
        Crée une nouvelle matrice identité. Une matrice identité est une matrice à 2 dimensions dont tous les éléments de la diagonal vaut 1
        Parameters:
        size - la taille de la matrice
        Returns:
        une nouvelle matrice identité
      • createVector

        protected Vector createVector​(long length)
        cree un nouveau Vector. Si la taille demandee est inferieur au seuil alors on cree une matrice plaine, sinon on cree une matrice creuse.
        Parameters:
        length -
        Returns: