List of usage examples for org.apache.commons.math3.util FastMath ulp
public static float ulp(float x)
From source file:RealFunctionValidation.java
public static SummaryStatistics assessAccuracy(final Method method, final DataInputStream in, final DataOutputStream out) throws IOException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { if (method.getReturnType() != Double.TYPE) { throw new IllegalArgumentException("method must return a double"); }//w w w . jav a 2 s. c om final Class<?>[] types = method.getParameterTypes(); for (int i = 0; i < types.length; i++) { if (!types[i].isPrimitive()) { final StringBuilder builder = new StringBuilder(); builder.append("argument #").append(i + 1).append(" of method ").append(method.getName()) .append("must be of primitive of type"); throw new IllegalArgumentException(builder.toString()); } } final SummaryStatistics stat = new SummaryStatistics(); final Object[] parameters = new Object[types.length]; while (true) { try { for (int i = 0; i < parameters.length; i++) { parameters[i] = readAndWritePrimitiveValue(in, out, types[i]); } final double expected = in.readDouble(); if (FastMath.abs(expected) > 1E-16) { final Object value = method.invoke(null, parameters); final double actual = ((Double) value).doubleValue(); final double err = FastMath.abs(actual - expected); final double ulps = err / FastMath.ulp(expected); out.writeDouble(expected); out.writeDouble(actual); out.writeDouble(ulps); stat.addValue(ulps); } } catch (EOFException e) { break; } } return stat; }
From source file:org.orekit.forces.gravity.potential.EGMFormatReaderTest.java
private void checkValue(final double value, final int n, final int m, final double constant, final int maxUlps) throws OrekitException { double factor = GravityFieldFactory.getUnnormalizationFactors(n, m)[n][m]; double normalized = factor * constant; double epsilon = maxUlps * FastMath.ulp(normalized); Assert.assertEquals(normalized, value, epsilon); }
From source file:org.orekit.forces.gravity.potential.GravityFieldFactoryTest.java
@Test public void testUnnormalizer() throws OrekitException { Utils.setDataRoot("potential/icgem-format"); final double shift = 1.23456e8; UnnormalizedSphericalHarmonicsProvider ref = GravityFieldFactory.getUnnormalizedProvider(5, 5); UnnormalizedSphericalHarmonics refHarmonics = ref.onDate(ref.getReferenceDate().shiftedBy(shift)); NormalizedSphericalHarmonicsProvider normalized = GravityFieldFactory.getNormalizedProvider(5, 5); UnnormalizedSphericalHarmonicsProvider unnormalized = GravityFieldFactory .getUnnormalizedProvider(normalized); UnnormalizedSphericalHarmonics unnormalizedHarmonics = unnormalized .onDate(unnormalized.getReferenceDate().shiftedBy(shift)); Assert.assertEquals(ref.getMaxDegree(), unnormalized.getMaxDegree()); Assert.assertEquals(ref.getMaxOrder(), unnormalized.getMaxOrder()); Assert.assertEquals(ref.getReferenceDate(), unnormalized.getReferenceDate()); Assert.assertEquals(ref.getAe(), unnormalized.getAe(), FastMath.ulp(ref.getAe())); Assert.assertEquals(ref.getMu(), unnormalized.getMu(), FastMath.ulp(ref.getMu())); Assert.assertEquals(ref.getOffset(AbsoluteDate.GPS_EPOCH), unnormalized.getOffset(AbsoluteDate.GPS_EPOCH), FastMath.ulp(ref.getOffset(AbsoluteDate.GPS_EPOCH))); for (int i = 0; i <= 5; ++i) { for (int j = 0; j <= i; ++j) { double cRef = refHarmonics.getUnnormalizedCnm(i, j); double cTest = unnormalizedHarmonics.getUnnormalizedCnm(i, j); Assert.assertEquals(cRef, cTest, FastMath.ulp(cRef)); double sRef = refHarmonics.getUnnormalizedSnm(i, j); double sTest = unnormalizedHarmonics.getUnnormalizedSnm(i, j); Assert.assertEquals(sRef, sTest, FastMath.ulp(sRef)); }//from ww w. jav a 2s . com } }
From source file:org.orekit.forces.gravity.potential.GravityFieldFactoryTest.java
@Test public void testNormalizer() throws OrekitException { Utils.setDataRoot("potential/icgem-format"); final double shift = 1.23456e8; NormalizedSphericalHarmonicsProvider ref = GravityFieldFactory.getNormalizedProvider(5, 5); NormalizedSphericalHarmonics refHarmonics = ref.onDate(ref.getReferenceDate().shiftedBy(shift)); UnnormalizedSphericalHarmonicsProvider unnormalized = GravityFieldFactory.getUnnormalizedProvider(5, 5); NormalizedSphericalHarmonicsProvider normalized = GravityFieldFactory.getNormalizedProvider(unnormalized); NormalizedSphericalHarmonics normalizedHarmonics = normalized .onDate(normalized.getReferenceDate().shiftedBy(shift)); Assert.assertEquals(ref.getMaxDegree(), normalized.getMaxDegree()); Assert.assertEquals(ref.getMaxOrder(), normalized.getMaxOrder()); Assert.assertEquals(ref.getReferenceDate(), normalized.getReferenceDate()); Assert.assertEquals(ref.getAe(), normalized.getAe(), FastMath.ulp(ref.getAe())); Assert.assertEquals(ref.getMu(), normalized.getMu(), FastMath.ulp(ref.getMu())); Assert.assertEquals(ref.getOffset(AbsoluteDate.GPS_EPOCH), normalized.getOffset(AbsoluteDate.GPS_EPOCH), FastMath.ulp(ref.getOffset(AbsoluteDate.GPS_EPOCH))); for (int i = 0; i <= 5; ++i) { for (int j = 0; j <= i; ++j) { double cRef = refHarmonics.getNormalizedCnm(i, j); double cTest = normalizedHarmonics.getNormalizedCnm(i, j); Assert.assertEquals(cRef, cTest, FastMath.ulp(cRef)); double sRef = refHarmonics.getNormalizedSnm(i, j); double sTest = normalizedHarmonics.getNormalizedSnm(i, j); Assert.assertEquals(sRef, sTest, FastMath.ulp(sRef)); }//w w w. j av a2 s . c om } }
From source file:org.orekit.forces.gravity.potential.GRGSFormatReaderTest.java
private void checkValue(final double value, final AbsoluteDate date, final int n, final int m, final int refYear, final int refMonth, final int refDay, final double constant, final double trend, final int maxUlps) throws OrekitException { double factor = GravityFieldFactory.getUnnormalizationFactors(n, m)[n][m]; AbsoluteDate refDate = new AbsoluteDate(refYear, refMonth, refDay, 12, 0, 0, TimeScalesFactory.getTT()); double dtYear = date.durationFrom(refDate) / Constants.JULIAN_YEAR; double normalized = factor * (constant + trend * dtYear); double epsilon = maxUlps * FastMath.ulp(normalized); Assert.assertEquals(normalized, value, epsilon); }
From source file:org.orekit.forces.gravity.potential.ICGEMFormatReaderTest.java
private void checkValue(final double value, final AbsoluteDate date, final int n, final int m, final int refYear, final int refMonth, final int refDay, final double constant, final double trend, final double cosYear, final double sinYear, final double cosHalfYear, final double sinHalfYear, final int maxUlps) throws OrekitException { double factor = GravityFieldFactory.getUnnormalizationFactors(n, m)[n][m]; AbsoluteDate refDate = new AbsoluteDate(refYear, refMonth, refDay, 12, 0, 0, TimeScalesFactory.getTT()); double dtYear = date.durationFrom(refDate) / Constants.JULIAN_YEAR; double normalized = factor * (constant + trend * dtYear + cosYear * FastMath.cos(MathUtils.TWO_PI * dtYear) + sinYear * FastMath.sin(MathUtils.TWO_PI * dtYear) + cosHalfYear * FastMath.cos(MathUtils.TWO_PI * dtYear * 2) + sinHalfYear * FastMath.sin(MathUtils.TWO_PI * dtYear * 2)); double epsilon = maxUlps * FastMath.ulp(normalized); Assert.assertEquals(normalized, value, epsilon); }
From source file:org.orekit.frames.HelmertTransformationTest.java
@Test public void testHelmert20002005() throws OrekitException { Frame itrf2008 = FramesFactory.getITRF(IERSConventions.IERS_2010, true); Frame itrf2000 = HelmertTransformation.Predefined.ITRF_2008_TO_ITRF_2000.createTransformedITRF(itrf2008, "2000"); Frame itrf2005 = HelmertTransformation.Predefined.ITRF_2008_TO_ITRF_2005.createTransformedITRF(itrf2008, "2005"); Vector3D pos2000 = new Vector3D(1234567.8, 2345678.9, 3456789.0); // check the Helmert transformation as per http://itrf.ign.fr/ITRF_solutions/2005/tp_05-00.php AbsoluteDate date = AbsoluteDate.J2000_EPOCH; Vector3D pos2005 = itrf2000.getTransformTo(itrf2005, date).transformPosition(pos2000); Vector3D generalOffset = pos2000.subtract(pos2005); Vector3D linearOffset = computeOffsetLinearly(0.1, -0.8, -5.8, 0.000, 0.000, 0.000, -0.2, 0.1, -1.8, 0.000, 0.000, 0.000, pos2000, 0.0); Vector3D error = generalOffset.subtract(linearOffset); Assert.assertEquals(0.0, error.getNorm(), FastMath.ulp(pos2000.getNorm())); date = date.shiftedBy(Constants.JULIAN_YEAR); pos2005 = itrf2000.getTransformTo(itrf2005, date).transformPosition(pos2000); generalOffset = pos2000.subtract(pos2005); linearOffset = computeOffsetLinearly(0.1, -0.8, -5.8, 0.000, 0.000, 0.000, -0.2, 0.1, -1.8, 0.000, 0.000, 0.000, pos2000, 1.0);// ww w. jav a2s . com error = generalOffset.subtract(linearOffset); Assert.assertEquals(0.0, error.getNorm(), FastMath.ulp(pos2000.getNorm())); }
From source file:org.orekit.frames.HelmertTransformationTest.java
@Test public void testHelmert19932000() throws OrekitException { Frame itrf2008 = FramesFactory.getITRF(IERSConventions.IERS_2010, true); Frame itrf2000 = HelmertTransformation.Predefined.ITRF_2008_TO_ITRF_2000.createTransformedITRF(itrf2008, "2000"); Frame itrf93 = HelmertTransformation.Predefined.ITRF_2008_TO_ITRF_93.createTransformedITRF(itrf2008, "93"); Vector3D pos93 = new Vector3D(1234567.8, 2345678.9, 3456789.0); // check the Helmert transformation as per ftp://itrf.ensg.ign.fr/pub/itrf/ITRF.TP AbsoluteDate date = new AbsoluteDate(1988, 1, 1, 12, 0, 0, TimeScalesFactory.getTT()); Vector3D pos2000 = itrf93.getTransformTo(itrf2000, date).transformPosition(pos93); Vector3D generalOffset = pos93.subtract(pos2000); Vector3D linearOffset = computeOffsetLinearly(12.7, 6.5, -20.9, -0.39, 0.80, -1.14, -2.9, -0.2, -0.6, -0.11, -0.19, 0.07, pos2000, 0.0);/*from w ww . ja va 2 s . c o m*/ Vector3D error = generalOffset.subtract(linearOffset); Assert.assertEquals(0.0, error.getNorm(), FastMath.ulp(pos93.getNorm())); date = date.shiftedBy(Constants.JULIAN_YEAR); pos2000 = itrf93.getTransformTo(itrf2000, date).transformPosition(pos93); generalOffset = pos93.subtract(pos2000); linearOffset = computeOffsetLinearly(12.7, 6.5, -20.9, -0.39, 0.80, -1.14, -2.9, -0.2, -0.6, -0.11, -0.19, 0.07, pos2000, 1.0); error = generalOffset.subtract(linearOffset); Assert.assertEquals(0.0, error.getNorm(), FastMath.ulp(pos93.getNorm())); }
From source file:org.orekit.propagation.analytical.AbstractAnalyticalPropagator.java
/** {@inheritDoc} */ public SpacecraftState propagate(final AbsoluteDate start, final AbsoluteDate target) throws PropagationException { try {//from w w w.jav a 2 s. com lastPropagationStart = start; final double dt = target.durationFrom(start); final double epsilon = FastMath.ulp(dt); interpolator.storeDate(start); SpacecraftState state = interpolator.getInterpolatedState(); // evaluate step size final double stepSize; if (getMode() == MASTER_MODE) { if (Double.isNaN(getFixedStepSize())) { stepSize = FastMath.copySign(state.getKeplerianPeriod() / 100, dt); } else { stepSize = FastMath.copySign(getFixedStepSize(), dt); } } else { stepSize = dt; } // initialize event detectors for (final EventState<?> es : eventsStates) { es.init(state, target); } // initialize step handler if (getStepHandler() != null) { getStepHandler().init(state, target); } // iterate over the propagation range statesInitialized = false; isLastStep = false; do { // go ahead one step size interpolator.shift(); final AbsoluteDate t = interpolator.getCurrentDate().shiftedBy(stepSize); if ((dt == 0) || ((dt > 0) ^ (t.compareTo(target) <= 0))) { // current step exceeds target interpolator.storeDate(target); } else { // current step is within range interpolator.storeDate(t); } // accept the step, trigger events and step handlers state = acceptStep(target, epsilon); } while (!isLastStep); // return the last computed state lastPropagationEnd = state.getDate(); setStartDate(state.getDate()); return state; } catch (PropagationException pe) { throw pe; } catch (OrekitException oe) { throw PropagationException.unwrap(oe); } catch (TooManyEvaluationsException tmee) { throw PropagationException.unwrap(tmee); } catch (NoBracketingException nbe) { throw PropagationException.unwrap(nbe); } }
From source file:org.orekit.time.AbsoluteDateTest.java
@Test public void testAccuracy() { TimeScale tai = TimeScalesFactory.getTAI(); double sec = 0.281; AbsoluteDate t = new AbsoluteDate(2010, 6, 21, 18, 42, sec, tai); double recomputedSec = t.getComponents(tai).getTime().getSecond(); Assert.assertEquals(sec, recomputedSec, FastMath.ulp(sec)); }