Tabnine Logo
DoubleMatrix.getColumnVector
Code IndexAdd Tabnine to your IDE (free)

How to use
getColumnVector
method
in
de.jungblut.math.DoubleMatrix

Best Java code snippets using de.jungblut.math.DoubleMatrix.getColumnVector (Showing top 9 results out of 315)

origin: de.jungblut.common/thomasjungblut-common

/**
 * Computes the relevance for each term in U (universe of entities) to the
 * terms in the seedset.
 *
 * @param seedSet S a subset of U, this are the indices where to find the
 *                items in the similarity matrix.
 * @return a vector of length of the universe of entities. Which index
 * encapsulates the relevance described in the paper as
 * S_rel(TERM_AT_INDEX_i,S)
 */
private DenseDoubleVector computeRelevanceScore(int[] seedSet) {
  final int termsLength = termNodes.length;
  final DenseDoubleVector relevanceScores = new DenseDoubleVector(termsLength);
  final double constantLoss = 1.0d / seedSet.length;
  for (int i = 0; i < termsLength; i++) {
    double sum = 0.0d;
    for (int j : seedSet) {
      DoubleVector columnVectorI = weightMatrix.getColumnVector(i);
      DoubleVector columnVectorJ = weightMatrix.getColumnVector(j);
      double similarity = 0.0d;
      if (columnVectorI != null && columnVectorJ != null) {
        similarity = similarityMeasurer.measureSimilarity(columnVectorI,
            columnVectorJ);
      }
      sum += similarity;
    }
    relevanceScores.set(i, constantLoss * sum);
  }
  return relevanceScores;
}
origin: de.jungblut.common/thomasjungblut-common

  stateSequence[index] = chooseState(optionalRandom.get(),
      transitionProbabilities
          .getColumnVector(stateSequence[index + 1]));
} else {
  stateSequence[index] = transitionProbabilities.getColumnVector(
      stateSequence[index + 1]).maxIndex();
origin: de.jungblut.math/tjungblut-math

/**
 * Creates a new matrix with the given vector into the first column and the
 * other matrix to the other columns. This is usually used in machine learning
 * algorithms that add a bias on the zero-index column.
 * 
 * @param first the new first column.
 * @param otherMatrix the other matrix to set on from the second column.
 */
public SparseDoubleRowMatrix(DenseDoubleVector first, DoubleMatrix otherMatrix) {
 this(otherMatrix.getRowCount(), otherMatrix.getColumnCount() + 1);
 setColumnVector(0, first);
 for (int i = 1; i < numColumns; i++) {
  setColumnVector(i, otherMatrix.getColumnVector(i - 1));
 }
}
origin: de.jungblut.math/tjungblut-math

/**
 * Creates a new matrix with the given vector into the first column and the
 * other matrix to the other columns. This is usually used in machine learning
 * algorithms that add a bias on the zero-index column.
 * 
 * @param first the new first column.
 * @param otherMatrix the other matrix to set on from the second column.
 */
public DenseDoubleMatrix(DenseDoubleVector first, DoubleMatrix otherMatrix) {
 this(otherMatrix.getRowCount(), otherMatrix.getColumnCount() + 1);
 // copy the first column
 System.arraycopy(first.toArray(), 0, matrix, 0, first.getDimension());
 int offset = first.getDimension();
 for (int col : otherMatrix.columnIndices()) {
  double[] clv = otherMatrix.getColumnVector(col).toArray();
  System.arraycopy(clv, 0, matrix, offset, clv.length);
  offset += clv.length;
 }
}
origin: de.jungblut.math/tjungblut-math

@Override
public DoubleMatrix divide(DoubleMatrix other) {
 SparseDoubleRowMatrix m = new SparseDoubleRowMatrix(other);
 for (int row : this.matrix.keys()) {
  Iterator<DoubleVectorElement> iterateNonZero = matrix.get(row)
    .iterateNonZero();
  while (iterateNonZero.hasNext()) {
   DoubleVectorElement e = iterateNonZero.next();
   m.set(row, e.getIndex(),
     get(row, e.getIndex()) / other.get(row, e.getIndex()));
  }
 }
 for (int col : other.columnIndices()) {
  Iterator<DoubleVectorElement> iterateNonZero = other.getColumnVector(col)
    .iterateNonZero();
  while (iterateNonZero.hasNext()) {
   DoubleVectorElement e = iterateNonZero.next();
   m.set(e.getIndex(), col,
     get(e.getIndex(), col) / other.get(e.getIndex(), col));
  }
 }
 return m;
}
origin: de.jungblut.common/thomasjungblut-common

public static void calculateGradients(DoubleMatrix[] thetas,
                   DoubleMatrix[] thetaGradients, DoubleMatrix[] ax, DoubleMatrix[] deltaX,
                   final int m, NetworkConfiguration conf) {
  // calculate the gradients of the weights
  for (int i = 0; i < thetaGradients.length; i++) {
    DoubleMatrix gradDXA = multiply(deltaX[i + 1], ax[i], true, false, conf);
    if (m != 1) {
      thetaGradients[i] = gradDXA.divide(m);
    } else {
      thetaGradients[i] = gradDXA;
    }
    if (conf.lambda != 0d) {
      thetaGradients[i] = thetaGradients[i].add((thetas[i]
          .multiply(conf.lambda / m)));
      // subtract the regularized bias
      DoubleVector regBias = thetas[i]
          .slice(0, thetas[i].getRowCount(), 0, 1).multiply(conf.lambda / m)
          .getColumnVector(0);
      thetaGradients[i].setColumnVector(0, regBias);
    }
  }
}
origin: de.jungblut.common/thomasjungblut-common

/**
 * @return the normalized matrix (0 mean and stddev of 1) as well as the mean
 * and the stddev.
 */
public static Tuple3<DoubleMatrix, DoubleVector, DoubleVector> meanNormalizeColumns(
    DoubleMatrix x) {
  DenseDoubleMatrix toReturn = new DenseDoubleMatrix(x.getRowCount(),
      x.getColumnCount());
  final int length = x.getColumnCount();
  DoubleVector meanVector = new DenseDoubleVector(length);
  DoubleVector stddevVector = new DenseDoubleVector(length);
  for (int col = 0; col < length; col++) {
    DoubleVector column = x.getColumnVector(col);
    double mean = column.sum() / column.getLength();
    meanVector.set(col, mean);
    double var = column.subtract(mean).pow(2).sum() / column.getLength();
    stddevVector.set(col, Math.sqrt(var));
  }
  for (int col = 0; col < length; col++) {
    DoubleVector column = x.getColumnVector(col)
        .subtract(meanVector.get(col)).divide(stddevVector.get(col));
    toReturn.setColumn(col, column.toArray());
  }
  return new Tuple3<>(toReturn, meanVector, stddevVector);
}
origin: de.jungblut.common/thomasjungblut-common

@Override
public DoubleMatrix gradient(DoubleMatrix matrix) {
  DoubleMatrix newInstance = newInstance(matrix);
  if (matrix.isSparse()) {
    // if we have a sparse matrix, it is more efficient to loop over the
    // sparse column vectors
    int[] columnIndices = matrix.columnIndices();
    for (int col : columnIndices) {
      newInstance.setColumnVector(col, gradient(matrix.getColumnVector(col)));
    }
  } else {
    // on dense matrices we can be faster by directly looping over the items
    for (int i = 0; i < matrix.getRowCount(); i++) {
      for (int j = 0; j < matrix.getColumnCount(); j++) {
        newInstance.set(i, j, gradient(matrix.get(i, j)));
      }
    }
  }
  return newInstance;
}
origin: de.jungblut.common/thomasjungblut-common

DoubleVector bias = thetaGradient.getColumnVector(0);
thetaGradient = thetaGradient.subtract(thetaGradient.multiply(lambda
    / data.getRowCount()));
de.jungblut.mathDoubleMatrixgetColumnVector

Javadoc

Get a whole column of the matrix as vector.

Popular methods of DoubleMatrix

  • get
    Get a specific value of the matrix.
  • getColumnCount
    Returns the number of columns in the matrix. Always a constant time operation.
  • getRowVector
    Get a single row of the matrix as a vector.
  • set
    Sets the value at the given row and column index.
  • columnIndices
  • getRowCount
    Returns the number of rows in this matrix. Always a constant time operation.
  • setColumnVector
    Sets a whole column at index col with the given vector.
  • setRowVector
    Sets the whole row at index rowIndex with the given vector.
  • add
    Adds the elements in the given matrix to the elements in this matrix.
  • deepCopy
  • divide
    Divides each element in a column by the related element in the given vector.
  • isSparse
  • divide,
  • isSparse,
  • multiply,
  • multiplyElementWise,
  • multiplyVectorRow,
  • pow,
  • rowIndices,
  • slice,
  • subtract

Popular in Java

  • Reactive rest calls using spring rest template
  • orElseThrow (Optional)
    Return the contained value, if present, otherwise throw an exception to be created by the provided s
  • setRequestProperty (URLConnection)
  • onRequestPermissionsResult (Fragment)
  • Container (java.awt)
    A generic Abstract Window Toolkit(AWT) container object is a component that can contain other AWT co
  • Graphics2D (java.awt)
    This Graphics2D class extends the Graphics class to provide more sophisticated control overgraphics
  • FileOutputStream (java.io)
    An output stream that writes bytes to a file. If the output file exists, it can be replaced or appen
  • SocketException (java.net)
    This SocketException may be thrown during socket creation or setting options, and is the superclass
  • ThreadPoolExecutor (java.util.concurrent)
    An ExecutorService that executes each submitted task using one of possibly several pooled threads, n
  • JFrame (javax.swing)
  • Top 12 Jupyter Notebook extensions
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now