Search in sources :

Example 16 with TIntObjectHashMap

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;
}
Also used : Coordinate(gdsc.core.match.Coordinate) TIntObjectHashMap(gnu.trove.map.hash.TIntObjectHashMap) ArrayList(java.util.ArrayList) Point(java.awt.Point) BasePoint(gdsc.core.match.BasePoint) PeakResult(gdsc.smlm.results.PeakResult)

Example 17 with TIntObjectHashMap

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;
}
Also used : ScoredSpot(gdsc.smlm.ij.plugins.BenchmarkSpotFilter.ScoredSpot) TIntObjectHashMap(gnu.trove.map.hash.TIntObjectHashMap) FilterResult(gdsc.smlm.ij.plugins.BenchmarkSpotFilter.FilterResult) PeakResultPoint(gdsc.smlm.ij.plugins.ResultsMatchCalculator.PeakResultPoint) BasePoint(gdsc.core.match.BasePoint)

Example 18 with TIntObjectHashMap

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;
}
Also used : TIntObjectHashMap(gnu.trove.map.hash.TIntObjectHashMap) HashMap(java.util.HashMap) TIntDoubleHashMap(gnu.trove.map.hash.TIntDoubleHashMap) TIntDoubleHashMap(gnu.trove.map.hash.TIntDoubleHashMap) TIntDoubleProcedure(gnu.trove.procedure.TIntDoubleProcedure) Feature(edu.cmu.ml.proppr.prove.wam.Feature)

Example 19 with TIntObjectHashMap

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;
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) NBTTagString(net.minecraft.nbt.NBTTagString) NBTTagList(net.minecraft.nbt.NBTTagList) TIntObjectHashMap(gnu.trove.map.hash.TIntObjectHashMap) NBTTagString(net.minecraft.nbt.NBTTagString) FontRenderer(net.minecraft.client.gui.FontRenderer) ItemStack(net.minecraft.item.ItemStack) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 20 with TIntObjectHashMap

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);
        }
    }
}
Also used : ModelBakeEvent(net.minecraftforge.client.event.ModelBakeEvent) TIntObjectHashMap(gnu.trove.map.hash.TIntObjectHashMap) TIntObjectMap(gnu.trove.map.TIntObjectMap) ModelRegistryEvent(net.minecraftforge.client.event.ModelRegistryEvent) Set(java.util.Set) GateRenderDefinitions(pl.asie.simplelogic.gates.render.GateRenderDefinitions) HashMap(java.util.HashMap) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) IModel(net.minecraftforge.client.model.IModel) HashSet(java.util.HashSet) PixelOperationSprite(pl.asie.charset.lib.render.sprite.PixelOperationSprite) Side(net.minecraftforge.fml.relauncher.Side) RendererGate(pl.asie.simplelogic.gates.render.RendererGate) RegistryUtils(pl.asie.charset.lib.utils.RegistryUtils) Map(java.util.Map) TextureStitchEvent(net.minecraftforge.client.event.TextureStitchEvent) ResourceLocation(net.minecraft.util.ResourceLocation) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent) SideOnly(net.minecraftforge.fml.relauncher.SideOnly) IModel(net.minecraftforge.client.model.IModel) PixelOperationSprite(pl.asie.charset.lib.render.sprite.PixelOperationSprite) TIntObjectHashMap(gnu.trove.map.hash.TIntObjectHashMap) HashMap(java.util.HashMap) GateRenderDefinitions(pl.asie.simplelogic.gates.render.GateRenderDefinitions) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) ResourceLocation(net.minecraft.util.ResourceLocation) TIntObjectHashMap(gnu.trove.map.hash.TIntObjectHashMap) TIntObjectMap(gnu.trove.map.TIntObjectMap) HashSet(java.util.HashSet) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Aggregations

TIntObjectHashMap (gnu.trove.map.hash.TIntObjectHashMap)43 ArrayList (java.util.ArrayList)15 LinkedList (java.util.LinkedList)13 PeakResultPoint (uk.ac.sussex.gdsc.smlm.results.PeakResultPoint)12 List (java.util.List)11 Coordinate (uk.ac.sussex.gdsc.core.match.Coordinate)10 Ticker (uk.ac.sussex.gdsc.core.logging.Ticker)9 MemoryPeakResults (uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults)9 TIntHashSet (gnu.trove.set.hash.TIntHashSet)8 IJ (ij.IJ)8 Prefs (ij.Prefs)8 PlugIn (ij.plugin.PlugIn)8 TextWindow (ij.text.TextWindow)8 Arrays (java.util.Arrays)8 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)8 AtomicReference (java.util.concurrent.atomic.AtomicReference)8 ImageJUtils (uk.ac.sussex.gdsc.core.ij.ImageJUtils)8 ExtendedGenericDialog (uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog)8 MathUtils (uk.ac.sussex.gdsc.core.utils.MathUtils)8 TIntProcedure (gnu.trove.procedure.TIntProcedure)7