List of usage examples for java.util BitSet BitSet
public BitSet()
From source file:de.upb.wdqa.wdvd.revisiontags.TagDownloaderRevisionData.java
/** * Converts the tags to a memory efficient byte[] representation *///from www . ja va 2 s. c o m private byte[] tagsToBytes(Set<DbTag> tags) { BitSet bitSet = new BitSet(); if (tags != null) { for (DbTag tag : tags) { bitSet.set(tag.getTagId()); } } return bitSet.toByteArray(); }
From source file:mastodon.algorithms.FlipPenaltyAlgorithm.java
protected void initialize() { stub = "Flip Penalty"; // Random.setSeed(4443245); pruningFreq = new HashMap<Integer, Integer>(); for (int i = 0; i < bts.getTaxaCount(); i++) { pruningFreq.put(i, 0);/*from w w w .j a va 2 s . c om*/ } maxScorePruning = new HashMap<BitSet, double[]>(); currPruning = new BitSet(); prevPruning = new BitSet(); prevScore = new double[] { 0, 0 }; maxScore = prevScore.clone(); maxScorePruning.put(prevPruning, maxScore); iterationCounter = 0; }
From source file:mastodon.algorithms.SALinearAlgorithm.java
protected void initialize() { if (minPrunedSpeciesCount == maxPrunedSpeciesCount) { stub = "SA Cons."; } else {/*from w w w . j a v a 2s . c o m*/ stub = "SA Lin."; } pruningFreq = new HashMap<Integer, Integer>(); for (int i = 0; i < bts.getTaxaCount(); i++) { pruningFreq.put(i, 0); } currTemp = initTemp; currPrunedSpeciesCount = minPrunedSpeciesCount; maxScorePruning = new HashMap<BitSet, double[]>(); currPruning = new BitSet(); for (int i = 0; i < currPrunedSpeciesCount; i++) { int choice = 0; do { choice = (int) (Random.nextDouble() * bts.getTaxaCount()); } while (currPruning.get(choice)); currPruning.set(choice); } prevPruning = (BitSet) currPruning.clone(); prevScore = bts.pruneFast(currPruning); bts.unPrune(); maxScore = prevScore.clone(); maxScorePruning.put(prevPruning, maxScore); double mean = 1.0; //needed when pruning 1 taxon (can't have a mean of 0 in PoissonDistribution()) if (currPrunedSpeciesCount > 1) { mean = 0.5 * (currPrunedSpeciesCount - 1); } pd = new PoissonDistribution(mean); setupIterations(); coolingRate = Math.pow(finalTemp / initTemp, 1.0 / stepIterations[currPrunedSpeciesCount - 1]); iterationCounter = 0; }
From source file:com.opengamma.analytics.math.minimization.NonLinearTransformFunctionTest.java
@Test public void testNullTransform() { BitSet fixed = new BitSet(); fixed.set(0);/*from w ww. j av a 2s . com*/ DoubleMatrix1D start = new DoubleMatrix1D(new double[] { Math.PI / 4, 1 }); UncoupledParameterTransforms transforms = new UncoupledParameterTransforms(start, NULL_TRANSFORMS, fixed); NonLinearTransformFunction transFunc = new NonLinearTransformFunction(FUNCTION, JACOBIAN, transforms); Function1D<DoubleMatrix1D, DoubleMatrix1D> func = transFunc.getFittingFunction(); Function1D<DoubleMatrix1D, DoubleMatrix2D> jacFunc = transFunc.getFittingJacobian(); DoubleMatrix1D x = new DoubleMatrix1D(new double[] { 0.5 }); final double rootHalf = Math.sqrt(0.5); DoubleMatrix1D y = func.evaluate(x); assertEquals(3, y.getNumberOfElements()); assertEquals(rootHalf * Math.cos(0.5), y.getEntry(0), 1e-9); assertEquals(rootHalf * Math.sin(0.5), y.getEntry(1), 1e-9); assertEquals(rootHalf, y.getEntry(2), 1e-9); DoubleMatrix2D jac = jacFunc.evaluate(x); assertEquals(3, jac.getNumberOfRows()); assertEquals(1, jac.getNumberOfColumns()); assertEquals(-rootHalf * Math.sin(0.5), jac.getEntry(0, 0), 1e-9); assertEquals(rootHalf * Math.cos(0.5), jac.getEntry(1, 0), 1e-9); assertEquals(0, jac.getEntry(2, 0), 1e-9); }
From source file:solidstack.io.DiskBuffer.java
/** * Constructs a disk map with the given block size. * * @param filePrefix The prefix of the temporary file. * @param blockSize The block size for the data written to the temporary file. *///from w w w . j a v a 2 s .com public DiskBuffer(String filePrefix, int blockSize) { try { this.tempFile = File.createTempFile(filePrefix, null); this.blockSize = blockSize; this.store = new RandomAccessFile(this.tempFile, "rw"); this.usedBlocks = new BitSet(); this.emptyBlockStart = 0; } catch (IOException e) { throw new FatalIOException(e); } }
From source file:sf.net.experimaestro.manager.plans.ProductReference.java
@Override public Operator prepare(Map<Operator, Operator> map, OperatorMap opMap) { // --- Loop over the cartesian product of the inputs Plan.OperatorIterable inputValues[] = new Plan.OperatorIterable[parents.size()]; {/*from w w w . j a v a 2 s . com*/ int index = 0; for (Operator input : parents) { inputValues[index] = new Plan.OperatorIterable(Arrays.asList(input), map, opMap); index++; } } // Create a new operator Operator inputOperators[] = new Operator[inputValues.length]; BitSet[] joins = new BitSet[inputOperators.length]; // Process union of operators for (int i = inputValues.length; --i >= 0;) { Plan.OperatorIterable values = inputValues[i]; Union union = new Union(); for (Operator operator : values) { union.addParent(operator); } if (union.getParents().size() == 1) inputOperators[i] = union.getParent(0); else inputOperators[i] = union; joins[i] = new BitSet(); opMap.add(inputOperators[i]); } // TODO: build a simplified graph of operators: // for each input, we only have LCAs (organized in a hierarchy) // Process this simplified graph step-wise, by merging // Find LCAs and store them in a map operator ID -> inputs for (int i = 0; i < inputOperators.length - 1; i++) { for (int j = i + 1; j < inputOperators.length; j++) { ArrayList<Operator> lca = opMap.findLCAs(inputOperators[i], inputOperators[j]); for (Operator operator : lca) { int key = opMap.get(operator); joins[i].set(key); joins[j].set(key); } } } // Build the lattice of operators Lattice lattice = new Lattice(opMap); for (int i = 0; i < joins.length; i++) { lattice.add(joins[i], inputOperators[i]); } MergeResult merge = lattice.merge(); // Build the trie structure for product/joins int[] mapping = new int[inputOperators.length]; for (int i = 0; i < parents.size(); i++) { mapping[i] = merge.map.get(inputOperators[i]); } ReorderNodes reorder = new ReorderNodes(mapping); reorder.addParent(merge.operator); return reorder; }
From source file:mastodon.algorithms.MHBisectionAlgorithm.java
protected void choosePruningCount() { if (iterationCounter % stepIterations == 0) { System.out.println(currPrunedSpeciesCount); System.out.println(maxScore[0] + " " + maxScore[1]); if (iterationCounter > 0) { if (maxScore[0] < minMapScore) { kLeft = currPrunedSpeciesCount; } else { kRight = currPrunedSpeciesCount; }/*from w w w. j a v a 2s.c o m*/ currPrunedSpeciesCount = (int) ((kRight + kLeft) / 2); } maxScore = new double[2]; maxScorePruning = new HashMap<BitSet, double[]>(); currPruning = new BitSet(); for (int i = 0; i < currPrunedSpeciesCount; i++) { int choice = 0; do { choice = (int) (Random.nextDouble() * bts.getTaxaCount()); } while (currPruning.get(choice)); currPruning.set(choice); } prevPruning = (BitSet) currPruning.clone(); prevScore = bts.pruneFast(currPruning); bts.unPrune(); maxScorePruning.put(prevPruning, prevScore); double mean = 1.0; //needed when pruning 1 taxon (can't have a mean of 0 in PoissonDistribution()) if (currPrunedSpeciesCount > 1) { mean = 0.5 * (currPrunedSpeciesCount - 1); } pd = new PoissonDistribution(mean); } }
From source file:ca.phon.ipa.features.FeatureSet.java
/** * Create a new instance of a feature set * /*w w w . ja v a2 s .co m*/ */ public FeatureSet() { this.features = new BitSet(); this.ipaChar = '\u0000'; }
From source file:ca.phon.ipa.features.FeatureSet.java
public FeatureSet(Set<String> features) { this.features = new BitSet(); this.ipaChar = '\u0000'; for (String f : features) { addFeature(f);/*from ww w . j a v a 2 s. c om*/ } }
From source file:mastodon.algorithms.SABisectionAlgorithm.java
protected void choosePruningCount() { if (iterationCounter % stepIterations == 0) { System.out.println(currPrunedSpeciesCount); System.out.println(maxScore[0] + " " + maxScore[1]); if (iterationCounter > 0) { if (maxScore[0] < minMapScore) { kLeft = currPrunedSpeciesCount; } else { kRight = currPrunedSpeciesCount; }/*from w w w . j a v a2 s.c o m*/ currPrunedSpeciesCount = (int) ((kRight + kLeft) / 2); } maxScore = new double[2]; maxScorePruning = new HashMap<BitSet, double[]>(); currPruning = new BitSet(); for (int i = 0; i < currPrunedSpeciesCount; i++) { int choice = 0; do { choice = (int) (Random.nextDouble() * bts.getTaxaCount()); } while (currPruning.get(choice)); currPruning.set(choice); } prevPruning = (BitSet) currPruning.clone(); prevScore = bts.pruneFast(currPruning); bts.unPrune(); maxScorePruning.put(prevPruning, prevScore); double mean = 1.0; //needed when pruning 1 taxon (can't have a mean of 0 in PoissonDistribution()) if (currPrunedSpeciesCount > 1) { mean = 0.5 * (currPrunedSpeciesCount - 1); } pd = new PoissonDistribution(mean); currTemp = initTemp; } currTemp *= coolingRate; }