本文整理汇总了Java中org.apache.commons.math.linear.RealVector.dotProduct方法的典型用法代码示例。如果您正苦于以下问题:Java RealVector.dotProduct方法的具体用法?Java RealVector.dotProduct怎么用?Java RealVector.dotProduct使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.math.linear.RealVector
的用法示例。
在下文中一共展示了RealVector.dotProduct方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: cosine
import org.apache.commons.math.linear.RealVector; //导入方法依赖的package包/类
public static double cosine(RealVector vec1, RealVector vec2) throws Exception
{
final double norm1 = vec1.getNorm();
final double norm2 = vec2.getNorm();
if (norm1 == 0 || norm2 == 0)
throw new Exception("Division by zero");
return vec1.dotProduct(vec2) / (norm1 * norm2);
}
示例2: getInnerProduct
import org.apache.commons.math.linear.RealVector; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public double getInnerProduct(final Matrix<?> m1, final Matrix<?> m2) {
Validate.notNull(m1, "m1");
Validate.notNull(m2, "m2");
if (m1 instanceof DoubleMatrix1D && m2 instanceof DoubleMatrix1D) {
final RealVector t1 = CommonsMathWrapper.wrap((DoubleMatrix1D) m1);
final RealVector t2 = CommonsMathWrapper.wrap((DoubleMatrix1D) m2);
return t1.dotProduct(t2);
}
throw new IllegalArgumentException("Can only find inner product of DoubleMatrix1D; have " + m1.getClass() + " and " + m2.getClass());
}
示例3: calculateYVariance
import org.apache.commons.math.linear.RealVector; //导入方法依赖的package包/类
/**
* Calculates the variance on the y by GLS.
* <pre>
* Var(y)=Tr(u' Omega^-1 u)/(n-k)
* </pre>
* @return The Y variance
*/
@Override
protected double calculateYVariance() {
RealVector residuals = calculateResiduals();
double t = residuals.dotProduct(getOmegaInverse().operate(residuals));
return t / (X.getRowDimension() - X.getColumnDimension());
}
示例4: calculateYVariance
import org.apache.commons.math.linear.RealVector; //导入方法依赖的package包/类
/**
* <p>Calculates the variance on the Y by OLS.
* </p>
* <p> Var(y) = Tr(u<sup>T</sup>u)/(n - k)
* </p>
* @return The Y variance
*/
@Override
protected double calculateYVariance() {
RealVector residuals = calculateResiduals();
return residuals.dotProduct(residuals) /
(X.getRowDimension() - X.getColumnDimension());
}
示例5: calculateErrorVariance
import org.apache.commons.math.linear.RealVector; //导入方法依赖的package包/类
/**
* Calculates the estimated variance of the error term using the formula
* <pre>
* Var(u) = Tr(u' Omega^-1 u)/(n-k)
* </pre>
* where n and k are the row and column dimensions of the design
* matrix X.
*
* @return error variance
* @since 2.2
*/
@Override
protected double calculateErrorVariance() {
RealVector residuals = calculateResiduals();
double t = residuals.dotProduct(getOmegaInverse().operate(residuals));
return t / (X.getRowDimension() - X.getColumnDimension());
}
示例6: cosAngle
import org.apache.commons.math.linear.RealVector; //导入方法依赖的package包/类
/**
* Compute the cosine of the angle between 2 vectors.
*
* @param v Vector.
* @param w Vector.
* @return cosine of the angle
*/
private double cosAngle(final RealVector v, final RealVector w) {
return v.dotProduct(w) / (v.getNorm() * w.getNorm());
}
示例7: calculateErrorVariance
import org.apache.commons.math.linear.RealVector; //导入方法依赖的package包/类
/**
* <p>Calculates the variance of the error term.</p>
* Uses the formula <pre>
* var(u) = u · u / (n - k)
* </pre>
* where n and k are the row and column dimensions of the design
* matrix X.
*
* @return error variance estimate
* @since 2.2
*/
protected double calculateErrorVariance() {
RealVector residuals = calculateResiduals();
return residuals.dotProduct(residuals) /
(X.getRowDimension() - X.getColumnDimension());
}
示例8: calculateResidualSumOfSquares
import org.apache.commons.math.linear.RealVector; //导入方法依赖的package包/类
/**
* Returns the sum of squared residuals.
*
* @return residual sum of squares
* @since 2.2
*/
public double calculateResidualSumOfSquares() {
final RealVector residuals = calculateResiduals();
return residuals.dotProduct(residuals);
}
示例9: cosAngle
import org.apache.commons.math.linear.RealVector; //导入方法依赖的package包/类
/**
* Compute the cosine of the angle between 2 vectors.
*
* @param v Vector.
* @param w Vector.
* @return the cosine of the angle between {@code v} and {@code w}.
*/
private double cosAngle(final RealVector v, final RealVector w) {
return v.dotProduct(w) / (v.getNorm() * w.getNorm());
}
示例10: distance
import org.apache.commons.math.linear.RealVector; //导入方法依赖的package包/类
/**
* Cosine similarity.
* @param v1 first vector
* @param v2 second vector
* @return The cosine of the angle between the vectors
*/
public static double distance(RealVector v1, RealVector v2) {
return (v1.dotProduct(v2)) / (v1.getNorm() * v2.getNorm());
}