public int size() { return queue.size(); }
public float getMeanWrongness() { if (queue.isEmpty()) return Float.NaN; return (float) queue.stream().mapToDouble((er -> er.wrongness)).sum() / queue.size(); } }
/** * Return a random sample of exactly numElements. * * @param numElements The number of elements to return * @return a random sample drawn with replacement. */ public List<ErrorRecord> getRandomSample(int numElements) { List<ErrorRecord> sample = new ObjectArrayList<>(); assert !queue.isEmpty() : "queue cannot be empty to return a random sample"; while (sample.size() < numElements) { for (ErrorRecord record : queue) { float value = random.nextFloat(); if (value < 1f / queue.size()) { sample.add(record); } if (sample.size() >= numElements) { break; } } } return sample; }
@Override public void reduce(IntWritable key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException { Int2IntAVLTreeMap links = new Int2IntAVLTreeMap(); // remove duplicate links for (IntWritable value : values) { if (links.containsKey(value.get())) { // increment 1 link count links.put(value.get(), links.get(value.get()) + 1); } else { links.put(value.get(), 1); } } context.getCounter(Counts.LINKS).increment(links.entrySet().size()); for (Entry<Integer, Integer> link : links.entrySet()) { String outputValue = String.valueOf(link.getKey()) + "," + String.valueOf(link.getValue()); context.write(key, new Text(outputValue)); } } }
/** * Enqueues a transcript with given score and info. * * @return true if the document has been actually enqueued. */ public synchronized boolean enqueue(float wrongness, INDArray features, INDArray label) { ErrorRecord dsi = new ErrorRecord(wrongness, features, label); if (queue.contains(dsi)) return false; if (queue.size() < maxSize) { queue.add(dsi); return true; } else { dsi = queue.first(); if (wrongness > dsi.wrongness) { queue.remove(dsi); dsi.wrongness = wrongness; dsi.features = features; dsi.label = label; queue.add(dsi); return true; } return false; } }