Example usage for java.lang Double MAX_VALUE

List of usage examples for java.lang Double MAX_VALUE

Introduction

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

Prototype

double MAX_VALUE

To view the source code for java.lang Double MAX_VALUE.

Click Source Link

Document

A constant holding the largest positive finite value of type double , (2-2-52)·21023.

Usage

From source file:edu.scripps.fl.curves.CurveFit.java

public static void fit(Curve curve) {
    log.debug("Fitting 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]);
    // max, min and range
    double minY = Double.MAX_VALUE;
    double maxY = -Double.MAX_VALUE;
    double maxResp = y[y.length - 1];
    for (int i = 0; i < y.length; i++) {
        minY = Math.min(minY, y[i]);
        maxY = Math.max(maxY, y[i]);
    }//from w ww.j a  v a2s . co  m
    curve.setResponseMin(minY);
    curve.setResponseMax(maxY);
    curve.setResponseRange(maxY - minY);
    curve.setMaxResponse(maxResp);
    // fit
    boolean flags[] = null;
    Map maps[] = null;
    double fitValues[] = null;
    Object fitResults[] = HillFit.doHill(x, y, null, HillConstants.FIT_ITER_NO, HillConstants.P4_FIT);
    if (fitResults != null) {
        flags = (boolean[]) fitResults[0];
        fitValues = (double[]) fitResults[1];
        maps = (Map[]) fitResults[2];
    }
    if (fitValues != null) {
        curve.setYZero(fitValues[6]);
        curve.setLogEC50(fitValues[0]);
        curve.setYInflection(fitValues[1]);
        curve.setHillSlope(fitValues[2]);
        curve.setR2(fitValues[3]);

        double ec50 = 1000000D * Math.exp(Math.log(10D) * curve.getLogEC50());
        double testEC50 = Math.pow(10, curve.getLogEC50());
        Double ic50 = null;
        double logIC50 = BatchHill.iccalc(curve.getYZero(), curve.getYInflection(), curve.getLogEC50(),
                curve.getHillSlope(), 50D);
        if (logIC50 < 0.0D)
            ic50 = 1000000D * Math.exp(Math.log(10D) * logIC50);
        int dn = Math.max(1, x.length - 4);
        double df = dn;
        double p = HillStat.calcPValue(curve.getYZero(), curve.getYInflection(), curve.getLogEC50(),
                curve.getHillSlope(), x, y, flags);
        int mask = 0;
        for (int i = 0; i < x.length; i++)
            if (!flags[i])
                mask++;
        double ss = HillStat.calcHillDeviation(curve.getLogEC50(), curve.getYZero(), curve.getYInflection(),
                curve.getHillSlope(), flags, null, x, y);
        curve.setEC50(ec50);
        curve.setIC50(ic50);
        curve.setPHill(p);
        curve.setSYX(ss / df);
        for (int ii = 0; ii < flags.length; ii++) {
            if (flags[ii] == true) {
                curve.setMasked(true);
                break;
            }
        }
    } else {
        curve.setLogEC50(null);
        curve.setHillSlope(null);
        curve.setR2(null);
        curve.setYInflection(null);
        curve.setYZero(null);
        curve.setEC50(null);
        curve.setIC50(null);
        curve.setPHill(null);
        curve.setSYX(null);
        curve.setMasked(false);
        flags = new boolean[x.length];
    }
    // masks
    List<Boolean> masks = new ArrayList<Boolean>(flags.length);
    CollectionUtils.addAll(masks, (Boolean[]) ConvertUtils.convert(flags, Boolean[].class));
    curve.setMask(masks);
    // classify
    curveClassification(curve, y, x, flags);
    // rank
    double rank = -BatchHill.calcRank(curve.getCurveClass(), curve.getMaxResponse(), curve.getResponseRange());
    curve.setRank(rank);
}

From source file:endrov.nucAutoJH.FitGaussian.java

private static double[] fitGaussian2D_(EvPixels p, double sigmaInit, final double midxInit,
        final double midyInit) {
    //sigma00, sigma01, sigma11, mu_x, mu_y, c 

    p = p.getReadOnly(EvPixelsType.DOUBLE);
    final double[] arrPixels = p.getArrayDouble();
    final int w = p.getWidth();
    final int h = p.getHeight();

    int extent = (int) Math.round(3 * sigmaInit);
    extent = Math.max(extent, 2);

    final int sx = Math.max(0, (int) (midxInit - extent));
    final int ex = Math.min(w, (int) (midxInit + extent + 1)); //+1 to the right?
    final int sy = Math.max(0, (int) (midyInit - extent));
    final int ey = Math.min(h, (int) (midyInit + extent + 1));

    double minIntensity = Double.MAX_VALUE;
    double maxIntensity = Double.MIN_VALUE;
    for (int y = sy; y < ey; y++) {
        int base = y * w;
        double dy2 = y - midyInit;
        dy2 = dy2 * dy2;/*from   w  w w. ja va2 s  .c  om*/
        for (int x = sx; x < ex; x++) {
            double dx2 = x - midxInit;
            dx2 = dx2 * dx2;
            double t = arrPixels[base + x];
            //if(dx2+dy2<=extent*extent)
            {
                if (t < minIntensity)
                    minIntensity = t;
                if (t > maxIntensity)
                    maxIntensity = t;
            }
        }
    }

    //double[] weights=new double[]{1};
    double[] startPoint = new double[] { sigmaInit, 0, sigmaInit, midxInit, midyInit, minIntensity,
            maxIntensity - minIntensity };
    //double[] output=new double[startPoint.length];

    try {
        MultivariateRealFunction func = new MultivariateRealFunction() {
            //      opt.optimize(

            public double value(double[] arg) throws FunctionEvaluationException, IllegalArgumentException {
                double sigma00 = arg[0];
                double sigma01 = arg[1];
                double sigma11 = arg[2];
                double mu0 = arg[3];
                double mu1 = arg[4];
                double C = arg[5];
                double D = arg[6];

                double sumError = 0;

                Matrix2d sigma = new Matrix2d(sigma00, sigma01, sigma01, sigma11);
                Matrix2d sigmaInv = new Matrix2d();
                sigma.invert(sigmaInv);
                double sigmaDet = sigma.determinant();
                double front = 1.0 / (2 * Math.PI * Math.sqrt(sigmaDet));
                //System.out.println("front: "+front);
                //System.out.println("sigma inv "+sigmaInv);

                if (mu0 < sx || mu0 > ex)
                    sumError += 1000000;
                if (mu1 < sy || mu1 > ey)
                    sumError += 1000000;
                if (sigma00 < 1)
                    sumError += 1000000;
                //if(sigma01<0)               sumError+=1000000;
                if (sigma11 < 1)
                    sumError += 1000000;
                if (D <= 0)
                    sumError += 1000000;

                for (int y = sy; y < ey; y++) {
                    int base = y * w;
                    double dy2 = y - midyInit;
                    dy2 = dy2 * dy2;
                    for (int x = sx; x < ex; x++) {
                        double dx2 = x - midxInit;
                        dx2 = dx2 * dx2;
                        double thisReal = arrPixels[base + x];
                        //                  if(dx2+dy2<=extent*extent)
                        {
                            //               DoubleMatrix2D sigma=new DenseDoubleMatrix2D(new double[][]{{sigma00,sigma01},{sigma01,sigma11}});
                            //double sigmaDet=sigma00*sigma11-sigma01*sigma01;

                            double dx0 = x - mu0;
                            double dx1 = y - mu1;

                            //http://en.wikipedia.org/wiki/Multivariate_normal_distribution

                            Vector2d vX = new Vector2d(dx0, dx1);
                            Vector2d op = new Vector2d(vX);
                            sigmaInv.transform(op);
                            double upper = -0.5 * op.dot(vX);
                            double exp = Math.exp(upper);

                            //System.out.println("front "+front+" "+exp+" C "+C+" thisreal"+thisReal+" upper "+upper);

                            if (upper > -0.4)
                                exp = 1;
                            else
                                exp = Math.max(0, 1 + upper + 0.4);

                            /*
                            if(exp<0.7)
                               exp=0;
                            else
                               exp=1;
                            */

                            double thisExpected = D * front * exp + C;
                            double diff = thisExpected - thisReal;
                            sumError += diff * diff;

                        }
                    }
                }

                //System.out.println(sigma00+"\t"+sigma01+"\t"+sigma11+"\tC"+C+"\tmu "+mu0+","+mu1+"\terr "+sumError);
                return sumError;
                //            return new double[]{sumError};
            }

        };

        NelderMead opt = new NelderMead();
        //LevenbergMarquardtOptimizer opt=new LevenbergMarquardtOptimizer();
        opt.setMaxIterations(10000);
        RealPointValuePair pair = opt.optimize(func, GoalType.MINIMIZE, startPoint);

        int numit = opt.getIterations();
        System.out.println("#it " + numit);
        System.out.println("err " + func.value(pair.getPointRef()));
        return pair.getPointRef();

        //         for(int i=0;i<startPoint.length;i++)
        //         System.out.println("i: "+i+"  "+output[i]);
        //, output, weights, startPoint);
    }
    /*
    catch (MaxIterationsExceededException e)
       {
       System.out.println("max it reached");
               
       }*/
    catch (Exception e) {
        e.printStackTrace();
    }

    //Maybe this is a bad point?
    System.out.println("max it reached");
    return startPoint;
    //      return output;
}

From source file:endrov.typeLineageAutoNucJH.FitGaussian.java

private static double[] fitGaussian2D_(EvPixels p, double sigmaInit, final double midxInit,
        final double midyInit) {
    //sigma00, sigma01, sigma11, mu_x, mu_y, c 

    p = p.getReadOnly(EvPixelsType.DOUBLE);
    final double[] arrPixels = p.getArrayDouble();
    final int w = p.getWidth();
    final int h = p.getHeight();

    int extent = (int) Math.round(3 * sigmaInit);
    extent = Math.max(extent, 2);

    final int sx = Math.max(0, (int) (midxInit - extent));
    final int ex = Math.min(w, (int) (midxInit + extent + 1)); //+1 to the right?
    final int sy = Math.max(0, (int) (midyInit - extent));
    final int ey = Math.min(h, (int) (midyInit + extent + 1));

    double minIntensity = Double.MAX_VALUE;
    double maxIntensity = -Double.MAX_VALUE;
    for (int y = sy; y < ey; y++) {
        int base = y * w;
        double dy2 = y - midyInit;
        dy2 = dy2 * dy2;// w  ww . j a v  a2s .c o  m
        for (int x = sx; x < ex; x++) {
            double dx2 = x - midxInit;
            dx2 = dx2 * dx2;
            double t = arrPixels[base + x];
            //if(dx2+dy2<=extent*extent)
            {
                if (t < minIntensity)
                    minIntensity = t;
                if (t > maxIntensity)
                    maxIntensity = t;
            }
        }
    }

    //double[] weights=new double[]{1};
    double[] startPoint = new double[] { sigmaInit, 0, sigmaInit, midxInit, midyInit, minIntensity,
            maxIntensity - minIntensity };
    //double[] output=new double[startPoint.length];

    try {
        MultivariateRealFunction func = new MultivariateRealFunction() {
            //      opt.optimize(

            public double value(double[] arg) throws FunctionEvaluationException, IllegalArgumentException {
                double sigma00 = arg[0];
                double sigma01 = arg[1];
                double sigma11 = arg[2];
                double mu0 = arg[3];
                double mu1 = arg[4];
                double C = arg[5];
                double D = arg[6];

                double sumError = 0;

                Matrix2d sigma = new Matrix2d(sigma00, sigma01, sigma01, sigma11);
                Matrix2d sigmaInv = new Matrix2d();
                sigma.invert(sigmaInv);
                double sigmaDet = sigma.determinant();
                double front = 1.0 / (2 * Math.PI * Math.sqrt(sigmaDet));
                //System.out.println("front: "+front);
                //System.out.println("sigma inv "+sigmaInv);

                if (mu0 < sx || mu0 > ex)
                    sumError += 1000000;
                if (mu1 < sy || mu1 > ey)
                    sumError += 1000000;
                if (sigma00 < 1)
                    sumError += 1000000;
                //if(sigma01<0)               sumError+=1000000;
                if (sigma11 < 1)
                    sumError += 1000000;
                if (D <= 0)
                    sumError += 1000000;

                for (int y = sy; y < ey; y++) {
                    int base = y * w;
                    double dy2 = y - midyInit;
                    dy2 = dy2 * dy2;
                    for (int x = sx; x < ex; x++) {
                        double dx2 = x - midxInit;
                        dx2 = dx2 * dx2;
                        double thisReal = arrPixels[base + x];
                        //                  if(dx2+dy2<=extent*extent)
                        {
                            //               DoubleMatrix2D sigma=new DenseDoubleMatrix2D(new double[][]{{sigma00,sigma01},{sigma01,sigma11}});
                            //double sigmaDet=sigma00*sigma11-sigma01*sigma01;

                            double dx0 = x - mu0;
                            double dx1 = y - mu1;

                            //http://en.wikipedia.org/wiki/Multivariate_normal_distribution

                            Vector2d vX = new Vector2d(dx0, dx1);
                            Vector2d op = new Vector2d(vX);
                            sigmaInv.transform(op);
                            double upper = -0.5 * op.dot(vX);
                            double exp = Math.exp(upper);

                            //System.out.println("front "+front+" "+exp+" C "+C+" thisreal"+thisReal+" upper "+upper);

                            if (upper > -0.4)
                                exp = 1;
                            else
                                exp = Math.max(0, 1 + upper + 0.4);

                            /*
                            if(exp<0.7)
                               exp=0;
                            else
                               exp=1;
                            */

                            double thisExpected = D * front * exp + C;
                            double diff = thisExpected - thisReal;
                            sumError += diff * diff;

                        }
                    }
                }

                //System.out.println(sigma00+"\t"+sigma01+"\t"+sigma11+"\tC"+C+"\tmu "+mu0+","+mu1+"\terr "+sumError);
                return sumError;
                //            return new double[]{sumError};
            }

        };

        NelderMead opt = new NelderMead();
        //LevenbergMarquardtOptimizer opt=new LevenbergMarquardtOptimizer();
        opt.setMaxIterations(10000);
        RealPointValuePair pair = opt.optimize(func, GoalType.MINIMIZE, startPoint);

        int numit = opt.getIterations();
        System.out.println("#it " + numit);
        System.out.println("err " + func.value(pair.getPointRef()));
        return pair.getPointRef();

        //         for(int i=0;i<startPoint.length;i++)
        //         System.out.println("i: "+i+"  "+output[i]);
        //, output, weights, startPoint);
    }
    /*
    catch (MaxIterationsExceededException e)
       {
       System.out.println("max it reached");
               
       }*/
    catch (Exception e) {
        e.printStackTrace();
    }

    //Maybe this is a bad point?
    System.out.println("max it reached");
    return startPoint;
    //      return output;
}

From source file:GaussianHat.java

public GaussianHat(double mean, double sd) {
    this(mean, sd, 0, Double.MAX_VALUE);
}

From source file:de.termininistic.serein.examples.benchmarks.functions.unimodal.RosenbrockFunction.java

@Override
public double map(RealVector v) {
    double fx = Double.MAX_VALUE;
    double[] x = v.toArray();
    int n = x.length;
    fx = 0.0;//from www. j  a v  a 2  s  . c  om
    for (int i = 0; i < n - 1; i++) {
        double term1 = (x[i + 1] - x[i] * x[i]);
        fx += 100 * term1 * term1 + (x[i] - 1) * (x[i] - 1);
    }
    return fx;
}

From source file:comp.web.core.DataUtil.java

public List<Product> getProds(String cat, String prod, String from, String to) {
    logger.log(Level.FINER, "get prods with filter {0} {1} {2} {3}", new Object[] { cat, prod, from, to });

    if (StringUtils.isBlank(cat) && StringUtils.isBlank(prod) && StringUtils.isBlank(from)
            && StringUtils.isBlank(to)) {
        return Collections.emptyList();
    }//  w  w w . ja  v a  2  s. co m

    String cat1 = StringUtils.stripToEmpty(cat) + "%";
    String prod1 = StringUtils.stripToEmpty(prod) + "%";
    double from1 = StringUtils.isNumeric(from) ? Double.parseDouble(from) : Double.MIN_VALUE;
    double to1 = StringUtils.isNumeric(to) ? Double.parseDouble(to) : Double.MAX_VALUE;

    EntityManager em = createEM();
    //        EntityTransaction tx = em.getTransaction();
    //        tx.begin();

    List<Product> products = em.createNamedQuery("priceList", Product.class).setParameter("cat", cat1)
            .setParameter("prod", prod1).setParameter("from", from1).setParameter("to", to1).getResultList();

    //        tx.commit();
    em.close();
    logger.log(Level.FINER, "get prods result size {0}", products.size());
    return products;
}

From source file:ch.aonyx.broker.ib.api.util.ByteArrayRequestBuilder.java

@Override
public RequestBuilder append(final double d) {
    if (d != Double.MAX_VALUE) {
        bytes = Bytes.concat(bytes, String.valueOf(d).getBytes());
    }//  www  .  ja v  a  2s  .  co  m
    appendEol();
    return this;
}

From source file:audio.cords.old.RegressionDemo.java

private static XYDataset regress(XYSeriesCollection data) {
    // Determine bounds
    double xMin = Double.MAX_VALUE, xMax = 0;
    for (int i = 0; i < data.getSeriesCount(); i++) {
        XYSeries ser = data.getSeries(i);
        for (int j = 0; j < ser.getItemCount(); j++) {
            double x = ser.getX(j).doubleValue();
            if (x < xMin) {
                xMin = x;/*from www . ja  va  2 s  . c  o m*/
            }
            if (x > xMax) {
                xMax = x;
            }
        }
    }
    // Create 2-point series for each of the original series
    XYSeriesCollection coll = new XYSeriesCollection();
    for (int i = 0; i < data.getSeriesCount(); i++) {
        XYSeries ser = data.getSeries(i);
        int n = ser.getItemCount();
        double sx = 0, sy = 0, sxx = 0, sxy = 0, syy = 0;
        for (int j = 0; j < n; j++) {
            double x = ser.getX(j).doubleValue();
            double y = ser.getY(j).doubleValue();
            sx += x;
            sy += y;
            sxx += x * x;
            sxy += x * y;
            syy += y * y;
        }
        double b = (n * sxy - sx * sy) / (n * sxx - sx * sx);
        double a = sy / n - b * sx / n;
        XYSeries regr = new XYSeries(ser.getKey());
        regr.add(xMin, a + b * xMin);
        regr.add(xMax, a + b * xMax);
        coll.addSeries(regr);
    }
    return coll;
}

From source file:com.netflix.config.DynamicFileConfigurationTest.java

static void modifyConfigFile() {
    new Thread() {
        public void run() {
            try {
                BufferedWriter writer = new BufferedWriter(
                        new OutputStreamWriter(new FileOutputStream(configFile), "UTF-8"));
                writer.write("abc=-2"); // this property should fail validation but should not affect update of other properties
                writer.newLine();/*from  w ww .j a  v a 2 s .  com*/
                writer.write("dprops1=" + String.valueOf(Long.MIN_VALUE));
                writer.newLine();
                writer.write("dprops2=" + String.valueOf(Double.MAX_VALUE));
                writer.newLine();
                writer.close();
                System.err.println(configFile.getPath() + " modified");
            } catch (Exception e) {
                e.printStackTrace();
                fail("Unexpected exception");
            }
        }
    }.start();
}

From source file:edu.iu.kmeans.regroupallgather.PointLoadTask.java

/**
 * Load data points from a file.// w  w  w.j  av a2s.  c o m
 * 
 * @param file
 * @param conf
 * @return
 * @throws IOException
 */
public static double[] loadPoints(String file, int pointsPerFile, int cenVecSize, Configuration conf)
        throws Exception {
    double[] points = new double[pointsPerFile * cenVecSize];
    Path pointFilePath = new Path(file);
    FileSystem fs = pointFilePath.getFileSystem(conf);
    FSDataInputStream in = fs.open(pointFilePath);
    try {
        for (int i = 0; i < points.length;) {
            points[i++] = Double.MAX_VALUE;
            for (int j = 1; j < cenVecSize; j++) {
                points[i++] = in.readDouble();
            }
        }
    } finally {
        in.close();
    }
    return points;
}