Jama.Matrix.arrayTimes()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(7.6k)|赞(0)|评价(0)|浏览(106)

本文整理了Java中Jama.Matrix.arrayTimes()方法的一些代码示例,展示了Matrix.arrayTimes()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Matrix.arrayTimes()方法的具体详情如下:
包路径:Jama.Matrix
类名称:Matrix
方法名:arrayTimes

Matrix.arrayTimes介绍

暂无

代码示例

代码示例来源:origin: stackoverflow.com

public class CosineSimilarity extends AbstractSimilarity {

 @Override
 protected double computeSimilarity(Matrix sourceDoc, Matrix targetDoc) {
  double dotProduct = sourceDoc.arrayTimes(targetDoc).norm1();
  double eucledianDist = sourceDoc.normF() * targetDoc.normF();
  return dotProduct / eucledianDist;
 }
}

代码示例来源:origin: gov.nist.math/jama

B = Matrix.random(A.getRowDimension(),A.getColumnDimension());
try {
 S = A.arrayTimes(S);
 errorCount = try_failure(errorCount,"arrayTimes conformance check... ","nonconformance not raised");
} catch ( IllegalArgumentException e ) {
 try_success("arrayTimes conformance check... ","");
C = A.arrayTimes(B);
try {
 check(C.arrayRightDivideEquals(B),A);

代码示例来源:origin: net.sf.meka/meka

/**
 * Multiply - multiply vectors a and b together.
 */
public static double[] multiply(final double[] a, final double[] b) throws Exception {
  Jama.Matrix a_ = new Jama.Matrix(a,1);
  Jama.Matrix b_ = new Jama.Matrix(b,1);
  Jama.Matrix c_ = a_.arrayTimes(b_);
  return c_.getArray()[0];
}

代码示例来源:origin: Waikato/meka

/**
 * Multiply - multiply vectors a and b together.
 */
public static double[] multiply(final double[] a, final double[] b) throws Exception {
  Jama.Matrix a_ = new Jama.Matrix(a,1);
  Jama.Matrix b_ = new Jama.Matrix(b,1);
  Jama.Matrix c_ = a_.arrayTimes(b_);
  return c_.getArray()[0];
}

代码示例来源:origin: openimaj/openimaj

@Override
public Double aggregate(DoubleSynchronisedTimeSeriesCollection series) {
  Matrix squarediffs = null;
  for (DoubleTimeSeries ds: series.allseries()) {
    if(squarediffs == null){
      squarediffs = new Matrix(new double[][]{ds.getData()});
    }
    else{
      squarediffs = squarediffs.minus(new Matrix(new double[][]{ds.getData()}));
      squarediffs = squarediffs.arrayTimes(squarediffs );
    }
  }
  return MatrixUtils.sum(squarediffs);
}

代码示例来源:origin: cmu-phil/tetrad

/**
 * Compute compute test set covariances
 *
 * @param loghyper column <code>Matrix</code> of hyperparameters
 * @param X        input dataset
 * @param Xstar    test set
 * @return [K(Xstar,Xstar) K(X,Xstar)]
 */
public Matrix[] compute(Matrix loghyper, Matrix X, Matrix Xstar) {
  if(loghyper.getColumnDimension()!=1 || loghyper.getRowDimension()!=numParameters())
    throw new IllegalArgumentException("Wrong number of hyperparameters, "+loghyper.getRowDimension()+" instead of "+numParameters());
  final double it2 = Math.exp(-2*loghyper.get(0,0));
  Matrix A = sumRows(Xstar.arrayTimes(Xstar));
  A= addValue(A,1).times(it2);
  Matrix B = X.times(Xstar.transpose());
  B = addValue(B,1).times(it2);
  return new Matrix[]{A,B};
}

代码示例来源:origin: openimaj/openimaj

@Override
  protected void mstep(EMGMM gmm, GaussianMixtureModelEM learner, Matrix X, Matrix responsibilities,
      Matrix weightedXsum,
      double[] norm)
{
    final Matrix avgX2uw = responsibilities.transpose().times(X.arrayTimes(X));
    for (int i = 0; i < gmm.gaussians.length; i++) {
      final Matrix weightedXsumi = new Matrix(new double[][] { weightedXsum.getArray()[i] });
      final Matrix avgX2uwi = new Matrix(new double[][] { avgX2uw.getArray()[i] });
      final Matrix avgX2 = avgX2uwi.times(norm[i]);
      final Matrix mu = ((AbstractMultivariateGaussian) gmm.gaussians[i]).mean;
      final Matrix avgMeans2 = MatrixUtils.pow(mu, 2);
      final Matrix avgXmeans = mu.arrayTimes(weightedXsumi).times(norm[i]);
      final Matrix covar = MatrixUtils.plus(avgX2.minus(avgXmeans.times(2)).plus(avgMeans2),
          learner.minCovar);
      ((DiagonalMultivariateGaussian) gmm.gaussians[i]).variance = covar.getArray()[0];
    }
  }
},

代码示例来源:origin: openimaj/openimaj

@Override
public Double aggregate(DoubleSynchronisedTimeSeriesCollection series) {
  Matrix squarediffs = null;
  int size = 0;
  for (DoubleTimeSeries ds: series.allseries()) {
    if(squarediffs == null){
      squarediffs = new Matrix(new double[][]{ds.getData()});
    }
    else{
      squarediffs = squarediffs.minus(new Matrix(new double[][]{ds.getData()}));
      squarediffs = squarediffs.arrayTimes(squarediffs );
    }
    size = ds.size();
  }
  return MatrixUtils.sum(squarediffs)/size;
}

代码示例来源:origin: openimaj/openimaj

@Override
  protected void mstep(EMGMM gmm, GaussianMixtureModelEM learner, Matrix X, Matrix responsibilities,
      Matrix weightedXsum,
      double[] norm)
{
    final Matrix avgX2uw = responsibilities.transpose().times(X.arrayTimes(X));
    for (int i = 0; i < gmm.gaussians.length; i++) {
      final Matrix weightedXsumi = new Matrix(new double[][] { weightedXsum.getArray()[i] });
      final Matrix avgX2uwi = new Matrix(new double[][] { avgX2uw.getArray()[i] });
      final Matrix avgX2 = avgX2uwi.times(norm[i]);
      final Matrix mu = ((AbstractMultivariateGaussian) gmm.gaussians[i]).mean;
      final Matrix avgMeans2 = MatrixUtils.pow(mu, 2);
      final Matrix avgXmeans = mu.arrayTimes(weightedXsumi).times(norm[i]);
      final Matrix covar = MatrixUtils.plus(avgX2.minus(avgXmeans.times(2)).plus(avgMeans2),
          learner.minCovar);
      ((SphericalMultivariateGaussian) gmm.gaussians[i]).variance = MatrixUtils.sum(covar)
          / X.getColumnDimension();
    }
  }
},

代码示例来源:origin: cmu-phil/tetrad

/**
 * Coompute the derivatives of this <code>CovarianceFunction</code> with respect
 * to the hyperparameter with index <code>idx</code>
 *
 * @param loghyper hyperparameters
 * @param X        input dataset
 * @param index    hyperparameter index
 * @return <code>Matrix</code> of derivatives
 */
public Matrix computeDerivatives(Matrix loghyper, Matrix X, int index) {
  if(loghyper.getColumnDimension()!=1 || loghyper.getRowDimension()!=numParameters())
    throw new IllegalArgumentException("Wrong number of hyperparameters, "+loghyper.getRowDimension()+" instead of "+numParameters());
  if(index>numParameters()-1)
    throw new IllegalArgumentException("Wrong hyperparameters index "+index+" it should be smaller or equal to "+(numParameters()-1));
  double ell = Math.exp(loghyper.get(0,0));
  double sf2 = Math.exp(2*loghyper.get(1,0));
  Matrix tmp = squareDist(X.transpose().times(1/ell));
  Matrix A = null;
  if(index==0){
    A = exp(tmp.times(-0.5)).arrayTimes(tmp).times(sf2);
  } else {
    A = exp(tmp.times(-0.5)).times(2*sf2);
  }
  return A;
}

代码示例来源:origin: cmu-phil/tetrad

/**
 * Compute compute test set covariances
 *
 * @param loghyper column <code>Matrix</code> of hyperparameters
 * @param X        input dataset
 * @param Xstar    test set
 * @return [K(Xstar,Xstar) K(X,Xstar)]
 */
public Matrix[] compute(Matrix loghyper, Matrix X, Matrix Xstar) {
  if(X.getColumnDimension()!=D)
    throw new IllegalArgumentException("The number of dimensions specified on the covariance function "+D+" must agree with the size of the input vector"+X.getColumnDimension());
  if(loghyper.getColumnDimension()!=1 || loghyper.getRowDimension()!=numParameters())
    throw new IllegalArgumentException("Wrong number of hyperparameters, "+loghyper.getRowDimension()+" instead of "+numParameters());
  final Matrix ell = exp(loghyper.getMatrix(0,D-1,0,0));                         // characteristic length scales
  Matrix diag = new Matrix(D,D);
  for(int i=0; i<D; i++)
    diag.set(i,i,1/ell.get(i,0));
  X = X.times(diag);
  Xstar = Xstar.times(diag);
  Matrix A = sumRows(Xstar.arrayTimes(Xstar));
  Matrix B = X.times(Xstar.transpose());
  return new Matrix[]{A,B};
}

代码示例来源:origin: net.sf.meka/meka

dZ[nW] = MatrixUtils.dsigma(Z[nW]).arrayTimes(E_y);
  dZ[i] = MatrixUtils.dsigma(Z[i]).arrayTimes(E);
  dZ[i] = new Matrix(MatrixUtils.removeBias(dZ[i].getArray()));

代码示例来源:origin: Waikato/meka

dZ[nW] = MatrixUtils.dsigma(Z[nW]).arrayTimes(E_y);
  dZ[i] = MatrixUtils.dsigma(Z[i]).arrayTimes(E);
  dZ[i] = new Matrix(MatrixUtils.removeBias(dZ[i].getArray()));

代码示例来源:origin: cmu-phil/tetrad

Matrix col = squareDist(X.getMatrix(0,X.getRowDimension()-1,index,index).transpose().times(1/ell.get(index,0)));
  A = K.arrayTimes(col);
} else {    // magnitude parameter
  A=K.times(2);

代码示例来源:origin: cmu-phil/tetrad

df0.set(i,0,sum(W.arrayTimes(covFunction.computeDerivatives(logtheta, x, i)))/2);

代码示例来源:origin: openimaj/openimaj

Matrix var = MatrixUtils.sumCols(mat.arrayTimes(mat)).times(1./inds.size()).minus(mean.arrayTimes(mean));

代码示例来源:origin: org.openimaj/sandbox

Matrix var = MatrixUtils.sumCols(mat.arrayTimes(mat)).times(1./inds.size()).minus(mean.arrayTimes(mean));

相关文章