List of usage examples for org.apache.commons.math3.analysis.integration TrapezoidIntegrator TrapezoidIntegrator
public TrapezoidIntegrator()
From source file:fr.amap.lidar.amapvox.commons.GTheta.java
/** * <p>Get the transmittance from the specified angle (radians or degrees) and the specified Leaf Angle Distribution.</p> * 0 is vertical, 90 is horizontal (zenithal angle, measured from vertical). * @param theta Angle/*from w w w .j a v a 2 s . c o m*/ * @param degrees true if the given angle is in degrees, false otherwise * @return directional transmittance (GTheta) */ public double getGThetaFromAngle(double theta, boolean degrees) { if (degrees) { if (theta > 90) { //get an angle between 0 and 90 theta = 180 - theta; } } else { if (theta > (Math.PI / 2.0)) { //get an angle between 0 and pi/2 theta = Math.PI - theta; } } if (transmittanceFunctions != null && !isBuildingTable) { //a table was built int indice = 0; if (degrees) { indice = (int) (theta / res); } else { indice = (int) (Math.toDegrees(theta) / res); } if (indice >= transmittanceFunctions.length) { indice = transmittanceFunctions.length - 1; } else if (indice < 0) { indice = 0; } return transmittanceFunctions[indice]; } else { //no table was built, get transmittance on the fly if (pdfArray == null) { setupDensityProbabilityArray(DEFAULT_STEP_NUMBER); } if (distribution.getType() == SPHERIC) { return 0.5; //the result for spherical distribution is always 0.5, saving processing time } else { if (degrees) { theta = Math.toRadians(theta); } if (theta == 0) { theta = Double.MIN_VALUE; } if (theta >= Math.PI / 2.0) { theta = (Math.PI / 2.0) - 0.00001; } UnivariateFunction function1 = new CustomFunction1(theta); UnivariateFunction function2 = new CustomFunction2(theta); TrapezoidIntegrator integrator = new TrapezoidIntegrator(); double sum = 0; for (int j = 0; j < nbIntervals; j++) { double thetaL = (serie_angulaire[j] + serie_angulaire[j + 1]) / 2.0d; double Fi = (pdfArray[j]) / SOM; double cotcot = Math.abs(1 / (Math.tan(theta) * Math.tan(thetaL))); double Hi; if (cotcot > 1 || Double.isInfinite(cotcot)) { Hi = integrator.integrate(10000, function1, serie_angulaire[j], serie_angulaire[j + 1]); } else { Hi = integrator.integrate(10000, function2, serie_angulaire[j], serie_angulaire[j + 1]); //System.out.println("nb evaluations: " + integrator.getEvaluations()); } double Gi = Fi * Hi / ((Math.PI / 2) / (double) serie_angulaire.length); //because we need the average value not the actual integral value!!!! sum += Gi; } return sum; } } }
From source file:ca.mcgill.networkdynamics.geoinference.evaluation.CrossValidationScorer.java
public static double computeAuc(TDoubleList errors) { double[] normalizedErrors = new double[errors.size()]; int[] errorsPerKm = new int[MAX_KM]; for (int i = 0; i < errors.size(); ++i) { int error = (int) (Math.round(errors.get(i))); errorsPerKm[error]++;/*from ww w .jav a2 s.c om*/ } // The accumulated sum of errors per km int[] errorsBelowEachKm = new int[errorsPerKm.length]; for (int i = 0; i < errorsBelowEachKm.length; ++i) { errorsBelowEachKm[i] = errorsPerKm[i]; if (i > 0) errorsBelowEachKm[i] += errorsBelowEachKm[i - 1]; } final double[] cdf = new double[errorsBelowEachKm.length]; double dSize = errors.size(); // to avoid casting all the time for (int i = 0; i < cdf.length; ++i) cdf[i] = errorsBelowEachKm[i] / dSize; final double maxLogKm = Math.log10(MAX_KM - 1); // At this point, the CDF is between [0, 20038], so we first need // log-scale the x-values and then to normalize it into [0, 1] UnivariateFunction logNormalizedScaledCdf = new UnivariateFunction() { public double value(double x) { // First, unscale by the log(MAX_DIST) so the valus is just // Math.log10(x) double unscaled = x * maxLogKm; // Second, invert the log transformation double errorInKm = Math.pow(10, unscaled); // Get the probability of having an error less than this // amount double prob = cdf[(int) (Math.round(errorInKm))]; // Now look up the CDF value for that error return prob; } }; TrapezoidIntegrator ti = new TrapezoidIntegrator(); double auc = ti.integrate(10_000_000, logNormalizedScaledCdf, 0, 1); return auc; }