当前位置: 首页>>代码示例>>Java>>正文


Java MathArrays.linearCombination方法代码示例

本文整理汇总了Java中org.apache.commons.math3.util.MathArrays.linearCombination方法的典型用法代码示例。如果您正苦于以下问题:Java MathArrays.linearCombination方法的具体用法?Java MathArrays.linearCombination怎么用?Java MathArrays.linearCombination使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.math3.util.MathArrays的用法示例。


在下文中一共展示了MathArrays.linearCombination方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: linearCombination

import org.apache.commons.math3.util.MathArrays; //导入方法依赖的package包/类
/** {@inheritDoc}
 * @exception DimensionMismatchException if number of free parameters
 * or orders do not match
 * @since 3.2
 */
public DerivativeStructure linearCombination(final double[] a, final DerivativeStructure[] b)
    throws DimensionMismatchException {

    // compute an accurate value, taking care of cancellations
    final double[] bDouble = new double[b.length];
    for (int i = 0; i < b.length; ++i) {
        bDouble[i] = b[i].getValue();
    }
    final double accurateValue = MathArrays.linearCombination(a, bDouble);

    // compute a simple value, with all partial derivatives
    DerivativeStructure simpleValue = b[0].getField().getZero();
    for (int i = 0; i < a.length; ++i) {
        simpleValue = simpleValue.add(b[i].multiply(a[i]));
    }

    // create a result with accurate value and all derivatives (not necessarily as accurate as the value)
    final double[] all = simpleValue.getAllDerivatives();
    all[0] = accurateValue;
    return new DerivativeStructure(simpleValue.getFreeParameters(), simpleValue.getOrder(), all);

}
 
开发者ID:biocompibens,项目名称:SME,代码行数:28,代码来源:DerivativeStructure.java

示例2: reset

import org.apache.commons.math3.util.MathArrays; //导入方法依赖的package包/类
/** Reset the instance as if built from two points.
 * <p>The line is oriented from p1 to p2</p>
 * @param p1 first point
 * @param p2 second point
 */
public void reset(final Vector2D p1, final Vector2D p2) {
    unlinkReverse();
    final double dx = p2.getX() - p1.getX();
    final double dy = p2.getY() - p1.getY();
    final double d = FastMath.hypot(dx, dy);
    if (d == 0.0) {
        angle        = 0.0;
        cos          = 1.0;
        sin          = 0.0;
        originOffset = p1.getY();
    } else {
        angle        = FastMath.PI + FastMath.atan2(-dy, -dx);
        cos          = dx / d;
        sin          = dy / d;
        originOffset = MathArrays.linearCombination(p2.getX(), p1.getY(), -p1.getX(), p2.getY()) / d;
    }
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:23,代码来源:Line.java

示例3: LineTransform

import org.apache.commons.math3.util.MathArrays; //导入方法依赖的package包/类
/** Build an affine line transform from a n {@code AffineTransform}.
 * @param cXX transform factor between input abscissa and output abscissa
 * @param cYX transform factor between input abscissa and output ordinate
 * @param cXY transform factor between input ordinate and output abscissa
 * @param cYY transform factor between input ordinate and output ordinate
 * @param cX1 transform addendum for output abscissa
 * @param cY1 transform addendum for output ordinate
 * @exception MathIllegalArgumentException if the transform is non invertible
 * @since 3.6
 */
LineTransform(final double cXX, final double cYX, final double cXY,
              final double cYY, final double cX1, final double cY1)
    throws MathIllegalArgumentException {

    this.cXX = cXX;
    this.cYX = cYX;
    this.cXY = cXY;
    this.cYY = cYY;
    this.cX1 = cX1;
    this.cY1 = cY1;

    c1Y = MathArrays.linearCombination(cXY, cY1, -cYY, cX1);
    c1X = MathArrays.linearCombination(cXX, cY1, -cYX, cX1);
    c11 = MathArrays.linearCombination(cXX, cYY, -cYX, cXY);

    if (FastMath.abs(c11) < 1.0e-20) {
        throw new MathIllegalArgumentException(LocalizedFormats.NON_INVERTIBLE_TRANSFORM);
    }

}
 
开发者ID:biocompibens,项目名称:SME,代码行数:31,代码来源:Line.java

示例4: intersection

import org.apache.commons.math3.util.MathArrays; //导入方法依赖的package包/类
/** Get the intersection point of the instance and another line.
 * @param other other line
 * @return intersection point of the instance and the other line
 * or null if there are no intersection points
 */
public Vector2D intersection(final Line other) {
    final double d = MathArrays.linearCombination(sin, other.cos, -other.sin, cos);
    if (FastMath.abs(d) < tolerance) {
        return null;
    }
    return new Vector2D(MathArrays.linearCombination(cos, other.originOffset, -other.cos, originOffset) / d,
                        MathArrays.linearCombination(sin, other.originOffset, -other.sin, originOffset) / d);
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:14,代码来源:Line.java

示例5: apply

import org.apache.commons.math3.util.MathArrays; //导入方法依赖的package包/类
/**
 * Compute the value of the bicubic polynomial.
 *
 * @param pX Powers of the x-coordinate.
 * @param pY Powers of the y-coordinate.
 * @param coeff Spline coefficients.
 * @return the interpolated value.
 */
private double apply(double[] pX, double[] pY, double[][] coeff) {
    double result = 0;
    for (int i = 0; i < N; i++) {
        final double r = MathArrays.linearCombination(coeff[i], pY);
        result += r * pX[i];
    }

    return result;
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:18,代码来源:BicubicInterpolatingFunction.java

示例6: apply

import org.apache.commons.math3.util.MathArrays; //导入方法依赖的package包/类
/** {@inheritDoc} */
public Vector2D apply(final Point<Euclidean2D> point) {
    final Vector2D p2D = (Vector2D) point;
    final double  x   = p2D.getX();
    final double  y   = p2D.getY();
    return new Vector2D(MathArrays.linearCombination(cXX, x, cXY, y, cX1, 1),
                        MathArrays.linearCombination(cYX, x, cYY, y, cY1, 1));
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:9,代码来源:Line.java

示例7: isConvex

import org.apache.commons.math3.util.MathArrays; //导入方法依赖的package包/类
/**
 * Checks whether the given hull vertices form a convex hull.
 * @param hullVertices the hull vertices
 * @return {@code true} if the vertices form a convex hull, {@code false} otherwise
 */
private boolean isConvex(final Vector2D[] hullVertices) {
    if (hullVertices.length < 3) {
        return true;
    }

    int sign = 0;
    for (int i = 0; i < hullVertices.length; i++) {
        final Vector2D p1 = hullVertices[i == 0 ? hullVertices.length - 1 : i - 1];
        final Vector2D p2 = hullVertices[i];
        final Vector2D p3 = hullVertices[i == hullVertices.length - 1 ? 0 : i + 1];

        final Vector2D d1 = p2.subtract(p1);
        final Vector2D d2 = p3.subtract(p2);

        final double crossProduct = MathArrays.linearCombination(d1.getX(), d2.getY(), -d1.getY(), d2.getX());
        final int cmp = Precision.compareTo(crossProduct, 0.0, tolerance);
        // in case of collinear points the cross product will be zero
        if (cmp != 0.0) {
            if (sign != 0.0 && cmp != sign) {
                return false;
            }
            sign = cmp;
        }
    }

    return true;
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:33,代码来源:ConvexHull2D.java

示例8: Rotation

import org.apache.commons.math3.util.MathArrays; //导入方法依赖的package包/类
/** Build the rotation that transforms a pair of vectors into another pair.

   * <p>Except for possible scale factors, if the instance were applied to
   * the pair (u<sub>1</sub>, u<sub>2</sub>) it will produce the pair
   * (v<sub>1</sub>, v<sub>2</sub>).</p>

   * <p>If the angular separation between u<sub>1</sub> and u<sub>2</sub> is
   * not the same as the angular separation between v<sub>1</sub> and
   * v<sub>2</sub>, then a corrected v'<sub>2</sub> will be used rather than
   * v<sub>2</sub>, the corrected vector will be in the (&pm;v<sub>1</sub>,
   * +v<sub>2</sub>) half-plane.</p>

   * @param u1 first vector of the origin pair
   * @param u2 second vector of the origin pair
   * @param v1 desired image of u1 by the rotation
   * @param v2 desired image of u2 by the rotation
   * @exception MathArithmeticException if the norm of one of the vectors is zero,
   * or if one of the pair is degenerated (i.e. the vectors of the pair are collinear)
   */
  public Rotation(Vector3D u1, Vector3D u2, Vector3D v1, Vector3D v2)
      throws MathArithmeticException {

      // build orthonormalized base from u1, u2
      // this fails when vectors are null or collinear, which is forbidden to define a rotation
      final Vector3D u3 = u1.crossProduct(u2).normalize();
      u2 = u3.crossProduct(u1).normalize();
      u1 = u1.normalize();

      // build an orthonormalized base from v1, v2
      // this fails when vectors are null or collinear, which is forbidden to define a rotation
      final Vector3D v3 = v1.crossProduct(v2).normalize();
      v2 = v3.crossProduct(v1).normalize();
      v1 = v1.normalize();

      // buid a matrix transforming the first base into the second one
      final double[][] m = new double[][] {
          {
              MathArrays.linearCombination(u1.getX(), v1.getX(), u2.getX(), v2.getX(), u3.getX(), v3.getX()),
              MathArrays.linearCombination(u1.getY(), v1.getX(), u2.getY(), v2.getX(), u3.getY(), v3.getX()),
              MathArrays.linearCombination(u1.getZ(), v1.getX(), u2.getZ(), v2.getX(), u3.getZ(), v3.getX())
          },
          {
              MathArrays.linearCombination(u1.getX(), v1.getY(), u2.getX(), v2.getY(), u3.getX(), v3.getY()),
              MathArrays.linearCombination(u1.getY(), v1.getY(), u2.getY(), v2.getY(), u3.getY(), v3.getY()),
              MathArrays.linearCombination(u1.getZ(), v1.getY(), u2.getZ(), v2.getY(), u3.getZ(), v3.getY())
          },
          {
              MathArrays.linearCombination(u1.getX(), v1.getZ(), u2.getX(), v2.getZ(), u3.getX(), v3.getZ()),
              MathArrays.linearCombination(u1.getY(), v1.getZ(), u2.getY(), v2.getZ(), u3.getY(), v3.getZ()),
              MathArrays.linearCombination(u1.getZ(), v1.getZ(), u2.getZ(), v2.getZ(), u3.getZ(), v3.getZ())
          }
      };

      double[] quat = mat2quat(m);
      q0 = quat[0];
      q1 = quat[1];
      q2 = quat[2];
      q3 = quat[3];

  }
 
开发者ID:biocompibens,项目名称:SME,代码行数:61,代码来源:Rotation.java

示例9: linearCombination

import org.apache.commons.math3.util.MathArrays; //导入方法依赖的package包/类
/** {@inheritDoc} */
public SparseGradient linearCombination(final double a1, final SparseGradient b1,
                                          final double a2, final SparseGradient b2) {

    // compute a simple value, with all partial derivatives
    SparseGradient out = b1.multiply(a1).add(b2.multiply(a2));

    // recompute an accurate value, taking care of cancellations
    out.value = MathArrays.linearCombination(a1, b1.value, a2, b2.value);

    return out;

}
 
开发者ID:biocompibens,项目名称:SME,代码行数:14,代码来源:SparseGradient.java

示例10: Vector3D

import org.apache.commons.math3.util.MathArrays; //导入方法依赖的package包/类
/** Linear constructor
 * Build a vector from three other ones and corresponding scale factors.
 * The vector built will be a1 * u1 + a2 * u2 + a3 * u3
 * @param a1 first scale factor
 * @param u1 first base (unscaled) vector
 * @param a2 second scale factor
 * @param u2 second base (unscaled) vector
 * @param a3 third scale factor
 * @param u3 third base (unscaled) vector
 */
public Vector3D(double a1, Vector3D u1, double a2, Vector3D u2,
                double a3, Vector3D u3) {
    this.x = MathArrays.linearCombination(a1, u1.x, a2, u2.x, a3, u3.x);
    this.y = MathArrays.linearCombination(a1, u1.y, a2, u2.y, a3, u3.y);
    this.z = MathArrays.linearCombination(a1, u1.z, a2, u2.z, a3, u3.z);
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:17,代码来源:Vector3D.java

示例11: crossProduct

import org.apache.commons.math3.util.MathArrays; //导入方法依赖的package包/类
/**
 * Compute the cross-product of the instance and the given points.
 * <p>
 * The cross product can be used to determine the location of a point
 * with regard to the line formed by (p1, p2) and is calculated as:
 * \[
 *    P = (x_2 - x_1)(y_3 - y_1) - (y_2 - y_1)(x_3 - x_1)
 * \]
 * with \(p3 = (x_3, y_3)\) being this instance.
 * <p>
 * If the result is 0, the points are collinear, i.e. lie on a single straight line L;
 * if it is positive, this point lies to the left, otherwise to the right of the line
 * formed by (p1, p2).
 *
 * @param p1 first point of the line
 * @param p2 second point of the line
 * @return the cross-product
 *
 * @see <a href="http://en.wikipedia.org/wiki/Cross_product">Cross product (Wikipedia)</a>
 */
public double crossProduct(final Vector2D p1, final Vector2D p2) {
    final double x1 = p2.getX() - p1.getX();
    final double y1 = getY() - p1.getY();
    final double x2 = getX() - p1.getX();
    final double y2 = p2.getY() - p1.getY();
    return MathArrays.linearCombination(x1, y1, -x2, y2);
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:28,代码来源:Vector2D.java

示例12: linearCombination

import org.apache.commons.math3.util.MathArrays; //导入方法依赖的package包/类
/** Compute linear combination.
 * The derivative structure built will be a1 * ds1 + a2 * ds2
 * @param a1 first scale factor
 * @param c1 first base (unscaled) component
 * @param offset1 offset of first operand in its array
 * @param a2 second scale factor
 * @param c2 second base (unscaled) component
 * @param offset2 offset of second operand in its array
 * @param result array where result must be stored (it may be
 * one of the input arrays)
 * @param resultOffset offset of the result in its array
 */
public void linearCombination(final double a1, final double[] c1, final int offset1,
                              final double a2, final double[] c2, final int offset2,
                              final double[] result, final int resultOffset) {
    for (int i = 0; i < getSize(); ++i) {
        result[resultOffset + i] =
                MathArrays.linearCombination(a1, c1[offset1 + i], a2, c2[offset2 + i]);
    }
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:21,代码来源:DSCompiler.java

示例13: getOffset

import org.apache.commons.math3.util.MathArrays; //导入方法依赖的package包/类
/** Get the offset (oriented distance) of a parallel line.
 * <p>This method should be called only for parallel lines otherwise
 * the result is not meaningful.</p>
 * <p>The offset is 0 if both lines are the same, it is
 * positive if the line is on the right side of the instance and
 * negative if it is on the left side, according to its natural
 * orientation.</p>
 * @param line line to check
 * @return offset of the line
 */
public double getOffset(final Line line) {
    return originOffset +
           (MathArrays.linearCombination(cos, line.cos, sin, line.sin) > 0 ? -line.originOffset : line.originOffset);
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:15,代码来源:Line.java


注:本文中的org.apache.commons.math3.util.MathArrays.linearCombination方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。