List of usage examples for org.apache.commons.math3.util FastMath max
public static double max(final double a, final double b)
From source file:com.sandbox.utils.HSLColor.java
/** * Convert a RGB Color to it corresponding HSL values. * * @param color the color to convert.//from w ww . j a v a 2 s .c o m * @param dest the optional array to store the result in. * @return an array containing the 3 HSL values. */ public static float[] fromRGB(final Color color, float[] dest) { // Get RGB values in the range 0 - 1 final float r = color.getRed() / 255f; final float g = color.getGreen() / 255f; final float b = color.getBlue() / 255f; // Minimum and Maximum RGB values are used in the HSL calculations final float min = FastMath.min(r, FastMath.min(g, b)); final float max = FastMath.max(r, FastMath.max(g, b)); // Calculate the Hue float h = 0; if (max == min) h = 0; else if (max == r) h = ((g - b) / (max - min) / 6f + 1) % 1; else if (max == g) h = (b - r) / (max - min) / 6f + 1f / 3f; else if (max == b) h = (r - g) / (max - min) / 6f + 2f / 3f; // Calculate the Luminance final float l = (max + min) / 2; // Calculate the Saturation float s = 0; if (max == min) s = 0; else if (l <= .5f) s = (max - min) / (max + min); else s = (max - min) / (2 - max - min); if (dest == null) dest = new float[3]; dest[0] = h; dest[1] = s; dest[2] = l; return dest; }
From source file:fuzzy.mf.TriangularMembershipFunction.java
public Double evaluate(Double x) { return FastMath.max(FastMath.min((x - a) / (b - a), (c - x) / (c - b)), 0.0); }
From source file:com.tussle.main.Utility.java
public static double addTowards(double value, double addend, double base) { if (addend == 0) return value; if (addend * (base - value - addend) > 0) return value + addend; else// w ww. j av a2 s . c o m return addend > 0 ? FastMath.max(base, value) : FastMath.min(base, value); }
From source file:gdsc.smlm.function.CCDCameraNoiseModel.java
public double variance(final double value) { return readNoise2 + FastMath.max(value - bias, 0.0); }
From source file:gdsc.smlm.function.EMCCDCameraNoiseModel.java
public double variance(final double value) { return readNoise2 + FastMath.max(value - bias, 0.0) * 2.0; }
From source file:gdsc.core.clustering.TimeCluster.java
/** * Get the time gap between the two clusters. If the clusters overlap then return 0. * /*from w ww .j ava 2 s .c om*/ * @param other * @return */ public int gap(TimeCluster other) { // Overlap: // |-----------| // |---------| // // Gap: // |-----------| // |---------| return FastMath.max(0, FastMath.max(start, other.start) - FastMath.min(end, other.end)); }
From source file:cloudnet.workloads.WorkloadModelBase.java
protected double adjustToBounds(double input) { if (minValue != null) { input = FastMath.max(input, minValue); }/* w w w. j av a 2 s . com*/ if (maxValue != null) { input = FastMath.min(input, maxValue); } return input; }
From source file:gdsc.smlm.utils.Convolution.java
/** * Calculates the <a href="http://en.wikipedia.org/wiki/Convolution"> * convolution</a> between two sequences. * <p>/*from w w w . j av a 2 s .c om*/ * The solution is obtained via straightforward computation of the convolution sum (and not via FFT). Whenever the * computation needs an element that would be located at an index outside the input arrays, the value is assumed to * be zero. * <p> * This has been taken from Apache Commons Math v3.3: org.apache.commons.math3.util.MathArrays * * @param x * First sequence. * Typically, this sequence will represent an input signal to a system. * @param h * Second sequence. * Typically, this sequence will represent the impulse response of the system. * @return the convolution of {@code x} and {@code h}. * This array's length will be {@code x.length + h.length - 1}. * @throws IllegalArgumentException * if either {@code x} or {@code h} is {@code null} or either {@code x} or {@code h} is empty. */ public static double[] convolve(double[] x, double[] h) throws IllegalArgumentException { checkInput(x, h); final int xLen = x.length; final int hLen = h.length; // initialize the output array final int totalLength = xLen + hLen - 1; final double[] y = new double[totalLength]; // straightforward implementation of the convolution sum for (int n = 0; n < totalLength; n++) { double yn = 0; int k = FastMath.max(0, n + 1 - xLen); int j = n - k; while (k < hLen && j >= 0) { yn += x[j--] * h[k++]; } y[n] = yn; } return y; }
From source file:com.cloudera.oryx.rdf.common.tree.DecisionTree.java
public static DecisionTree fromExamplesWithDefault(List<Example> examples) { ExampleSet exampleSet = new ExampleSet(examples); Config config = ConfigUtils.getDefaultConfig(); int numFeatures = exampleSet.getNumFeatures(); double fractionOfFeaturesToTry = config.getDouble("model.fraction-features-to-try"); int featuresToTry = FastMath.max(1, (int) (fractionOfFeaturesToTry * numFeatures)); int minNodeSize = config.getInt("model.min-node-size"); double minInfoGainNats = config.getDouble("model.min-info-gain-nats"); int suggestedMaxSplitCandidates = config.getInt("model.max-split-candidates"); int maxDepth = config.getInt("model.max-depth"); return new DecisionTree(numFeatures, featuresToTry, minNodeSize, minInfoGainNats, suggestedMaxSplitCandidates, maxDepth, exampleSet); }
From source file:de.tuberlin.uebb.jbop.example.DSCompilerFactory.java
/** * Get the compiler for number of free parameters and order. * /* w w w.j a va 2 s. com*/ * @param parameters * number of free parameters * @param order * derivation order * @return cached rules set */ public static IDSCompiler getCompiler(final int parameters, final int order) { // get the cached compilers final IDSCompiler[][] cache = compilers.get(); if ((cache != null) && (cache.length > parameters) && (cache[parameters].length > order)) { if (cache[parameters][order] != null) { // the compiler has already been created return cache[parameters][order]; } } // we need to create more compilers final int maxParameters = FastMath.max(parameters, cache == null ? 0 : cache.length); final int maxOrder = FastMath.max(order, cache == null ? 0 : cache[0].length); final IDSCompiler[][] newCache = new IDSCompiler[maxParameters + 1][maxOrder + 1]; if (cache != null) { // preserve the already created compilers for (int i = 0; i < cache.length; ++i) { System.arraycopy(cache[i], 0, newCache[i], 0, cache[i].length); } } // create the array in increasing diagonal order for (int diag = 0; diag <= (parameters + order); ++diag) { for (int o = FastMath.max(0, diag - parameters); o <= FastMath.min(order, diag); ++o) { final int p = diag - o; if (newCache[p][o] == null) { final IDSCompiler valueCompiler = (p == 0) ? null : newCache[p - 1][o]; final IDSCompiler derivativeCompiler = (o == 0) ? null : newCache[p][o - 1]; final int[][] sizes = compileSizes(p, o, valueCompiler); final int[][] derivativesIndirection = compileDerivativesIndirection(p, o, valueCompiler, derivativeCompiler); final int[] lowerIndirection = compileLowerIndirection(p, o, valueCompiler, derivativeCompiler); final int[][][] multiplicationIndirection = compileMultiplicationIndirection(p, o, valueCompiler, derivativeCompiler, lowerIndirection); final int[][][] compositionIndirection = compileCompositionIndirection(p, o, valueCompiler, derivativeCompiler, sizes, derivativesIndirection); final IDSCompiler dsCompiler = new DSCompiler(p, o, sizes, derivativesIndirection, lowerIndirection, multiplicationIndirection, compositionIndirection); final Optimizer optimizer = new Optimizer(); IDSCompiler optimized; try { optimized = optimizer.optimize(dsCompiler, "__" + p + "x" + o); } catch (final JBOPClassException e) { throw new RuntimeException("IDSCompiler couldn't be created.", e); } newCache[p][o] = optimized; } } } // atomically reset the cached compilers array compilers.compareAndSet(cache, newCache); return newCache[parameters][order]; }