Example usage for org.apache.commons.math3.analysis.differentiation DerivativeStructure DerivativeStructure

List of usage examples for org.apache.commons.math3.analysis.differentiation DerivativeStructure DerivativeStructure

Introduction

In this page you can find the example usage for org.apache.commons.math3.analysis.differentiation DerivativeStructure DerivativeStructure.

Prototype

public DerivativeStructure(final double a1, final DerivativeStructure ds1, final double a2,
        final DerivativeStructure ds2) throws DimensionMismatchException 

Source Link

Document

Linear combination constructor.

Usage

From source file:de.tuberlin.uebb.jbop.example.DSExampleOrig.java

@SuppressWarnings("unused")
public void createCompilers() {
    new DerivativeStructure(3, 3, 0, 0);
}

From source file:de.tuberlin.uebb.jbop.example.DSExampleOrig.java

@Test
public DerivativeStructure run() {
    x = new DerivativeStructure(3, 3, 0, x0);
    y = new DerivativeStructure(3, 3, 1, y0);
    z = new DerivativeStructure(3, 3, 2, z0);
    // ax/*  w w w .ja va2  s .c om*/
    final DerivativeStructure ax2 = x.pow(2).multiply(a);//
    // ay
    final DerivativeStructure ay2 = y.pow(2).multiply(a);//
    // az
    final DerivativeStructure az2 = z.pow(2).multiply(a);//
    // + bx
    final DerivativeStructure bx = x.multiply(b);
    // + by
    final DerivativeStructure by = y.multiply(b);
    // + bz
    final DerivativeStructure bz = z.multiply(b);

    final DerivativeStructure multiply = ax2.multiply(ay2).multiply(az2);
    final DerivativeStructure multiply2 = bx.multiply(by).multiply(bz);

    return multiply.add(multiply2).add(c);
}

From source file:com.bwc.ora.models.Lrp.java

/**
 * Get the local maximums from a collection of Points.
 *
 * @param lrpSeries/*from  w  ww  . j  a v  a  2  s. co  m*/
 * @param seriesTitle
 * @return
 */
public static XYSeries getMaximumsWithHiddenPeaks(XYSeries lrpSeries, String seriesTitle) {
    XYSeries maxPoints = new XYSeries(seriesTitle);

    //convert to x and y coordinate arrays
    double[][] xyline = lrpSeries.toArray();

    //use a spline interpolator to converts points into an equation
    UnivariateInterpolator interpolator = new SplineInterpolator();
    UnivariateFunction function = interpolator.interpolate(xyline[0], xyline[1]);

    // create a differentiator using 5 points and 0.01 step
    FiniteDifferencesDifferentiator differentiator = new FiniteDifferencesDifferentiator(5, 0.01);

    // create a new function that computes both the value and the derivatives
    // using DerivativeStructure
    UnivariateDifferentiableFunction completeF = differentiator.differentiate(function);

    // now we can compute the value and its derivatives
    // here we decided to display up to second order derivatives,
    // because we feed completeF with order 2 DerivativeStructure instances
    //find local minima in second derivative, these indicate the peaks (and hidden peaks)
    //of the input
    for (double x = xyline[0][0] + 1; x < xyline[0][xyline[0].length - 1] - 1; x += 0.5) {
        DerivativeStructure xDSc = new DerivativeStructure(1, 2, 0, x);
        DerivativeStructure xDSl = new DerivativeStructure(1, 2, 0, x - 0.5);
        DerivativeStructure xDSr = new DerivativeStructure(1, 2, 0, x + 0.5);
        DerivativeStructure yDSc = completeF.value(xDSc);
        DerivativeStructure yDSl = completeF.value(xDSl);
        DerivativeStructure yDSr = completeF.value(xDSr);
        double c2d = yDSc.getPartialDerivative(2);
        if (c2d < yDSl.getPartialDerivative(2) && c2d < yDSr.getPartialDerivative(2)) {
            maxPoints.add((int) Math.round(x), yDSc.getValue());
        }
    }

    return maxPoints;
}

From source file:com.itemanalysis.psychometrics.irt.estimation.IrtExaminee.java

/**
 * Returns value of loglikelihood using DerivativeStructure per interface requirements
 * @param t//from w  w  w .  j  a v a 2  s .c  o  m
 * @return
 */
public DerivativeStructure value(DerivativeStructure t) {
    return new DerivativeStructure(1, 0, 0, logLikelihood(t.getValue()));
}

From source file:com.itemanalysis.psychometrics.irt.estimation.IrtExaminee.java

/**
 * Returns first derivative of loglikelihood using DerivativeStructure per interface requirements
 * @param t/*from  ww  w  .  j a v a2 s  .  c o m*/
 * @return
 */
public DerivativeStructure derivLogLikelihood(DerivativeStructure t) {
    return new DerivativeStructure(1, 1, 0, derivLogLikelihood(t.getValue()));
}

From source file:org.orekit.forces.BoxAndSolarArraySpacecraft.java

/** {@inheritDoc} */
public FieldVector3D<DerivativeStructure> dragAcceleration(final AbsoluteDate date, final Frame frame,
        final Vector3D position, final Rotation rotation, final double mass, final double density,
        final Vector3D relativeVelocity, final String paramName) throws OrekitException {

    if (!DRAG_COEFFICIENT.equals(paramName)) {
        throw new OrekitException(OrekitMessages.UNSUPPORTED_PARAMETER_NAME, paramName, DRAG_COEFFICIENT);
    }/*from   w w  w.jav a  2 s .  co m*/

    final DerivativeStructure dragCoeffDS = new DerivativeStructure(1, 1, 0, dragCoeff);

    // relative velocity in spacecraft frame
    final Vector3D v = rotation.applyTo(relativeVelocity);

    // solar array contribution
    final Vector3D solarArrayFacet = new Vector3D(solarArrayArea, getNormal(date, frame, position, rotation));
    double sv = FastMath.abs(Vector3D.dotProduct(solarArrayFacet, v));

    // body facets contribution
    for (final Facet facet : facets) {
        final double dot = Vector3D.dotProduct(facet.getNormal(), v);
        if (dot < 0) {
            // the facet intercepts the incoming flux
            sv -= facet.getArea() * dot;
        }
    }

    return new FieldVector3D<DerivativeStructure>(dragCoeffDS.multiply(sv * density / (2.0 * mass)),
            relativeVelocity);

}

From source file:org.orekit.forces.gravity.HolmesFeatherstoneAttractionModel.java

/** {@inheritDoc} */
public FieldVector3D<DerivativeStructure> accelerationDerivatives(final SpacecraftState s,
        final String paramName) throws OrekitException, IllegalArgumentException {

    complainIfNotSupported(paramName);/*from   w  w w. j a  v a 2  s.  c o m*/

    // get the position in body frame
    final AbsoluteDate date = s.getDate();
    final Transform fromBodyFrame = bodyFrame.getTransformTo(s.getFrame(), date);
    final Transform toBodyFrame = fromBodyFrame.getInverse();
    final Vector3D position = toBodyFrame.transformPosition(s.getPVCoordinates().getPosition());

    // gradient of the non-central part of the gravity field
    final Vector3D gInertial = fromBodyFrame.transformVector(new Vector3D(gradient(date, position)));

    return new FieldVector3D<DerivativeStructure>(
            new DerivativeStructure(1, 1, gInertial.getX(), gInertial.getX() / mu),
            new DerivativeStructure(1, 1, gInertial.getY(), gInertial.getY() / mu),
            new DerivativeStructure(1, 1, gInertial.getZ(), gInertial.getZ() / mu));

}

From source file:org.orekit.forces.gravity.NewtonianAttraction.java

/** {@inheritDoc} */
public FieldVector3D<DerivativeStructure> accelerationDerivatives(final SpacecraftState s,
        final String paramName) throws OrekitException {

    complainIfNotSupported(paramName);//from   w w w  .j a va2s .c  o  m

    final Vector3D position = s.getPVCoordinates().getPosition();
    final double r2 = position.getNormSq();
    final DerivativeStructure muds = new DerivativeStructure(1, 1, 0, mu);
    return new FieldVector3D<DerivativeStructure>(muds.divide(-r2 * FastMath.sqrt(r2)), position);

}

From source file:org.orekit.forces.gravity.Relativity.java

@Override
public FieldVector3D<DerivativeStructure> accelerationDerivatives(final SpacecraftState s,
        final String paramName) throws OrekitException {

    complainIfNotSupported(paramName);//from   w ww.  ja  va2 s . c  om
    final DerivativeStructure gmDS = new DerivativeStructure(1, 1, 0, this.gm);

    final PVCoordinates pv = s.getPVCoordinates();
    final Vector3D p = pv.getPosition();
    final Vector3D v = pv.getVelocity();
    //radius
    final double r2 = p.getNormSq();
    final double r = FastMath.sqrt(r2);
    //speed
    final double s2 = v.getNormSq();
    final double c2 = Constants.SPEED_OF_LIGHT * Constants.SPEED_OF_LIGHT;
    //eq. 3.146
    return new FieldVector3D<DerivativeStructure>(gmDS.multiply(4 / r).subtract(s2), p,
            new DerivativeStructure(1, 1, 4 * p.dotProduct(v)), v).scalarMultiply(gmDS.divide(r2 * r * c2));
}

From source file:org.orekit.forces.gravity.ThirdBodyAttraction.java

/** {@inheritDoc} */
public FieldVector3D<DerivativeStructure> accelerationDerivatives(final SpacecraftState s,
        final String paramName) throws OrekitException {

    complainIfNotSupported(paramName);//  w  ww .  j  a  v  a2 s . c  om

    // compute bodies separation vectors and squared norm
    final Vector3D centralToBody = body.getPVCoordinates(s.getDate(), s.getFrame()).getPosition();
    final double r2Central = centralToBody.getNormSq();
    final Vector3D satToBody = centralToBody.subtract(s.getPVCoordinates().getPosition());
    final double r2Sat = satToBody.getNormSq();

    final DerivativeStructure gmds = new DerivativeStructure(1, 1, 0, gm);

    // compute relative acceleration
    return new FieldVector3D<DerivativeStructure>(gmds.divide(r2Sat * FastMath.sqrt(r2Sat)), satToBody,
            gmds.divide(-r2Central * FastMath.sqrt(r2Central)), centralToBody);

}