Java Code Examples for org.apache.commons.math.linear.RealVector#dotProduct()

The following examples show how to use org.apache.commons.math.linear.RealVector#dotProduct() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GLSMultipleLinearRegression.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * 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());
}
 
Example 2
Source File: OLSMultipleLinearRegression.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * <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());
}
 
Example 3
Source File: OLSMultipleLinearRegression.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * <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());
}
 
Example 4
Source File: GLSMultipleLinearRegression.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * 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());
}
 
Example 5
Source File: OLSMultipleLinearRegression.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * <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());
}
 
Example 6
Source File: GLSMultipleLinearRegression.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * 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());
}
 
Example 7
Source File: OLSMultipleLinearRegression.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * <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());
}
 
Example 8
Source File: GLSMultipleLinearRegression.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * 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
 */
@Override
protected double calculateErrorVariance() {
    RealVector residuals = calculateResiduals();
    double t = residuals.dotProduct(getOmegaInverse().operate(residuals));
    return t / (X.getRowDimension() - X.getColumnDimension());

}
 
Example 9
Source File: GLSMultipleLinearRegression.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * 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());
}
 
Example 10
Source File: GLSMultipleLinearRegression.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * 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());

}
 
Example 11
Source File: GLSMultipleLinearRegression.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * 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());
}
 
Example 12
Source File: Cosine.java    From datafu with Apache License 2.0 2 votes vote down vote up
/**
 * 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());
}
 
Example 13
Source File: MicrosphereInterpolatingFunction.java    From astor with GNU General Public License v2.0 2 votes vote down vote up
/**
 * 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());
}
 
Example 14
Source File: OLSMultipleLinearRegression.java    From astor with GNU General Public License v2.0 2 votes vote down vote up
/**
 * 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);
}
 
Example 15
Source File: MicrosphereInterpolatingFunction.java    From astor with GNU General Public License v2.0 2 votes vote down vote up
/**
 * 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());
}
 
Example 16
Source File: MicrosphereInterpolatingFunction.java    From astor with GNU General Public License v2.0 2 votes vote down vote up
/**
 * 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());
}
 
Example 17
Source File: MicrosphereInterpolatingFunction.java    From astor with GNU General Public License v2.0 2 votes vote down vote up
/**
 * 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());
}
 
Example 18
Source File: MicrosphereInterpolatingFunction.java    From astor with GNU General Public License v2.0 2 votes vote down vote up
/**
 * 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());
}
 
Example 19
Source File: OLSMultipleLinearRegression.java    From astor with GNU General Public License v2.0 2 votes vote down vote up
/**
 * 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);
}
 
Example 20
Source File: MicrosphereInterpolatingFunction.java    From astor with GNU General Public License v2.0 2 votes vote down vote up
/**
 * 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());
}