public H2D() { offset = new MultiIndex(xAxis.getNBins(), yAxis.getNBins()); hBuffer = new double[offset.getArraySize()]; this.attr.getProperties().setProperty("title", ""); this.attr.getProperties().setProperty("xtitle", ""); this.attr.getProperties().setProperty("ytitle", ""); }
/** * Sets the bins to the x and y axes and creates the buffer of the histogram * * @param bx number of bins on the x axis * @param xmin the minimum value on the x axis * @param xmax the maximum value on the x axis * @param by number of bins on the y axis * @param ymin the minimum value on the y axis * @param ymax the maximum value on the y axis */ public final void set(int bx, double xmin, double xmax, int by, double ymin, double ymax) { xAxis.set(bx, xmin, xmax); yAxis.set(by, ymin, ymax); offset = new MultiIndex(bx, by); int buff = offset.getArraySize(); hBuffer = new double[buff]; }
/** * Finds which bin has that value. * * @param x The x value to search for * @param y The y value to search for * @return The bin, in array indexing format, which holds that x-y value */ public int findBin(double x, double y) { int bx = xAxis.getBin(x); int by = yAxis.getBin(y); if (this.isValidBins(bx, by)) { return (offset.getArrayIndex(bx, by)); } return -1; }
/** * Creates a 2D Histogram with the specified parameters. * * @param name the name of the histogram * @param bx the number of x axis bins * @param xmin the minimum x axis value * @param xmax the maximum x axis value * @param by the number of y axis bins * @param ymin the minimum y axis value * @param ymax the maximum y axis value */ public H2D(String name, int bx, double xmin, double xmax, int by, double ymin, double ymax) { hName = name; this.set(bx, xmin, xmax, by, ymin, ymax); offset = new MultiIndex(bx, by); hBuffer = new double[offset.getArraySize()]; this.attr.getProperties().setProperty("title", ""); this.attr.getProperties().setProperty("xtitle", ""); this.attr.getProperties().setProperty("ytitle", ""); }
/** * Finds the bin content at that bin * * @param bx The x coordinate of the bin * @param by The y coordinate of the bin * @return The content at that bin */ public double getBinContent(int bx, int by) { if (this.isValidBins(bx, by)) { int buff = offset.getArrayIndex(bx, by); if (buff >= 0 && buff < hBuffer.length) { return hBuffer[buff]; } else { System.out.println("[Index] error for binx = " + bx + " biny = " + by); } } return 0.0; }
/* * Test MultiIndex. */ @SuppressWarnings("unchecked") @Test public void test_MultiIndex() throws Exception { ApplicationSetup.setProperty("termpipelines", ""); ApplicationSetup.setProperty("indexer.meta.forward.keys", "filename"); ApplicationSetup.setProperty("indexer.meta.forward.keylens", "100"); ApplicationSetup.setProperty("indexer.meta.reverse.keys", "filename"); Index i1 = IndexTestUtils.makeIndex(new String[] {"0"}, new String[] {"one two three"}); Index i2 = IndexTestUtils.makeIndex(new String[] {"1"}, new String[] {"two three four"}); Index i3 = IndexTestUtils.makeIndex(new String[] {"2"}, new String[] {"three four five"}); MultiIndex mindex = new MultiIndex(new Index[] {i1, i2, i3}); assertNotNull(mindex); Lexicon<String> lexicon = (Lexicon<String>) mindex.getIndexStructure("lexicon"); assertNotNull(lexicon); PostingIndex<?> inverted = (PostingIndex<?>) mindex.getIndexStructure("inverted"); assertNotNull(inverted); MetaIndex metaindex = (MetaIndex) mindex.getIndexStructure("meta"); assertNotNull(metaindex); DocumentIndex docindex = (DocumentIndex) mindex.getIndexStructure("document"); assertNotNull(docindex); CollectionStatistics stats = (CollectionStatistics) mindex.getIndexStructure("collectionstatistics"); assertNotNull(stats); }
/** * Sets the bin to that value * * @param bx The x coordinate of the bin * @param by The y coordinate of the bin * @param w The desired value to set the bin to */ public void setBinContent(int bx, int by, double w) { if (this.isValidBins(bx, by)) { int buff = offset.getArrayIndex(bx, by); hBuffer[buff] = w; } }