本文整理了Java中cern.colt.matrix.linalg.Algebra.mult()
方法的一些代码示例,展示了Algebra.mult()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Algebra.mult()
方法的具体详情如下:
包路径:cern.colt.matrix.linalg.Algebra
类名称:Algebra
方法名:mult
[英]Inner product of two vectors; Sum(x[i] * y[i]). Also known as dot product.
Equivalent to x.zDotProduct(y).
[中]两个向量的内积;和(x[i]*y[i])。也称为点积。
相当于x.zdot积(y)。
代码示例来源:origin: blazegraph/database
/**
* Returns the two-norm (aka <i>euclidean norm</i>) of vector <tt>x</tt>; equivalent to <tt>mult(x,x)</tt>.
*/
public double norm2(DoubleMatrix1D x) {
return mult(x,x);
}
/**
代码示例来源:origin: com.github.vincentk/joptimizer
@Override
public double[][] hessian(double[] X) {
DoubleMatrix1D x = DoubleFactory1D.dense.make(X);
DoubleMatrix1D g = ALG.mult(A, x).assign(b, Functions.plus).assign(Functions.exp);
double den = g.zSum();
DoubleMatrix1D r = DoubleFactory1D.dense.make(dim);
for(int i=0; i<dim; i++){
double d = 0d;
for(int k=0; k<A.rows(); k++){
d += g.get(k) * A.get(k, i);
}
r.set(i, d);
}
DoubleMatrix2D ret = DoubleFactory2D.dense.make(dim, dim);
ret.assign(ALG.multOuter(r, r, null).assign(Mult.mult(-1d/Math.pow(den, 2))), Functions.plus);
for(int k=0; k<A.rows(); k++){
ret.assign(ALG.multOuter(A.viewRow(k), A.viewRow(k), null).assign(Mult.mult(g.get(k))).assign(Mult.mult(1d/den)), Functions.plus);
}
return ret.toArray();
}
代码示例来源:origin: com.blazegraph/colt
/**
* Returns the two-norm (aka <i>euclidean norm</i>) of vector <tt>x</tt>; equivalent to <tt>mult(x,x)</tt>.
*/
public double norm2(DoubleMatrix1D x) {
return mult(x,x);
}
/**
代码示例来源:origin: com.github.vincentk/joptimizer
/**
* Surrogate duality gap.
*
* @see "Convex Optimization, 11.59"
*/
private double getSurrogateDualityGap(DoubleMatrix1D fiX, DoubleMatrix1D L) {
return -ALG.mult(fiX, L);
}
代码示例来源:origin: com.github.vincentk/joptimizer
/**
* Surrogate duality gap.
*
* @see "Convex Optimization, 11.59"
*/
private double getSurrogateDualityGap(DoubleMatrix1D fiX, DoubleMatrix1D L) {
return -ALG.mult(fiX, L);
}
代码示例来源:origin: com.github.vincentk/joptimizer
@Override
public final double value(double[] X) {
DoubleMatrix1D x = DoubleFactory1D.dense.make(X);
double ret = r;
if (P != null) {
ret += 0.5 * ALG.mult(x, ALG.mult(P, x));
}
if (q != null) {
ret += ALG.mult(q, x);
}
return ret;
}
代码示例来源:origin: blazegraph/database
/**
* Linear algebraic matrix power; <tt>B = A<sup>k</sup> <==> B = A*A*...*A</tt>.
* @param A the source matrix; must be square.
* @param k the exponent, can be any number.
* @return a new result matrix.
*
* @throws IllegalArgumentException if <tt>!Testing.isSquare(A)</tt>.
*/
private DoubleMatrix2D xpowSlow(DoubleMatrix2D A, int k) {
//cern.colt.Timer timer = new cern.colt.Timer().start();
DoubleMatrix2D result = A.copy();
for (int i=0; i<k-1; i++) {
result = mult(result,A);
}
//timer.stop().display();
return result;
}
}
代码示例来源:origin: com.blazegraph/colt
/**
* Linear algebraic matrix power; <tt>B = A<sup>k</sup> <==> B = A*A*...*A</tt>.
* @param A the source matrix; must be square.
* @param k the exponent, can be any number.
* @return a new result matrix.
*
* @throws IllegalArgumentException if <tt>!Testing.isSquare(A)</tt>.
*/
private DoubleMatrix2D xpowSlow(DoubleMatrix2D A, int k) {
//cern.colt.Timer timer = new cern.colt.Timer().start();
DoubleMatrix2D result = A.copy();
for (int i=0; i<k-1; i++) {
result = mult(result,A);
}
//timer.stop().display();
return result;
}
}
代码示例来源:origin: com.github.vincentk/joptimizer
/**
* @TODO: check this!!!
* @see "http://mathworld.wolfram.com/PositiveDefiniteMatrix.html"
*/
public static DoubleMatrix2D randomValuesPositiveMatrix(int rows, int cols, double min, double max, Long seed) {
DoubleMatrix2D Q = Utils.randomValuesMatrix(rows, cols, min, max, seed);
DoubleMatrix2D P = Algebra.DEFAULT.mult(Q, Algebra.DEFAULT.transpose(Q.copy()));
return Algebra.DEFAULT.mult(P, P);
}
代码示例来源:origin: blazegraph/database
QMatrix = Algebra.DEFAULT.mult (transposeMatrix,patternMatrix);
inverseQMatrix = Algebra.DEFAULT.inverse (QMatrix);
pseudoInverseMatrix = Algebra.DEFAULT.mult (inverseQMatrix,transposeMatrix);
weightMatrix = Algebra.DEFAULT.mult (patternMatrix,pseudoInverseMatrix);
System.out.println("done.");
代码示例来源:origin: com.blazegraph/colt
QMatrix = Algebra.DEFAULT.mult (transposeMatrix,patternMatrix);
inverseQMatrix = Algebra.DEFAULT.inverse (QMatrix);
pseudoInverseMatrix = Algebra.DEFAULT.mult (inverseQMatrix,transposeMatrix);
weightMatrix = Algebra.DEFAULT.mult (patternMatrix,pseudoInverseMatrix);
System.out.println("done.");
代码示例来源:origin: cmu-phil/tetrad
private double lik(DoubleMatrix2D K, DoubleMatrix2D S, int n, int k) {
Algebra algebra = new Algebra();
DoubleMatrix2D SK = algebra.mult(S, K);
return (algebra.trace(SK) - Math.log(algebra.det(SK)) - k) * n;
}
代码示例来源:origin: com.github.vincentk/joptimizer
@Override
public double value(double[] X) {
DoubleMatrix1D x = DoubleFactory1D.dense.make(X);
DoubleMatrix1D g = ALG.mult(A, x).assign(b, Functions.plus).assign(Functions.exp);
return Math.log(g.zSum());
}
代码示例来源:origin: lessthanoptimal/Java-Matrix-Benchmark
@Override
public long process(BenchmarkMatrix[] inputs, BenchmarkMatrix[] outputs, long numTrials) {
DenseDoubleMatrix2D matA = inputs[0].getOriginal();
DenseDoubleMatrix2D matB = inputs[1].getOriginal();
Algebra alg = new Algebra();
DoubleMatrix2D result = null;
long prev = System.nanoTime();
for( long i = 0; i < numTrials; i++ ) {
result = alg.mult(matA,matB);
}
long elapsed = System.nanoTime()-prev;
if( outputs != null ) {
outputs[0] = new ColtBenchmarkMatrix(result);
}
return elapsed;
}
}
代码示例来源:origin: com.github.vincentk/joptimizer
@Override
public final double[] gradient(double[] X) {
DoubleMatrix1D x = DoubleFactory1D.dense.make(X);
DoubleMatrix1D ret = null;
if(P!=null){
if (q != null) {
//P.x + q
//ret = P.zMult(x, q.copy(), 1, 1, false);
ret = ColtUtils.zMult(P, x, q, 1);
} else {
ret = ALG.mult(P, x);
}
}else{
ret = q;
}
return ret.toArray();
}
代码示例来源:origin: com.github.vincentk/joptimizer
/**
* Calculate the scaled residual
* <br> ||Ax-b||_oo/( ||A||_oo . ||x||_oo + ||b||_oo ), with
* <br> ||x||_oo = max(||x[i]||)
*/
public static double calculateScaledResidual(DoubleMatrix2D A, DoubleMatrix2D X, DoubleMatrix2D B){
double residual = -Double.MAX_VALUE;
double niX = Algebra.DEFAULT.normInfinity(X);
double niB = Algebra.DEFAULT.normInfinity(B);
if(Double.compare(niX, 0.)==0 && Double.compare(niB, 0.)==0){
return 0;
}else{
double num = Algebra.DEFAULT.normInfinity(Algebra.DEFAULT.mult(A, X).assign(B, Functions.minus));
double den = Algebra.DEFAULT.normInfinity(A) * niX + niB;
residual = num / den;
//log.debug("scaled residual: " + residual);
return residual;
}
}
代码示例来源:origin: com.github.vincentk/joptimizer
@Override
public double[] gradient(double[] X) {
DoubleMatrix1D x = DoubleFactory1D.dense.make(X);
DoubleMatrix1D g = ALG.mult(A, x).assign(b, Functions.plus).assign(Functions.exp);
double den = g.zSum();
double[] R = new double[dim];
for(int i=0; i<dim; i++){
double d = 0d;
for(int k=0; k<A.rows(); k++){
d += g.get(k) * A.get(k, i);
}
R[i] = d/den;
}
return R;
}
代码示例来源:origin: blazegraph/database
/**
*/
public static void doubleTest14(int r1, int c, int r2) {
double[] values = {0, 1, 2, 3};
DoubleMatrix2D a = DoubleFactory2D.dense.ascending(r1,c);
DoubleMatrix2D b = Transform.mult(DoubleFactory2D.dense.ascending(c,r2), -1);
//System.out.println(a);
//System.out.println(b);
//System.out.println(Basic.product(a,b));
a.assign(0);
b.assign(0);
cern.colt.Timer timer = new cern.colt.Timer().start();
LinearAlgebra.mult(a,b);
timer.stop().display();
}
/**
代码示例来源:origin: com.blazegraph/colt
/**
*/
public static void doubleTest14(int r1, int c, int r2) {
double[] values = {0, 1, 2, 3};
DoubleMatrix2D a = DoubleFactory2D.dense.ascending(r1,c);
DoubleMatrix2D b = Transform.mult(DoubleFactory2D.dense.ascending(c,r2), -1);
//System.out.println(a);
//System.out.println(b);
//System.out.println(Basic.product(a,b));
a.assign(0);
b.assign(0);
cern.colt.Timer timer = new cern.colt.Timer().start();
LinearAlgebra.mult(a,b);
timer.stop().display();
}
/**
代码示例来源:origin: cmu-phil/tetrad
private double multiLL(DoubleMatrix2D coeffs, Node dep, List<Node> indep){
DoubleMatrix2D indepData = factory2D.make(internalData.subsetColumns(indep).getDoubleData().toArray());
List<Node> depList = new ArrayList<>();
depList.add(dep);
DoubleMatrix2D depData = factory2D.make(internalData.subsetColumns(depList).getDoubleData().toArray());
int N = indepData.rows();
DoubleMatrix2D probs = Algebra.DEFAULT.mult(factory2D.appendColumns(factory2D.make(N, 1, 1.0), indepData), coeffs);
probs = factory2D.appendColumns(factory2D.make(indepData.rows(), 1, 1.0), probs).assign(Functions.exp);
double ll = 0;
for(int i = 0; i < N; i++){
DoubleMatrix1D curRow = probs.viewRow(i);
curRow.assign(Functions.div(curRow.zSum()));
ll += Math.log(curRow.get((int)depData.get(i,0)));
}
return ll;
}
内容来源于网络,如有侵权,请联系作者删除!