Java Code Examples for java.util.BitSet#size()
The following examples show how to use
java.util.BitSet#size() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UncoupledParameterTransforms.java From Strata with Apache License 2.0 | 6 votes |
/** * * @param startValues fixed parameter values (if no parameters are fixed this is completely ignored) * @param transforms Array of ParameterLimitsTransform (which can be the NullTransform which does NOT transform the parameter) which transform * a constrained function parameter (e.g. must be between -1 and 1) to a unconstrained fit parameter. * @param fixed BitSet with an element set to <b>true</b> if that parameter is fixed */ public UncoupledParameterTransforms(DoubleArray startValues, ParameterLimitsTransform[] transforms, BitSet fixed) { ArgChecker.notNull(startValues, "null start values"); ArgChecker.notEmpty(transforms, "must specify transforms"); ArgChecker.notNull(fixed, "must specify what is fixed (even if none)"); _nMP = startValues.size(); ArgChecker.isTrue(_nMP == transforms.length, "Have {}-dimensional start value but {} transforms", _nMP, transforms.length); _freeParameters = new boolean[_nMP]; for (int i = 0; i < _nMP; i++) { if (i < fixed.size()) { _freeParameters[i] = !fixed.get(i); } else { _freeParameters[i] = true; } } int count = fixed.cardinality(); ArgChecker.isTrue(count < _nMP, "all parameters are fixed"); _nFP = _nMP - count; _startValues = startValues; _transforms = transforms; }
Example 2
Source File: Similarity.java From ReactionDecoder with GNU Lesser General Public License v3.0 | 6 votes |
/** * * @param Molecule1 BitSet * @param Molecule2 BitSet * @return <B>Similarity <U>Tanimoto, Jaccard</U> </B> * <B>c/(a+b-c)></B> * @throws java.lang.Exception */ public static synchronized float getTanimotoSimilarity(BitSet Molecule1, BitSet Molecule2) throws Exception { BitSet bitset1 = (BitSet) Molecule1.clone(); BitSet bitset2 = (BitSet) Molecule2.clone(); float _bitset1_cardinality = bitset1.cardinality(); float _bitset2_cardinality = bitset2.cardinality(); // System.out.println("bitset1: "+ bitset1.size() + " " + " bitset2" + bitset2.size()); if (bitset1.size() != bitset2.size()) { throw new Exception("BitSets must have the same bit length"); } BitSet one_and_two = (BitSet) bitset1.clone(); one_and_two.and(bitset2); float _common_bit_count = one_and_two.cardinality(); return _common_bit_count / (_bitset1_cardinality + _bitset2_cardinality - _common_bit_count); }
Example 3
Source File: Similarity.java From ReactionDecoder with GNU Lesser General Public License v3.0 | 6 votes |
/** * * @param Molecule1 * @param Molecule2 * @return <B>Similarity <U>Cosine,Ochiai,Carbo</U></B> * <B>c/sqrt(a*b)</B> * @throws Exception */ public static synchronized double getCosineSimilarity(BitSet Molecule1, BitSet Molecule2) throws Exception { BitSet bitset1 = (BitSet) Molecule1.clone(); BitSet bitset2 = (BitSet) Molecule2.clone(); float _bitset1_cardinality = bitset1.cardinality(); float _bitset2_cardinality = bitset2.cardinality(); if (bitset1.size() != bitset2.size()) { throw new Exception("Bisets must have the same bit length"); } BitSet one_and_two = (BitSet) bitset1.clone(); one_and_two.and(bitset2); float _common_bit_count = one_and_two.cardinality(); return _common_bit_count / (sqrt(_bitset1_cardinality * _bitset2_cardinality)); }
Example 4
Source File: GeoTimeSerie.java From warp10-platform with Apache License 2.0 | 6 votes |
public void reset(long[] ticks, long[] locations, long[] elevations, BitSet values, int size) throws IOException { int n = ticks.length; if (n != values.size() || (null != locations && n != locations.length) || (null != elevations && n != elevations.length)) { throw new IOException("Incoherent array lengths"); } this.ticks = ticks; this.locations = locations; this.elevations = elevations; this.doubleValues = null; this.longValues = null; this.booleanValues = values; this.stringValues = null; this.sorted = false; this.values = size; this.sizehint = n; this.type = TYPE.BOOLEAN; }
Example 5
Source File: JavaVMemServiceImpl.java From mnemonic with Apache License 2.0 | 6 votes |
public int findStartIdx(BitSet blocksMap, int requiredBlocks) { int startIdx = -1, blocks = 0, idx = 0; for (idx = 0; idx < blocksMap.size(); ++idx) { if (!blocksMap.get(idx)) { blocks++; } else { blocks = 0; } if (blocks == requiredBlocks) { break; } } if (blocks == requiredBlocks) { startIdx = idx - blocks + 1; } return startIdx; }
Example 6
Source File: af.java From MiBandDecompiled with Apache License 2.0 | 6 votes |
protected static byte[] a(BitSet bitset) { byte abyte0[] = new byte[bitset.size() / 8]; int i = 0; while (i < bitset.size()) { int j = i / 8; int k = 7 - i % 8; byte byte0 = abyte0[j]; int l; if (bitset.get(i)) { l = 1; } else { l = 0; } abyte0[j] = (byte)(byte0 | l << k); i++; } return abyte0; }
Example 7
Source File: Distance.java From ReactionDecoder with GNU Lesser General Public License v3.0 | 6 votes |
/** * * @param Molecule1 BitSet * @param Molecule2 BitSet * <B>Note:</B> Can be Normalized to the range 1 to 0 if all attributes are * normalized to this range and the result is divided in N * @return <B>Distance (Dissimilarity) <U>Euclidean</U></B> * <B>sqrt(a+b-2c)</B> * <B>sqrt(OnA+OnB-2*c)</B> * @throws java.lang.Exception */ public static double getEuclideanDistance(BitSet Molecule1, BitSet Molecule2) throws Exception { A = (BitSet) Molecule1.clone(); B = (BitSet) Molecule2.clone(); float _bitset1_cardinality = A.cardinality(); float _bitset2_cardinality = B.cardinality(); if (A.size() != B.size()) { throw new Exception("Bisets must have the same bit length"); } BitSet one_and_two = (BitSet) A.clone(); one_and_two.and(B); float _common_bit_count = one_and_two.cardinality(); double Val = sqrt((_bitset1_cardinality + _bitset2_cardinality - _common_bit_count) - _common_bit_count); return Val; }
Example 8
Source File: BitSetDemo.java From util4j with Apache License 2.0 | 6 votes |
/** * 求素数 有无限个。一个大于1的自然数,如果除了1和它本身外,不能被其他自然数整除(除0以外)的数称之为素数(质数) 否则称为合数 */ public static void computePrime() { BitSet sieve = new BitSet(1024); int size = sieve.size(); for (int i = 2; i < size; i++) sieve.set(i); int finalBit = (int) Math.sqrt(sieve.size()); for (int i = 2; i < finalBit; i++) if (sieve.get(i)) for (int j = 2 * i; j < size; j += i) sieve.clear(j); int counter = 0; for (int i = 1; i < size; i++) { if (sieve.get(i)) { System.out.printf("%5d", i); if (++counter % 15 == 0) System.out.println(); } } System.out.println(); }
Example 9
Source File: BloomFilter.java From Distributed-KV with Apache License 2.0 | 6 votes |
/** * 由bitset生成对应的bytebuf * @param bitSet * @param bitSetSize bitset实际大小 * @return bytebuf */ private ByteBuf bitSetToResult(BitSet bitSet, int bitSetSize) { // 测试 // if (bitSet.size() != bitSetSize) { // LOG.debug("bitSet.size() = " + bitSet.size()); // LOG.debug("bitSetSize = " + bitSetSize); // } // 计算ret所需大小 int retSize = (bitSet.size() / 8) + Integer.BYTES; LOG.debug("retSize = " + retSize); // 分配bytebuf ByteBuf ret = PooledByteBufAllocator.DEFAULT.buffer(retSize); // 先将bytebuf填充满 ret.writerIndex(retSize); // 将bitset中的数据映射到bytebuf中 for (int i = 0; i < bitSet.size(); i++) { int index = i / 8; int offset = 7 - i % 8; byte b = ret.getByte(index); b |= (bitSet.get(i) ? 1 : 0) << offset; ret.setByte(index, b); } // 将bitset大小信息添加到最后 ret.setInt((bitSet.size() / 8), bitSetSize); return ret; }
Example 10
Source File: Distance.java From ReactionDecoder with GNU Lesser General Public License v3.0 | 6 votes |
/** * * @param Molecule1 * @param Molecule2 * @return <B>Distance (Dissimilarity)<U> Soergel</U></B> * <B>1-c/[a+b-c]=[a+b-2*c]/[a+b-c]</B> * @throws Exception */ public static double getSoergelDistance(BitSet Molecule1, BitSet Molecule2) throws Exception { A = (BitSet) Molecule1.clone(); B = (BitSet) Molecule2.clone(); float _bitset1_cardinality = A.cardinality(); float _bitset2_cardinality = B.cardinality(); if (A.size() != B.size()) { throw new Exception("Bisets must have the same bit length"); } BitSet one_and_two = (BitSet) A.clone(); one_and_two.and(B); float _common_bit_count = one_and_two.cardinality(); double Val = (_bitset1_cardinality + _bitset2_cardinality - _common_bit_count) / _common_bit_count; return Val; }
Example 11
Source File: ReactionFingerprinter.java From ReactionDecoder with GNU Lesser General Public License v3.0 | 5 votes |
/** * * @param molSet * @throws CDKException */ private static IPatternFingerprinter getSumOfFingerprints(IAtomContainerSet molSet) throws CDKException, Exception { FingerprintGenerator molFingerprint = new FingerprintGenerator(); IPatternFingerprinter fp = new PatternFingerprinter(getFingerprinterSize()); for (IAtomContainer mol : molSet.atomContainers()) { BitSet booleanArray = molFingerprint.getFingerprint(mol); for (int i = 0; i < booleanArray.size(); i++) { if (booleanArray.get(i)) { fp.add(new Feature(valueOf(i), 1.0)); } } } return fp; }
Example 12
Source File: Combination.java From CardFantasy with BSD 2-Clause "Simplified" License | 5 votes |
private static <T> List <T> generateOne(List <T> elements, BitSet bs) { List <T> entry = new ArrayList <T> (bs.size()); for (int i = 0; i < bs.size(); ++i) { if (bs.get(i)) { entry.add(elements.get(i)); } } return entry; }
Example 13
Source File: InstructorScheduleConnector.java From unitime with Apache License 2.0 | 5 votes |
protected static Date firstDate(DatePattern dp, int dayCode) { if (dp == null) return null; BitSet weekCode = dp.getPatternBitSet(); if (weekCode.isEmpty()) return null; Calendar cal = Calendar.getInstance(Locale.US); cal.setLenient(true); Date dpFirstDate = DateUtils.getDate(1, dp.getSession().getPatternStartMonth(), dp.getSession().getSessionStartYear()); cal.setTime(dpFirstDate); int idx = weekCode.nextSetBit(0); cal.add(Calendar.DAY_OF_YEAR, idx); while (idx < weekCode.size()) { if (weekCode.get(idx)) { int dow = cal.get(Calendar.DAY_OF_WEEK); switch (dow) { case Calendar.MONDAY: if ((dayCode & DayCode.MON.getCode()) != 0) return cal.getTime(); break; case Calendar.TUESDAY: if ((dayCode & DayCode.TUE.getCode()) != 0) return cal.getTime(); break; case Calendar.WEDNESDAY: if ((dayCode & DayCode.WED.getCode()) != 0) return cal.getTime(); break; case Calendar.THURSDAY: if ((dayCode & DayCode.THU.getCode()) != 0) return cal.getTime(); break; case Calendar.FRIDAY: if ((dayCode & DayCode.FRI.getCode()) != 0) return cal.getTime(); break; case Calendar.SATURDAY: if ((dayCode & DayCode.SAT.getCode()) != 0) return cal.getTime(); break; case Calendar.SUNDAY: if ((dayCode & DayCode.SUN.getCode()) != 0) return cal.getTime(); break; } } cal.add(Calendar.DAY_OF_YEAR, 1); idx++; } return null; }
Example 14
Source File: CollatingIterator.java From Penetration_Testing_POC with Apache License 2.0 | 5 votes |
/** * Returns <code>true</code> iff any bit in the given set is * <code>true</code>. */ private boolean anyValueSet(BitSet set) { for (int i = 0; i < set.size(); i++) { if (set.get(i)) { return true; } } return false; }
Example 15
Source File: DataConvert.java From MeteoInfo with GNU Lesser General Public License v3.0 | 5 votes |
public static byte[] toByteArray_bak(BitSet bitSet) { ByteArrayOutputStream baos = new ByteArrayOutputStream(bitSet.size()); try { ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(bitSet); } catch (IOException ex) { ex.printStackTrace(); } return baos.toByteArray(); }
Example 16
Source File: BufrDataInfo.java From MeteoInfo with GNU Lesser General Public License v3.0 | 5 votes |
public byte[] toByteArray(BitSet bs) { if (bs.size() == 0) { return new byte[0]; } // Find highest bit int hiBit = -1; for (int i = 0; i < bs.size(); i++) { if (bs.get(i)) { hiBit = i; } } int n = (hiBit + 8) / 8; byte[] bytes = new byte[n]; if (n == 0) { return bytes; } Arrays.fill(bytes, (byte) 0); for (int i = 0; i < n * 8; i++) { if (bs.get(i)) { setBit(i, bytes); } } return bytes; }
Example 17
Source File: FindPartitionConditions.java From Bats with Apache License 2.0 | 5 votes |
public FindPartitionConditions(BitSet dirs, RexBuilder builder) { // go deep super(true); this.dirs = dirs; this.builder = builder; this.referencedDirs = new BitSet(dirs.size()); }
Example 18
Source File: ClusteringModelEvaluator.java From jpmml-evaluator with GNU Affero General Public License v3.0 | 4 votes |
private <V extends Number> ClusterAffinityDistribution<V> evaluateSimilarity(ValueFactory<V> valueFactory, ComparisonMeasure comparisonMeasure, List<ClusteringField> clusteringFields, List<FieldValue> values){ ClusteringModel clusteringModel = getModel(); List<Cluster> clusters = clusteringModel.getClusters(); ClusterAffinityDistribution<V> result = createClusterAffinityDistribution(Classification.Type.SIMILARITY, clusters); BitSet flags = MeasureUtil.toBitSet(values); for(Cluster cluster : clusters){ BitSet clusterFlags = CacheUtil.getValue(cluster, ClusteringModelEvaluator.clusterFlagCache); if(flags.size() != clusterFlags.size()){ throw new InvalidElementException(cluster); } Value<V> similarity = MeasureUtil.evaluateSimilarity(valueFactory, comparisonMeasure, clusteringFields, flags, clusterFlags); result.put(cluster, similarity); } return result; }
Example 19
Source File: MolFingerprint.java From ReactionDecoder with GNU Lesser General Public License v3.0 | 4 votes |
private synchronized void set(BitSet bitset) { arrayFingerprint = new boolean[bitset.size()]; for (int i = 0; i < bitset.length(); i++) { arrayFingerprint[i] = (bitset.get(i)); } }
Example 20
Source File: FindPartitionConditions.java From Bats with Apache License 2.0 | 4 votes |
public FindPartitionConditions(BitSet dirs) { // go deep super(true); this.dirs = dirs; this.referencedDirs = new BitSet(dirs.size()); }