public void factorize(SparseMatrix matrix, int dimensions) { try { File mFile = File.createTempFile("matlab-input", ".dat"); MatrixIO.writeMatrix(matrix, mFile, Format.MATLAB_SPARSE); factorize(new MatrixFile(mFile, Format.MATLAB_SPARSE), dimensions); } catch (IOException ioe) { LOG.log(Level.SEVERE, "Converting to matlab file", ioe); } }
/** * {@inheritDoc} */ public void factorize(MatrixFile mFile, int dimensions) { try { Matrix[] SVD = SvdlibjDriver.svd( mFile.getFile(), mFile.getFormat(), dimensions); dataClasses = SVD[0]; scaledDataClasses = false; classFeatures = SVD[2]; scaledClassFeatures = false; singularValues = new double[dimensions]; for (int k = 0; k < dimensions; ++k) singularValues[k] = SVD[1].get(k, k); } catch (IOException ioe) { throw new IOError(ioe); } }
/** * {@inheritDoc} */ public void factorize(MatrixFile mFile, int numDimensions) { factorize((SparseMatrix) mFile.load(), numDimensions); }
/** * Projects the rows of the input matrix into a lower dimensional subspace * using the Locality Preserving Projection (LPP) algorithm and the affinity * matrix as a guide to locality. * * @param inputMatrix a matrix file whose rows will be projected * @param affinityMatrix a square matrix whose entries denote locality * between the rows of the inputMatrix. Note that this matrix's * dimensions must be equal to the number of rows in the input * matrix. * @param dimensions the number of dimensions into which the inputMatrix * should be projected * * @return a file containing the LPP-reduced data in {@code DENSE_TEXT} * format. * * @throws IOError if any exception occurrs during processing */ public static MatrixFile project(MatrixFile inputMatrix, MatrixFile affinityMatrix, int dimensions) { try { File outputFile = File.createTempFile("lcc-output-matrix", ".dat"); execute(inputMatrix.getFile(), affinityMatrix.getFile(), dimensions, outputFile); return new MatrixFile(outputFile, MatrixIO.Format.DENSE_TEXT); } catch (IOException ioe) { throw new IOError(ioe); } }
File matrixFile = input.getFile(); MatrixIO.Format format = input.getFormat(); return new MatrixFile(affMatrixFile, MatrixIO.Format.MATLAB_SPARSE); } catch (IOException ioe) { throw new IOError(ioe);
/** * Executes the LPP script, thereby computing the locality preserving * projection of the data matrix to the specified number of dimension, using * the affinity matrix to determine locality, and returning the result as a * {@link Matrix}. * * @param dataMatrix a matrix where each row is a data points to be * projected * @param affMatrixFile the file containing the affinity matrix that * connects data points in the {@code dataMatrixFile} * @param dims the number of dimensions to which the matrix should be * reduced */ private static Matrix execute(Matrix dataMatrix, MatrixFile affMatrixFile, int dims) throws IOException { // Write the input matrix to a file for Matlab/Octave to use File mInput = File.createTempFile("lpp-input-data-matrix",".dat"); mInput.deleteOnExit(); MatrixIO.writeMatrix(dataMatrix, mInput, MatrixIO.Format.MATLAB_SPARSE); // Create an output matrix to hold the results of the computation from // Matlab until they can be read back into memory File output = File.createTempFile("lpp-output-matrix",".dat"); // Exceute the LPP code execute(mInput, affMatrixFile.getFile(), dims, output); // Upon finishing, read the matrix back into memory. return MatrixIO.readMatrix(output, MatrixIO.Format.DENSE_TEXT); }
File matrixFile = input.getFile(); MatrixIO.Format format = input.getFormat(); return new MatrixFile(affMatrixFile, MatrixIO.Format.MATLAB_SPARSE); } catch (IOException ioe) { throw new IOError(ioe);
/** * Projects the rows of the input matrix into a lower dimensional subspace * using the Locality Preserving Projection (LPP) algorithm and the affinity * matrix as a guide to locality. * * @param inputMatrix a matrix file whose rows will be projected * @param affinityMatrix a square matrix whose entries denote locality * between the rows of the inputMatrix. Note that this matrix's * dimensions must be equal to the number of rows in the input * matrix. * @param dimensions the number of dimensions into which the inputMatrix * should be projected * * @return a file containing the LPP-reduced data in {@code DENSE_TEXT} * format. * * @throws IOError if any exception occurrs during processing */ public static MatrixFile project(MatrixFile inputMatrix, MatrixFile affinityMatrix, int dimensions) { try { File outputFile = File.createTempFile("lcc-output-matrix", ".dat"); execute(inputMatrix.getFile(), affinityMatrix.getFile(), dimensions, outputFile); return new MatrixFile(outputFile, MatrixIO.Format.DENSE_TEXT); } catch (IOException ioe) { throw new IOError(ioe); } }
/** * Executes the LPP script, thereby computing the locality preserving * projection of the data matrix to the specified number of dimension, using * the affinity matrix to determine locality, and returning the result as a * {@link Matrix}. * * @param dataMatrix a matrix where each row is a data points to be * projected * @param affMatrixFile the file containing the affinity matrix that * connects data points in the {@code dataMatrixFile} * @param dims the number of dimensions to which the matrix should be * reduced */ private static Matrix execute(Matrix dataMatrix, MatrixFile affMatrixFile, int dims) throws IOException { // Write the input matrix to a file for Matlab/Octave to use File mInput = File.createTempFile("lpp-input-data-matrix",".dat"); mInput.deleteOnExit(); MatrixIO.writeMatrix(dataMatrix, mInput, MatrixIO.Format.MATLAB_SPARSE); // Create an output matrix to hold the results of the computation from // Matlab until they can be read back into memory File output = File.createTempFile("lpp-output-matrix",".dat"); // Exceute the LPP code execute(mInput, affMatrixFile.getFile(), dims, output); // Upon finishing, read the matrix back into memory. return MatrixIO.readMatrix(output, MatrixIO.Format.DENSE_TEXT); }
File matrixFile = input.getFile(); MatrixIO.Format format = input.getFormat(); return new MatrixFile(affMatrixFile, MatrixIO.Format.MATLAB_SPARSE); } catch (IOException ioe) { throw new IOError(ioe);
public void factorize(SparseMatrix matrix, int dimensions) { try { File mFile = File.createTempFile("octave-input", ".dat"); mFile.deleteOnExit(); MatrixIO.writeMatrix(matrix, mFile, Format.MATLAB_SPARSE); factorize(new MatrixFile(mFile, Format.MATLAB_SPARSE), dimensions); } catch (IOException ioe) { LOG.log(Level.SEVERE, "Converting to matlab file", ioe); } }
/** * {@inheritDoc} */ public void factorize(MatrixFile mFile, int numDimensions) { factorize((SparseMatrix) mFile.load(), numDimensions); }
File matrixFile = input.getFile(); MatrixIO.Format format = input.getFormat(); return new MatrixFile(affMatrixFile, MatrixIO.Format.MATLAB_SPARSE); } catch (IOException ioe) { throw new IOError(ioe);
public void factorize(SparseMatrix matrix, int dimensions) { try { File mFile = File.createTempFile("matlab-input", ".dat"); MatrixIO.writeMatrix(matrix, mFile, Format.MATLAB_SPARSE); factorize(new MatrixFile(mFile, Format.MATLAB_SPARSE), dimensions); } catch (IOException ioe) { LOG.log(Level.SEVERE, "Converting to matlab file", ioe); } }
/** * {@inheritDoc} */ public void factorize(MatrixFile mFile, int numDimensions) { factorize((SparseMatrix) mFile.load(), numDimensions); }
/** * {@inheritDoc} * * @param properties {@inheritDoc} See this class's {@link VectorSpaceModel * javadoc} for the full list of supported properties. */ public void processSpace(Properties properties) { try { Transform transform = null; // Load any optionally specifie transform class String transformClass = properties.getProperty(MATRIX_TRANSFORM_PROPERTY); if (transformClass != null) transform = ReflectionUtil.getObjectInstance( transformClass); MatrixFile processedSpace = super.processSpace(transform); System.out.printf("Matrix saved in %s as %s%n", processedSpace.getFile(), processedSpace.getFormat()); wordSpace = MatrixIO.readMatrix(processedSpace.getFile(), processedSpace.getFormat()); System.out.printf("loaded word space of %d x %d%n", wordSpace.rows(), wordSpace.columns()); } catch (IOException ioe) { throw new IOError(ioe); } } }
public void factorize(SparseMatrix matrix, int dimensions) { try { File mFile = File.createTempFile("octave-input", ".dat"); MatrixIO.writeMatrix(matrix, mFile, Format.MATLAB_SPARSE); factorize(new MatrixFile(mFile, Format.MATLAB_SPARSE), dimensions); } catch (IOException ioe) { LOG.log(Level.SEVERE, "Converting to matlab file", ioe); } }
/** * {@inheritDoc} */ public void factorize(MatrixFile mFile, int numDimensions) { factorize((SparseMatrix) mFile.load(), numDimensions); }