Example usage for java.lang Math E

List of usage examples for java.lang Math E

Introduction

In this page you can find the example usage for java.lang Math E.

Prototype

double E

To view the source code for java.lang Math E.

Click Source Link

Document

The double value that is closer than any other to e, the base of the natural logarithms.

Usage

From source file:dev.maisentito.suca.commands.EvalCommandHandler.java

@Override
public void handleCommand(MessageEvent event, String[] args) throws Throwable {
    double result = new ExpressionBuilder(StringUtils.join(args, ' ')).variables("pi", "e").build()
            .setVariable("pi", Math.PI).setVariable("e", Math.E).evaluate();

    event.respond("eval: result: " + result);
}

From source file:de.termininistic.serein.examples.benchmarks.functions.multimodal.AckleyFunction.java

@Override
public double map(RealVector v) {
    double[] x = v.toArray();
    int n = x.length;
    double sum1 = 0.0, sum2 = 0.0;

    for (int i = 0; i < n; i++) {
        sum1 += x[i] * x[i];//from   w  ww .j a va  2  s  .c o m
        sum2 += Math.cos(2 * Math.PI * x[i]);
    }
    double fx = -20 * Math.exp(-0.2 * Math.sqrt(sum1 / n)) - Math.exp(sum2 / n) + 20 + Math.E;
    return fx;
}

From source file:syncleus.gremlann.model.Autoencoder.java

final public static double sigmoid(final double x) {
    return 1.0 / (1.0 + Math.pow(Math.E, -x));
}

From source file:math2605.gn_exp.java

private static void setR(List<String[]> pairs, double a, double b, double c, RealMatrix r) {
    int row = 0;//  w  w  w .java  2  s.  c om
    for (String[] p : pairs) {
        double x = Double.parseDouble(p[0]);
        double fx = a * Math.pow(Math.E, b * x) + c;
        double y = Double.parseDouble(p[1]);
        double resid = y - fx;
        r.setEntry(row, 0, resid);
        row++;
    }
}

From source file:com.bc.jexp.impl.DefaultNamespace.java

private void registerDefaultSymbols() {
    registerSymbol(SymbolFactory.createConstant("PI", Math.PI));
    registerSymbol(SymbolFactory.createConstant("E", Math.E));
    registerSymbol(SymbolFactory.createConstant("NaN", Double.NaN));
}

From source file:math2605.gn_exp.java

private static void setJ(List<String[]> pairs, double a, double b, double c, RealMatrix r, RealMatrix J) {
    for (int i = 0; i < r.getRowDimension(); i++) {
        double x = Double.parseDouble(pairs.get(i)[0]);
        for (int j = 0; j < 3; j++) {
            double entry = -1;
            if (j == 0) {
                entry = -(Math.pow(Math.E, b * x));
            } else if (j == 1) {
                entry = -a * x * Math.pow(Math.E, b * x);
            }/*from  w ww  .j av a  2 s  .  c  om*/
            J.setEntry(i, j, entry);
        }
    }
}

From source file:de.huberlin.wbi.hiway.scheduler.WienerProcessModel.java

public double getEstimate(double timestamp, double alpha) {
    if (alpha == 0.5 && measurements.size() > 0) {
        return logarithmize ? Math.pow(Math.E, measurements.getLast().runtime)
                : Math.max(measurements.getLast().runtime, Double.MIN_NORMAL);
    }// www .  j  a  v  a  2  s  .co  m

    if (differences.size() < 2) {
        return 0d;
    }

    Runtime lastMeasurement = measurements.getLast();

    double variance = 0d;
    double avgDifference = sumOfDifferences / differences.size();
    for (double difference : differences) {
        variance += Math.pow(difference - avgDifference, 2d);
    }
    variance /= differences.size() - 1;

    variance *= timestamp - lastMeasurement.timestamp;

    double estimate = lastMeasurement.runtime;
    if (variance > 0d) {
        NormalDistribution nd = new NormalDistribution(lastMeasurement.runtime, Math.sqrt(variance));
        estimate = nd.inverseCumulativeProbability(alpha);
    }

    estimate = logarithmize ? Math.pow(Math.E, estimate) : Math.max(estimate, 0d);

    return estimate;
}

From source file:ubic.gemma.core.datastructure.matrix.ExpressionDataDoubleMatrixUtil.java

/**
 * Ensures that the given matrix is on a Log2 scale.
 * ! Does not update the QT !//from ww w  .j a  v  a2 s  . c  om
 *
 * @param quantitationType the quantitation type to be checked for the scale.
 * @param dmatrix the matrix to be transformed to a log2 scale if necessary.
 * @return a data matrix that is guaranteed to be on a log2 scale.
 */
public static ExpressionDataDoubleMatrix ensureLog2Scale(QuantitationType quantitationType,
        ExpressionDataDoubleMatrix dmatrix) {
    ScaleType scaleType = ExpressionDataDoubleMatrixUtil.findScale(quantitationType, dmatrix.getMatrix());

    if (scaleType.equals(ScaleType.LOG2)) {
        ExpressionDataDoubleMatrixUtil.log.info("Data is already on a log2 scale");
    } else if (scaleType.equals(ScaleType.LN)) {
        ExpressionDataDoubleMatrixUtil.log.info(" **** Converting from ln to log2 **** ");
        MatrixStats.convertToLog2(dmatrix.getMatrix(), Math.E);
    } else if (scaleType.equals(ScaleType.LOG10)) {
        ExpressionDataDoubleMatrixUtil.log.info(" **** Converting from log10 to log2 **** ");
        MatrixStats.convertToLog2(dmatrix.getMatrix(), 10);
    } else if (scaleType.equals(ScaleType.LINEAR)) {
        ExpressionDataDoubleMatrixUtil.log.info(" **** LOG TRANSFORMING **** ");
        MatrixStats.logTransform(dmatrix.getMatrix());
    } else if (scaleType.equals(ScaleType.COUNT)) {
        /*
         * Since we store log2cpm this shouldn't be reached any more. We don't do it in place.
         */
        ExpressionDataDoubleMatrixUtil.log.info(" **** Converting from count to log2 counts per million **** ");
        DoubleMatrix1D librarySize = MatrixStats.colSums(dmatrix.getMatrix());
        DoubleMatrix<CompositeSequence, BioMaterial> log2cpm = MatrixStats.convertToLog2Cpm(dmatrix.getMatrix(),
                librarySize);
        dmatrix = new ExpressionDataDoubleMatrix(dmatrix, log2cpm);
    } else {
        throw new UnknownLogScaleException("Can't figure out what scale the data are on");
    }
    return dmatrix;
}

From source file:edu.cornell.mannlib.vitro.webapp.search.documentBuilding.CalculateParameters.java

public float calculateBeta(String uri) {
    float beta = 0;
    int Conn = 0;
    Query query;//from  w  ww.j  av a 2s  .  co m
    QuerySolutionMap initialBinding = new QuerySolutionMap();
    QuerySolution soln = null;
    Resource uriResource = ResourceFactory.createResource(uri);
    initialBinding.add("uri", uriResource);
    dataset.getLock().enterCriticalSection(Lock.READ);
    QueryExecution qexec = null;
    try {
        query = QueryFactory.create(betaQuery, Syntax.syntaxARQ);
        qexec = QueryExecutionFactory.create(query, dataset, initialBinding);
        ResultSet results = qexec.execSelect();
        List<String> resultVars = results.getResultVars();
        if (resultVars != null && resultVars.size() != 0) {
            soln = results.next();
            Conn = Integer.parseInt(soln.getLiteral(resultVars.get(0)).getLexicalForm());
        }
    } catch (Throwable t) {
        if (!shutdown)
            log.error(t, t);
    } finally {
        if (qexec != null)
            qexec.close();
        dataset.getLock().leaveCriticalSection();
    }

    beta = (float) Conn;
    //beta *= 100;
    beta += 1;

    // sigmoid function to keep beta between 0 to 1;

    beta = (float) (1 / (1 + Math.pow(Math.E, (-beta))));

    if (beta > 1)
        log.info("Beta higher than 1 : " + beta);
    else if (beta <= 0)
        log.info("Beta lower < = 0 : " + beta);
    return beta;
}

From source file:com.binu.LogarithmicGraph.DrawGraphAsyncTask.java

@Override
protected Object doInBackground(Object[] params) {

    Bitmap bitmapBackground = Bitmap.createBitmap(mViewWidth, mViewHeight, Bitmap.Config.ARGB_8888);

    Canvas canvasBackground = new Canvas(bitmapBackground);
    Paint paint = new Paint();
    paint.setStrokeWidth(1f);/*  w  w w  .j a v a 2 s  .  c  o  m*/
    int starty = 0;
    int endy = mViewHeight;
    canvasBackground.drawColor(Color.BLACK);
    double ratio = Math.pow(Math.E, Math.log(MAX_FREQUENCY / MIN_FREQUENCY) / mViewWidth);
    mLogScaledX_values = new double[mViewWidth];
    for (int i = 0; i < mViewWidth; i++) {
        if (i == 0) {
            mLogScaledX_values[i] = 20;
        } else {
            mLogScaledX_values[i] = mLogScaledX_values[i - 1] * ratio;
        }
    }

    //Major lines
    for (int i = 0; i < MAJOR_GRIDLINE_POINTS.length; i++) {
        paint.setColor(ContextCompat.getColor(mContext, R.color.graph_grid_color));
        float xStart = (float) findNearestNumberPosition(mLogScaledX_values, MAJOR_GRIDLINE_POINTS[i]);
        float textSize = (getPixelDensity(mContext) * mLabelTextSize) / 480;
        paint.setTextSize(textSize);
        Log.i("Density", "" + getPixelDensity(mContext));
        if (Math.round(MAJOR_GRIDLINE_POINTS[i]) == 20) {
            if (isShowLabels())
                canvasBackground.drawText(getFormattedLabel(MAJOR_GRIDLINE_POINTS[i]),
                        xStart + (getPixelDensity(mContext) * 10) / 480,
                        endy - (getPixelDensity(mContext) * 10) / 480, paint);
        } else if (Math.round(MAJOR_GRIDLINE_POINTS[i]) == 20000) {
            if (isShowLabels())
                canvasBackground.drawText(getFormattedLabel(MAJOR_GRIDLINE_POINTS[i]),
                        xStart - (getPixelDensity(mContext) * 70) / 480,
                        endy - (getPixelDensity(mContext) * 10) / 480, paint);
        } else {
            if (isShowLabels())
                canvasBackground.drawText(getFormattedLabel(MAJOR_GRIDLINE_POINTS[i]),
                        xStart - (getPixelDensity(mContext) * 30) / 480,
                        endy - (getPixelDensity(mContext) * 10) / 480, paint);
            canvasBackground.drawLine(xStart, starty, xStart + 1, endy, paint);
        }
    }

    //Minor lines
    for (int i = 0; i < MINOR_GRIDLINE_POINTS.length; i++) {
        paint.setColor(ContextCompat.getColor(mContext, R.color.graph_grid_color_dull));
        float xStart = (float) findNearestNumberPosition(mLogScaledX_values, MINOR_GRIDLINE_POINTS[i]);
        canvasBackground.drawLine(xStart, starty, xStart + 1, endy, paint);

        if (isShowLabels()) {
            paint.setColor(ContextCompat.getColor(mContext, R.color.graph_grid_color));
            if (MINOR_GRIDLINE_POINTS[i] == 50 || MINOR_GRIDLINE_POINTS[i] == 500
                    || MINOR_GRIDLINE_POINTS[i] == 5000)
                canvasBackground.drawText(getFormattedLabel(MINOR_GRIDLINE_POINTS[i]),
                        xStart - (getPixelDensity(mContext) * 30) / 480,
                        endy - (getPixelDensity(mContext) * 10) / 480, paint);
        }
    }

    float[] Y_points = calculateGraphYAxis();
    float div = mViewHeight / (Y_points.length - 1);
    //Level lines
    for (int i = 0; i < Y_points.length - 1; i++) {
        paint.setColor(ContextCompat.getColor(mContext, R.color.graph_grid_color_dull));
        canvasBackground.drawLine(0, div * (i + 1), mViewWidth, (div * (i + 1)) + 1, paint);
    }

    //Level labels
    if (isShowLabels()) {
        for (int i = 0; i < Y_points.length; i++) {
            paint.setColor(ContextCompat.getColor(mContext, R.color.graph_grid_color));
            if (i == 0)
                canvasBackground.drawText("dB", 0, (div * i) + (getPixelDensity(mContext) * 50) / 480, paint);
            else if (i == Y_points.length - 1)
                canvasBackground.drawText("", 0, div * i, paint);
            else
                canvasBackground.drawText("" + Math.round(Y_points[i]), 0, div * i, paint);
        }
    }

    BitmapDrawable drawable = new BitmapDrawable(mContext.getResources(), bitmapBackground);
    mDrawableBackground = drawable;

    //Plotting the curve points

    Bitmap bitmapForeground = Bitmap.createBitmap(mViewWidth, mViewHeight, Bitmap.Config.ARGB_8888);
    Canvas canvasForeground = new Canvas(bitmapForeground);
    Paint plotPaint = new Paint();
    plotPaint.setStyle(Paint.Style.STROKE);
    plotPaint.setStrokeCap(Paint.Cap.ROUND);
    plotPaint.setStrokeWidth(PLOT_THICKNESS);
    plotPaint.setAntiAlias(true);
    plotPaint.setColor(ContextCompat.getColor(mContext, R.color.graph_plot_color));

    for (int i = 0; i < X_values.length; i++) {
        //            canvasForeground.drawCircle(i, mViewHeight - mPlotPoint[i], 2f, plotPaint);
        /*float startX, float startY, float stopX, float stopY,
        @NonNull Paint paint*/
        float startX = (float) getGetPixelValueForX(X_values[i]);
        float startY = mViewHeight
                - getPixelValueFromdB((int) GAIN_MAX, (int) GAIN_MIN, mViewHeight, Y_values[i]);
        float stopX;
        float stopY;
        if (i == X_values.length - 1) {
            stopX = (float) getGetPixelValueForX(X_values[i]);
            stopY = mViewHeight - getPixelValueFromdB((int) GAIN_MAX, (int) GAIN_MIN, mViewHeight, Y_values[i]);
        } else {
            stopX = (float) getGetPixelValueForX(X_values[i + 1]);
            stopY = mViewHeight
                    - getPixelValueFromdB((int) GAIN_MAX, (int) GAIN_MIN, mViewHeight, Y_values[i + 1]);
        }

        canvasForeground.drawLine(startX, startY, stopX, stopY, plotPaint);

    }

    BitmapDrawable drawableFore = new BitmapDrawable(mContext.getResources(), bitmapForeground);
    mDrawableForeground = drawableFore;
    return null;
}