List of usage examples for java.lang Math log10
@HotSpotIntrinsicCandidate public static double log10(double a)
From source file:norbert.mynemo.core.selection.UserRecommenderSelector.java
/** * Evaluates the given recommender type for several configurations. The number of neighbors for * each evaluation is chosen via an optimizer. The number of evaluation performed depends of the * number of steps necessary for the evaluation results to converge. The number of evaluations * performed is also bounded by an internal maximum. * * <p>//from www . j av a 2 s.c o m * The given recommender type must be part of the user similarity based family. * * @return all evaluations done during the selection process */ public Collection<RecommenderEvaluation> select(RecommenderType type, double minimumCoverage) { checkArgument(type.getFamily() == RecommenderFamily.USER_SIMILARITY_BASED); checkArgument(0 <= minimumCoverage && minimumCoverage <= 1, "The minimum coverage must be" + "between 0 and 1."); final UserBasedRecommenderEvaluationFunction function = new UserBasedRecommenderEvaluationFunction( configuration, type, minimumCoverage); // find a good initial guess: test 10%, 20% 90% of maximum neighbors double secondBestInitialValue = 1; double bestInitialValue = 0; double bestEvalResult = Integer.MAX_VALUE; for (double factor = 0.1; factor <= 0.9; factor += 0.1) { double currentNumNeighbors = maxNeighbors * factor; double evalResult = function.value(currentNumNeighbors); if (evalResult < bestEvalResult) { bestEvalResult = evalResult; secondBestInitialValue = bestInitialValue; bestInitialValue = currentNumNeighbors; } } // initialize the quality parameters of the CMAES optimizer final double minNeighbors = 1; final double initialGuessNeighbors = bestInitialValue; final double sigmaNeighbors = Math.min(Math.abs(bestInitialValue - secondBestInitialValue), Math.min(maxNeighbors - bestInitialValue, bestInitialValue - 1)); // not sure about that final int populationSize = (int) (Math.log10(maxNeighbors) / Math.log10(2)); // inhibit the exception throw if the maximum number of evaluation is reached final int maxCmaesEvaluations = Integer.MAX_VALUE; // not sure about that final int maxCmaesIterations = (int) (Math.log10(maxNeighbors) / Math.log10(2)); // initialize the other parameters final ConvergenceChecker<PointValuePair> checker = new MaxIterationChecker<PointValuePair>(20); final ObjectiveFunction objectiveFunction = new ObjectiveFunction(function); final CMAESOptimizer optimizer = new CMAESOptimizer(maxCmaesIterations, 1.0, true, 0, 0, new JDKRandomGenerator(), false, checker); final MaxEval maxEval = new MaxEval(maxCmaesEvaluations); final GoalType goalType = GoalType.MINIMIZE; final SimpleBounds bounds = new SimpleBounds(new double[] { minNeighbors, minNeighbors }, new double[] { maxNeighbors, maxNeighbors }); final InitialGuess initialGuess = new InitialGuess( new double[] { initialGuessNeighbors, initialGuessNeighbors }); final CMAESOptimizer.PopulationSize popSize = new CMAESOptimizer.PopulationSize((populationSize)); final CMAESOptimizer.Sigma sigma = new CMAESOptimizer.Sigma( new double[] { sigmaNeighbors, sigmaNeighbors }); // run the optimizer optimizer.optimize(objectiveFunction, goalType, initialGuess, popSize, sigma, bounds, maxEval); return function.getEvaluations(); }
From source file:net.phyloviz.mstsstatistics.EdgeMST.java
public void calcMatrixUV(SparseDoubleMatrix2D m) { double d;// w w w. ja v a2 s .c o m Algebra a = new Algebra(); int size = m.size(); int[] members = new int[size - 1]; int index = 0; for (int i = 0; i < size; i++) { if (i != this.getSource() || i != this.getDest()) { members[index] = i; index++; } } _rationmsts = Math.log10(Math.abs(a.det(m.viewSelection(members, members)))); }
From source file:sanger.team16.gui.genevar.eqtl.gene.RegionalPlot.java
private JFreeChart createChart(String geneChromosome, int geneStart, int distanceToTSS, double threshold, XYDataset dataset) {/* w w w .j av a 2 s .c o m*/ JFreeChart chart = ChartFactory.createScatterPlot(null, "Position on chromosome " + geneChromosome + " (bp)", "-log10(P)", dataset, PlotOrientation.VERTICAL, true, true, false); XYPlot plot = (XYPlot) chart.getPlot(); plot.setBackgroundPaint(Color.WHITE); plot.setDomainGridlinePaint(Color.lightGray); //plot.setRangeGridlinePaint(Color.lightGray); //plot.setRangeCrosshairVisible(true); //NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis(); //domainAxis.setRange(geneStart - distance, geneStart + distance); //domainAxis.setUpperMargin(1000); //domainAxis.setLowerMargin(1000); //ValueAxis rangeAxis = plot.getRangeAxis(); //rangeAxis.setUpperMargin(dataset.getYValue(0, 0)/5); //rangeAxis.setLowerBound(0); XYItemRenderer renderer = plot.getRenderer(); int size = dataset.getSeriesCount(); for (int i = 0; i < size; i++) { //int scale = (int) Math.round((255 - (255 * dataset.getYValue(i, 0)) / top) / 1.4); //renderer.setSeriesPaint(i, new Color(255, scale, scale)); renderer.setSeriesPaint(i, new Color(255, 0, 0)); renderer.setSeriesShape(i, ShapeUtilities.createDiamond((float) 3)); renderer.setBaseSeriesVisibleInLegend(false); } ValueMarker upperMarker = new ValueMarker(-Math.log10(threshold)); upperMarker.setPaint(Color.gray); //upperMarker.setLabelOffsetType(LengthAdjustmentType.EXPAND); //upperMarker.setLabel("-log10(10E-4)"); //upperMarker.setLabelPaint(Color.red); //upperMarker.setLabelAnchor(RectangleAnchor.TOP_RIGHT); //upperMarker.setLabelTextAnchor(TextAnchor.BOTTOM_RIGHT); float[] f = { 4, 3, 4, 3 }; upperMarker.setStroke(new BasicStroke(1.0f, 1, 1, 0, f, 1.0f)); plot.addRangeMarker(upperMarker); ValueMarker marker = new ValueMarker(0.0); marker.setPaint(Color.lightGray); plot.addRangeMarker(marker); XYSeries series = new XYSeries("Range"); series.add(geneStart - distanceToTSS, -0.05); series.add(geneStart + distanceToTSS, -0.05); ((XYSeriesCollection) dataset).addSeries(series); renderer.setSeriesVisible(dataset.getSeriesCount() - 1, false, false); return chart; }
From source file:sanger.team16.gui.genevar.mqtl.gene.RegionalPlot.java
private JFreeChart createChart(String geneChromosome, int geneStart, int distanceToTSS, double threshold, XYDataset dataset) {/*w ww .j a va 2s . co m*/ JFreeChart chart = ChartFactory.createScatterPlot(null, "Position on chromosome " + geneChromosome + " (bp)", "-log10(P)", dataset, PlotOrientation.VERTICAL, true, true, false); XYPlot plot = (XYPlot) chart.getPlot(); plot.setBackgroundPaint(Color.WHITE); plot.setDomainGridlinePaint(Color.lightGray); //plot.setRangeGridlinePaint(Color.lightGray); //plot.setRangeCrosshairVisible(true); //NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis(); //domainAxis.setRange(geneStart - distance, geneStart + distance); //domainAxis.setUpperMargin(1000); //domainAxis.setLowerMargin(1000); //ValueAxis rangeAxis = plot.getRangeAxis(); //rangeAxis.setUpperMargin(dataset.getYValue(0, 0)/5); //rangeAxis.setLowerBound(0); XYItemRenderer renderer = plot.getRenderer(); int size = dataset.getSeriesCount(); for (int i = 0; i < size; i++) { //int scale = (int) Math.round((255 - (255 * dataset.getYValue(i, 0)) / top) / 1.4); //renderer.setSeriesPaint(i, new Color(255, scale, scale)); renderer.setSeriesPaint(i, new Color(50, 205, 50)); renderer.setSeriesShape(i, ShapeUtilities.createDiamond((float) 3)); renderer.setBaseSeriesVisibleInLegend(false); } ValueMarker upperMarker = new ValueMarker(-Math.log10(threshold)); upperMarker.setPaint(Color.gray); //upperMarker.setLabelOffsetType(LengthAdjustmentType.EXPAND); //upperMarker.setLabel("-log10(10E-4)"); //upperMarker.setLabelPaint(Color.red); //upperMarker.setLabelAnchor(RectangleAnchor.TOP_RIGHT); //upperMarker.setLabelTextAnchor(TextAnchor.BOTTOM_RIGHT); float[] f = { 4, 3, 4, 3 }; upperMarker.setStroke(new BasicStroke(1.0f, 1, 1, 0, f, 1.0f)); plot.addRangeMarker(upperMarker); ValueMarker marker = new ValueMarker(0.0); marker.setPaint(Color.lightGray); plot.addRangeMarker(marker); XYSeries series = new XYSeries("Range"); series.add(geneStart - distanceToTSS, -0.05); series.add(geneStart + distanceToTSS, -0.05); ((XYSeriesCollection) dataset).addSeries(series); renderer.setSeriesVisible(dataset.getSeriesCount() - 1, false, false); return chart; }
From source file:net.sf.mzmine.modules.visualization.twod.TwoDXYPlot.java
public boolean render(final Graphics2D g2, final Rectangle2D dataArea, int index, PlotRenderingInfo info, CrosshairState crosshairState) { // if this is not TwoDDataSet if (index != 0) return super.render(g2, dataArea, index, info, crosshairState); // prepare some necessary constants final int x = (int) dataArea.getX(); final int y = (int) dataArea.getY(); final int width = (int) dataArea.getWidth(); final int height = (int) dataArea.getHeight(); final double imageRTMin = (double) getDomainAxis().getRange().getLowerBound(); final double imageRTMax = (double) getDomainAxis().getRange().getUpperBound(); final double imageRTStep = (imageRTMax - imageRTMin) / width; final double imageMZMin = (double) getRangeAxis().getRange().getLowerBound(); final double imageMZMax = (double) getRangeAxis().getRange().getUpperBound(); final double imageMZStep = (imageMZMax - imageMZMin) / height; if ((zoomOutBitmap != null) && (imageRTMin == totalRTRange.getMin()) && (imageRTMax == totalRTRange.getMax()) && (imageMZMin == totalMZRange.getMin()) && (imageMZMax == totalMZRange.getMax()) && (zoomOutBitmap.getWidth() == width) && (zoomOutBitmap.getHeight() == height)) { g2.drawImage(zoomOutBitmap, x, y, null); return true; }/*from w ww .jav a 2 s . c om*/ // Save current time Date renderStartTime = new Date(); // prepare a double array of summed intensities double values[][] = new double[width][height]; maxValue = 0; // now this is an instance variable Random r = new Random(); for (int i = 0; i < width; i++) for (int j = 0; j < height; j++) { double pointRTMin = imageRTMin + (i * imageRTStep); double pointRTMax = pointRTMin + imageRTStep; double pointMZMin = imageMZMin + (j * imageMZStep); double pointMZMax = pointMZMin + imageMZStep; double lv = dataset.getMaxIntensity(new Range(pointRTMin, pointRTMax), new Range(pointMZMin, pointMZMax), plotMode); if (logScale) { lv = Math.log10(lv); if (lv < 0 || Double.isInfinite(lv)) lv = 0; values[i][j] = lv; //values[r.nextInt(width)][r.nextInt(height)] = lv; } else { values[i][j] = lv; } if (lv > maxValue) maxValue = lv; } // This should never happen, but just for correctness if (maxValue == 0) return false; // Normalize all values for (int i = 0; i < width; i++) for (int j = 0; j < height; j++) { values[i][j] /= maxValue; } // prepare a bitmap of required size BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); // draw image points for (int i = 0; i < width; i++) for (int j = 0; j < height; j++) { Color pointColor = paletteType.getColor(values[i][j]); image.setRGB(i, height - j - 1, pointColor.getRGB()); } // if we are zoomed out, save the values if ((imageRTMin == totalRTRange.getMin()) && (imageRTMax == totalRTRange.getMax()) && (imageMZMin == totalMZRange.getMin()) && (imageMZMax == totalMZRange.getMax())) { zoomOutBitmap = image; } // Paint image g2.drawImage(image, x, y, null); Date renderFinishTime = new Date(); logger.finest("Finished rendering 2D visualizer, " + (renderFinishTime.getTime() - renderStartTime.getTime()) + " ms"); return true; }
From source file:de.tudarmstadt.lt.lm.mapbased.CountingLM.java
public double getNgramLogProbabilityFromIds(List<Integer> ngram) { // check length assert ngram//w w w. j av a 2s . c om .size() <= _order : "Length of Ngram must be lower or equal to the order of the language model."; if (ngram.size() < 1) return Double.NEGATIVE_INFINITY; // c(w_1 ... w_n) Integer nominator = _ngrams_of_order.getQuantity(ngram); if (nominator == 0) return Double.NEGATIVE_INFINITY; // c(w_1) / N if (ngram.size() == 1) return Math.log10(nominator) - Math.log10(_sum_one_grams); // c(w_1 ... w_n-1) Integer denominator = _ngrams_of_lower_order.getQuantity(ngram.subList(0, ngram.size() - 1)); if (denominator == 0) return Double.NEGATIVE_INFINITY; double logprob = Math.log10(nominator) - Math.log10(denominator); return logprob; }
From source file:feature.lowLevel.audio.FeatureExtractor.java
/** * @param waveSegment audio data//from ww w.j ava 2 s.com * @param opt Feature Extraction Options * @param fftWindowSize size of window for FFT calculation * @return RealMatrixExt array containing one RealMatrixExt for each feature set extracted */ public RealMatrixExt[] extractFeatureSets(short[] waveSegment, FeatureExtractionOptions opt, int fftWindowSize) { int segmentSize = waveSegment.length; int fi = 0; // feature set index RealMatrixExt[] featureSets = new RealMatrixExt[opt.getNumberOfFeatureSets()]; /* convert to double precision and */ /* scale wave data to adjust according to hearing threshold */ @SuppressWarnings("unused") double divisor; if (sampleSizeInBits == 8) { divisor = 256; } else { divisor = 32768; } double[] wav = new double[segmentSize]; for (int i = 0; i < segmentSize; i++) { wav[i] = waveSegment[i]; } /* * compute spectrogram for each wave segment (with 50 % overlap in FFT computation) */ double[][] spec = Spectrogram.computeSpectrogram(wav, fftWindowSize, fftWindowSize / 2, Window.HAMMING); int nFrames = spec.length; /* group to bark bands */ BarkScale barkScale = new BarkScale(sampleRate, fftWindowSize); int nBands = barkScale.getNumberOfBarkBands(); double[][] specBark = new double[nFrames][nBands]; for (int t = 0; t < nFrames; t++) { specBark[t] = barkScale.apply(spec[t]); } /* decibel */ for (int t = 0; t < nFrames; t++) { for (int b = 0; b < nBands; b++) { if (specBark[t][b] < 1) { specBark[t][b] = 0; // in Matlab code this is 1 } else { specBark[t][b] = 10.0 * Math.log10(specBark[t][b]); // in } } } /* Sone */ for (int t = 0; t < nFrames; t++) { for (int b = 0; b < nBands; b++) { if (specBark[t][b] >= 40) { specBark[t][b] = Math.pow(2, ((specBark[t][b] - 40) / 10)); } else { specBark[t][b] = Math.pow((specBark[t][b] / 40), 2.642); } } } /* transpose matrix (for efficient row processing) */ RealMatrix specBarkT = new RealMatrixExt(specBark).transpose(); /* compute SSD features */ if (opt.hasSSD()) { featureSets[fi++] = computeStatisticalSpectrumDescriptor(specBarkT, opt.getBandLimit()); } if (!(opt.hasRP() || opt.hasRH())) return featureSets; /* FFT */ double[][] specModAmp = new double[nBands][]; FFT FFTreal = new FFT(); for (int b = 0; b < nBands; b++) { // compute FFT magnitude of each band specModAmp[b] = FFTreal.computeMagnitude(specBarkT.getRow(b)); } /* Fluctuation Strength Curve */ // resolution of modulation frequency axis (0.17 Hz) double modulationFreqResolution = 1 / ((double) segmentSize / (double) sampleRate); for (int b = 0; b < nBands; b++) { specModAmp[b][0] = 0; // omit DC component (would cause deviations while blurring) for (int t = 1; t <= nFrames; t++) // skip DC component (avoid div/0) { double modFreq = modulationFreqResolution * t; double fluctWeight = 1 / (modFreq / 4 + 4 / modFreq); specModAmp[b][t] = specModAmp[b][t] * fluctWeight; } } /* Blurring */ int bandLimit = opt.getBandLimit(); int modAmplLimit = opt.getModAmpLimit(); double[][] result = new double[bandLimit][modAmplLimit]; if (nBands < bandLimit) { // requested number of bands is > than actual # of bands // fill remainder with 0 for (int b = nBands; b < bandLimit; b++) { Arrays.fill(result[b], 0); } bandLimit = nBands; } for (int b = 0; b < bandLimit; b++) { for (int t = 1; t <= modAmplLimit; t++) { // skip DC component: start with 1 result[b][t - 1] = specModAmp[b][t]; } } RealMatrixExt rhythmPattern = new RealMatrixExt(result); rhythmPattern.setType(RealMatrixExt.TYPE_RP); if (opt.hasRP()) { featureSets[fi++] = rhythmPattern; } /* compute RH features */ if (opt.hasRH()) { featureSets[fi++] = computeRhythmHistogram(rhythmPattern); } return featureSets; }
From source file:eagle.security.userprofile.model.kde.UserProfileKDEModeler.java
private void computeProbabilityDensityEstimation(RealMatrix inputMat) { probabilityEstimation = new double[inputMat.getRowDimension()]; for (int i = 0; i < probabilityEstimation.length; i++) probabilityEstimation[i] = 1.0;/*from www . j a v a2 s . c o m*/ for (int i = 0; i < inputMat.getRowDimension(); i++) { for (int j = 0; j < inputMat.getColumnDimension(); j++) { if (statistics[j].getStddev() > 0) { double stddev = statistics[j].getStddev(); double mean = statistics[j].getMean(); double sqrt2PI = Math.sqrt(2.0 * Math.PI); double denominatorFirstPart = sqrt2PI * stddev; double squareMeanNormal = Math.pow((inputMat.getEntry(i, j) - mean), 2); double twoPowStandardDev = Math.pow(stddev, 2); double twoTimesTwoPowStandardDev = 2.0 * twoPowStandardDev; probabilityEstimation[i] *= ((1.00 / denominatorFirstPart) * (Math.exp(-(squareMeanNormal / twoTimesTwoPowStandardDev)))); } } } java.util.List<Double> listProb = new ArrayList<Double>(); for (int i = 0; i < probabilityEstimation.length; i++) { probabilityEstimation[i] = Math.log10(probabilityEstimation[i]); listProb.add(probabilityEstimation[i]); } Collections.sort(listProb); int i = 0; for (double d : listProb) probabilityEstimation[i++] = d; minProbabilityEstimate = probabilityEstimation[probabilityEstimation.length - 1]; maxProbabilityEstimate = probabilityEstimation[0]; int len = probabilityEstimation.length; int nintyFivePercentIndex = (int) Math.round(0.05 * len); int medianPercentIndex = (int) Math.round(0.5 * len); if (medianPercentIndex >= len) medianProbabilityEstimate = probabilityEstimation[medianPercentIndex - 1]; else medianProbabilityEstimate = probabilityEstimation[medianPercentIndex]; nintyFivePercentileEstimate = probabilityEstimation[nintyFivePercentIndex]; }
From source file:edu.scripps.fl.curves.CurveFit.java
public static void curveClassification(Curve curve) { double y[] = (double[]) ConvertUtils.convert(curve.getResponses(), double[].class); double x[] = (double[]) ConvertUtils.convert(curve.getConcentrations(), double[].class); for (int ii = 0; ii < x.length; ii++) x[ii] = Math.log10(x[ii]); boolean flags[] = (boolean[]) ConvertUtils.convert(curve.getMask(), boolean[].class); curveClassification(curve, y, x, flags); }
From source file:com.bc.jexp.impl.DefaultNamespace.java
private void registerDefaultFunctions() { registerFunction(new AbstractFunction.D("sin", 1) { public double evalD(final EvalEnv env, final Term[] args) { return FastMath.sin(args[0].evalD(env)); }/*from w w w. j a va 2 s.c o m*/ }); registerFunction(new AbstractFunction.D("cos", 1) { public double evalD(final EvalEnv env, final Term[] args) { return FastMath.cos(args[0].evalD(env)); } }); registerFunction(new AbstractFunction.D("tan", 1) { public double evalD(final EvalEnv env, final Term[] args) { return FastMath.tan(args[0].evalD(env)); } }); registerFunction(new AbstractFunction.D("asin", 1) { public double evalD(final EvalEnv env, final Term[] args) { return FastMath.asin(args[0].evalD(env)); } }); registerFunction(new AbstractFunction.D("acos", 1) { public double evalD(final EvalEnv env, final Term[] args) { return FastMath.acos(args[0].evalD(env)); } }); registerFunction(new AbstractFunction.D("atan", 1) { public double evalD(final EvalEnv env, final Term[] args) { return FastMath.atan(args[0].evalD(env)); } }); registerFunction(new AbstractFunction.D("atan2", 2) { public double evalD(final EvalEnv env, final Term[] args) { return Math.atan2(args[0].evalD(env), args[1].evalD(env)); } }); registerFunction(new AbstractFunction.D("log", 1) { public double evalD(final EvalEnv env, final Term[] args) { return Math.log(args[0].evalD(env)); } }); registerFunction(new AbstractFunction.D("log10", 1) { public double evalD(EvalEnv env, Term[] args) throws EvalException { return Math.log10(args[0].evalD(env)); } }); registerFunction(new AbstractFunction.D("exp", 1) { public double evalD(final EvalEnv env, final Term[] args) { return FastMath.exp(args[0].evalD(env)); } }); registerFunction(new AbstractFunction.D("exp10", 1) { public double evalD(EvalEnv env, Term[] args) throws EvalException { return FastMath.pow(10.0, args[0].evalD(env)); } }); registerFunction(new AbstractFunction.D("sqr", 1) { public double evalD(final EvalEnv env, final Term[] args) { double v = args[0].evalD(env); return v * v; } }); registerFunction(new AbstractFunction.D("sqrt", 1) { public double evalD(final EvalEnv env, final Term[] args) { return Math.sqrt(args[0].evalD(env)); } }); registerFunction(new AbstractFunction.D("pow", 2) { public double evalD(final EvalEnv env, final Term[] args) { return FastMath.pow(args[0].evalD(env), args[1].evalD(env)); } }); registerFunction(new AbstractFunction.I("min", 2) { public int evalI(final EvalEnv env, final Term[] args) { return Math.min(args[0].evalI(env), args[1].evalI(env)); } }); registerFunction(new AbstractFunction.D("min", 2) { public double evalD(final EvalEnv env, final Term[] args) { return Math.min(args[0].evalD(env), args[1].evalD(env)); } }); registerFunction(new AbstractFunction.I("max", 2) { public int evalI(final EvalEnv env, final Term[] args) { return Math.max(args[0].evalI(env), args[1].evalI(env)); } }); registerFunction(new AbstractFunction.D("max", 2) { public double evalD(final EvalEnv env, final Term[] args) { return Math.max(args[0].evalD(env), args[1].evalD(env)); } }); registerFunction(new AbstractFunction.D("floor", 1) { public double evalD(EvalEnv env, Term[] args) throws EvalException { return Math.floor(args[0].evalD(env)); } }); registerFunction(new AbstractFunction.D("round", 1) { public double evalD(EvalEnv env, Term[] args) throws EvalException { return Math.round(args[0].evalD(env)); } }); registerFunction(new AbstractFunction.D("ceil", 1) { public double evalD(EvalEnv env, Term[] args) throws EvalException { return Math.ceil(args[0].evalD(env)); } }); registerFunction(new AbstractFunction.D("rint", 1) { public double evalD(EvalEnv env, Term[] args) throws EvalException { return Math.rint(args[0].evalD(env)); } }); registerFunction(new AbstractFunction.I("sign", 1) { public int evalI(final EvalEnv env, final Term[] args) { return ExtMath.sign(args[0].evalI(env)); } }); registerFunction(new AbstractFunction.D("sign", 1) { public double evalD(final EvalEnv env, final Term[] args) { return ExtMath.sign(args[0].evalD(env)); } }); registerFunction(new AbstractFunction.I("abs", 1) { public int evalI(final EvalEnv env, final Term[] args) { return Math.abs(args[0].evalI(env)); } }); registerFunction(new AbstractFunction.D("abs", 1) { public double evalD(final EvalEnv env, final Term[] args) { return Math.abs(args[0].evalD(env)); } }); registerFunction(new AbstractFunction.D("deg", 1) { public double evalD(final EvalEnv env, final Term[] args) { return Math.toDegrees(args[0].evalD(env)); } }); registerFunction(new AbstractFunction.D("rad", 1) { public double evalD(final EvalEnv env, final Term[] args) { return Math.toRadians(args[0].evalD(env)); } }); registerFunction(new AbstractFunction.D("ampl", 2) { public double evalD(final EvalEnv env, final Term[] args) { final double a = args[0].evalD(env); final double b = args[1].evalD(env); return Math.sqrt(a * a + b * b); } }); registerFunction(new AbstractFunction.D("phase", 2) { public double evalD(final EvalEnv env, final Term[] args) { final double a = args[0].evalD(env); final double b = args[1].evalD(env); return Math.atan2(b, a); } }); registerFunction(new AbstractFunction.B("feq", 2) { public boolean evalB(EvalEnv env, Term[] args) throws EvalException { final double x1 = args[0].evalD(env); final double x2 = args[1].evalD(env); return ExtMath.feq(x1, x2, EPS); } }); registerFunction(new AbstractFunction.B("feq", 3) { public boolean evalB(EvalEnv env, Term[] args) throws EvalException { final double x1 = args[0].evalD(env); final double x2 = args[1].evalD(env); final double eps = args[2].evalD(env); return ExtMath.feq(x1, x2, eps); } }); registerFunction(new AbstractFunction.B("fneq", 2) { public boolean evalB(EvalEnv env, Term[] args) throws EvalException { final double x1 = args[0].evalD(env); final double x2 = args[1].evalD(env); return ExtMath.fneq(x1, x2, EPS); } }); registerFunction(new AbstractFunction.B("fneq", 3) { public boolean evalB(EvalEnv env, Term[] args) throws EvalException { final double x1 = args[0].evalD(env); final double x2 = args[1].evalD(env); final double eps = args[2].evalD(env); return ExtMath.fneq(x1, x2, eps); } }); registerFunction(new AbstractFunction.B("inf", 1) { public boolean evalB(EvalEnv env, Term[] args) throws EvalException { return Double.isInfinite(args[0].evalD(env)); } }); registerFunction(new AbstractFunction.B("nan", 1) { public boolean evalB(EvalEnv env, Term[] args) throws EvalException { return Double.isNaN(args[0].evalD(env)); } }); registerFunction(new AbstractFunction.D("distance", -1) { public double evalD(final EvalEnv env, final Term[] args) { double sqrSum = 0.0; final int n = args.length / 2; for (int i = 0; i < n; i++) { final double v = args[i + n].evalD(env) - args[i].evalD(env); sqrSum += v * v; } return Math.sqrt(sqrSum); } }); registerFunction(new AbstractFunction.D("distance_deriv", -1) { public double evalD(final EvalEnv env, final Term[] args) { double sqrSum = 0.0; final int n = args.length / 2; for (int i = 0; i < n - 1; i++) { final double v1 = args[i + 1].evalD(env) - args[i].evalD(env); final double v2 = args[i + n + 1].evalD(env) - args[i + n].evalD(env); sqrSum += (v1 - v2) * (v1 - v2); } return Math.sqrt(sqrSum); } }); registerFunction(new AbstractFunction.D("distance_integ", -1) { public double evalD(final EvalEnv env, final Term[] args) { double sqrSum = 0.0; double v1Sum = 0.0; double v2Sum = 0.0; final int n = args.length / 2; for (int i = 0; i < n; i++) { v1Sum += args[i].evalD(env); v2Sum += args[i + n].evalD(env); sqrSum += (v2Sum - v1Sum) * (v2Sum - v1Sum); } return Math.sqrt(sqrSum); } }); registerFunction(new AbstractFunction.B("inrange", -1) { public boolean evalB(final EvalEnv env, final Term[] args) { final int n1 = args.length / 3; final int n2 = n1 + args.length / 3; for (int i = 0; i < n1; i++) { final double v = args[i].evalD(env); final double v1 = args[i + n1].evalD(env); final double v2 = args[i + n2].evalD(env); if (v < v1 || v > v2) { return false; } } return true; } }); registerFunction(new AbstractFunction.B("inrange_deriv", -1) { public boolean evalB(final EvalEnv env, final Term[] args) { final int n1 = args.length / 3; final int n2 = 2 * n1; for (int i = 0; i < n1 - 1; i++) { final double v = args[i + 1].evalD(env) - args[i].evalD(env); final double v1 = args[i + n1 + 1].evalD(env) - args[i + n1].evalD(env); final double v2 = args[i + n2 + 1].evalD(env) - args[i + n2].evalD(env); if (v < v1 || v > v2) { return false; } } return true; } }); registerFunction(new AbstractFunction.B("inrange_integ", -1) { public boolean evalB(final EvalEnv env, final Term[] args) { final int n1 = args.length / 3; final int n2 = 2 * n1; double vSum = 0.0; double v1Sum = 0.0; double v2Sum = 0.0; for (int i = 0; i < n1; i++) { vSum += args[i].evalD(env); v1Sum += args[i + n1].evalD(env); v2Sum += args[i + n2].evalD(env); if (vSum < v1Sum || vSum > v2Sum) { return false; } } return true; } }); }