private Map<T, Double> normalize() { if (isNormalised) return normalised; Map<T, Double> temp = createMapDataStructure(); double highestLogProbability = Double.NEGATIVE_INFINITY; for (Entry<T, Double> entry : map.entrySet()) {
/** * Assigns a probability to a label, discarding any previously assigned probability. * * @param t the label to which the probability is being assigned * @param probability the probability to assign */ public void set(T t, double probability) { isNormalised = false; map.put(t, log(probability)); }
/** * Returns the probabilities associated with all labels * * @return the HashMap of labels and their probabilities */ public Map<T, Double> getAll() { return normalize(); }
static double[] eval(Context[] context, float[] values, double[] prior, EvalParameters model, boolean normalize) { Probabilities<Integer> probabilities = new LogProbabilities<>(); double[] outcomeTotals = model instanceof NaiveBayesEvalParameters ? ((NaiveBayesEvalParameters) model).getOutcomeTotals() : new double[prior.length];
static double[] eval(Context[] context, float[] values, double[] prior, EvalParameters model, boolean normalize) { Probabilities<Integer> probabilities = new LogProbabilities<>(); double[] outcomeTotals = model instanceof NaiveBayesEvalParameters ? ((NaiveBayesEvalParameters) model).getOutcomeTotals() : new double[prior.length];
/** * Assigns a probability to a label, discarding any previously assigned probability, * if the new probability is greater than the old one. * * @param t the label to which the probability is being assigned * @param probability the probability to assign */ public void setIfLarger(T t, double probability) { double logProbability = log(probability); Double p = map.get(t); if (p == null || logProbability > p) { isNormalised = false; map.put(t, logProbability); } }
/** * Returns the probability associated with a label * * @param t the label whose probability needs to be returned * @return the probability associated with the label */ public Double get(T t) { Double d = normalize().get(t); if (d == null) return 0.0; return d; }
private Map<T, Double> normalize() { if (isNormalised) return normalised; Map<T, Double> temp = createMapDataStructure(); double highestLogProbability = Double.NEGATIVE_INFINITY; for (Entry<T, Double> entry : map.entrySet()) {
static double[] eval(Context[] context, float[] values, double[] prior, EvalParameters model, boolean normalize) { Probabilities<Integer> probabilities = new LogProbabilities<>(); Context[] params = model.getParams(); double[] outcomeTotals = model instanceof NaiveBayesEvalParameters
/** * Compounds the existing probability mass on the label with the new probability passed in to the method. * * @param t the label whose probability mass is being updated * @param probability the probability weight to add * @param count the amplifying factor for the probability compounding */ public void addIn(T t, double probability, int count) { isNormalised = false; Double p = map.get(t); if (p == null) p = 0.0; probability = log(probability) * count; map.put(t, p + probability); }
/** * Returns the probabilities associated with all labels * * @return the HashMap of labels and their probabilities */ public Map<T, Double> getAll() { return normalize(); }
private Map<T, Double> normalize() { if (isNormalised) return normalised; Map<T, Double> temp = createMapDataStructure(); double highestLogProbability = Double.NEGATIVE_INFINITY; for (Entry<T, Double> entry : map.entrySet()) {
/** * Assigns a probability to a label, discarding any previously assigned probability. * * @param t the label to which the probability is being assigned * @param probability the probability to assign */ public void set(T t, double probability) { isNormalised = false; map.put(t, log(probability)); }
/** * Returns the probabilities associated with all labels * * @return the HashMap of labels and their probabilities */ public Map<T, Double> getAll() { return normalize(); }
/** * Assigns a probability to a label, discarding any previously assigned probability. * * @param t the label to which the probability is being assigned * @param probability the probability to assign */ public void set(T t, double probability) { isNormalised = false; map.put(t, log(probability)); }
/** * Returns the probability associated with a label * * @param t the label whose probability needs to be returned * @return the probability associated with the label */ public Double get(T t) { Double d = normalize().get(t); if (d == null) return 0.0; return d; }
/** * Compounds the existing probability mass on the label with the new probability passed in to the method. * * @param t the label whose probability mass is being updated * @param probability the probability weight to add * @param count the amplifying factor for the probability compounding */ public void addIn(T t, double probability, int count) { isNormalised = false; Double p = map.get(t); if (p == null) p = 0.0; probability = log(probability) * count; map.put(t, p + probability); }
/** * Returns the probability associated with a label * * @param t the label whose probability needs to be returned * @return the probability associated with the label */ public Double get(T t) { Double d = normalize().get(t); if (d == null) return 0.0; return d; }
/** * Assigns a probability to a label, discarding any previously assigned probability, * if the new probability is greater than the old one. * * @param t the label to which the probability is being assigned * @param probability the probability to assign */ public void setIfLarger(T t, double probability) { double logProbability = log(probability); Double p = map.get(t); if (p == null || logProbability > p) { isNormalised = false; map.put(t, logProbability); } }
/** * Assigns a probability to a label, discarding any previously assigned probability, * if the new probability is greater than the old one. * * @param t the label to which the probability is being assigned * @param probability the probability to assign */ public void setIfLarger(T t, double probability) { double logProbability = log(probability); Double p = map.get(t); if (p == null || logProbability > p) { isNormalised = false; map.put(t, logProbability); } }