@Override public void run() { for(int i = 0; i < al.size(); i++) { int a = al.get(i); for(int j = i + 1; j < al.size(); j++) { int b = al.get(j); double lenDiff; lenDiff = Math.abs(featureLen[a]-featureLen[b]); lenDiff /=Math.max(featureLen[a],featureLen[b]); if(lenDiff>lenDiffThresh) continue; int ids,idl; if(a<=b){ ids = a; idl=b; }else{ ids = b; idl=a; } if(similarityMap[ids] == null) similarityMap[ids] = new TIntIntHashMap(); synchronized (similarityMap[ids]) { similarityMap[ids].adjustOrPutValue(idl, 1, 1); } } } } }
int pI = data[l][t] + templets.offset[t][pS]; // 特征索引:找到对应weights的维数 if (tI != pI) { diffF.adjustOrPutValue(tI, 1, 1); diffF.adjustOrPutValue(pI, -1, -1);
@Override public int increment(int key, int value) { return data.adjustOrPutValue(key, value, value); }
/** See {@link gnu.trove.map.hash.TIntIntHashMap#adjustOrPutValue(int, int, int)} */ public int adjustOrPutValue(int key, int adjustAmount, int putAmount) { return delegate.adjustOrPutValue(key, adjustAmount, putAmount); }
/** See {@link gnu.trove.map.hash.TIntIntHashMap#adjustOrPutValue(int, int, int)} */ public int adjustOrPutValue(int key, int adjustAmount, int putAmount) { return delegate.adjustOrPutValue(key, adjustAmount, putAmount); }
public void add (ServiceInfo serviceInfo) { servicesActive.add(serviceInfo.serviceId); serviceInfo.durationByRouteType.forEachEntry((routeType, serviceDurationSeconds) -> { durationByRouteType.adjustOrPutValue(routeType, serviceDurationSeconds, serviceDurationSeconds); return true; // Continue iteration. }); tripCount += serviceInfo.tripIds.size(); } }
@Override public void validateTrip(Trip trip, Route route, List<StopTime> stopTimes, List<Stop> stops) { int firstStopDeparture = stopTimes.get(0).departure_time; int lastStopArrival = stopTimes.get(stopTimes.size() - 1).arrival_time; if (firstStopDeparture == Entity.INT_MISSING || lastStopArrival == Entity.INT_MISSING) { // ERR return; } int tripDurationSeconds = lastStopArrival - firstStopDeparture; if (tripDurationSeconds <= 0) { // ERR return; } // Get the map from modes to service durations in seconds for this trip's service ID. // Create a new empty map if it doesn't yet exist. ServiceInfo serviceInfo = serviceInfoForServiceId.computeIfAbsent(trip.service_id, ServiceInfo::new); if (route != null) { // Increment the service duration for this trip's transport mode and service ID. serviceInfo.durationByRouteType.adjustOrPutValue(route.route_type, tripDurationSeconds, tripDurationSeconds); } // Record which trips occur on each service_id. serviceInfo.tripIds.add(trip.trip_id); // TODO validate mode codes }
/** * @param is * @param invCor * @return the cluster with the maximum */ public static IntIntPair findMaxClassCount(int[] is, Map<Integer, Integer> invCor) { TIntIntHashMap classCounts = new TIntIntHashMap(); int max = 0; int c = 0; for (int i : is) { Integer c_i = invCor.get(i); if(c_i == null) continue; int count = classCounts.adjustOrPutValue(c_i, 1, 1); if(count > max){ max = count; c = c_i; } } return IntIntPair.pair(c, max); }
@Override public void update(String data, Integer value) { for (final FunctionHashPair map : this.maps) { final int hash = map.firstObject().computeHashCode(data); final int loc = Math.abs(hash) % this.nwords; map.secondObject().adjustOrPutValue(loc, value, value); } }
@Override public void update(String data, Integer value) { for (final FunctionHashPair map : this.maps) { final int hash = map.firstObject().computeHashCode(data); final int loc = Math.abs(hash) % this.nwords; map.secondObject().adjustOrPutValue(loc, value, value); } }
/** * @param is * @param invCor * @return the cluster with the maximum */ public static IntIntPair findMaxClassCount(int[] is, Map<Integer, Integer> invCor) { TIntIntHashMap classCounts = new TIntIntHashMap(); int max = 0; int c = 0; for (int i : is) { Integer c_i = invCor.get(i); if(c_i == null) continue; int count = classCounts.adjustOrPutValue(c_i, 1, 1); if(count > max){ max = count; c = c_i; } } return IntIntPair.pair(c, max); }
while (yData[yIndex] != 1) yIndex++; final int currentCount = this.examples.adjustOrPutValue(yIndex, 1, 1); if (currentCount < this.maxTests) {
@Override public void train(List<? extends Annotated<OBJECT, ANNOTATION>> data) { final HashSet<ANNOTATION> annotationsSet = new HashSet<ANNOTATION>(); final TIntIntHashMap nAnnotationCounts = new TIntIntHashMap(); int maxVal = 0; for (final Annotated<OBJECT, ANNOTATION> sample : data) { final Collection<ANNOTATION> annos = sample.getAnnotations(); annotationsSet.addAll(annos); nAnnotationCounts.adjustOrPutValue(annos.size(), 1, 1); if (annos.size() > maxVal) maxVal = annos.size(); } annotations = new ArrayList<ANNOTATION>(annotationsSet); rnd = new Uniform(0, annotations.size() - 1, new MersenneTwister()); numAnnotations.train(data); }
private void countCellsPerColumn() throws IOException { for (int id : matrix.getRowIds()) { MatrixRow row = matrix.getRow(id); for (int i = 0; i < row.getNumCols(); i++) { colCounts.adjustOrPutValue(row.getColIndex(i), 1, 1); } } colIds = colCounts.keys(); LOG.info("found " + colIds.length + " unique column ids in matrix"); Arrays.sort(colIds); }
private void countCellsPerColumn() throws IOException { for (int id : matrix.getRowIds()) { MatrixRow row = matrix.getRow(id); for (int i = 0; i < row.getNumCols(); i++) { colCounts.adjustOrPutValue(row.getColIndex(i), 1, 1); } } colIds = colCounts.keys(); LOG.info("found " + colIds.length + " unique column ids in matrix"); Arrays.sort(colIds); }
@Override public <O, A> void train(List<? extends Annotated<O, A>> data) { TIntIntHashMap nAnnotationCounts = new TIntIntHashMap(); int maxVal = 0; for (Annotated<O, A> sample : data) { Collection<A> annos = sample.getAnnotations(); nAnnotationCounts.adjustOrPutValue(annos.size(), 1, 1); if (annos.size()>maxVal) maxVal = annos.size(); } //build distribution and rng for the number of annotations double [] distr = new double[maxVal+1]; for (int i=0; i<=maxVal; i++) distr[i] = nAnnotationCounts.get(i); numAnnotations = new EmpiricalWalker(distr, Empirical.NO_INTERPOLATION, new MersenneTwister()); }
@Override protected void detectInactive(IndexClusters oldClusters, IndexClusters newClusters, TIntSet inactiveRows, List<int[]> completedClusters) { Map<Integer, IntDoublePair> stability = calculateStability(oldClusters,newClusters, inactiveRows); for (Entry<Integer, IntDoublePair> e : stability.entrySet()) { int[] completedCluster = oldClusters.clusters()[e.getKey()]; if(e.getValue().second >= threshold){ for (int i = 0; i < completedCluster.length; i++) { int index = completedCluster[i]; inactiveRows.add(index); this.seenCount.remove(index); } completedClusters.add(completedCluster); } else{ for (int i = 0; i < completedCluster.length; i++) { int index = completedCluster[i]; int newCount = this.seenCount.adjustOrPutValue(index, 1, 1); if(newCount>= this.lifetime){ this.seenCount.remove(index); inactiveRows.add(index); completedClusters.add(new int[]{index}); } } } } }
private void calculateScores() throws IOException { // initialize buffers OpenBitSet docPointers = new OpenBitSet(reader.maxDoc()); TermPositions tp = null; List<Term> uniqueTerms = new LinkedList<Term>(new LinkedHashSet<Term>(terms)); uniqueTermSize = uniqueTerms.size(); roughThresholdFreq = (int) (uniqueTermSize * (threshold*0.01f)); for (Iterator<Term> iter = uniqueTerms.iterator(); iter.hasNext();) { try { tp = reader.termPositions(iter.next()); while (tp.next()) { int f = scoredDocs.adjustOrPutValue(tp.doc(), 1, 1); if (f > roughThresholdFreq) { docPointers.fastSet(tp.doc()); } } } finally { if (tp != null) { tp.close(); } } } if (docPointers.cardinality() > 0) { docPointerIterator = (OpenBitSetIterator) docPointers.iterator(); } }
private void prepareDataCollection() { this.dataCollection = new ArrayList<InputOutputPair<Vector, Vector>>(); final double[][] xArr = this.xVals.getArray(); final double[][] yArr = this.yVals.getArray(); for (int i = 0; i < xArr.length; i++) { final Vector xVector = VectorFactory.getDefault().copyArray(xArr[i]); final double[] yValues = new double[10]; final int number = (int) (yArr[i][0] % 10); final int count = examples.adjustOrPutValue(number, 1, 1); yValues[number] = 1; final Vector yVector = VectorFactory.getDefault().copyValues(yValues); if (this.maxExamples != -1 && count > maxExamples) { if (count > maxTests + maxExamples) { continue; } List<IndependentPair<Vector, Vector>> numberTest = this.tests.get(number); if (numberTest == null) { this.tests.put(number, numberTest = new ArrayList<IndependentPair<Vector, Vector>>()); } numberTest.add(IndependentPair.pair(xVector, yVector)); totalTests++; } else { this.dataCollection.add(DefaultInputOutputPair.create(xVector, yVector)); } } }
@Override public void propagate(int evtmask) throws ContradictionException { SetVar intersection = vars[k]; // Maps elements in sets to the number of occurences of those elements. TIntIntHashMap count = new TIntIntHashMap(); for (int i = 0; i < k; i++) { ISetIterator iter = vars[i].getLB().iterator(); while (iter.hasNext()) { int j = iter.nextInt(); if (!intersection.getUB().contains(j) && count.adjustOrPutValue(j, 1, 1) >= k - 1) { // intersection does not contain j but k - 1 sets contains // j, hence the last set must not contain j. findSetThatDoesNotContainJInLB(j).remove(j, this); } } } for (int i = 0; i <= k; i++) { sdm[i].unfreeze(); } }