private static void getBiomeSounds(@Nonnull final TObjectFloatHashMap<SoundEffect> result) { // Need to collect sounds from all the applicable biomes // along with their weights. final TObjectIntIterator<BiomeInfo> info = AreaSurveyHandler.getBiomes().iterator(); while (info.hasNext()) { info.advance(); final List<SoundEffect> bs = new ArrayList<SoundEffect>(); info.key().findSoundMatches(bs); for (final SoundEffect sound : bs) { final int w = info.value(); result.adjustOrPutValue(sound, w, w); } } // Scale the volumes in the resulting list based on the weights final int area = AreaSurveyHandler.getBiomeArea(); final TObjectFloatIterator<SoundEffect> itr = result.iterator(); while (itr.hasNext()) { itr.advance(); final float scale = 0.1F + 0.9F * ((float) itr.value() / (float) area); itr.setValue(scale); } }
@Override public void analyseImage(MBFImage image) { final int width = image.getWidth(); final int height = image.getHeight(); image.analyseWith(saliencyGenerator); final TObjectFloatHashMap<ConnectedComponent> componentMap = saliencyGenerator.getSaliencyComponents(); asSum = 0; aseSum = 0; componentMap.forEachEntry(new TObjectFloatProcedure<ConnectedComponent>() { @Override public boolean execute(ConnectedComponent c, float s) { final double as = c.calculateArea() * s; final double D = closestDistance(c, width, height); asSum += as; aseSum += as * Math.exp(-(D * D) / (2 * SIGMA)); return true; } }); }
public void queueAmbientSounds(@Nonnull final TObjectFloatHashMap<SoundEffect> sounds) { // Iterate through the existing emitters: // * If done, remove // * If not in the incoming list, fade // * If it does exist, update volume throttle and unfade if needed final Iterator<Entry<SoundEffect, Emitter>> itr = this.emitters.entrySet().iterator(); while (itr.hasNext()) { final Entry<SoundEffect, Emitter> e = itr.next(); final Emitter emitter = e.getValue(); if (emitter.isDonePlaying()) { DSurround.log().debug("Removing emitter: %s", emitter.toString()); itr.remove(); } else if (sounds.contains(e.getKey())) { emitter.setVolumeThrottle(sounds.get(e.getKey())); if (emitter.isFading()) emitter.unfade(); // Set to 0 so that the "new sound" logic below // will ignore. Cheaper than removing the object // from the collection. sounds.put(e.getKey(), 0F); } else { if (!emitter.isFading()) emitter.fade(); } } // Any sounds left in the list are new and need // an emitter created. final TObjectFloatIterator<SoundEffect> newSounds = sounds.iterator(); while (newSounds.hasNext()) { newSounds.advance(); if (newSounds.value() > 0) { final SoundEffect effect = newSounds.key(); this.emitters.put(effect, new PlayerEmitter(effect)); } } }
@Override public List<ScoreElement> getSimilar(SegmentContainer sc, ReadableQueryConfig qc) { TObjectFloatHashMap<String> tagScores = new TObjectFloatHashMap<>(); for(Tag tag : sc.getTags()){ if(!tag.hasId() && !tag.hasName()){ LOGGER.info("skipping empty tag"); continue; } if(!tag.hasId()){ List<Tag> tags = tagHandler.getTagsByName(tag.getName()); for(Tag t : tags){ tagScores.put(t.getId(), 1f); } }else{ tagScores.put(tag.getId(), 1f); } } return processTagScores(tagScores); }
@Override public void analyseImage(MBFImage image) { image.analyseWith(saliencyGenerator); final TObjectFloatHashMap<ConnectedComponent> componentMap = saliencyGenerator.getSaliencyComponents(); final float max = ArrayUtils.maxValue(componentMap.values()); final FImage map = new FImage(image.getWidth(), image.getHeight()); final float thresh = max * alpha; final BoundingBoxRenderer<Float> renderer = new BoundingBoxRenderer<Float>(map, 1F, true); componentMap.forEachEntry(new TObjectFloatProcedure<ConnectedComponent>() { @Override public boolean execute(ConnectedComponent cc, float sal) { if (sal >= thresh) { // note that this is reversed from the // paper, which doesn't seem to make // sense. renderer.process(cc); } return true; } }); roiProportion = 0; for (int y = 0; y < map.height; y++) for (int x = 0; x < map.width; x++) roiProportion += map.pixels[y][x]; roiProportion /= (map.width * map.height); // smaller simplicity means // smaller ROI }
protected DisjointSetForest<Pixel> segmentGraph(int numVertices, List<SimpleWeightedEdge<Pixel>> edges) { // sort edges by weight Collections.sort(edges, SimpleWeightedEdge.ASCENDING_COMPARATOR); // make a disjoint-set forest DisjointSetForest<Pixel> u = new DisjointSetForest<Pixel>(numVertices); for (SimpleWeightedEdge<Pixel> edge : edges) { u.add(edge.from); u.add(edge.to); } // init thresholds TObjectFloatHashMap<Pixel> threshold = new TObjectFloatHashMap<Pixel>(); for (Pixel p : u) { threshold.put(p, k); } // for each edge, in non-decreasing weight order... for (int i = 0; i < edges.size(); i++) { SimpleWeightedEdge<Pixel> pedge = edges.get(i); // components connected by this edge Pixel a = u.find(pedge.from); Pixel b = u.find(pedge.to); if (a != b) { if ((pedge.weight <= threshold.get(a)) && (pedge.weight <= threshold.get(b))) { a = u.union(a, b); threshold.put(a, pedge.weight + (k / u.size(a))); } } } return u; }
public static TObjectFloatHashMap<String> loadTStringFloatMap(String path) throws IOException { TObjectFloatHashMap<String> dict = new TObjectFloatHashMap<String>(); BufferedReader bfr = new BufferedReader(new InputStreamReader(new FileInputStream(path), "utf8")); String line = null; while ((line = bfr.readLine()) != null) { if (line.length() == 0) continue; int idx = line.lastIndexOf("\t"); dict.put(line.substring(0, idx), Float.parseFloat(line.substring(idx + 1))); } bfr.close(); return dict; }
@Override public List<ScoreElement> getSimilar(String shotId, ReadableQueryConfig qc) { List<Map<String, PrimitiveTypeProvider>> rows = this.selector.getRows("id", shotId); TObjectFloatHashMap<String> tagScores = new TObjectFloatHashMap<>(); for(Map<String, PrimitiveTypeProvider> row : rows){ String tagId = row.get("tag").getString(); float score = row.get("score").getFloat(); tagScores.put(tagId, score); } return processTagScores(tagScores); }
public AutoDeltaObjectFloatMap(Function<ByteBuffer, K> keyCreator) { this.changes = new ArrayList<>(5); this.container = new TObjectFloatHashMap<>(); this.baselineCommandCount = 0; this.keyCreator = keyCreator; }
public AutoDeltaStringFloatMap() { this.changes = new ArrayList<>(5); this.container = new TObjectFloatHashMap<>(); this.baselineCommandCount = 0; }
public HateList() { this.hateList = new TObjectFloatHashMap<>(); this.recentHateList = new TLongHashSet(); }
public void cleanup() { inputItems = new TObjectFloatHashMap<String>(); inputSignals = new HashMap<String, Map<String, Integer>>(); outputItems = bf.newDefaultBag(); }
public void cleanup() { inputItems = new TObjectFloatHashMap<String>(); outputItems = bf.newDefaultBag(); }
/** * Get a map of component->saliency for all the components in * the image * @return component->saliency map */ public TObjectFloatHashMap<ConnectedComponent> getSaliencyComponents() { return componentMap; }