public static Histogram<String> build(ArrayList<String> mlList) { Histogram<String> hm = new Histogram<>(); for (String ml : mlList) { hm.increment(new Mail(ml).getDomain()); } return hm; }
private DefaultCategoryDataset createDataset() { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); for (String key : histogram.keySet()) { dataset.addValue(histogram.get(key), "", key); } return dataset; }
public void testUInt_withValidator() { final int[][] values = new int[][] { TestHelper.createUInts( new long[] { 2147483644L, 2147483645L, 2147483646L, 2147483647L, 2147483648L, 2147483649L, 2147483650L, 2147483651L }), TestHelper.createUInts(new long[] {2147483645L, 2147483647L, 2147483649L, 2147483651L}), TestHelper.createUInts(new long[] {2147483647L, 2147483648L, 2147483649L}) }; final boolean unsigned = true; final IndexValidator validator = new IndexValidator() { public boolean validateIndex(int index) { return index % 3 != 0; } }; final Histogram histogram = new Histogram(new int[6], 2147483645, 2147483650L); for (int i = 0; i < values.length; i++) { histogram.aggregate(values[i], unsigned, validator, ProgressMonitor.NULL); } final int[] exp = new int[] {1, 1, 1, 2, 3, 0}; assertEquals("", equal(exp, histogram.getBinCounts())); }
@Override public double computeLikelihood(int classIndex, AttributeValue v) { if (v instanceof Null) return 1.0; if (!(v instanceof Histogram)) throw new IllegalArgumentException( "Error: value " + v + " is not a Histogram for OntologyBernoulliEstimator."); Histogram val = null; if (v instanceof MappedHistogram) { List<URI> domain = mCut.get(); MappedHistogram allV = (MappedHistogram) v; val = allV.induce(domain); } else { val = (Histogram) v; } if (val.size() != mCut.size()) throw new IllegalArgumentException( "Error: size of " + v + " (" + val.size() + ") does not match the size of current cut (" + mCut.size() + ")."); initLikelihood(); Log.info(Arrays.toString(val.getIntArray(0))); return MathUtil.logBernoulliDist(mParameters[classIndex], val.getIntArray(0)); }
public void testUInt() { final int[][] values = new int[][] { TestHelper.createUInts( new long[] { 2147483644L, 2147483645L, 2147483646L, 2147483647L, 2147483648L, 2147483649L, 2147483650L, 2147483651L }), TestHelper.createUInts(new long[] {2147483645L, 2147483647L, 2147483649L, 2147483651L}), TestHelper.createUInts(new long[] {2147483647L, 2147483648L, 2147483649L}) }; final boolean unsigned = true; final Histogram histogram = new Histogram(new int[6], 2147483645, 2147483650L); for (int i = 0; i < values.length; i++) { histogram.aggregate(values[i], unsigned, IndexValidator.TRUE, ProgressMonitor.NULL); } final int[] exp = new int[] {2, 1, 3, 2, 3, 1}; assertEquals("", equal(exp, histogram.getBinCounts())); }
@Override protected int[] filterPixels(int width, int height, int[] inPixels, Rect transformedSpace) { Histogram histogram = new Histogram(inPixels, width, height, 0, width); int i, j; if (histogram.getNumSamples() > 0) { lut = new int[3][256]; float low = lowLevel * 255; float high = highLevel * 255; if (low == high) high++; for (i = 0; i < 3; i++) { for (j = 0; j < 256; j++) lut[i][j] = PixelUtils.clamp( (int) (255 * (lowOutputLevel + (highOutputLevel - lowOutputLevel) * (j - low) / (high - low)))); } } else lut = null; i = 0; for (int y = 0; y < height; y++) for (int x = 0; x < width; x++) { inPixels[i] = filterRGB(x, y, inPixels[i]); i++; } lut = null; return inPixels; }
public static Histogram<String> build(ArrayList<String> mailList) { Histogram<String> histo = new Histogram<>(); for (String mail : mailList) { histo.increment(new Mail(mail).getDominio()); } return histo; }
public double computeLL() { if (mLL == null) { mLL = 0.0; for (int j = 0; j < mClassHistogram.size(); j++) { mLL += mClassHistogram.get(j) * Math.log(mClassHistogram.get(j) / mNumInstances); } } return mLL; }
public static void main(String[] args) { Integer[] array = {2, 2, 11, 4, 2, 6, 11, 2, 3, 5, 11, 5, 100}; String[] array1 = {"Ana", "Juan", "Pedro", "Juan", "Pedro", "Juan", "Pedro"}; Histogram<Integer> histogram = BuildHisto.computHisto(array); for (Object key : histogram.keySet()) { System.out.println(key + ":" + histogram.get(key)); } }
public void actionPerformed(ActionEvent event) { Object source = new Object(); source = event.getSource(); String data, histo = ""; if (source == btnRun) { Histogram gram = new Histogram(txtWord.getText()); data = gram.getData(); histo = gram.getHistogram(); JOptionPane.showMessageDialog(null, data + "\n" + histo); } }
@Test public void testScheduleFixedRateCallable() throws Exception { assertThat(submitted.getCount()).isZero(); assertThat(running.getCount()).isZero(); assertThat(completed.getCount()).isZero(); assertThat(duration.getCount()).isZero(); assertThat(scheduledOnce.getCount()).isZero(); assertThat(scheduledRepetitively.getCount()).isZero(); assertThat(scheduledOverrun.getCount()).isZero(); assertThat(percentOfPeriod.getCount()).isZero(); ScheduledFuture<?> theFuture = instrumentedScheduledExecutor.scheduleAtFixedRate( new Runnable() { public void run() { assertThat(submitted.getCount()).isZero(); assertThat(running.getCount()).isEqualTo(1); assertThat(scheduledOnce.getCount()).isEqualTo(0); assertThat(scheduledRepetitively.getCount()).isEqualTo(1); try { TimeUnit.MILLISECONDS.sleep(50); } catch (InterruptedException ex) { Thread.currentThread().interrupt(); } return; } }, 10L, 10L, TimeUnit.MILLISECONDS); TimeUnit.MILLISECONDS.sleep(100); theFuture.cancel(true); TimeUnit.MILLISECONDS.sleep(100); assertThat(submitted.getCount()).isZero(); assertThat(running.getCount()).isZero(); assertThat(completed.getCount()).isNotEqualTo(0); assertThat(duration.getCount()).isNotEqualTo(0); assertThat(duration.getSnapshot().size()).isNotEqualTo(0); assertThat(scheduledOnce.getCount()).isZero(); assertThat(scheduledRepetitively.getCount()).isEqualTo(1); assertThat(scheduledOverrun.getCount()).isNotEqualTo(0); assertThat(percentOfPeriod.getCount()).isNotEqualTo(0); }
protected void setUp() throws Exception { // Cluster a bunch in the center int min = RANGE / 3; for (int i = 0; i < NUM_SAMPLES; i++) { int val = rand.nextInt(min) + min; h.put(val); fast_h.fastPut(val); } for (int i = 0; i < NUM_SAMPLES; i++) { int val = rand.nextInt(RANGE); h.put(val); fast_h.fastPut(val); } }
@Override public void processHistogram(MetricName name, Histogram histogram, PrintStream stream) { final Snapshot snapshot = histogram.getSnapshot(); stream.printf(locale, " min = %2.2f\n", histogram.getMin()); stream.printf(locale, " max = %2.2f\n", histogram.getMax()); stream.printf(locale, " mean = %2.2f\n", histogram.getMean()); stream.printf(locale, " stddev = %2.2f\n", histogram.getStdDev()); stream.printf(locale, " median = %2.2f\n", snapshot.getMedian()); stream.printf(locale, " 75%% <= %2.2f\n", snapshot.get75thPercentile()); stream.printf(locale, " 95%% <= %2.2f\n", snapshot.get95thPercentile()); stream.printf(locale, " 98%% <= %2.2f\n", snapshot.get98thPercentile()); stream.printf(locale, " 99%% <= %2.2f\n", snapshot.get99thPercentile()); stream.printf(locale, " 99.9%% <= %2.2f\n", snapshot.get999thPercentile()); }
@Test public void testScheduleCallable() throws Exception { assertThat(submitted.getCount()).isZero(); assertThat(running.getCount()).isZero(); assertThat(completed.getCount()).isZero(); assertThat(duration.getCount()).isZero(); assertThat(scheduledOnce.getCount()).isZero(); assertThat(scheduledRepetitively.getCount()).isZero(); assertThat(scheduledOverrun.getCount()).isZero(); assertThat(percentOfPeriod.getCount()).isZero(); final Object obj = new Object(); ScheduledFuture<Object> theFuture = instrumentedScheduledExecutor.schedule( new Callable<Object>() { public Object call() { assertThat(submitted.getCount()).isZero(); assertThat(running.getCount()).isEqualTo(1); assertThat(completed.getCount()).isZero(); assertThat(duration.getCount()).isZero(); assertThat(scheduledOnce.getCount()).isEqualTo(1); assertThat(scheduledRepetitively.getCount()).isZero(); assertThat(scheduledOverrun.getCount()).isZero(); assertThat(percentOfPeriod.getCount()).isZero(); return obj; } }, 10L, TimeUnit.MILLISECONDS); assertThat(theFuture.get()).isEqualTo(obj); assertThat(submitted.getCount()).isZero(); assertThat(running.getCount()).isZero(); assertThat(completed.getCount()).isEqualTo(1); assertThat(duration.getCount()).isEqualTo(1); assertThat(duration.getSnapshot().size()).isEqualTo(1); assertThat(scheduledOnce.getCount()).isEqualTo(1); assertThat(scheduledRepetitively.getCount()).isZero(); assertThat(scheduledOverrun.getCount()).isZero(); assertThat(percentOfPeriod.getCount()).isZero(); }
@Test public void testSampleRange() { Histogram h = new Histogram(40, 2); double base = 1; for (int i = 0; i < 40; i++) { // System.out.println(i); assertEquals(i * 4 + 0, h.sample(base)); assertEquals(i * 4 + 1, h.sample(base * 1.25)); assertEquals(i * 4 + 2, h.sample(base * 1.5)); assertEquals(i * 4 + 3, h.sample(base * 1.75)); base *= 2; } // System.out.println(base); }
// TODO handle uncaught exceptions public FitsImage(Fits fitsFile, ImageController controller) throws FitsException, IOException { this.controller = controller; this.fitsFile = fitsFile; this.hdu = (ImageHDU) fitsFile.getHDU(0); ; width = hdu.getAxes()[1]; height = hdu.getAxes()[0]; this.tiler = hdu.getTiler(); setNanColour(controller.getNanColour()); prepareData(); createHistogram(); minValue = histogram.getMinValue(); maxValue = histogram.getMaxValue(); writeImage(); }
@Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub if (e.getSource() == columnView) { histogram.switchColumnView(); } if (e.getSource() == lineView) { histogram.switchLineView(); } if (e.getSource() == numberView) { histogram.switchNumberView(); } }
public void testRule(NumericalRule rule, int minSupport, float minAccuracy) throws SQLException { // System.out.println("!!!"+rule.getRuleString()+"!!!"); String prediction = rule.getHead().getConstant(); int positivesCount = 0; int negativesCount = 0; String sparql = createTestQuery(rule); // System.out.println(sparql); long t = System.currentTimeMillis(); ResultSet rs = (ResultSet) qh.executeQuery(sparql); // System.out.println("Executed in "+(System.currentTimeMillis()-t)); float overallAcc = ((float) ArrayTools.sum( ArrayTools.multiply( rule.getAccuracyDistribution(), rule.getSupportDistribution()))) / ((float) ArrayTools.sum(rule.getSupportDistribution())); float[] acc = ArrayTools.getAccuraciesWithMinSupport( rule.getSupportDistribution(), rule.getBodySupportDistribution(), minSupport); String ranges = ""; for (int i = 0; i < acc.length; i++) { if (acc[i] >= minAccuracy) ranges += "+"; else ranges += "-"; } // System.out.println(ranges); // ArrayTools.print(acc); float lastNum = Float.NaN; while (rs.next()) { float num = rs.getFloat(1); String observation = rs.getString(2).replaceAll("\"", ""); int count = rs.getInt(3); int bucket = histogram.getBucket(num); if (acc[bucket] >= minAccuracy) { if (prediction.equals(observation)) positivesCount += count; else negativesCount += count; } lastNum = num; } int coveringCount = positivesCount + negativesCount; float predictionAccuracy = ((float) positivesCount) / (((float) (coveringCount))); // System.out.println(rule.getRuleString() + "\n[" + predictionAccuracy + "," + coveringCount + // "] = ("+positivesCount+"/"+negativesCount+")"); rule.observedConfidence = predictionAccuracy; rule.observedPositives = positivesCount; rule.observedNegatives = negativesCount; rule.observedOverallConfidence = overallAcc; }
// @Override public Snapshot getSnapshot() { final double[] values = histogram.getSnapshot().getValues(); final double[] converted = new double[values.length]; for (int i = 0; i < values.length; i++) { converted[i] = convertFromNS(values[i]); } return new Snapshot(converted); }
public void testFloat() { final float[][] values = new float[][] { new float[] {-3, -2, -1, 0, 1, 2, 3, 4}, new float[] {-2, 0, 2, 4}, new float[] {0, 1, 2} }; final boolean unsigned = false; final Histogram histogram = new Histogram(new int[6], -2, 3); for (int i = 0; i < values.length; i++) { histogram.aggregate(values[i], unsigned, IndexValidator.TRUE, ProgressMonitor.NULL); } final int[] exp = new int[] {2, 1, 3, 2, 3, 1}; assertEquals("", equal(exp, histogram.getBinCounts())); }
@Test public void testScheduleRunnable() throws Exception { assertThat(submitted.getCount()).isZero(); assertThat(running.getCount()).isZero(); assertThat(completed.getCount()).isZero(); assertThat(duration.getCount()).isZero(); assertThat(scheduledOnce.getCount()).isZero(); assertThat(scheduledRepetitively.getCount()).isZero(); assertThat(scheduledOverrun.getCount()).isZero(); assertThat(percentOfPeriod.getCount()).isZero(); ScheduledFuture<?> theFuture = instrumentedScheduledExecutor.schedule( new Runnable() { public void run() { assertThat(submitted.getCount()).isZero(); assertThat(running.getCount()).isEqualTo(1); assertThat(completed.getCount()).isZero(); assertThat(duration.getCount()).isZero(); assertThat(scheduledOnce.getCount()).isEqualTo(1); assertThat(scheduledRepetitively.getCount()).isZero(); assertThat(scheduledOverrun.getCount()).isZero(); assertThat(percentOfPeriod.getCount()).isZero(); } }, 10L, TimeUnit.MILLISECONDS); theFuture.get(); assertThat(submitted.getCount()).isZero(); assertThat(running.getCount()).isZero(); assertThat(completed.getCount()).isEqualTo(1); assertThat(duration.getCount()).isEqualTo(1); assertThat(duration.getSnapshot().size()).isEqualTo(1); assertThat(scheduledOnce.getCount()).isEqualTo(1); assertThat(scheduledRepetitively.getCount()).isZero(); assertThat(scheduledOverrun.getCount()).isZero(); assertThat(percentOfPeriod.getCount()).isZero(); }
public void testDoubleArray() { final DoubleList[] values = new DoubleList[] { TestHelper.createArray(new int[] {-3, -2, -1, 0, 1, 2, 3, 4}), TestHelper.createArray(new int[] {-2, 0, 2, 4}), TestHelper.createArray(new int[] {0, 1, 2}) }; final boolean unsigned = false; final Histogram histogram = new Histogram(new int[6], -2, 3); for (int i = 0; i < values.length; i++) { histogram.aggregate(values[i], unsigned, IndexValidator.TRUE, ProgressMonitor.NULL); } final int[] exp = new int[] {2, 1, 3, 2, 3, 1}; assertEquals("", equal(exp, histogram.getBinCounts())); }
public void testUByte() { final byte[][] values = new byte[][] { TestHelper.createUBytes(new short[] {124, 125, 126, 127, 128, 129, 130, 131}), TestHelper.createUBytes(new short[] {125, 127, 129, 131}), TestHelper.createUBytes(new short[] {127, 128, 129}) }; final boolean unsigned = true; final Histogram histogram = new Histogram(new int[6], 125, 130); for (int i = 0; i < values.length; i++) { histogram.aggregate(values[i], unsigned, IndexValidator.TRUE, ProgressMonitor.NULL); } final int[] exp = new int[] {2, 1, 3, 2, 3, 1}; assertEquals("", equal(exp, histogram.getBinCounts())); }
private void initLikelihood() { if (mParameters != null) return; mParameters = new double[mClassHistogram.size()][]; for (int j = 0; j < mClassHistogram.size(); j++) { Map<URI, Double> valueHistogram = mValueHistograms.get(j); final double classCount = mClassHistogram.get(j); mParameters[j] = new double[mCut.size()]; for (int i = 0; i < mParameters[j].length; i++) { URI key = mCut.get().get(i); mParameters[j][i] = (valueHistogram.get(key) + 1.0) / (classCount + 2.0); } Log.info(Arrays.toString(mParameters[j])); } }
public void testUShort() { final short[][] values = new short[][] { TestHelper.createUShorts( new int[] {32764, 32765, 32766, 32767, 32768, 32769, 32770, 32771}), TestHelper.createUShorts(new int[] {32765, 32767, 32769, 32771}), TestHelper.createUShorts(new int[] {32767, 32768, 32769}) }; final boolean unsigned = true; final Histogram histogram = new Histogram(new int[6], 32765, 32770); for (int i = 0; i < values.length; i++) { histogram.aggregate(values[i], unsigned, IndexValidator.TRUE, ProgressMonitor.NULL); } final int[] exp = new int[] {2, 1, 3, 2, 3, 1}; assertEquals("", equal(exp, histogram.getBinCounts())); }
@Override public void GenerateFeatures(EntityMention mention) throws SQLException { Set<String> words = new HashSet<String>(); for (Sentence sentence : document) { words.addAll(Arrays.asList(sentence.getTokens())); } // get a histogram of all words in sentences Histogram documentHistogram = Histogram.extractFromSentenceArray(document, words); Map<Entity, Features> candidateFeatures = mention.candidateFeatures; for (Entry<Entity, Features> entry : candidateFeatures.entrySet()) { Entity candidate = entry.getKey(); String[] tokens = Util.tokenizeText(wiki.GetCleanedWikiText(candidate.wikiTitle)); Histogram hist = Histogram.fromTokens(tokens); double dotProduct = Util.computeDotProduct(documentHistogram, hist); entry.getValue().setFeature(GetFeatureName(), dotProduct); } }
private static void checkZeros(ExpDataManager expMan) { int neverabove = 0; int sometimes = 0; int always = 0; Histogram h = new Histogram(0.1); for (String gene : HGNC.getAllSymbols()) { if (!expMan.contains(gene)) continue; double r = expMan.getNonZeroRatio(gene); h.count(r); if (r == 0) neverabove++; else if (r == 1) always++; else sometimes++; } System.out.println("neverabove = " + neverabove); System.out.println("always = " + always); System.out.println("sometimes = " + sometimes); h.print(); }
private synchronized void computeHistogram(Rectangle visibleRect, PlanarImage image) { int channels = image.getSampleModel().getNumBands(); Histogram hist = new Histogram(256, 256, 512, channels); bins = hist.getBins(); // Raster raster = image.getData(visibleRect); Rectangle bounds = visibleRect; // image.getBounds(); int pixel[] = null; int maxPixels = 256; int incX = bounds.width >= 2 * maxPixels ? bounds.width / maxPixels : 1; int incY = bounds.height >= 2 * maxPixels ? bounds.height / maxPixels : 1; double log2 = Math.log(2); int minTileX = image.XToTileX(bounds.x); int maxTileX = image.XToTileX(bounds.x + bounds.width - 1); int minTileY = image.YToTileY(bounds.y); int maxTileY = image.YToTileY(bounds.y + bounds.height - 1); for (int tx = minTileX; tx <= maxTileX; tx++) for (int ty = minTileY; ty <= maxTileY; ty++) { Raster raster = image.getTile(tx, ty); int minX = Math.max(bounds.x, raster.getMinX()); int maxX = Math.min(bounds.x + bounds.width, raster.getMinX() + raster.getWidth()); int minY = Math.max(bounds.y, raster.getMinY()); int maxY = Math.min(bounds.y + bounds.height, raster.getMinY() + raster.getHeight()); for (int x = minX; x < maxX; x += incX) for (int y = minY; y < maxY; y += incY) { pixel = raster.getPixel(x, y, pixel); for (int c = 0; c < channels; c++) { int v = (int) (511 * logTable[pixel[c]] / (16 * log2)); if (v > 255) bins[c][v - 256]++; else bins[c][0]++; } } } bins = hist.getBins(); }
private IntervalXYDataset getHistrogrammedDataAttributes( String[] attributes, long barsize, long timesize) { IntervalXYDataset dataset = null; if (no_intervals) { dataset = new XYSeriesCollection(); } else { dataset = new YIntervalSeriesCollection(); } for (int index = 0; index < attributes.length; index++) { Histogram histogram = new Histogram(barsize); String attribute = attributes[index]; for (ProcessInstance pi : mylog.getInstances()) { Date begin; try { begin = pi.getAuditTrailEntryList().get(0).getTimestamp(); } catch (Exception e) { Message.add(e.getMessage(), Message.ERROR); return null; } // starting time of process instance int j = 0; for (AuditTrailEntry ate : pi.getListOfATEs()) { if (ate.getAttributes().containsKey(attribute)) { Double val; val = Double.valueOf(ate.getAttributes().get(attribute)); if (xbox.getSelectedIndex() == 2) { histogram.addValue(j, val); } if (xbox.getSelectedIndex() == 3) { histogram.addValue(timediff(begin, ate.getTimestamp()), val); } j++; } } } if (no_intervals) { ((XYSeriesCollection) dataset).addSeries(histogram.getXYSeries(attribute, timesize)); } else { ((YIntervalSeriesCollection) dataset) .addSeries(histogram.getYIntervalSeries(attribute, timesize)); } } return dataset; }
private void validateHistogram( final Index index, int expectedColumns, HistogramEntryDescription... entries) { final IndexStatisticsService statsService = statsService(); if (analyzedIndexes.add(index)) { ddl() .updateTableStatistics( session(), index.leafMostTable().getName(), Collections.singleton(index.getIndexName().getName())); } if (entries != null) { IndexStatistics stats = statsService.getIndexStatistics(session(), index); Histogram histogram = stats.getHistogram(0, expectedColumns); assertEquals("histogram column count", expectedColumns, histogram.getColumnCount()); List<HistogramEntry> actualEntries = histogram.getEntries(); List<HistogramEntryDescription> expectedList = Arrays.asList(entries); AssertUtils.assertCollectionEquals("entries", expectedList, actualEntries); } }