private double computeCurrentValue() { double offset = this.slider.getValue(); if (this.isIntegral) { return Math.rint(this.baseValue + Math.signum(offset) * 4 * Math.expm1(Math.abs(offset) * 4)); } else { return this.baseValue + Math.signum(offset) * Math.expm1(Math.abs(offset) * 5); } }
/** * This is the Taylor expansion of the first derivative of $$\frac{\exp(x)-1}{x}$$ * * @param x value * @return result */ public static double epsilonP(final double x) { if (Math.abs(x) > 1e-7) { return ((x - 1) * Math.expm1(x) + x) / x / x; } return taylor(x, COEFF2); }
/** {@inheritDoc} */ public OpenMapRealVector mapExpm1ToSelf() { Iterator iter = entries.iterator(); while (iter.hasNext()) { iter.advance(); entries.put(iter.key(), Math.expm1(iter.value())); } return this; }
/** * This is the Taylor expansion of the second derivative of $$\frac{\exp(x)-1}{x}$$ * * @param x value * @return result */ public static double epsilonPP(final double x) { if (Math.abs(x) > 1e-5) { final double x2 = x * x; final double x3 = x * x2; return (Math.expm1(x) * (x2 - 2 * x + 2) + x2 - 2 * x) / x3; } return taylor(x, COEFF3); }
public int simulateAneal() { double[] schedule = new double[25000]; int sum = 0; int conflict; for (int i = 0; i < schedule.length; i++) { schedule[i] = 35 - (35.0 / 25000.0) * (i + 1); conflict = h(queen); double T = schedule[i]; if (T == 0) { if (conflict != 0) { sum = -(i + 1); } else { sum = i + 1; } break; } if (conflict == 0) { sum = i + 1; break; } Queen[] newTemp = new Queen[8]; for (int a = 0; a < 8; a++) { newTemp[a] = new Queen(queen[a].x, queen[a].y); } Queen[] newQueens = randomGetStates(newTemp); int E = h(queen) - h(newQueens); if (E > 0) { this.queen = newQueens; } else { double value = E / (double) T; double posibility = Math.expm1(value) + 1.0; if (Math.random() < posibility) { this.queen = newQueens; } } } return sum; }
public double getCRB() { double p = h / var; AllPAMSymbolGenerator gen = new AllPAMSymbolGenerator(); double bestcrb = Double.NEGATIVE_INFINITY; double[] d = new double[T]; for (int i = 0; i < Math.pow(M, T); i++) { double[] nextsym = gen.getNext(); // System.out.println(nextsym.length); for (int j = 0; j < T; j++) { d[j] = x[j] - nextsym[j]; } double magd2 = VectorFunctions.sum2(d); if (magd2 > 0.5) { double std = VectorFunctions.dot(x, d); double crb = var / (magx2 - p * std * std / Math.expm1(p * magd2)); if (crb > bestcrb) bestcrb = crb; } } return bestcrb; }
public static double R_Log1_Exp(double x, boolean lower_tail, boolean log_p) { return ((x) > -Math.log(2.0) ? Math.log(-Math.expm1(x)) : Math.log1p(-Math.exp(x))); }
@Override public Object visit(RealUnaryExpression n, Void arg) { Double doubleObject = (Double) n.getOperand().accept(this, null); double doubleVal = doubleObject.doubleValue(); Operator op = n.getOperator(); switch (op) { case ABS: return Math.abs(doubleVal); case ACOS: return Math.acos(doubleVal); case ASIN: return Math.asin(doubleVal); case ATAN: return Math.atan(doubleVal); case CBRT: return Math.cbrt(doubleVal); case CEIL: return Math.ceil(doubleVal); case COS: return Math.cos(doubleVal); case COSH: return Math.cosh(doubleVal); case EXP: return Math.exp(doubleVal); case EXPM1: return Math.expm1(doubleVal); case FLOOR: return Math.floor(doubleVal); case LOG: return Math.log(doubleVal); case LOG10: return Math.log10(doubleVal); case LOG1P: return Math.log1p(doubleVal); case NEG: return -doubleVal; case NEXTUP: return Math.nextUp(doubleVal); case RINT: return Math.rint(doubleVal); case SIGNUM: return Math.signum(doubleVal); case SIN: return Math.sin(doubleVal); case SINH: return Math.sinh(doubleVal); case SQRT: return Math.sqrt(doubleVal); case TAN: return Math.tan(doubleVal); case TANH: return Math.tanh(doubleVal); case TODEGREES: return Math.toDegrees(doubleVal); case TORADIANS: return Math.toRadians(doubleVal); case ULP: return Math.ulp(doubleVal); default: log.warn("RealUnaryExpression: unimplemented operator: " + op); return null; } }
// To add/remove functions change evaluateOperator() and registration public double evaluateFunction(String fncnam, ArgParser fncargs) throws ArithmeticException { switch (Character.toLowerCase(fncnam.charAt(0))) { case 'a': { if (fncnam.equalsIgnoreCase("abs")) { return Math.abs(fncargs.next()); } if (fncnam.equalsIgnoreCase("acos")) { return Math.acos(fncargs.next()); } if (fncnam.equalsIgnoreCase("asin")) { return Math.asin(fncargs.next()); } if (fncnam.equalsIgnoreCase("atan")) { return Math.atan(fncargs.next()); } } break; case 'c': { if (fncnam.equalsIgnoreCase("cbrt")) { return Math.cbrt(fncargs.next()); } if (fncnam.equalsIgnoreCase("ceil")) { return Math.ceil(fncargs.next()); } if (fncnam.equalsIgnoreCase("cos")) { return Math.cos(fncargs.next()); } if (fncnam.equalsIgnoreCase("cosh")) { return Math.cosh(fncargs.next()); } } break; case 'e': { if (fncnam.equalsIgnoreCase("exp")) { return Math.exp(fncargs.next()); } if (fncnam.equalsIgnoreCase("expm1")) { return Math.expm1(fncargs.next()); } } break; case 'f': { if (fncnam.equalsIgnoreCase("floor")) { return Math.floor(fncargs.next()); } } break; case 'g': { // if(fncnam.equalsIgnoreCase("getExponent" )) { return // Math.getExponent(fncargs.next()); } needs Java 6 } break; case 'l': { if (fncnam.equalsIgnoreCase("log")) { return Math.log(fncargs.next()); } if (fncnam.equalsIgnoreCase("log10")) { return Math.log10(fncargs.next()); } if (fncnam.equalsIgnoreCase("log1p")) { return Math.log1p(fncargs.next()); } } break; case 'm': { if (fncnam.equalsIgnoreCase("max")) { return Math.max(fncargs.next(), fncargs.next()); } if (fncnam.equalsIgnoreCase("min")) { return Math.min(fncargs.next(), fncargs.next()); } } break; case 'n': { // if(fncnam.equalsIgnoreCase("nextUp" )) { return Math.nextUp // (fncargs.next()); } needs Java 6 } break; case 'r': { if (fncnam.equalsIgnoreCase("random")) { return Math.random(); } // impure if (fncnam.equalsIgnoreCase("round")) { return Math.round(fncargs.next()); } if (fncnam.equalsIgnoreCase("roundHE")) { return Math.rint(fncargs.next()); } // round half-even } break; case 's': { if (fncnam.equalsIgnoreCase("signum")) { return Math.signum(fncargs.next()); } if (fncnam.equalsIgnoreCase("sin")) { return Math.sin(fncargs.next()); } if (fncnam.equalsIgnoreCase("sinh")) { return Math.sinh(fncargs.next()); } if (fncnam.equalsIgnoreCase("sqrt")) { return Math.sqrt(fncargs.next()); } } break; case 't': { if (fncnam.equalsIgnoreCase("tan")) { return Math.tan(fncargs.next()); } if (fncnam.equalsIgnoreCase("tanh")) { return Math.tanh(fncargs.next()); } if (fncnam.equalsIgnoreCase("toDegrees")) { return Math.toDegrees(fncargs.next()); } if (fncnam.equalsIgnoreCase("toRadians")) { return Math.toRadians(fncargs.next()); } } break; case 'u': { if (fncnam.equalsIgnoreCase("ulp")) { return Math.ulp(fncargs.next()); } } break; // no default } throw new UnsupportedOperationException( "MathEval internal function setup is incorrect - internal function \"" + fncnam + "\" not handled"); }
@Override public double op(double d) { return Math.expm1(d); }
/** * This is the Taylor expansion of $$\frac{\exp(x)-1}{x}$$ - note for $$|x| > 10^{-10}$$ the * expansion is note used * * @param x value * @return result */ public static double epsilon(final double x) { if (Math.abs(x) > 1e-10) { return Math.expm1(x) / x; } return taylor(x, COEFF1); }