/** * Convert the given 2d byte array to a 2d array of ints. * The bytes are assumed to actually represent int * values in the range 0..255, and so have 128 added * to each value. * * @param arr the byte array * @return an array of ints */ public static int[][] byteToInt(byte [][] arr) { int[][] ret = new int[arr.length][]; for(int i = 0; i < arr.length; i++){ ret[i] = byteToInt(arr[i]); } return ret; }
/** * Convert the given 2d int array to a 2d array of bytes. * The ints are assumed to be in the range 0..255, * and so 128 is subtracted before casting to a byte. * * @param arr the int array * @return an array of bytes */ public static byte[][] intToByte(int [][] arr) { byte[][] ret = new byte[arr.length][]; for(int i = 0; i < arr.length; i++){ ret[i] = intToByte(arr[i]); } return ret; } }
@Override public SpatialClusters<int[]> create(byte[][] data) { final IntRandomForest rf = new IntRandomForest(ntrees, decisions); rf.cluster(ByteArrayConverter.byteToInt(data)); return rf; }
this.sampleKeypoints = (byte[][]) read; } else { this.sampleKeypoints = ByteArrayConverter.intToByte((int[][]) read);
@Override public SpatialClusters<int[]> create(byte[][] data) { IntKMeans c = null; c = new IntKMeans(confInt(data[0].length)); return c.cluster(ByteArrayConverter.byteToInt(data)); }
else cluster = ((HardAssigner<int[], ?, ?>) assigner).assign(ByteArrayConverter .byteToInt(fff.data));
else cluster = ((HardAssigner<int[], ?, ?>) assigner).assign(ByteArrayConverter .byteToInt(fff.data)); pw.format("%s %d\n", fff.location.trim(), cluster);
@Override public SpatialClusters<?> create(byte[][] data) { if (this.precision == Precision.BYTE) { RandomSetByteClusterer c = null; c = new RandomSetByteClusterer(data[0].length, K); if (seed >= 0) c.setSeed(seed); System.err.printf("Building BYTE vocabulary tree\n"); return c.cluster(data); } else { RandomSetIntClusterer c = null; c = new RandomSetIntClusterer(data[0].length, K); if (seed >= 0) c.setSeed(seed); System.err.printf("Building INT vocabulary tree\n"); return c.cluster(ByteArrayConverter.byteToInt(data)); } }
@Override public SpatialClusters<?> create(byte[][] data) { if (this.precision == Precision.BYTE) { RandomByteClusterer c = null; c = new RandomByteClusterer(data[0].length, K); if (seed >= 0) c.setSeed(seed); System.err.printf("Building BYTE vocabulary tree\n"); return c.cluster(data); } else { RandomIntClusterer c = null; c = new RandomIntClusterer(data[0].length, K); if (seed >= 0) c.setSeed(seed); System.err.printf("Building INT vocabulary tree\n"); return c.cluster(ByteArrayConverter.byteToInt(data)); } }
if (samplesToLoad.size() == 0) continue; final int[][] features = ByteArrayConverter.byteToInt(sb.getStoredSamples(samplesToLoad.toArray())); for (int i = 0; i < samplesToLoad.size(); i++) { int j = 0;
@Override public void getData(int startRow, int stopRow, int[][] output) { int added = 0; for (final SampleBatch sb : batches) { try { if (sb.getEndIndex() < startRow) continue; // Before this range if (sb.getStartIndex() > stopRow) continue; // After this range // So it must be within this range in some sense, find out where final int startDelta = startRow - sb.getStartIndex(); final int stopDelta = stopRow - sb.getStartIndex(); final int interestedStart = startDelta < 0 ? 0 : startDelta; final int interestedEnd = stopDelta + sb.getStartIndex() > sb.getEndIndex() ? sb.getEndIndex() - sb.getStartIndex() : stopDelta; final int[][] subSamples = ByteArrayConverter.byteToInt(sb.getStoredSamples(interestedStart, interestedEnd)); for (int i = 0; i < subSamples.length; i++) { System.arraycopy(subSamples[i], 0, output[added + i], 0, subSamples[i].length); } added += subSamples.length; } catch (final Exception e) { e.printStackTrace(); } } }
@Override public SpatialClusters<?> create(byte[][] data) { if (this.precision == Precision.BYTE) { final KMeansConfiguration<ByteNearestNeighbours, byte[]> kmc = new KMeansConfiguration<ByteNearestNeighbours, byte[]>(); if (exactMode) { kmc.setNearestNeighbourFactory(new ByteNearestNeighboursExact.Factory()); } else { kmc.setNearestNeighbourFactory(new ByteNearestNeighboursKDTree.Factory()); } final HierarchicalByteKMeans tree = new HierarchicalByteKMeans(kmc, data[0].length, K, depth); System.err.printf("Building vocabulary tree\n"); return tree.cluster(data); } else { final KMeansConfiguration<IntNearestNeighbours, int[]> kmc = new KMeansConfiguration<IntNearestNeighbours, int[]>(); if (exactMode) { kmc.setNearestNeighbourFactory(new IntNearestNeighboursExact.Factory()); } else { kmc.setNearestNeighbourFactory(new IntNearestNeighboursKDTree.Factory()); } final HierarchicalIntKMeans tree = new HierarchicalIntKMeans(kmc, data[0].length, K, depth); System.err.printf("Building vocabulary tree\n"); return tree.cluster(ByteArrayConverter.byteToInt(data)); } }
@Override public SpatialClusters<?> create(byte[][] data) throws Exception { SpatialClusterer<?, ?> c = null; if (this.precision == Precision.BYTE) { c = new ByteKMeans(confByte(data[0].length)); ((ByteKMeans) c).seed(seed); if (clusterInitOp == null) clusterInitOp = clusterInit.getOptions(); clusterInitOp.setClusterInit((ByteKMeans) c); return ((ByteKMeans) c).cluster(data); } else { c = new IntKMeans(confInt(data[0].length)); ((IntKMeans) c).seed(seed); return ((IntKMeans) c).cluster(ByteArrayConverter.byteToInt(data)); } }