Example usage for java.lang Double NaN

List of usage examples for java.lang Double NaN

Introduction

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

Prototype

double NaN

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

Click Source Link

Document

A constant holding a Not-a-Number (NaN) value of type double .

Usage

From source file:com.idylwood.utils.MathUtils.java

public final static double max(double... values) {
    if (values.length == 0)
        return Double.NaN;
    double ret = values[0];
    for (int i = 1; i < values.length; i++)
        if (values[i] > ret)
            ret = values[i];//from  w w  w .  jav  a2  s  .  co  m
    return ret;
}

From source file:com.google.android.glass.sample.compass.model.Landmarks.java

/**
 * Converts a JSON object that represents a place into a {@link Place} object.
 *//*from  w w w  .j a  va2 s.c om*/
private Place jsonObjectToPlace(JSONObject object) {
    String name = object.optString("name");
    double latitude = object.optDouble("latitude", Double.NaN);
    double longitude = object.optDouble("longitude", Double.NaN);

    if (!name.isEmpty() && !Double.isNaN(latitude) && !Double.isNaN(longitude)) {
        return new Place(latitude, longitude, name);
    } else {
        return null;
    }
}

From source file:com.hichinaschool.flashcards.libanki.Card.java

public Card(Collection col, long id) {
    mCol = col;/*from   w w w .j  a  v a  2s  .  c o  m*/
    mTimerStarted = Double.NaN;
    mQA = null;
    mNote = null;
    if (id != 0) {
        mId = id;
        load();
    } else {
        // to flush, set nid, ord, and due
        mId = Utils.timestampID(mCol.getDb(), "cards");
        mDid = 1;
        mCrt = Utils.intNow();
        mType = 0;
        mQueue = 0;
        mIvl = 0;
        mFactor = 0;
        mReps = 0;
        mLapses = 0;
        mLeft = 0;
        mODue = 0;
        mFlags = 0;
        mData = "";
    }
}

From source file:egat.replicatordynamics.SymmetricConstrainedAmoebaSearch.java

public Strategy run(SymmetricGame game, Strategy initialStrategy, Set<Action> restrictedActions,
        boolean randomize) {

    Action[] actions = game.getActions().toArray(new Action[0]);

    boolean[] mask = new boolean[actions.length];

    int restrictedCount = 0;

    for (int i = 0; i < actions.length; i++) {

        mask[i] = restrictedActions.contains(actions[i]);

        if (mask[i]) {

            restrictedCount++;//w  ww  .  java  2s  .c  o m

        }

    }

    int[] restricted = new int[restrictedCount];

    for (int i = 0, restrictedIndex = 0; i < actions.length; i++) {

        if (mask[i]) {

            restricted[restrictedIndex++] = i;

        }
    }

    Player[] players = game.players().toArray(new Player[0]);

    PayoffMatrix pm = createPayoffMatrix(game, players, actions);

    // Normalize to a uniform distribution
    double[] distribution = new double[actions.length];

    double[] bestDist = new double[actions.length];

    if (initialStrategy == null) {
        double sum = 0.0;
        for (int i = 0; i < bestDist.length; i++) {
            if (mask[i]) {
                bestDist[i] = Math.random();
                sum += bestDist[i];
            }
        }

        for (int i = 0; i < bestDist.length; i++) {
            if (mask[i]) {
                bestDist[i] /= sum;
            }
        }

    } else {
        for (int i = 0; i < actions.length; i++) {
            if (mask[i]) {
                bestDist[i] = initialStrategy.getProbability(actions[i]).doubleValue();
            }
        }
    }

    double bestRegret = pm.regret(bestDist);

    // Initialize current strategy
    Strategy currentStrategy = buildStrategy(actions, bestDist, restricted);

    fireUpdatedStrategy(currentStrategy, 0, Double.NaN);

    int SIMPLICES = restricted.length;
    double[][] X = new double[SIMPLICES][SIMPLICES - 1];
    double[] centroid = new double[SIMPLICES - 1];
    double[] reflect = new double[SIMPLICES - 1];
    double[] expand = new double[SIMPLICES - 1];
    double[] contract = new double[SIMPLICES - 1];
    double[] V = new double[SIMPLICES];
    double[] cur = distribution.clone();

    if (!randomize) {
        for (int r = 0, n = SIMPLICES - 1; r < n; r++) {
            X[0][r] = 0.0;
        }

        V[0] = calculateObjective(pm, X[0], restricted, distribution);

        for (int s = 1; s < SIMPLICES; s++) {
            System.arraycopy(X[0], 0, X[s], 0, SIMPLICES - 1);

            X[s][s - 1] = 1.0;

            V[s] = calculateObjective(pm, X[s], restricted, distribution);
        }
    } else {

        for (int s = 0; s < SIMPLICES; s++) {
            generateSimplex(X[s]);
            V[s] = calculateObjective(pm, X[s], restricted, distribution);
        }
    }

    int highest = -1;
    int lowest = -1;
    int second = -1;

    for (int s = 0; s < SIMPLICES; s++) {
        if (lowest < 0 || V[s] < V[lowest]) {
            lowest = s;
        }

        if (second < 0 || V[s] > V[second]) {

            if (highest < 0 || V[s] > V[highest]) {
                second = highest;
                highest = s;
            } else {
                second = s;
            }

        }
    }

    double curRegret = Double.POSITIVE_INFINITY;

    loop: for (int iteration = 1; SIMPLICES > 1; iteration++) {

        generateCentroid(centroid, X, SIMPLICES, highest);

        generateTowards(reflect, centroid, X[highest], 1.0);

        double reflectV = calculateObjective(pm, reflect, restricted, distribution);

        // Reflect
        if (V[lowest] <= reflectV && reflectV < V[second]) {
            replaceHighest(reflect, reflectV, X, V, highest);

            // Expand
        } else if (reflectV < V[lowest]) {

            generateTowards(expand, centroid, X[highest], 2.0);

            double expandV = calculateObjective(pm, expand, restricted, distribution);

            if (expandV < reflectV) {
                replaceHighest(expand, expandV, X, V, highest);
            } else {
                replaceHighest(reflect, reflectV, X, V, highest);
            }

            // Contract
        } else {

            generateAway(contract, X[highest], centroid, 0.5);

            double contractV = calculateObjective(pm, contract, restricted, distribution);

            if (contractV < V[highest]) {
                replaceHighest(contract, contractV, X, V, highest);

                // Reduction
            } else {
                for (int s = 0; s < SIMPLICES; s++) {
                    if (s != lowest) {

                        generateAway(X[s], X[lowest], X[s], 0.5);

                        V[s] = calculateObjective(pm, X[s], restricted, distribution);
                    }
                }
            }
        }

        highest = -1;
        lowest = -1;
        second = -1;

        for (int s = 0; s < SIMPLICES; s++) {
            if (lowest < 0 || V[s] < V[lowest]) {
                lowest = s;
            }

            if (second < 0 || V[s] > V[second]) {

                if (highest < 0 || V[s] > V[highest]) {
                    second = highest;
                    highest = s;
                } else {
                    second = s;
                }

            }
        }

        Arrays.fill(cur, 0.0);
        double sum = 0.0;
        for (int r = 0; r < restricted.length - 1; r++) {
            cur[restricted[r]] = Math.max(0, X[lowest][r]);
            sum += cur[restricted[r]];
        }

        cur[restricted[restricted.length - 1]] = Math.max(0.0, 1 - sum);
        sum += cur[restricted[restricted.length - 1]];

        for (int r = 0; r < restricted.length; r++) {
            cur[restricted[r]] /= sum;
        }

        curRegret = pm.regret(cur);

        if (curRegret < bestRegret) {
            System.arraycopy(cur, 0, bestDist, 0, cur.length);
            bestRegret = curRegret;
        }

        // Build the new strategy
        currentStrategy = buildStrategy(actions, bestDist, restricted);

        fireUpdatedStrategy(currentStrategy, iteration, bestRegret);

        // Calculate the norm
        double norm = V[highest] - V[lowest];

        // Check termination condition
        if (terminate(norm, iteration))
            break;
    }

    return currentStrategy;
}

From source file:com.itemanalysis.psychometrics.polycor.Covariance.java

public double correlationStandardError() {
    if (N < 3)
        return Double.NaN;
    double r = correlation(true);
    double r2 = Math.pow(r, 2);
    double se = Math.sqrt((1 - r2) / (N - 2.0));
    return se;/*from  w  w  w  .  ja va 2s . co  m*/
}

From source file:org.ow2.proactive_grid_cloud_portal.rm.RMRestTest.java

private RrdDb createRrdDb() throws IOException {
    final long start = (System.currentTimeMillis() - 10000) / 1000;
    final long end = System.currentTimeMillis() / 1000;

    RrdDef rrdDef = new RrdDef("testDB", start - 1, 300);
    for (String dataSource : RMRest.dataSources) {
        rrdDef.addDatasource(dataSource, DsType.GAUGE, 600, 0, Double.NaN);
    }/*from w w w .j  a  v a 2s . c  o m*/
    rrdDef.addArchive(ConsolFun.AVERAGE, 0.5, 1, 150);
    RrdDb rrdDb = new RrdDb(rrdDef, org.rrd4j.core.RrdBackendFactory.getFactory("MEMORY"));
    Sample sample = rrdDb.createSample();

    long time = start;
    while (time <= end + 172800L) {
        sample.setTime(time);
        for (String dataSource : RMRest.dataSources) {
            sample.setValue(dataSource, 1.042);
        }
        sample.update();
        time += new Random().nextDouble() * 300 + 1;
    }
    return rrdDb;
}

From source file:edu.cornell.med.icb.goby.stats.ChiSquareTestCalculator.java

@Override
public DifferentialExpressionInfo evaluate(
        final DifferentialExpressionCalculator differentialExpressionCalculator,
        final NormalizationMethod method, final DifferentialExpressionResults results,
        final DifferentialExpressionInfo info, final String... group) {

    // expected counts in each group, assuming the counts for the DE are spread  among the groups according to sample
    // global count proportions
    final double[] expectedCounts = new double[group.length];

    //  counts observed in each group:
    final long[] observedCounts = new long[group.length];
    final double[] groupProportions = new double[group.length];

    final int chiSquarePValuesStatIndex = defineStatisticId(results, "chi-square-test", method, group);

    int i = 0;//from  w  w w  .  ja  v a 2  s.  com

    double pValue = 1;
    // estimate the sumOfCountsForDE of counts over all the samples included in any group compared.
    final long sumOfCountsForDE = 0;
    int numSamples = 0;
    double sumObservedCounts = 0;

    for (final String oneGroupId : group) {
        final ObjectArraySet<String> samplesForGroup = differentialExpressionCalculator.getSamples(oneGroupId);

        for (final String sample : samplesForGroup) {
            final long observedCount = differentialExpressionCalculator.getOverlapCount(sample,
                    info.getElementId());
            final double sampleProportion = differentialExpressionCalculator.getSampleProportion(sample);
            observedCounts[i] += observedCount;
            groupProportions[i] += sampleProportion;
            sumObservedCounts += observedCount;
            numSamples++;
        }
        if (observedCounts[i] == 0) {
            // Chi Square is not defined if any observed counts are zero.
            info.statistics.size(results.getNumberOfStatistics());
            info.statistics.set(chiSquarePValuesStatIndex, Double.NaN);
            return info;
        }
        ++i;
    }

    i = 0;
    final double nGroups = group.length;
    for (int groupIndex = 0; groupIndex < nGroups; groupIndex++) {
        expectedCounts[groupIndex] += groupProportions[groupIndex] * sumObservedCounts;
    }

    final ChiSquareTest chisquare = new ChiSquareTestImpl();

    try {
        final double pValueRaw = chisquare.chiSquareTest(expectedCounts, observedCounts);
        // math commons can return negative p-values?
        pValue = Math.abs(pValueRaw);
    } catch (MaxIterationsExceededException e) {
        LOG.error("elementId:" + info.getElementId());
        LOG.error("expected:" + DoubleArrayList.wrap(expectedCounts).toString());
        LOG.error("observed:" + LongArrayList.wrap(observedCounts).toString());
        LOG.error(e);
        pValue = 1;
    } catch (MathException e) {
        e.printStackTrace();
    }

    info.statistics.size(results.getNumberOfStatistics());
    info.statistics.set(chiSquarePValuesStatIndex, pValue);
    return info;
}

From source file:eqtlmappingpipeline.util.ModuleEqtWestraReplication.java

/**
 * @param args the command line arguments
 */// w w  w. j  av  a2 s  .  c  om
public static void main(String[] args) throws IOException, LdCalculatorException {

    System.out.println(HEADER);
    System.out.println();
    System.out.flush(); //flush to make sure header is before errors
    try {
        Thread.sleep(25); //Allows flush to complete
    } catch (InterruptedException ex) {
    }

    CommandLineParser parser = new PosixParser();
    final CommandLine commandLine;
    try {
        commandLine = parser.parse(OPTIONS, args, true);
    } catch (ParseException ex) {
        System.err.println("Invalid command line arguments: " + ex.getMessage());
        System.err.println();
        new HelpFormatter().printHelp(" ", OPTIONS);
        System.exit(1);
        return;
    }

    final String[] genotypesBasePaths = commandLine.getOptionValues("g");
    final RandomAccessGenotypeDataReaderFormats genotypeDataType;
    final String replicationQtlFilePath = commandLine.getOptionValue("e");
    final String interactionQtlFilePath = commandLine.getOptionValue("i");
    final String outputFilePath = commandLine.getOptionValue("o");
    final double ldCutoff = Double.parseDouble(commandLine.getOptionValue("ld"));
    final int window = Integer.parseInt(commandLine.getOptionValue("w"));

    System.out.println("Genotype: " + Arrays.toString(genotypesBasePaths));
    System.out.println("Interaction file: " + interactionQtlFilePath);
    System.out.println("Replication file: " + replicationQtlFilePath);
    System.out.println("Output: " + outputFilePath);
    System.out.println("LD: " + ldCutoff);
    System.out.println("Window: " + window);

    try {
        if (commandLine.hasOption("G")) {
            genotypeDataType = RandomAccessGenotypeDataReaderFormats
                    .valueOf(commandLine.getOptionValue("G").toUpperCase());
        } else {
            if (genotypesBasePaths[0].endsWith(".vcf")) {
                System.err.println(
                        "Only vcf.gz is supported. Please see manual on how to do create a vcf.gz file.");
                System.exit(1);
                return;
            }
            try {
                genotypeDataType = RandomAccessGenotypeDataReaderFormats
                        .matchFormatToPath(genotypesBasePaths[0]);
            } catch (GenotypeDataException e) {
                System.err
                        .println("Unable to determine input 1 type based on specified path. Please specify -G");
                System.exit(1);
                return;
            }
        }
    } catch (IllegalArgumentException e) {
        System.err.println("Error parsing --genotypesFormat \"" + commandLine.getOptionValue("G")
                + "\" is not a valid input data format");
        System.exit(1);
        return;
    }

    final RandomAccessGenotypeData genotypeData;

    try {
        genotypeData = genotypeDataType.createFilteredGenotypeData(genotypesBasePaths, 100, null, null, null,
                0.8);
    } catch (TabixFileNotFoundException e) {
        LOGGER.fatal("Tabix file not found for input data at: " + e.getPath() + "\n"
                + "Please see README on how to create a tabix file");
        System.exit(1);
        return;
    } catch (IOException e) {
        LOGGER.fatal("Error reading input data: " + e.getMessage(), e);
        System.exit(1);
        return;
    } catch (IncompatibleMultiPartGenotypeDataException e) {
        LOGGER.fatal("Error combining the impute genotype data files: " + e.getMessage(), e);
        System.exit(1);
        return;
    } catch (GenotypeDataException e) {
        LOGGER.fatal("Error reading input data: " + e.getMessage(), e);
        System.exit(1);
        return;
    }

    ChrPosTreeMap<ArrayList<ReplicationQtl>> replicationQtls = new ChrPosTreeMap<>();

    CSVReader replicationQtlReader = new CSVReader(new FileReader(replicationQtlFilePath), '\t');
    String[] replicationHeader = replicationQtlReader.readNext();
    String[] replicationLine;
    while ((replicationLine = replicationQtlReader.readNext()) != null) {

        try {

            GeneticVariant variant = genotypeData.getSnpVariantByPos(replicationLine[REPLICATION_SNP_CHR_COL],
                    Integer.parseInt(replicationLine[REPLICATION_SNP_POS_COL]));
            if (variant == null) {
                continue;
            }

            Alleles variantAlleles = variant.getVariantAlleles();
            String[] replicationAllelesString = StringUtils.split(replicationLine[REPLICATION_ALLELES_COL],
                    '/');

            Alleles replicationAlleles = Alleles.createBasedOnString(replicationAllelesString[0],
                    replicationAllelesString[1]);
            Allele assessedAlleleReplication = Allele.create(replicationLine[REPLICATION_ALLELE_ASSESSED_COL]);

            boolean isAmbigous = replicationAlleles.isAtOrGcSnp();

            if (!variantAlleles.equals(replicationAlleles)) {
                if (variantAlleles.equals(replicationAlleles.getComplement())) {
                    assessedAlleleReplication = assessedAlleleReplication.getComplement();
                } else {
                    continue;
                }
            }

            ReplicationQtl replicationQtl = new ReplicationQtl(replicationLine[REPLICATION_SNP_CHR_COL],
                    Integer.parseInt(replicationLine[REPLICATION_SNP_POS_COL]),
                    replicationLine[REPLICATION_GENE_COL],
                    Double.parseDouble(replicationLine[REPLICATION_BETA_COL]),
                    assessedAlleleReplication.getAlleleAsString(), replicationLine, isAmbigous);
            ArrayList<ReplicationQtl> posReplicationQtls = replicationQtls.get(replicationQtl.getChr(),
                    replicationQtl.getPos());
            if (posReplicationQtls == null) {
                posReplicationQtls = new ArrayList<>();
                replicationQtls.put(replicationQtl.getChr(), replicationQtl.getPos(), posReplicationQtls);
            }
            posReplicationQtls.add(replicationQtl);

        } catch (Exception e) {
            System.out.println(Arrays.toString(replicationLine));
            throw e;
        }
    }

    int interactionSnpNotInGenotypeData = 0;
    int noReplicationQtlsInWindow = 0;
    int noReplicationQtlsInLd = 0;
    int multipleReplicationQtlsInLd = 0;
    int replicationTopSnpNotInGenotypeData = 0;

    final CSVWriter outputWriter = new CSVWriter(new FileWriter(new File(outputFilePath)), '\t', '\0');
    final String[] outputLine = new String[15 + EXTRA_COL_FROM_REPLICATION.length];
    int c = 0;
    outputLine[c++] = "Chr";
    outputLine[c++] = "Pos";
    outputLine[c++] = "SNP";
    outputLine[c++] = "Gene";
    outputLine[c++] = "Module";
    outputLine[c++] = "DiscoveryZ";
    outputLine[c++] = "ReplicationZ";
    outputLine[c++] = "DiscoveryZCorrected";
    outputLine[c++] = "ReplicationZCorrected";
    outputLine[c++] = "DiscoveryAlleleAssessed";
    outputLine[c++] = "ReplicationAlleleAssessed";
    outputLine[c++] = "bestLd";
    outputLine[c++] = "bestLd_dist";
    outputLine[c++] = "nextLd";
    outputLine[c++] = "replicationAmbigous";
    for (int i = 0; i < EXTRA_COL_FROM_REPLICATION.length; ++i) {
        outputLine[c++] = replicationHeader[EXTRA_COL_FROM_REPLICATION[i]];
    }
    outputWriter.writeNext(outputLine);

    HashSet<String> notFound = new HashSet<>();

    CSVReader interactionQtlReader = new CSVReader(new FileReader(interactionQtlFilePath), '\t');
    interactionQtlReader.readNext();//skip header
    String[] interactionQtlLine;
    while ((interactionQtlLine = interactionQtlReader.readNext()) != null) {

        String snp = interactionQtlLine[1];
        String chr = interactionQtlLine[2];
        int pos = Integer.parseInt(interactionQtlLine[3]);
        String gene = interactionQtlLine[4];
        String alleleAssessed = interactionQtlLine[9];
        String module = interactionQtlLine[12];
        double discoveryZ = Double.parseDouble(interactionQtlLine[10]);

        GeneticVariant interactionQtlVariant = genotypeData.getSnpVariantByPos(chr, pos);

        if (interactionQtlVariant == null) {
            System.err.println("Interaction QTL SNP not found in genotype data: " + chr + ":" + pos);
            ++interactionSnpNotInGenotypeData;
            continue;
        }

        ReplicationQtl bestMatch = null;
        double bestMatchR2 = Double.NaN;
        Ld bestMatchLd = null;
        double nextBestR2 = Double.NaN;

        ArrayList<ReplicationQtl> sameSnpQtls = replicationQtls.get(chr, pos);

        if (sameSnpQtls != null) {
            for (ReplicationQtl sameSnpQtl : sameSnpQtls) {
                if (sameSnpQtl.getGene().equals(gene)) {
                    bestMatch = sameSnpQtl;
                    bestMatchR2 = 1;
                }
            }
        }

        NavigableMap<Integer, ArrayList<ReplicationQtl>> potentionalReplicationQtls = replicationQtls
                .getChrRange(chr, pos - window, true, pos + window, true);

        for (ArrayList<ReplicationQtl> potentialReplicationQtls : potentionalReplicationQtls.values()) {

            for (ReplicationQtl potentialReplicationQtl : potentialReplicationQtls) {

                if (!potentialReplicationQtl.getGene().equals(gene)) {
                    continue;
                }

                GeneticVariant potentialReplicationQtlVariant = genotypeData
                        .getSnpVariantByPos(potentialReplicationQtl.getChr(), potentialReplicationQtl.getPos());

                if (potentialReplicationQtlVariant == null) {
                    notFound.add(potentialReplicationQtl.getChr() + ":" + potentialReplicationQtl.getPos());
                    ++replicationTopSnpNotInGenotypeData;
                    continue;
                }

                Ld ld = interactionQtlVariant.calculateLd(potentialReplicationQtlVariant);
                double r2 = ld.getR2();

                if (r2 > 1) {
                    r2 = 1;
                }

                if (bestMatch == null) {
                    bestMatch = potentialReplicationQtl;
                    bestMatchR2 = r2;
                    bestMatchLd = ld;
                } else if (r2 > bestMatchR2) {
                    bestMatch = potentialReplicationQtl;
                    nextBestR2 = bestMatchR2;
                    bestMatchR2 = r2;
                    bestMatchLd = ld;
                }

            }
        }

        double replicationZ = Double.NaN;
        double replicationZCorrected = Double.NaN;
        double discoveryZCorrected = Double.NaN;

        String replicationAlleleAssessed = null;

        if (bestMatch != null) {
            replicationZ = bestMatch.getBeta();
            replicationAlleleAssessed = bestMatch.getAssessedAllele();

            if (pos != bestMatch.getPos()) {

                String commonHap = null;
                double commonHapFreq = -1;
                for (Map.Entry<String, Double> hapFreq : bestMatchLd.getHaplotypesFreq().entrySet()) {

                    double f = hapFreq.getValue();

                    if (f > commonHapFreq) {
                        commonHapFreq = f;
                        commonHap = hapFreq.getKey();
                    }

                }

                String[] commonHapAlleles = StringUtils.split(commonHap, '/');

                discoveryZCorrected = commonHapAlleles[0].equals(alleleAssessed) ? discoveryZ : discoveryZ * -1;
                replicationZCorrected = commonHapAlleles[1].equals(replicationAlleleAssessed) ? replicationZ
                        : replicationZ * -1;

            } else {

                discoveryZCorrected = discoveryZ;
                replicationZCorrected = alleleAssessed.equals(replicationAlleleAssessed) ? replicationZ
                        : replicationZ * -1;
                //replicationZCorrected = alleleAssessed.equals(replicationAlleleAssessed) || alleleAssessed.equals(String.valueOf(Utils.getComplementNucleotide(replicationAlleleAssessed.charAt(0)))) ? replicationZ : replicationZ * -1;

            }

        }

        c = 0;
        outputLine[c++] = chr;
        outputLine[c++] = String.valueOf(pos);
        outputLine[c++] = snp;
        outputLine[c++] = gene;
        outputLine[c++] = module;
        outputLine[c++] = String.valueOf(discoveryZ);
        outputLine[c++] = bestMatch == null ? "NA" : String.valueOf(replicationZ);
        outputLine[c++] = bestMatch == null ? "NA" : String.valueOf(discoveryZCorrected);
        outputLine[c++] = bestMatch == null ? "NA" : String.valueOf(replicationZCorrected);
        outputLine[c++] = alleleAssessed;
        outputLine[c++] = bestMatch == null ? "NA" : String.valueOf(bestMatch.getAssessedAllele());
        outputLine[c++] = String.valueOf(bestMatchR2);
        outputLine[c++] = bestMatch == null ? "NA" : String.valueOf(Math.abs(pos - bestMatch.getPos()));
        outputLine[c++] = String.valueOf(nextBestR2);
        outputLine[c++] = bestMatch == null ? "NA" : String.valueOf(bestMatch.isIsAmbigous());

        if (bestMatch == null) {
            for (int i = 0; i < EXTRA_COL_FROM_REPLICATION.length; ++i) {
                outputLine[c++] = "NA";
            }
        } else {
            for (int i = 0; i < EXTRA_COL_FROM_REPLICATION.length; ++i) {
                outputLine[c++] = bestMatch.getLine()[EXTRA_COL_FROM_REPLICATION[i]];
            }
        }

        outputWriter.writeNext(outputLine);

    }

    outputWriter.close();

    for (String e : notFound) {
        System.err.println("Not found: " + e);
    }

    System.out.println("interactionSnpNotInGenotypeData: " + interactionSnpNotInGenotypeData);
    System.out.println("noReplicationQtlsInWindow: " + noReplicationQtlsInWindow);
    System.out.println("noReplicationQtlsInLd: " + noReplicationQtlsInLd);
    System.out.println("multipleReplicationQtlsInLd: " + multipleReplicationQtlsInLd);
    System.out.println("replicationTopSnpNotInGenotypeData: " + replicationTopSnpNotInGenotypeData);

}

From source file:com.clust4j.algo.ClustTests.java

@Test(expected = NaNException.class)
public void ensureNanException() {
    double[][] d = new double[][] { new double[] { 1, 2, 3 }, new double[] { Double.NaN, 0, 1 } };

    new KMeans(toMat(d), 2);
}

From source file:fr.amap.lidar.format.jleica.LPointShotExtractor.java

public LPointShotExtractor(GriddedPointScan scan) throws Exception {

    this.scan = scan;

    scan.computeExtremumsAngles();//from  w  w  w . jav a 2 s  .  c  om

    scan.openScanFile(scan.getFile());

    angles = new SimpleSpherCoords[this.scan.getHeader().getNumRows()][this.scan.getHeader().getNumCols()];

    azimuts = new boolean[this.scan.getHeader().getNumCols()];
    zenithals = new boolean[this.scan.getHeader().getNumRows()];

    //azimutsRegression  = new SimpleRegression[this.scan.getHeader().getNumCols()];
    //zenithalsRegression = new SimpleRegression[this.scan.getHeader().getNumRows()];

    //azimuts = new SimpleRegression[this.scan.getHeader().getNumCols()];
    //zenithals = new SimpleRegression[this.scan.getHeader().getNumRows()];

    Iterator<LPoint> iterator = scan.iterator();

    while (iterator.hasNext()) {

        LPoint point = iterator.next();

        if (point.valid) {

            double x, y, z;

            if (scan.getHeader().isPointInDoubleFormat()) {
                x = ((LDoublePoint) point).x;
                y = ((LDoublePoint) point).y;
                z = ((LDoublePoint) point).z;
            } else {
                x = ((LFloatPoint) point).x;
                y = ((LFloatPoint) point).y;
                z = ((LFloatPoint) point).z;
            }

            Vector3d dir = new Vector3d(x, y, z);
            dir.normalize();

            SphericalCoordinates sc = new SphericalCoordinates(new Vector3D(dir.x, dir.y, dir.z));

            angles[point.rowIndex][point.columnIndex] = new SimpleSpherCoords();
            angles[point.rowIndex][point.columnIndex].azimut = sc.getTheta();
            angles[point.rowIndex][point.columnIndex].zenith = sc.getPhi();

            azimuts[point.columnIndex] = true;
            zenithals[point.rowIndex] = true;
        }
    }

    int lastValidRowIndex = -1;
    int lastValidColumnIndex = -1;

    for (int row = 0; row < angles.length; row++) {

        for (int column = 0; column < angles[0].length; column++) {

            if (angles[row][column] == null) {

                double azimut = Double.NaN;
                double zenithal = Double.NaN;

                if (azimuts[column]) {
                    for (int i = row + 1, j = row - 1; i < angles.length || j >= 0; i++, j--) {

                        if (i < angles.length && angles[i][column] != null) {
                            azimut = angles[i][column].azimut;
                            azimuts[column] = true;
                            break;
                        }

                        if (j >= 0 && angles[j][column] != null) {
                            azimut = angles[j][column].azimut;
                            azimuts[column] = true;
                            break;
                        }
                    }
                }

                if (azimuts[column]) {

                    for (int i = row + 1, j = row - 1; i < angles.length || j >= 0; i++, j--) {

                        if (i < angles.length && angles[i][column] != null) {
                            zenithal = (angles[i][column].zenith + ((i - row) * scan.getElevationStepAngle()));
                            azimuts[column] = true;
                            break;
                        }

                        if (j >= 0 && angles[j][column] != null) {
                            zenithal = (angles[j][column].zenith - ((row - j) * scan.getElevationStepAngle()));
                            azimuts[column] = true;
                            break;
                        }
                    }
                }

                /*if(zenithals[row]){
                        
                for(int i=column+1, j=column-1;i<angles[0].length || j>=0;i++, j--){
                        
                    if(i<angles[0].length && angles[row][i] != null){
                        zenithal = angles[row][i].zenith;
                        zenithals[row] = true;
                        break;
                    }
                        
                    if(j >=0 && angles[row][j] != null){
                        zenithal = angles[row][j].zenith;
                        zenithals[row] = true;
                        break;
                    }
                }
                }*/

                if (Double.isNaN(azimut)) {
                    azimut = (scan.getAzim_min()
                            - ((column - scan.getColIndexAzimMin()) * scan.getAzimutalStepAngle()));
                }

                if (Double.isNaN(zenithal)) {
                    if (lastValidRowIndex != -1) {
                        zenithal = (angles[lastValidRowIndex][lastValidColumnIndex].zenith
                                - ((row - lastValidRowIndex) * scan.getElevationStepAngle()));
                    } else {
                        zenithal = (scan.getElev_min()
                                - ((row - scan.getRowIndexElevMin()) * scan.getElevationStepAngle()));
                    }

                }

                angles[row][column] = new SimpleSpherCoords(azimut, zenithal);

            } else {
                lastValidRowIndex = row;
                lastValidColumnIndex = column;
            }
        }
    }

}