Java Code Examples for no.uib.cipr.matrix.Vector#set()

The following examples show how to use no.uib.cipr.matrix.Vector#set() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ILUT.java    From matrix-toolkits-java with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public Vector transSolve(Vector b, Vector x) {
    if (!(x instanceof DenseVector))
        return super.transSolve(b, x);

    x.set(b);

    double[] xd = ((DenseVector) x).getData();

    for (int i = numRows - 1; i >= 0; --i) {

        // Get row i
        SparseVector row = LU.getRow(i);
        int[] index = row.getIndex();
        double[] data = row.getData();

        // At this stage, x[i] is known, so move it over to the right
        // hand side for the remaining equations
        for (int j = 0; j < diagind[i]; ++j)
            xd[index[j]] -= data[j] * xd[i];

    }

    return x;
}
 
Example 2
Source File: UnitLowerCompRowMatrix.java    From matrix-toolkits-java with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public Vector transSolve(Vector b, Vector x) {
    if (!(x instanceof DenseVector))
        return super.transSolve(b, x);

    x.set(b);

    double[] xd = ((DenseVector) x).getData();

    for (int i = numRows - 1; i >= 0; --i)

        // At this stage, x[i] is known, so move it over to the right hand
        // side for the remaining equations
        for (int j = rowptr[i]; j < diagind[i]; ++j)
            xd[colind[j]] -= data[j] * xd[i];

    return x;
}
 
Example 3
Source File: UpperCompRowMatrix.java    From matrix-toolkits-java with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public Vector transSolve(Vector b, Vector x) {
    if (!(x instanceof DenseVector))
        return super.transSolve(b, x);

    x.set(b);

    double[] xd = ((DenseVector) x).getData();

    for (int i = 0; i < numRows; ++i) {

        // Solve for the current entry
        xd[i] /= data[diagind[i]];

        // Move this known solution over to the right hand side for the
        // remaining equations
        for (int j = diagind[i] + 1; j < rowptr[i + 1]; ++j)
            xd[colind[j]] -= data[j] * xd[i];
    }

    return x;
}
 
Example 4
Source File: TaggerEmbeddings.java    From EasySRL with Apache License 2.0 5 votes vote down vote up
private void loadVector(final Vector vector, final File file) throws IOException {
	final Iterator<String> lines = Util.readFileLineByLine(file);
	int row = 0;
	while (lines.hasNext()) {

		final String data = lines.next();
		vector.set(row, Double.valueOf(data));
		row++;
	}
}
 
Example 5
Source File: TaggerEmbeddings.java    From easyccg with MIT License 5 votes vote down vote up
private void loadVector(Vector vector, File file) throws IOException
{
  Iterator<String> lines = Util.readFileLineByLine(file);
  int row=0;
  while (lines.hasNext()) {

    String data = lines.next();
    vector.set(row, Double.valueOf(data));
    row++;
  }
}
 
Example 6
Source File: ILUT.java    From matrix-toolkits-java with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public Vector transSolve(Vector b, Vector x) {
    if (!(x instanceof DenseVector))
        return super.transSolve(b, x);

    x.set(b);

    double[] xd = ((DenseVector) x).getData();

    for (int i = 0; i < numRows; ++i) {

        // Get row i
        SparseVector row = LU.getRow(i);
        int[] index = row.getIndex();
        int used = row.getUsed();
        double[] data = row.getData();

        // Solve for the current entry
        xd[i] /= data[diagind[i]];

        // Move this known solution over to the right hand side for the
        // remaining equations
        for (int j = diagind[i] + 1; j < used; ++j)
            xd[index[j]] -= data[j] * xd[i];
    }

    return x;
}
 
Example 7
Source File: AMG.java    From matrix-toolkits-java with GNU Lesser General Public License v3.0 5 votes vote down vote up
public Vector apply(Vector b, Vector x) {
    u[0].set(x);
    f[0].set(b);

    transpose = false;
    cycle(0);

    return x.set(u[0]);
}
 
Example 8
Source File: AMG.java    From matrix-toolkits-java with GNU Lesser General Public License v3.0 5 votes vote down vote up
public Vector transApply(Vector b, Vector x) {
    u[0].set(x);
    f[0].set(b);

    transpose = true;
    cycle(0);

    return x.set(u[0]);
}
 
Example 9
Source File: TaggerEmbeddings.java    From EasySRL with Apache License 2.0 4 votes vote down vote up
public TaggerEmbeddings(final File modelFolder, final double beta, final int maxTagsPerWord,
		final CutoffsDictionaryInterface cutoffs) throws IOException {
	super(cutoffs, beta, loadCategories(new File(modelFolder, "categories")), maxTagsPerWord);
	try {
		final FilenameFilter embeddingsFileFilter = new PatternFilenameFilter("embeddings.*");

		// If we're using POS tags or lexical features, load l.
		this.posFeatures = loadSparseFeatures(new File(modelFolder + "/postags"));
		this.lexicalFeatures = loadSparseFeatures(new File(modelFolder + "/frequentwords"));

		// Load word embeddings.
		embeddingsFeatures = loadEmbeddings(true, modelFolder.listFiles(embeddingsFileFilter));

		// Load embeddings for capitalization and suffix features.
		discreteFeatures = new HashMap<>();
		discreteFeatures.putAll(loadEmbeddings(false, new File(modelFolder, "capitals")));
		discreteFeatures.putAll(loadEmbeddings(false, new File(modelFolder, "suffix")));
		totalFeatures = (embeddingsFeatures.get(unknownLower).length + discreteFeatures.get(unknownSuffix).length
				+ discreteFeatures.get(capsLower).length + posFeatures.size() + lexicalFeatures.size())
				* (2 * contextWindow + 1);

		// Load the list of categories used by the model.
		categoryToIndex = new HashMap<>();
		for (int i = 0; i < lexicalCategories.size(); i++) {
			categoryToIndex.put(lexicalCategories.get(i), i);
		}

		// Load the weight matrix used by the classifier.
		weightMatrix = new DenseMatrix(lexicalCategories.size(), totalFeatures);
		loadMatrix(weightMatrix, new File(modelFolder, "classifier"));

		weightMatrixRows = new ArrayList<>(lexicalCategories.size());
		for (int i = 0; i < lexicalCategories.size(); i++) {
			final Vector row = new DenseVector(totalFeatures);
			for (int j = 0; j < totalFeatures; j++) {
				row.set(j, weightMatrix.get(i, j));
			}
			weightMatrixRows.add(row);
		}

		bias = new DenseVector(lexicalCategories.size());

		loadVector(bias, new File(modelFolder, "bias"));

	} catch (final Exception e) {
		throw new RuntimeException(e);
	}
}
 
Example 10
Source File: TaggerEmbeddings.java    From easyccg with MIT License 4 votes vote down vote up
public TaggerEmbeddings(File modelFolder, int maxSentenceLength, double beta, int maxTagsPerWord) {
  try {
    FilenameFilter embeddingsFileFilter = new PatternFilenameFilter("embeddings.*");

    // If we're using POS tags or lexical features, load l.
    this.posFeatures = loadSparseFeatures(new File(modelFolder + "/postags"));     
    this.lexicalFeatures = loadSparseFeatures(new File(modelFolder + "/frequentwords"));     
    
    // Load word embeddings.
    embeddingsFeatures = loadEmbeddings(true, modelFolder.listFiles(embeddingsFileFilter));
    
    // Load embeddings for capitalization and suffix features.
    discreteFeatures = new HashMap<String, double[]>();
    discreteFeatures.putAll(loadEmbeddings(false, new File(modelFolder, "capitals")));
    discreteFeatures.putAll(loadEmbeddings(false, new File(modelFolder, "suffix")));
    totalFeatures = 
      (embeddingsFeatures.get(unknownLower).length + 
          discreteFeatures.get(unknownSuffix).length + 
          discreteFeatures.get(capsLower).length +
          posFeatures.size()  + lexicalFeatures.size())       * (2 * contextWindow + 1);
    
    // Load the list of categories used by the model.
    lexicalCategories = loadCategories(new File(modelFolder, "categories"));
    
    // Load the weight matrix used by the classifier.
    weightMatrix = new DenseMatrix(lexicalCategories.size(), totalFeatures);
    loadMatrix(weightMatrix, new File(modelFolder, "classifier"));

    weightMatrixRows = new ArrayList<Vector>(lexicalCategories.size());
    for (int i=0; i<lexicalCategories.size(); i++) {
      Vector row = new DenseVector(totalFeatures);
      for (int j=0; j<totalFeatures; j++) {
        row.set(j, weightMatrix.get(i, j));
      }
      weightMatrixRows.add(row);
    }

    bias = new DenseVector(lexicalCategories.size());
    this.beta = beta;
    this.maxTagsPerWord = maxTagsPerWord;

    int maxCategoryID = 0;
    for (Category c : lexicalCategories) {
      maxCategoryID = Math.max(maxCategoryID, c.getID());
    }
    
    this.tagDict = ImmutableMap.copyOf(loadTagDictionary(modelFolder));
    
    terminalFactory = new SyntaxTreeNodeFactory(maxSentenceLength, maxCategoryID);
    loadVector(bias, new File(modelFolder, "bias"));

  }
  catch (Exception e) {
    throw new RuntimeException(e);
  }
}
 
Example 11
Source File: AbstractIterativeSolver.java    From matrix-toolkits-java with GNU Lesser General Public License v3.0 4 votes vote down vote up
public Vector apply(Vector b, Vector x) {
    return x.set(b);
}
 
Example 12
Source File: AbstractIterativeSolver.java    From matrix-toolkits-java with GNU Lesser General Public License v3.0 4 votes vote down vote up
public Vector transApply(Vector b, Vector x) {
    return x.set(b);
}