Codota Logo
DoubleMatrix.getRowCount
Code IndexAdd Codota to your IDE (free)

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

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

  • Add the Codota plugin to your IDE and get smart completions
private void myMethod () {
Gson g =
  • Codota Iconnew Gson()
  • Codota IconGsonBuilder gsonBuilder;gsonBuilder.create()
  • Codota Iconnew GsonBuilder().create()
  • Smart code suggestions by Codota
}
origin: de.jungblut.common/thomasjungblut-common

/**
 * @param x      normal feature matrix, column 0 should contain the bias.
 * @param y      normal outcome matrix, for multiple classes use the one-hot
 *               encoding. This matrix should be transposed.
 * @param lambda l1 reg parameter.
 */
public LogisticRegressionCostFunction(DoubleMatrix x, DoubleMatrix y,
                   double lambda) {
  this.x = x;
  this.lambda = lambda;
  this.m = x.getRowCount();
  this.xTransposed = this.x.transpose();
  this.y = y;
}
origin: de.jungblut.common/thomasjungblut-common

@Override
public double calculateLoss(DoubleMatrix y, DoubleMatrix hypothesis) {
  double sum = 0d;
  for (int col = 0; col < y.getColumnCount(); col++) {
    for (int row = 0; row < y.getRowCount(); row++) {
      double diff = y.get(row, col) - hypothesis.get(row, col);
      sum += (diff * diff);
    }
  }
  return sum / y.getRowCount();
}
origin: de.jungblut.common/thomasjungblut-common

@Override
public double calculateLoss(DoubleMatrix y, DoubleMatrix hypothesis) {
  DoubleMatrix multiplyElementWise = y.multiplyElementWise(hypothesis);
  double sum = 0d;
  for (int i = 0; i < multiplyElementWise.getRowCount(); i++) {
    sum += FastMath.max(0, 1 - multiplyElementWise.get(i, 0));
  }
  return sum / multiplyElementWise.getRowCount();
}
origin: de.jungblut.common/thomasjungblut-common

private static double estimateLikelihood(DoubleMatrix alpha) {
  // sum the last row in our alpha matrix generated by the forward algorithm,
  // this denotes the endstate of our sequence.
  return alpha.getRowVector(alpha.getRowCount() - 1).sum();
}
origin: de.jungblut.common/thomasjungblut-common

@Override
public double calculateLoss(DoubleMatrix y, DoubleMatrix hypothesis) {
  double sum = 0d;
  for (int col = 0; col < y.getColumnCount(); col++) {
    for (int row = 0; row < y.getRowCount(); row++) {
      sum += FastMath.abs(y.get(row, col) - hypothesis.get(row, col));
    }
  }
  return sum / y.getRowCount();
}
origin: de.jungblut.common/thomasjungblut-common

public ConditionalLikelihoodCostFunction(DoubleMatrix features,
                     DoubleMatrix outcome) {
  this.features = features;
  this.outcome = outcome;
  this.m = outcome.getRowCount();
  this.classes = outcome.getColumnCount() == 1 ? 2 : outcome.getColumnCount();
}
origin: de.jungblut.common/thomasjungblut-common

static DoubleMatrix binarize(Random r, DoubleMatrix hiddenActivations) {
  for (int i = 0; i < hiddenActivations.getRowCount(); i++) {
    for (int j = 0; j < hiddenActivations.getColumnCount(); j++) {
      hiddenActivations.set(i, j,
          hiddenActivations.get(i, j) > r.nextDouble() ? 1d : 0d);
    }
  }
  return hiddenActivations;
}
origin: de.jungblut.common/thomasjungblut-common

@Override
public double calculateLoss(DoubleMatrix y, DoubleMatrix hypothesis) {
  return y.subtract(hypothesis).sum() / y.getRowCount();
}
origin: de.jungblut.common/thomasjungblut-common

protected DoubleMatrix newInstance(DoubleMatrix mat) {
  if (mat.isSparse()) {
    return new SparseDoubleRowMatrix(mat.getRowCount(), mat.getColumnCount());
  } else {
    return new DenseDoubleMatrix(mat.getRowCount(), mat.getColumnCount());
  }
}
origin: de.jungblut.common/thomasjungblut-common

/**
 * Folds a single matrix into a single vector by rows.
 */
public static DoubleVector foldMatrix(DoubleMatrix mat) {
  DoubleVector vec = new DenseDoubleVector(mat.getRowCount()
      * mat.getColumnCount());
  int index = 0;
  for (int i = 0; i < mat.getRowCount(); i++) {
    for (int j = 0; j < mat.getColumnCount(); j++) {
      vec.set(index++, mat.get(i, j));
    }
  }
  return vec;
}
origin: de.jungblut.common/thomasjungblut-common

@Override
public double calculateLoss(DoubleMatrix y, DoubleMatrix hypothesis) {
  return y.multiplyElementWise(MathUtils.logMatrix(hypothesis)).sum()
      / y.getRowCount();
}
origin: de.jungblut.math/tjungblut-math

/**
 * Row-copies the given matrix to this sparse implementation.
 * 
 * @param mat the matrix to copy.
 */
public SparseDoubleRowMatrix(DoubleMatrix mat) {
 this(mat.getRowCount(), mat.getColumnCount());
 for (int i = 0; i < numColumns; i++) {
  setRowVector(i, mat.getRowVector(i));
 }
}
origin: de.jungblut.common/thomasjungblut-common

/**
 * Sets the weights in the whole matrix uniformly between -eInit and eInit
 * (eInit is the standard deviation) with zero mean.
 */
private void setWeightsUniformly(RandomDataImpl rnd, double eInit) {
  for (int i = 0; i < weights.getColumnCount(); i++) {
    for (int j = 0; j < weights.getRowCount(); j++) {
      weights.set(j, i, rnd.nextUniform(-eInit, eInit));
    }
  }
}
origin: de.jungblut.common/thomasjungblut-common

public static double calculateRegularization(DoubleMatrix[] thetas,
                       final int m, NetworkConfiguration conf) {
  double regularization = 0d;
  // only calculate the regularization term if lambda is not 0
  if (conf.lambda != 0d) {
    for (DoubleMatrix theta : thetas) {
      regularization += (theta.slice(0, theta.getRowCount(), 1,
          theta.getColumnCount())).pow(2).sum();
    }
    regularization = (conf.lambda / (2.0d * m)) * regularization;
  }
  return regularization;
}
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.common/thomasjungblut-common

@Override
public DoubleMatrix apply(DoubleMatrix matrix) {
  DoubleMatrix dm = newInstance(matrix);
  for (int row = 0; row < matrix.getRowCount(); row++) {
    DoubleVector apply = apply(matrix.getRowVector(row));
    if (apply.getLength() != 0) {
      dm.setRowVector(row, apply);
    }
  }
  return dm;
}
origin: de.jungblut.math/tjungblut-math

@Override
public DoubleMatrix add(DoubleMatrix other) {
 SparseDoubleRowMatrix result = new SparseDoubleRowMatrix(
   other.getRowCount(), other.getColumnCount());
 for (int row : this.matrix.keys()) {
  Iterator<DoubleVectorElement> iterate = matrix.get(row).iterate();
  while (iterate.hasNext()) {
   DoubleVectorElement e = iterate.next();
   result.set(row, e.getIndex(),
     e.getValue() + other.get(row, e.getIndex()));
  }
 }
 return result;
}
origin: de.jungblut.math/tjungblut-math

@Override
public DoubleMatrix subtract(DoubleMatrix other) {
 SparseDoubleRowMatrix result = new SparseDoubleRowMatrix(
   other.getRowCount(), other.getColumnCount());
 for (int row : this.matrix.keys()) {
  Iterator<DoubleVectorElement> iterate = matrix.get(row).iterate();
  while (iterate.hasNext()) {
   DoubleVectorElement e = iterate.next();
   result.set(row, e.getIndex(),
     e.getValue() - other.get(row, e.getIndex()));
  }
 }
 return result;
}
origin: de.jungblut.common/thomasjungblut-common

/**
 * @return a log'd matrix that was guarded against edge cases of the
 * logarithm.
 */
public static DoubleMatrix logMatrix(DoubleMatrix input) {
  DenseDoubleMatrix log = new DenseDoubleMatrix(input.getRowCount(),
      input.getColumnCount());
  for (int row = 0; row < log.getRowCount(); row++) {
    for (int col = 0; col < log.getColumnCount(); col++) {
      double d = input.get(row, col);
      log.set(row, col, guardedLogarithm(d));
    }
  }
  return log;
}
origin: de.jungblut.common/thomasjungblut-common

@Override
public double calculateLoss(DoubleMatrix y, DoubleMatrix hypothesis) {
  DoubleMatrix negativeOutcome = y.subtractBy(1.0d);
  DoubleMatrix inverseOutcome = y.multiply(-1d);
  DoubleMatrix negativeHypo = hypothesis.subtractBy(1d);
  DoubleMatrix negativeLogHypo = MathUtils.logMatrix(negativeHypo);
  DoubleMatrix positiveLogHypo = MathUtils.logMatrix(hypothesis);
  DoubleMatrix negativePenalty = negativeOutcome
      .multiplyElementWise(negativeLogHypo);
  DoubleMatrix positivePenalty = inverseOutcome
      .multiplyElementWise(positiveLogHypo);
  return (positivePenalty.subtract(negativePenalty)).sum() / y.getRowCount();
}
de.jungblut.mathDoubleMatrixgetRowCount

Javadoc

Returns the number of rows in this matrix. Always a constant time operation.

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
  • getColumnVector
    Get a whole column of the matrix as vector.
  • 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

  • Creating JSON documents from java classes using gson
  • setScale (BigDecimal)
  • getResourceAsStream (ClassLoader)
    Returns a stream for the resource with the specified name. See #getResource(String) for a descriptio
  • runOnUiThread (Activity)
  • InetAddress (java.net)
    This class represents an Internet Protocol (IP) address. An IP address is either a 32-bit or 128-bit
  • Queue (java.util)
    A collection designed for holding elements prior to processing. Besides basic java.util.Collection o
  • Set (java.util)
    A collection that contains no duplicate elements. More formally, sets contain no pair of elements e1
  • TimeUnit (java.util.concurrent)
    A TimeUnit represents time durations at a given unit of granularity and provides utility methods to
  • Filter (javax.servlet)
    A filter is an object that performs filtering tasks on either the request to a resource (a servlet o
  • Options (org.apache.commons.cli)
    Main entry-point into the library. Options represents a collection of Option objects, which describ
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now