/** * Returns the dot product of two vectors x and y, which is <tt>Sum(x[i]*y[i])</tt>. * Where <tt>x == this</tt>. * Operates on cells at indexes <tt>0 .. Math.min(size(),y.size())</tt>. * @param y the second vector. * @return the sum of products. */ public double zDotProduct(DoubleMatrix1D y) { return zDotProduct(y,0,size); } /**
/** * Returns the dot product of two vectors x and y, which is <tt>Sum(x[i]*y[i])</tt>. * Where <tt>x == this</tt>. * Operates on cells at indexes <tt>0 .. Math.min(size(),y.size())</tt>. * @param y the second vector. * @return the sum of products. */ public double zDotProduct(DoubleMatrix1D y) { return zDotProduct(y,0,size); } /**
public double ddot(DoubleMatrix1D x, DoubleMatrix1D y) { return x.zDotProduct(y); } public void dgemm(boolean transposeA, boolean transposeB, double alpha, DoubleMatrix2D A, DoubleMatrix2D B, double beta, DoubleMatrix2D C) {
public double ddot(DoubleMatrix1D x, DoubleMatrix1D y) { return x.zDotProduct(y); } public void dgemm(boolean transposeA, boolean transposeB, double alpha, DoubleMatrix2D A, DoubleMatrix2D B, double beta, DoubleMatrix2D C) {
/** * Inner product of two vectors; <tt>Sum(x[i] * y[i])</tt>. * Also known as dot product. * <br> * Equivalent to <tt>x.zDotProduct(y)</tt>. * * @param x the first source vector. * @param y the second source matrix. * @return the inner product. * * @throws IllegalArgumentException if <tt>x.size() != y.size()</tt>. */ public double mult(DoubleMatrix1D x, DoubleMatrix1D y) { return x.zDotProduct(y); } /**
/** * Inner product of two vectors; <tt>Sum(x[i] * y[i])</tt>. * Also known as dot product. * <br> * Equivalent to <tt>x.zDotProduct(y)</tt>. * * @param x the first source vector. * @param y the second source matrix. * @return the inner product. * * @throws IllegalArgumentException if <tt>x.size() != y.size()</tt>. */ public double mult(DoubleMatrix1D x, DoubleMatrix1D y) { return x.zDotProduct(y); } /**
/** * Returns the dot product of two vectors x and y, which is <tt>Sum(x[i]*y[i])</tt>. * Where <tt>x == this</tt>. * @param y the second vector. * @param nonZeroIndexes the indexes of cells in <tt>y</tt>having a non-zero value. * @return the sum of products. */ protected double zDotProduct(DoubleMatrix1D y, IntArrayList nonZeroIndexes) { return zDotProduct(y,0,size,nonZeroIndexes); /* double sum = 0; int[] nonZeroIndexElements = nonZeroIndexes.elements(); for (int index=nonZeroIndexes.size(); --index >= 0; ) { int i = nonZeroIndexElements[index]; sum += getQuick(i) * y.getQuick(i); } return sum; */ } /**
/** * Returns the dot product of two vectors x and y, which is <tt>Sum(x[i]*y[i])</tt>. * Where <tt>x == this</tt>. * @param y the second vector. * @param nonZeroIndexes the indexes of cells in <tt>y</tt>having a non-zero value. * @return the sum of products. */ protected double zDotProduct(DoubleMatrix1D y, IntArrayList nonZeroIndexes) { return zDotProduct(y,0,size,nonZeroIndexes); /* double sum = 0; int[] nonZeroIndexElements = nonZeroIndexes.elements(); for (int index=nonZeroIndexes.size(); --index >= 0; ) { int i = nonZeroIndexElements[index]; sum += getQuick(i) * y.getQuick(i); } return sum; */ } /**
DoubleMatrix1D a = new DenseDoubleMatrix1D(new double[]{1,0.5}}); DoubleMatrix1D b = new DenseDoubleMatrix1D(new double[]{0.5,1}}); double cosineDistance = a.zDotProduct(b)/Math.sqrt(a.zDotProduct(a)*b.zDotProduct(b))
/** * Objective function value at X. * This is C.X */ @Override protected double getF0(DoubleMatrix1D X) { return getC().zDotProduct(X); }
/** * Sum[ (x[i]-center[i])^2 ] - radius^2. */ @Override public double value(double[] X) { DoubleMatrix1D x = DoubleFactory1D.dense.make(X); DoubleMatrix1D D = x.assign(C, Functions.minus); double d = D.zDotProduct(D) - Math.pow(radius, 2); return d; }
protected double product(DoubleMatrix1D v1, DoubleMatrix1D v2) { if (v1 instanceof SparseDoubleMatrix1D) { return productQuick(v1, v2); } else if (v2 instanceof SparseDoubleMatrix1D) { return productQuick(v2, v1); } else { return v1.zDotProduct(v2); } }
@Override public FastRecommendation getRecommendation(int uidx, IntStream candidates) { DoubleMatrix1D pu; pu = factorization.getUserVector(uidx2user(uidx)); if (pu == null) { return new FastRecommendation(uidx, new ArrayList<>()); } DenseDoubleMatrix2D q = factorization.getItemMatrix(); List<Tuple2id> items = candidates .mapToObj(iidx -> tuple(iidx, q.viewRow(iidx).zDotProduct(pu))) .sorted(comparingDouble(Tuple2id::v2).reversed()) .collect(toList()); return new FastRecommendation(uidx, items); }
return super.zDotProduct(y, from, length);
double sumOfProducts = cols[i].zDotProduct(cols[j]); double cov = (sumOfProducts - sums[i]*sums[j]/rows) / rows; covariance.setQuick(i,j,cov);
double sumOfProducts = cols[i].zDotProduct(cols[j]); double cov = (sumOfProducts - sums[i]*sums[j]/rows) / rows; covariance.setQuick(i,j,cov);
for (int k = 0; k < j; k++) { double s = Lrows[k].zDotProduct(Lrows[j],0,k);
for (int k = 0; k < j; k++) { double s = Lrows[k].zDotProduct(Lrows[j],0,k);
/** Generates and returns the (economy-sized) orthogonal factor <tt>Q</tt>. @return <tt>Q</tt> */ public DoubleMatrix2D getQ () { cern.jet.math.Functions F = cern.jet.math.Functions.functions; DoubleMatrix2D Q = QR.like(); //double[][] Q = X.getArray(); for (int k = n-1; k >= 0; k--) { DoubleMatrix1D QRcolk = QR.viewColumn(k).viewPart(k,m-k); Q.setQuick(k,k, 1); for (int j = k; j < n; j++) { if (QR.getQuick(k,k) != 0) { DoubleMatrix1D Qcolj = Q.viewColumn(j).viewPart(k,m-k); double s = QRcolk.zDotProduct(Qcolj); s = -s / QR.getQuick(k,k); Qcolj.assign(QRcolk, F.plusMult(s)); } } } return Q; } /**
/** Generates and returns the (economy-sized) orthogonal factor <tt>Q</tt>. @return <tt>Q</tt> */ public DoubleMatrix2D getQ () { cern.jet.math.Functions F = cern.jet.math.Functions.functions; DoubleMatrix2D Q = QR.like(); //double[][] Q = X.getArray(); for (int k = n-1; k >= 0; k--) { DoubleMatrix1D QRcolk = QR.viewColumn(k).viewPart(k,m-k); Q.setQuick(k,k, 1); for (int j = k; j < n; j++) { if (QR.getQuick(k,k) != 0) { DoubleMatrix1D Qcolj = Q.viewColumn(j).viewPart(k,m-k); double s = QRcolk.zDotProduct(Qcolj); s = -s / QR.getQuick(k,k); Qcolj.assign(QRcolk, F.plusMult(s)); } } } return Q; } /**