Example usage for java.lang Double max

List of usage examples for java.lang Double max

Introduction

In this page you can find the example usage for java.lang Double max.

Prototype

public static double max(double a, double b) 

Source Link

Document

Returns the greater of two double values as if by calling Math#max(double,double) Math.max .

Usage

From source file:carfuzzy.Operations.java

public double trapezoidalMembership(int input, double[] boundries) {
    double a, b, c, d;
    a = boundries[0];/*from  ww w.  j a va  2s  .  co  m*/
    b = boundries[1];
    c = boundries[2];
    d = boundries[3];
    return Double.max(Double.min(Double.min((input - a) / (b - a), 1), (d - input) / (d - c)), 0);
}

From source file:carfuzzy.Operations.java

public double triangularMembership(double x, double[] boundries) {
    double a = boundries[0], b = boundries[1], c = boundries[2];
    if (x >= a && x <= c) { // acceptable range {
        double res;
        res = Double.max(Double.min(((x - a) / (b - a)), ((c - x) / (c - b))), 0);
        return res;
    } else {/*from   ww w  . j  av a 2  s. c o m*/
        return 0;
    }
}

From source file:fr.amap.lidar.amapvox.commons.LeafAngleDistribution.java

/**
 * Get the density probability from angle
 * @param angle must be in radians from in [0,2pi]
 * @return pdf function// w w  w.ja v  a  2  s.  c  o m
 */
public double getDensityProbability(double angle) {

    double density = 0;

    double tmp = Math.PI / 2.0;
    if (angle == tmp) {
        angle = tmp - 0.000001;
    }

    //angle = Math.PI/2.0 - angle; ??inversion des coefficients

    switch (type) {

    //warning : in wang paper there is an inversion between planophile, and erectophile
    case PLANOPHILE:
        density = (2.0 / Math.PI) * (1 + Math.cos(2 * angle));
        break;
    case ERECTOPHILE:
        density = (2.0 / Math.PI) * (1 - Math.cos(2 * angle));
        break;
    case PLAGIOPHILE:
        density = (2.0 / Math.PI) * (1 - Math.cos(4 * angle));
        break;
    case EXTREMOPHILE:
        density = (2.0 / Math.PI) * (1 + Math.cos(4 * angle));
        break;
    case SPHERIC:
        density = Math.sin(angle);
        break;
    case UNIFORM:
        density = 2.0 / Math.PI;
        break;
    case HORIZONTAL:
        break;
    case VERTICAL:
        break;
    case ELLIPTICAL:
        break;
    case ELLIPSOIDAL:

        double res;

        if (x == 1) {
            res = Math.sin(angle);
        } else {

            double eps, lambda = 0;

            if (x < 1) {
                eps = Math.sqrt(1 - (x * x));
                lambda = x + (Math.asin(eps) / eps);
            }
            if (x > 1) {
                eps = Math.sqrt(1 - Math.pow(x, -2));
                lambda = x + Math.log((1 + eps) / (1 + eps)) / (2 * eps * x);
            }

            res = (2 * Math.pow(x, 3) * Math.sin(angle)) / (lambda
                    * Math.pow((Math.pow(Math.cos(angle), 2)) + (x * x * Math.pow(Math.sin(angle), 2)), 2));
        }

        return res;

    case TWO_PARAMETER_BETA:

        //angle = Math.PI/2.0 - angle;
        double te = 2 * angle / Math.PI;
        te = Double.max(te, 1E-09);
        te = Double.min(te, 1 - 1E-09);

        density = distribution.density(te) / (Math.PI / 2.0);

        break;
    }

    return density;
}

From source file:Util.PacketGenerator.java

public static void GenerateGraph() {
    try {/*  w w w.  j a  v  a2s .  co  m*/
        for (int j = 6; j <= 6; j++) {
            File real = new File("D:\\Mestrado\\SketchMatrix\\trunk\\Simulations\\Analise\\Scenario1\\Topology"
                    + j + "\\Real.csv");
            for (int k = 1; k <= 4; k++) {
                File simu = new File(
                        "D:\\Mestrado\\SketchMatrix\\trunk\\Simulations\\Analise\\Scenario1\\Topology" + j
                                + "\\SimulacaoInstancia" + k + ".csv");

                FileInputStream simuFIS = new FileInputStream(simu);
                DataInputStream simuDIS = new DataInputStream(simuFIS);
                BufferedReader simuBR = new BufferedReader(new InputStreamReader(simuDIS));

                FileInputStream realFIS = new FileInputStream(real);
                DataInputStream realDIS = new DataInputStream(realFIS);
                BufferedReader realBR = new BufferedReader(new InputStreamReader(realDIS));

                String lineSimu = simuBR.readLine();
                String lineReal = realBR.readLine();

                XYSeries matrix = new XYSeries("Matriz", false, true);
                while (lineSimu != null && lineReal != null) {

                    lineSimu = lineSimu.replaceAll(",", ".");
                    String[] simuMatriz = lineSimu.split(";");
                    String[] realMatriz = lineReal.split(";");

                    for (int i = 0; i < simuMatriz.length; i++) {
                        try {
                            Integer valorReal = Integer.parseInt(realMatriz[i]);
                            Float valorSimu = Float.parseFloat(simuMatriz[i]);
                            matrix.add(valorReal.doubleValue() / 1000.0, valorSimu.doubleValue() / 1000.0);
                        } catch (NumberFormatException ex) {

                        }
                    }
                    lineSimu = simuBR.readLine();
                    lineReal = realBR.readLine();
                }

                simuFIS.close();
                simuDIS.close();
                simuBR.close();

                realFIS.close();
                realDIS.close();
                realBR.close();

                double maxPlot = Double.max(matrix.getMaxX(), matrix.getMaxY()) * 1.1;
                XYSeries middle = new XYSeries("Referncia");
                ;
                middle.add(0, 0);
                middle.add(maxPlot, maxPlot);
                XYSeries max = new XYSeries("Superior 20%");
                max.add(0, 0);
                max.add(maxPlot, maxPlot * 1.2);
                XYSeries min = new XYSeries("Inferior 20%");
                min.add(0, 0);
                min.add(maxPlot, maxPlot * 0.8);

                XYSeriesCollection dataset = new XYSeriesCollection();
                dataset.addSeries(middle);
                dataset.addSeries(matrix);
                dataset.addSeries(max);
                dataset.addSeries(min);
                JFreeChart chart;
                if (k == 4) {
                    chart = ChartFactory.createXYLineChart("Matriz de Trfego", "Real", "CMO-MT", dataset);
                } else {
                    chart = ChartFactory.createXYLineChart("Matriz de Trfego", "CMO-MT", "Zhao", dataset);
                }
                chart.setBackgroundPaint(Color.WHITE);
                chart.getPlot().setBackgroundPaint(Color.WHITE);
                chart.getTitle().setFont(new Font("Times New Roman", Font.BOLD, 13));

                chart.getLegend().setItemFont(new Font("Times New Roman", Font.TRUETYPE_FONT, 10));

                chart.getXYPlot().getDomainAxis().setLabelFont(new Font("Times New Roman", Font.BOLD, 10));
                chart.getXYPlot().getDomainAxis()
                        .setTickLabelFont(new Font("Times New Roman", Font.TRUETYPE_FONT, 1));
                chart.getXYPlot().getRangeAxis().setLabelFont(new Font("Times New Roman", Font.BOLD, 10));
                chart.getXYPlot().getRangeAxis()
                        .setTickLabelFont(new Font("Times New Roman", Font.TRUETYPE_FONT, 1));

                XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) chart.getXYPlot().getRenderer();

                renderer.setSeriesLinesVisible(1, false);
                renderer.setSeriesShapesVisible(1, true);

                renderer.setSeriesStroke(0, new BasicStroke(2.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER,
                        10.0f, new float[] { 0.1f }, 0.0f));
                renderer.setSeriesShape(1, new Ellipse2D.Float(-1.5f, -1.5f, 3f, 3f));
                renderer.setSeriesStroke(2, new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER,
                        10.0f, new float[] { 3.0f }, 0.0f));
                renderer.setSeriesStroke(3, new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER,
                        10.0f, new float[] { 3.0f }, 0.0f));

                renderer.setSeriesPaint(0, Color.BLACK);
                renderer.setSeriesPaint(1, Color.BLACK);
                renderer.setSeriesPaint(2, Color.BLACK);
                renderer.setSeriesPaint(3, Color.BLACK);

                int width = (int) (192 * 1.5f); /* Width of the image */

                int height = (int) (144 * 1.5f); /* Height of the image */

                File XYChart = new File(
                        "D:\\Mestrado\\SketchMatrix\\trunk\\Simulations\\Analise\\Scenario1\\Topology" + j
                                + "\\SimulacaoInstancia" + k + ".jpeg");
                ChartUtilities.saveChartAsJPEG(XYChart, chart, width, height);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:io.pravega.segmentstore.server.host.stat.AutoScaleProcessor.java

void report(String streamSegmentName, long targetRate, byte type, long startTime, double twoMinuteRate,
        double fiveMinuteRate, double tenMinuteRate, double twentyMinuteRate) {
    log.info("received traffic for {} with twoMinute rate = {} and targetRate = {}", streamSegmentName,
            twoMinuteRate, targetRate);/*  w w w  .  ja  v  a  2 s. co m*/
    if (initialized.get()) {
        // note: we are working on caller's thread. We should not do any blocking computation here and return as quickly as
        // possible.
        // So we will decide whether to scale or not and then unblock by asynchronously calling 'writeEvent'
        if (type != WireCommands.CreateSegment.NO_SCALE) {
            long currentTime = System.currentTimeMillis();
            if (currentTime - startTime > configuration.getCooldownDuration().toMillis()) {
                log.debug("cool down period elapsed for {}", streamSegmentName);

                // report to see if a scale operation needs to be performed.
                if ((twoMinuteRate > 5.0 * targetRate && currentTime - startTime > TWO_MINUTES)
                        || (fiveMinuteRate > 2.0 * targetRate && currentTime - startTime > FIVE_MINUTES)
                        || (tenMinuteRate > targetRate && currentTime - startTime > TEN_MINUTES)) {
                    int numOfSplits = (int) (Double.max(Double.max(twoMinuteRate, fiveMinuteRate),
                            tenMinuteRate) / targetRate);
                    log.debug("triggering scale up for {}", streamSegmentName);

                    triggerScaleUp(streamSegmentName, numOfSplits);
                }

                if (twoMinuteRate < targetRate && fiveMinuteRate < targetRate && tenMinuteRate < targetRate
                        && twentyMinuteRate < targetRate / 2.0 && currentTime - startTime > TWENTY_MINUTES) {
                    log.debug("triggering scale down for {}", streamSegmentName);

                    triggerScaleDown(streamSegmentName, false);
                }
            }
        }
    }
}

From source file:AnalysisModule.DataAnalysis.java

public void simulateBitmapAnalyse(List<Scenario> lstScenario) throws Exception {
    Double valor;//from   w ww . ja  va2s .  c  om

    bitmapAnalyse(lstScenario);
    for (Scenario scenario : lstScenario) {
        for (Topology topology : scenario.lstTopology) {
            File table = new File(topology.getSaidasDir() + "Resumo.csv");
            FileWriter fw = new FileWriter(table);
            PrintWriter pw = new PrintWriter(fw);
            pw.write(";Instancia 1;Instancia 2;Instancia 3;Instancia 4\n");
            pw.write("Tipo;BITMAP;BITMAP;BITMAP;COUNTER\n");
            pw.write("Size(KB);");
            for (Instance instance : topology.getLstInstance()) {
                pw.write(String.format("%6.2f", (instance.getBitMapSize() / 8.0) / 1024.0) + ";");
            }
            pw.write("\n");
            pw.write("Treshold;0,1;0,3;0,5;-\n");
            pw.write("RMSE;");
            for (Instance instance : topology.getLstInstance()) {
                double error = 0;
                int counter = 0;
                for (int i = 0; i < topology.getNumberOfSwitches(); i++) {
                    for (int j = i + 1; j < topology.getNumberOfSwitches(); j++) {
                        error += Math.pow(topology.getTrafficMatrix()[i][j] - instance.trafficMatrix[i][j], 2);
                        counter++;
                    }
                }
                error = Math.sqrt(error / counter);
                System.out.println("RMSE: " + error);
                pw.write(String.format("%10.8f", error) + ";");
            }
            pw.write("\n");
            pw.write("RMSRE;");
            for (Instance instance : topology.getLstInstance()) {
                double error = 0;
                int counter = 0;
                double T = 0;
                for (int i = 0; i < topology.getNumberOfSwitches(); i++) {
                    for (int j = i + 1; j < topology.getNumberOfSwitches(); j++) {
                        if (instance.trafficMatrix[i][j] > T) {
                            error += Math.pow((topology.getTrafficMatrix()[i][j] - instance.trafficMatrix[i][j])
                                    / instance.trafficMatrix[i][j], 2);
                            counter++;
                        }
                    }
                }
                error = Math.sqrt(error / counter);
                System.out.println("RMSRE: " + error);
                pw.write(String.format("%10.8f", error) + ";");
            }
            pw.write("\n");
            pw.write("Observers;");
            for (Instance instance : topology.getLstInstance()) {
                int nbSw = 0;
                for (Switch sw : instance.networkSwitch.values()) {
                    if (sw.isObserver) {
                        nbSw++;
                    }
                }
                pw.write(nbSw + ";");
            }
            pw.write("\n");
            pw.write("RelNbSw;");
            for (Instance instance : topology.getLstInstance()) {
                int nbSw = 0;
                for (Switch sw : instance.networkSwitch.values()) {
                    if (sw.isObserver) {
                        nbSw++;
                    }
                }
                pw.write(String.format("%4.2f", 100.0 * (float) nbSw / (float) topology.getNumberOfSwitches())
                        + ";");
            }
            pw.write("\n");
            pw.close();
            fw.close();
            for (Instance instance : topology.getLstInstance()) {
                HashMap<Double, List<HashMap<Integer, Integer>>> orderMap = new HashMap<>();
                File bmpFile = new File(
                        topology.getSaidasDir() + "SimulacaoInstancia" + instance.getId() + ".csv");
                if (!bmpFile.exists()) {
                    bmpFile.createNewFile();
                }
                FileWriter fout = new FileWriter(bmpFile);
                PrintWriter oos = new PrintWriter(fout);
                for (int i = 0; i < topology.getNumberOfSwitches(); i++) {
                    oos.print(";Router " + (i + 1));
                }
                for (int i = 0; i < topology.getNumberOfSwitches(); i++) {
                    oos.println();
                    oos.print("Router " + (i + 1));
                    for (int j = 0; j < topology.getNumberOfSwitches(); j++) {
                        int sourceId = i;
                        int destinationId = j;
                        if (sourceId > topology.getNumberOfSwitches()
                                || destinationId > topology.getNumberOfSwitches()) {
                            System.out.println("Erro no nmero de switches");
                            throw new Exception("Erro no nmero de switches");
                        } else {
                            doPrintElement(oos, i, j, instance.trafficMatrix[i][j]);

                            //                                if (i < j) {
                            //                                    if (orderMap.containsKey(instance.trafficMatrix[i][j])) {
                            //
                            //                                        HashMap<Integer, Integer> mapNodes = new HashMap<>();
                            //                                        mapNodes.put(i + 1, j + 1);
                            //                                        orderMap.get(instance.trafficMatrix[i][j]).add(mapNodes);
                            //                                    } else {
                            //                                        LinkedList listaHashMap = new LinkedList();
                            //                                        HashMap<Integer, Integer> mapNodes = new HashMap<>();
                            //                                        mapNodes.put(i + 1, j + 1);
                            //                                        listaHashMap.add(mapNodes);
                            //                                        orderMap.put(instance.trafficMatrix[i][j], listaHashMap);
                            //                                    }
                            //                                }
                        }
                    }
                }
                oos.close();
                fout.close();

                //                    Map<Double, List<HashMap<Integer, Integer>>> map = new TreeMap<>(orderMap);
                //                    System.out.println("Instancia" + instance.getId() + " After Sorting:");
                //                    Set set2 = map.entrySet();
                //                    Iterator iterator2 = set2.iterator();
                //                    while (iterator2.hasNext()) {
                //                        Map.Entry me2 = (Map.Entry) iterator2.next();
                //                        System.out.print(me2.getKey() + ": ");
                //                        System.out.println(me2.getValue());
                //                    }
                // Plot Graf
                XYSeries matrix = new XYSeries("Matrix", false, true);
                for (int i = 0; i < topology.getNumberOfSwitches(); i++) {
                    for (int j = i + 1; j < topology.getNumberOfSwitches(); j++) {
                        matrix.add((double) topology.getTrafficMatrix()[i][j], instance.trafficMatrix[i][j]);
                    }
                }
                double maxPlot = Double.max(matrix.getMaxX(), matrix.getMaxY()) * 1.1;
                XYSeries middle = new XYSeries("Real");
                middle.add(0, 0);
                middle.add(maxPlot, maxPlot);
                XYSeries max = new XYSeries("Max");
                max.add(0, 0);
                max.add(maxPlot, maxPlot * 1.2);
                XYSeries min = new XYSeries("Min");
                min.add(0, 0);
                min.add(maxPlot, maxPlot * 0.8);

                XYSeriesCollection dataset = new XYSeriesCollection();
                dataset.addSeries(middle);
                dataset.addSeries(matrix);
                dataset.addSeries(max);
                dataset.addSeries(min);
                JFreeChart chart = ChartFactory.createXYLineChart("Matriz de Trfego", "Real", "Estimado",
                        dataset);
                chart.setBackgroundPaint(new ChartColor(255, 255, 255));

                XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) chart.getXYPlot().getRenderer();
                renderer.setSeriesLinesVisible(1, false);
                renderer.setSeriesShapesVisible(1, true);

                int width = 640 * 2; /* Width of the image */

                int height = 480 * 2; /* Height of the image */

                File XYChart = new File(
                        topology.getSaidasDir() + "SimulacaoInstancia" + instance.getId() + ".jpeg");
                ChartUtilities.saveChartAsJPEG(XYChart, chart, width, height);
            }
        }
    }
}

From source file:sentinets.Prediction.java

public int performClassification() {
    for (int i = 0; i < unlabled.numInstances(); i++) {
        double clsLabel = 0;
        //Double[][] instanceDist = classDist.get(i);
        double[] dist = { -1., -1. };
        //int distIndex = 0;
        if (classifierType == MODELTYPE.SENTIMENT || classifierType == MODELTYPE.SENTIMENT_WORD
                || classifierType == MODELTYPE.CUSTOM) {
            //distIndex = 0;
        }//from   ww w  .  ja va  2s. co m
        //System.out.println(unlabled.instance(i).toString(4));
        try {
            dist = cls.distributionForInstance(unlabled.instance(i));
            //System.out.println("Distributions for "+filePrefix+" :\t"+dist[0]+","+dist[1]+","+dist[2]);
            //instanceDist[distIndex][0] = dist[0];
            //instanceDist[distIndex][1] = dist[1];
            clsLabel = cls.classifyInstance(unlabled.instance(i));
            //System.out.println("CLSLABEL: " + clsLabel);
        } catch (Exception e) {
            e.printStackTrace();
            System.err.println("Classification task failed.");
            return 1;
        }
        labled.instance(i).setClassValue(clsLabel);
        original.instance(i).setValue(clsIndex, clsLabel);
        if (showProbability) {
            original.instance(i).setValue(classProbIndex, Double.max(dist[0], dist[1]));
        }
        //classDist.set(i, instanceDist);
    }
    return 0;
}