use of gnu.trove.map.hash.TIntObjectHashMap in project GDSC-SMLM by aherbert.
the class ResultsMatchCalculator method getCoordinates.
/**
* Build a map between the peak id (time point) and a list of coordinates
*
* @param results
* @param integerCoordinates
* True if the values should be rounded down to integers
* @return
*/
public static TIntObjectHashMap<ArrayList<Coordinate>> getCoordinates(List<PeakResult> results, boolean integerCoordinates) {
TIntObjectHashMap<ArrayList<Coordinate>> coords = new TIntObjectHashMap<ArrayList<Coordinate>>();
if (results.size() > 0) {
ResultsMatchCalculator instance = new ResultsMatchCalculator();
// Do not use HashMap directly to build the coords object since there
// will be many calls to getEntry(). Instead sort the results and use
// a new list for each time point
Collections.sort(results);
int minT = results.get(0).getFrame();
int maxT = results.get(results.size() - 1).getEndFrame();
// Create lists
ArrayList<ArrayList<Coordinate>> tmpCoords = new ArrayList<ArrayList<Coordinate>>(maxT - minT + 1);
for (int t = minT; t <= maxT; t++) {
tmpCoords.add(new ArrayList<Coordinate>());
}
// Add the results to the lists
for (PeakResult p : results) {
final float x, y;
if (integerCoordinates) {
x = (int) p.getXPosition();
y = (int) p.getYPosition();
} else {
x = p.getXPosition();
y = p.getYPosition();
}
for (int t = p.getFrame() - minT, i = p.getEndFrame() - p.getFrame() + 1; i-- > 0; t++) tmpCoords.get(t).add(instance.new PeakResultPoint(t + minT, x, y, p));
}
// Put in the map
for (int t = minT, i = 0; t <= maxT; t++, i++) {
coords.put(t, tmpCoords.get(i));
}
}
return coords;
}
use of gnu.trove.map.hash.TIntObjectHashMap in project GDSC-SMLM by aherbert.
the class BenchmarkSpotFit method subsetFilterResults.
/**
* Extract all the filter candidates in order until the desired number of positives have been reached and the number
* of negatives matches the configured parameters.
*
* @param filterResults
* @return The filter candidates
*/
private TIntObjectHashMap<FilterCandidates> subsetFilterResults(TIntObjectHashMap<FilterResult> filterResults, int fitting) {
// Convert fractions from percent
final double f1 = Math.min(1, fractionPositives / 100.0);
final double f2 = fractionNegativesAfterAllPositives / 100.0;
final int[] counter = new int[2];
final TIntObjectHashMap<FilterCandidates> subset = new TIntObjectHashMap<FilterCandidates>();
fP = fN = 0;
nP = nN = 0;
final double[] fX = new double[2];
final int[] nX = new int[2];
filterResults.forEachEntry(new TIntObjectProcedure<FilterResult>() {
public boolean execute(int frame, FilterResult r) {
// Determine the number of positives to find. This score may be fractional.
fX[0] += r.result.getTP();
fX[1] += r.result.getFP();
// Q. Is r.result.getTP() not the same as the total of r.spots[i].match?
// A. Not if we used fractional scoring.
int c = 0;
for (int i = r.spots.length; i-- > 0; ) {
if (r.spots[i].match)
c++;
}
nX[0] += c;
nX[1] += (r.spots.length - c);
// Make the target use the fractional score
final double np2 = r.result.getTP() * f1;
double targetP = np2;
// Set the target using the closest
if (f1 < 1) {
double np = 0;
double min = r.result.getTP();
for (ScoredSpot spot : r.spots) {
if (spot.match) {
np += spot.getScore();
double d = np2 - np;
if (d < min) {
min = d;
targetP = np;
} else {
break;
}
}
}
//if (targetP < np2)
// System.out.printf("np2 = %.2f, targetP = %.2f\n", np2, targetP);
}
// Count the number of positive & negatives
int p = 0, n = 0;
double np = 0, nn = 0;
boolean reachedTarget = false;
int nAfter = 0;
int count = 0;
for (ScoredSpot spot : r.spots) {
count++;
nn += spot.antiScore();
if (spot.match) {
np += spot.getScore();
p++;
if (!reachedTarget) {
reachedTarget = np >= targetP;
}
} else {
n++;
if (reachedTarget) {
nAfter++;
}
}
if (reachedTarget) {
// Check if we have reached both the limits
if (nAfter >= negativesAfterAllPositives && (double) n / (n + p) >= f2)
break;
}
}
counter[0] += count;
counter[1] += r.spots.length;
// Debug
//System.out.printf("Frame %d : %.1f / (%.1f + %.1f). p=%d, n=%d, after=%d, f=%.1f\n", result.getKey().intValue(),
// r.result.getTP(), r.result.getTP(), r.result.getFP(), p, n,
// nAfter, (double) n / (n + p));
// We can use all the candidates but only fit up to count
subset.put(frame, new FilterCandidates(p, n, np, nn, r.spots, count));
return true;
}
});
fP = fX[0];
fN = fX[1];
nP = nX[0];
nN = nX[1];
// We now add all the candidates but only fit the first N
int target = counter[0];
int total = counter[1];
int added = total - target;
if (extraOptions && added > target)
Utils.log("Added %s to %s (total = %d)", Utils.pleural(added, "neighbour"), Utils.pleural(target, "candidate"), total);
return subset;
}
use of gnu.trove.map.hash.TIntObjectHashMap in project ProPPR by TeamCohen.
the class LightweightStateGraph method getFeatures.
public Map<Feature, Double> getFeatures(State u, State v) {
int ui = this.nodeTab.getId(u), vi = this.nodeTab.getId(v);
if (!edgeFeatureDict.containsKey(ui))
return DEFAULT_FD;
TIntObjectHashMap<TIntDoubleHashMap> fu = edgeFeatureDict.get(ui);
if (!fu.containsKey(vi))
return DEFAULT_FD;
TIntDoubleHashMap fuvi = fu.get(vi);
final HashMap<Feature, Double> ret = new HashMap<Feature, Double>();
fuvi.forEachEntry(new TIntDoubleProcedure() {
@Override
public boolean execute(int fi, double wt) {
ret.put(featureTab.getSymbol(fi), wt);
return true;
}
});
return ret;
}
use of gnu.trove.map.hash.TIntObjectHashMap in project Geolosys by oitsjustjose.
the class ItemFieldManual method getBook.
@SideOnly(Side.CLIENT)
public ItemStack getBook(Book book) {
NBTTagCompound tags = new NBTTagCompound();
List<NBTTagString> pages = Lists.newArrayList();
FontRenderer fontRenderer = Minecraft.getMinecraft().fontRenderer;
TIntObjectHashMap<String> contents = new TIntObjectHashMap<>();
for (Page page : book.pages) {
StringBuilder sb = new StringBuilder();
String title = page.getTitle();
String text = page.getText();
if (title == null || text == null || title.isEmpty() || text.isEmpty()) {
System.out.println("Well you succ");
break;
}
contents.put(pages.size(), title);
sb.append(TextFormatting.UNDERLINE).append(title).append(TextFormatting.RESET).append("\n\n").append(text);
String formattedString = sb.toString();
List<String> splitStrings = fontRenderer.listFormattedStringToWidth(formattedString, 116);
StringBuilder sb2 = new StringBuilder();
int lineNumber = 0;
for (String s : splitStrings) {
sb2.append(s).append("\n");
lineNumber++;
if (lineNumber >= 13) {
pages.add(new NBTTagString(sb2.toString()));
sb2 = new StringBuilder();
lineNumber = 0;
}
}
if (lineNumber != 0) {
pages.add(new NBTTagString(sb2.toString()));
}
}
final NBTTagList pageList = new NBTTagList();
pageList.appendTag((NBTBase) new NBTTagString(TextFormatting.BOLD + "\n\n\n\n Geolosys\n Field Manual"));
final int offset = 3 + contents.size() / 13;
final int[] keys = contents.keys();
Arrays.sort(keys);
StringBuilder builder3 = new StringBuilder("Contents:\n\n");
int i = 2;
for (final int key : keys) {
String line;
int a;
for (line = contents.get(key), a = key + offset; fontRenderer.listFormattedStringToWidth(line + " " + a, 116).size() > 1; line = line.substring(0, line.length() - 1)) {
;
}
for (line += " "; fontRenderer.listFormattedStringToWidth(line + " " + a, 116).size() == 1; line += " ") {
;
}
line += a;
builder3.append(line).append('\n');
if (++i >= 13) {
i = 0;
pageList.appendTag(new NBTTagString(builder3.toString()));
builder3 = new StringBuilder();
}
}
if (i != 0) {
pageList.appendTag(new NBTTagString(builder3.toString()));
}
for (final NBTTagString page2 : pages) {
pageList.appendTag(page2);
}
tags.setTag("pages", pageList);
tags.setString("title", HelperFunctions.getTranslation("geolosys.field_manual.name"));
tags.setString("author", "oitsjustjose");
final ItemStack stack = new ItemStack(Items.WRITTEN_BOOK);
stack.setTagCompound(tags);
return stack;
}
use of gnu.trove.map.hash.TIntObjectHashMap in project Charset by CharsetMC.
the class ProxyClient method onTextureStitch.
@SubscribeEvent
@SideOnly(Side.CLIENT)
public void onTextureStitch(TextureStitchEvent.Pre event) {
GateRenderDefinitions.INSTANCE.load("simplelogic:gatedefs/base.json", SimpleLogicGates.logicDefinitions);
for (ResourceLocation rs : SimpleLogicGates.logicClasses.keySet()) {
Set<ResourceLocation> textures = new HashSet<>();
Map<String, TIntObjectMap<String>> colorMasks = new HashMap<>();
// step 1: gather colormasks
int i = 0;
for (GateRenderDefinitions.Layer layer : GateRenderDefinitions.INSTANCE.getGateDefinition(rs).layers) {
if (layer.color_mask != null) {
layer.texture = rs.getResourceDomain() + ":blocks/" + rs.getResourcePath() + "/layer_" + i;
colorMasks.computeIfAbsent(layer.textureBase, (k) -> new TIntObjectHashMap<>()).put(Integer.parseInt(layer.color_mask, 16), layer.texture);
}
i++;
}
// step 2: gather textures
GateRenderDefinitions.Definition def = GateRenderDefinitions.INSTANCE.getGateDefinition(rs);
for (IModel model : def.getAllModels()) {
textures.addAll(model.getTextures());
}
for (GateRenderDefinitions.Layer layer : GateRenderDefinitions.INSTANCE.getGateDefinition(rs).layers) {
if (layer.texture != null) {
textures.add(new ResourceLocation(layer.texture));
}
}
// step 3: add colormasked textures
for (String baseTexture : colorMasks.keySet()) {
TIntObjectMap<String> resultingTextures = colorMasks.get(baseTexture);
resultingTextures.forEachEntry((color, resultingTexture) -> {
event.getMap().setTextureEntry(new PixelOperationSprite(resultingTexture, new ResourceLocation(baseTexture), ((getter, x, y, value) -> (value & 0xFFFFFF) == color ? -1 : 0)));
textures.remove(new ResourceLocation(resultingTexture));
return true;
});
event.getMap().setTextureEntry(new PixelOperationSprite(baseTexture, new ResourceLocation(baseTexture), (((getter, x, y, value) -> {
if (resultingTextures.containsKey(value & 0xFFFFFF)) {
return 0;
} else {
return value;
}
}))));
textures.remove(new ResourceLocation(baseTexture));
}
// step 4: add non-colormasked textures
for (ResourceLocation location : textures) {
event.getMap().registerSprite(location);
}
}
}
Aggregations