code
stringlengths
73
34.1k
label
stringclasses
1 value
@Deprecated private static ArrayList<FrequencyTableEntry> hashToFreqEntries( HashMap<String, ArrayList<Integer>> hash) { ArrayList<FrequencyTableEntry> res = new ArrayList<FrequencyTableEntry>(); for (Entry<String, ArrayList<Integer>> e : hash.entrySet()) { char[] payload = e.getKey().toCharArray(...
java
private static double distance(double[] subseries, double[] series, int from, int to, double nThreshold) throws Exception { double[] subsequence = tp.znorm(tp.subseriesByCopy(series, from, to), nThreshold); Double sum = 0D; for (int i = 0; i < subseries.length; i++) { double tmp = subseries[i] -...
java
public void addShingledSeries(String key, Map<String, Integer> shingledSeries) { // allocate the weights array corresponding to the time series int[] counts = new int[this.indexTable.size()]; // fill in the counts for (String str : shingledSeries.keySet()) { Integer idx = this.indexTable.get(str);...
java
public static void main(String[] args) throws Exception { NormalAlphabet na = new NormalAlphabet(); SAXProcessor sp = new SAXProcessor(); String dataFileName = args[0]; System.out.println("data file: " + dataFileName); double[] ts = TSProcessor.readFileColumn(dataFileName, 0, 0); System.out.p...
java
public void markVisited(int loc) { if (checkBounds(loc)) { if (ZERO == this.registry[loc]) { this.unvisitedCount--; } this.registry[loc] = ONE; } else { throw new RuntimeException( "The location " + loc + " out of bounds [0," + (this.registry.length - 1) + "]"); ...
java
public void markVisited(int from, int upTo) { if (checkBounds(from) && checkBounds(upTo - 1)) { for (int i = from; i < upTo; i++) { this.markVisited(i); } } else { throw new RuntimeException("The location " + from + "," + upTo + " out of bounds [0," + (this.registry.lengt...
java
public int getNextRandomUnvisitedPosition() { // if all are visited, return -1 // if (0 == this.unvisitedCount) { return -1; } // if there is space continue with random sampling // int i = this.randomizer.nextInt(this.registry.length); while (ONE == registry[i]) { i = this....
java
public boolean isNotVisited(int loc) { if (checkBounds(loc)) { return (ZERO == this.registry[loc]); } else { throw new RuntimeException( "The location " + loc + " out of bounds [0," + (this.registry.length - 1) + "]"); } }
java
public boolean isVisited(int from, int upTo) { if (checkBounds(from) && checkBounds(upTo - 1)) { // perform the visit check // for (int i = from; i < upTo; i++) { if (ONE == this.registry[i]) { return true; } } return false; } else { throw new Ru...
java
public boolean isVisited(int loc) { if (checkBounds(loc)) { return (ONE == this.registry[loc]); } else { throw new RuntimeException( "The location " + loc + " out of bounds [0," + (this.registry.length - 1) + "]"); } }
java
public ArrayList<Integer> getUnvisited() { if (0 == this.unvisitedCount) { return new ArrayList<Integer>(); } ArrayList<Integer> res = new ArrayList<Integer>(this.unvisitedCount); for (int i = 0; i < this.registry.length; i++) { if (ZERO == this.registry[i]) { res.add(i); } ...
java
public ArrayList<Integer> getVisited() { if (0 == (this.registry.length - this.unvisitedCount)) { return new ArrayList<Integer>(); } ArrayList<Integer> res = new ArrayList<Integer>(this.registry.length - this.unvisitedCount); for (int i = 0; i < this.registry.length; i++) { if (ONE == this.r...
java
public static Map<String, List<double[]>> readUCRData(String fileName) throws IOException, NumberFormatException { Map<String, List<double[]>> res = new HashMap<String, List<double[]>>(); BufferedReader br = new BufferedReader(new FileReader(new File(fileName))); String line = ""; while ((line =...
java
public static String datasetStats(Map<String, List<double[]>> data, String name) { int globalMinLength = Integer.MAX_VALUE; int globalMaxLength = Integer.MIN_VALUE; double globalMinValue = Double.MAX_VALUE; double globalMaxValue = Double.MIN_VALUE; for (Entry<String, List<double[]>> e : data.entr...
java
public static void saveData(Map<String, List<double[]>> data, File file) throws IOException { BufferedWriter bw = new BufferedWriter(new FileWriter(file)); for (Entry<String, List<double[]>> classEntry : data.entrySet()) { String classLabel = classEntry.getKey(); for (double[] arr : classEntry.get...
java
public double[] readTS(String dataFileName, int loadLimit) throws SAXException, IOException { Path path = Paths.get(dataFileName); if (!(Files.exists(path))) { throw new SAXException("unable to load data - data source not found."); } BufferedReader reader = Files.newBufferedReader(path, D...
java
public double max(double[] series) { double max = Double.MIN_VALUE; for (int i = 0; i < series.length; i++) { if (max < series[i]) { max = series[i]; } } return max; }
java
public double min(double[] series) { double min = Double.MAX_VALUE; for (int i = 0; i < series.length; i++) { if (min > series[i]) { min = series[i]; } } return min; }
java
public double mean(double[] series) { double res = 0D; int count = 0; for (double tp : series) { res += tp; count += 1; } if (count > 0) { return res / ((Integer) count).doubleValue(); } return Double.NaN; }
java
public double median(double[] series) { double[] clonedSeries = series.clone(); Arrays.sort(clonedSeries); double median; if (clonedSeries.length % 2 == 0) { median = (clonedSeries[clonedSeries.length / 2] + (double) clonedSeries[clonedSeries.length / 2 - 1]) / 2; } els...
java
public double stDev(double[] series) { double num0 = 0D; double sum = 0D; int count = 0; for (double tp : series) { num0 = num0 + tp * tp; sum = sum + tp; count += 1; } double len = ((Integer) count).doubleValue(); return Math.sqrt((len * num0 - sum * sum) / (len ...
java
public double[] znorm(double[] series, double normalizationThreshold) { double[] res = new double[series.length]; double sd = stDev(series); if (sd < normalizationThreshold) { // return series.clone(); // return array of zeros return res; } double mean = mean(series); ...
java
public char[] ts2String(double[] vals, double[] cuts) { char[] res = new char[vals.length]; for (int i = 0; i < vals.length; i++) { res[i] = num2char(vals[i], cuts); } return res; }
java
public int[] ts2Index(double[] series, double[] cuts) throws Exception { int[] res = new int[series.length]; for (int i = 0; i < series.length; i++) { res[i] = num2index(series[i], cuts); } return res; }
java
public char num2char(double value, double[] cuts) { int idx = 0; if (value >= 0) { idx = cuts.length; while ((idx > 0) && (cuts[idx - 1] > value)) { idx--; } } else { while ((idx < cuts.length) && (cuts[idx] <= value)) { idx++; } } retur...
java
public int num2index(double value, double[] cuts) { int count = 0; while ((count < cuts.length) && (cuts[count] <= value)) { count++; } return count; }
java
public double[] subseriesByCopy(double[] series, int start, int end) throws IndexOutOfBoundsException { if ((start > end) || (start < 0) || (end > series.length)) { throw new IndexOutOfBoundsException("Unable to extract subseries, series length: " + series.length + ", start: " + start + ",...
java
public String seriesToString(double[] series, NumberFormat df) { StringBuffer sb = new StringBuffer(); sb.append('['); for (double d : series) { sb.append(df.format(d)).append(','); } sb.delete(sb.length() - 2, sb.length() - 1).append("]"); return sb.toString(); }
java
public double[] normOne(double[] data) { double[] res = new double[data.length]; double max = max(data); for (int i = 0; i < data.length; i++) { res[i] = data[i] / max; } return res; }
java
public List<DiscordRecord> getTopHits(Integer num) { if (num >= this.discords.size()) { return this.discords; } List<DiscordRecord> res = this.discords.subList(this.discords.size() - num, this.discords.size()); return res; }
java
public void setZValues(double[][] zValues, double low, double high) { this.zValues = zValues; this.lowValue = low; this.highValue = high; }
java
public void setBackgroundColour(Color backgroundColour) { if (backgroundColour == null) { backgroundColour = Color.WHITE; } this.backgroundColour = backgroundColour; }
java
public static double max(double[][] values) { double max = 0; for (int i = 0; i < values.length; i++) { for (int j = 0; j < values[i].length; j++) { max = (values[i][j] > max) ? values[i][j] : max; } } return max; }
java
public static double min(double[][] values) { double min = Double.MAX_VALUE; for (int i = 0; i < values.length; i++) { for (int j = 0; j < values[i].length; j++) { min = (values[i][j] < min) ? values[i][j] : min; } } return min; }
java
@Override public int compareTo(DiscordRecord other) { if (null == other) { throw new NullPointerException("Unable compare to null!"); } return Double.compare(other.getNNDistance(), this.nnDistance); }
java
public static double gaussian() { // use the polar form of the Box-Muller transform double r, x, y; do { x = uniform(-1.0, 1.0); y = uniform(-1.0, 1.0); r = x * x + y * y; } while (r >= 1 || r == 0); return x * Math.sqrt(-2 * Math.log(r) / r); // Remark: y * Math.sqrt(-2 *...
java
public static void shuffle(double[] a) { int N = a.length; for (int i = 0; i < N; i++) { int r = i + uniform(N - i); // between i and N-1 double temp = a[i]; a[i] = a[r]; a[r] = temp; } }
java
public void dropByIndex(int idx) { SAXRecord entry = realTSindex.get(idx); if (null != entry) { realTSindex.remove(idx); entry.removeIndex(idx); if (entry.getIndexes().isEmpty()) { records.remove(String.valueOf(entry.getPayload())); } } }
java
public void add(char[] str, int idx) { SAXRecord rr = records.get(String.valueOf(str)); if (null == rr) { rr = new SAXRecord(str, idx); this.records.put(String.valueOf(str), rr); } else { rr.addIndex(idx); } this.realTSindex.put(idx, rr); }
java
public void addAll(SAXRecords records) { for (SAXRecord record : records) { char[] payload = record.getPayload(); for (Integer i : record.getIndexes()) { this.add(payload, i); } } }
java
public void addAll(HashMap<Integer, char[]> records) { for (Entry<Integer, char[]> e : records.entrySet()) { this.add(e.getValue(), e.getKey()); } }
java
public String getSAXString(String separatorToken) { StringBuffer sb = new StringBuffer(); ArrayList<Integer> index = new ArrayList<Integer>(); index.addAll(this.realTSindex.keySet()); Collections.sort(index, new Comparator<Integer>() { public int compare(Integer int1, Integer int2) { retur...
java
public ArrayList<Integer> getAllIndices() { ArrayList<Integer> res = new ArrayList<Integer>(this.realTSindex.size()); res.addAll(this.realTSindex.keySet()); Collections.sort(res); return res; }
java
public void buildIndex() { this.stringPosToRealPos = new HashMap<Integer, Integer>(); int counter = 0; for (Integer idx : getAllIndices()) { this.stringPosToRealPos.put(counter, idx); counter++; } }
java
public void excludePositions(ArrayList<Integer> positions) { for (Integer p : positions) { if (realTSindex.containsKey(p)) { SAXRecord rec = realTSindex.get(p); rec.removeIndex(p); if (rec.getIndexes().isEmpty()) { this.records.remove(String.valueOf(rec.getPayload())); ...
java
public ArrayList<SAXRecord> getSimpleMotifs(int num) { ArrayList<SAXRecord> res = new ArrayList<SAXRecord>(num); DoublyLinkedSortedList<Entry<String, SAXRecord>> list = new DoublyLinkedSortedList<Entry<String, SAXRecord>>( num, new Comparator<Entry<String, SAXRecord>>() { @Override p...
java
public void cancel() { try { executorService.shutdown(); if (!executorService.awaitTermination(30, TimeUnit.MINUTES)) { executorService.shutdownNow(); // Cancel currently executing tasks if (!executorService.awaitTermination(30, TimeUnit.MINUTES)) { LOGGER.error("Pool did not t...
java
public static void main(String[] args) throws Exception { SAXProcessor sp = new SAXProcessor(); // data // double[] dat = TSProcessor.readFileColumn(DAT_FNAME, 1, 0); // TSProcessor tp = new TSProcessor(); // double[] dat = tp.readTS("src/resources/dataset/asys40.txt", 0); // double[] dat ...
java
private static double[] toDoubleAray(Integer[] intArray, HashSet<Integer> skipIndex) { double[] res = new double[intArray.length - skipIndex.size()]; int skip = 0; for (int i = 0; i < intArray.length; i++) { if (skipIndex.contains(i)) { skip++; continue; } res[i - skip] = i...
java
public VirtualFile getFile(VirtualFile mountPoint, VirtualFile target) { final String path = target.getPathNameRelativeTo(mountPoint); return rootNode.getFile(new Path(path), mountPoint); }
java
public List<String> getChildNames(VirtualFile mountPoint, VirtualFile target) { List<String> names = new LinkedList<String>(); AssemblyNode targetNode = null; if (mountPoint.equals(target)) { targetNode = rootNode; } else { targetNode = rootNode.find(target.getPat...
java
public File createFile(String relativePath, InputStream sourceData) throws IOException { final File tempFile = getFile(relativePath); boolean ok = false; try { final FileOutputStream fos = new FileOutputStream(tempFile); try { VFSUtils.copyStream(sourceDat...
java
private static void init() { String pkgs = System.getProperty("java.protocol.handler.pkgs"); if (pkgs == null || pkgs.trim().length() == 0) { pkgs = "org.jboss.net.protocol|org.jboss.vfs.protocol"; System.setProperty("java.protocol.handler.pkgs", pkgs); } else if (pkgs.co...
java
public static Closeable mount(VirtualFile mountPoint, FileSystem fileSystem) throws IOException { final VirtualFile parent = mountPoint.getParent(); if (parent == null) { throw VFSMessages.MESSAGES.rootFileSystemAlreadyMounted(); } final String name = mountPoint.getName(); ...
java
protected static void visit(VirtualFile file, VirtualFileVisitor visitor) throws IOException { if (file == null) { throw VFSMessages.MESSAGES.nullArgument("file"); } visitor.visit(file); }
java
static Set<String> getSubmounts(VirtualFile virtualFile) { final ConcurrentMap<VirtualFile, Map<String, Mount>> mounts = VFS.mounts; final Map<String, Mount> mountMap = mounts.get(virtualFile); if (mountMap == null) { return emptyRemovableSet(); } return new HashSet<S...
java
public static Closeable mountReal(File realRoot, VirtualFile mountPoint) throws IOException { return doMount(new RealFileSystem(realRoot), mountPoint); }
java
public static Closeable mountTemp(VirtualFile mountPoint, TempFileProvider tempFileProvider) throws IOException { boolean ok = false; final TempDir tempDir = tempFileProvider.createTempDir("tmpfs"); try { final MountHandle handle = doMount(new RealFileSystem(tempDir.getRoot()), mount...
java
public static Closeable mountZipExpanded(File zipFile, VirtualFile mountPoint, TempFileProvider tempFileProvider) throws IOException { boolean ok = false; final TempDir tempDir = tempFileProvider.createTempDir(zipFile.getName()); try { final File rootFile = tempDir.getRoot(); ...
java
public static Closeable mountZipExpanded(InputStream zipData, String zipName, VirtualFile mountPoint, TempFileProvider tempFileProvider) throws IOException { try { boolean ok = false; final TempDir tempDir = tempFileProvider.createTempDir(zipName); try { final...
java
public static Closeable mountAssembly(VirtualFileAssembly assembly, VirtualFile mountPoint) throws IOException { return doMount(new AssemblyFileSystem(assembly), mountPoint); }
java
private void closeCurrent() throws IOException { virtualJarInputStream.closeEntry(); currentEntry.crc = crc.getValue(); crc.reset(); }
java
private boolean bufferLocalFileHeader() throws IOException { buffer.reset(); JarEntry jarEntry = virtualJarInputStream.getNextJarEntry(); if (jarEntry == null) { return false; } currentEntry = new ProcessedEntry(jarEntry, totalRead); processedEntries.add(currentEntry); ...
java
private boolean bufferNextCentralFileHeader() throws IOException { buffer.reset(); if (currentCentralEntryIdx == processedEntries.size()) { return false; } ProcessedEntry entry = processedEntries.get(currentCentralEntryIdx++); JarEntry jarEntry = entry.jarEntry; bufferInt(ZipE...
java
private void bufferCentralDirectoryEnd() throws IOException { buffer.reset(); long lengthOfCentral = totalRead - centralOffset; int count = processedEntries.size(); bufferInt(JarEntry.ENDSIG); // End of central directory signature bufferShort(0); // Number ...
java
private void bufferInt(long i) { buffer((byte) (i & 0xff)); buffer((byte) ((i >>> 8) & 0xff)); buffer((byte) ((i >>> 16) & 0xff)); buffer((byte) ((i >>> 24) & 0xff)); }
java
private void buffer(byte b) { if (buffer.hasCapacity()) { buffer.put(b); } else { throw VFSMessages.MESSAGES.bufferDoesntHaveEnoughCapacity(); } }
java
String getPathName(boolean url) { if (pathName == null || pathName.isEmpty()) { VirtualFile[] path = getParentFiles(); final StringBuilder builder = new StringBuilder(path.length * 30 + 50); for (int i = path.length - 1; i > -1; i--) { final VirtualFile parent...
java
public long getLastModified() { final SecurityManager sm = System.getSecurityManager(); if (sm != null) { sm.checkPermission(new VirtualFilePermission(getPathName(), "read")); } final VFS.Mount mount = VFS.getMount(this); if (sm != null) { return AccessCon...
java
public InputStream openStream() throws IOException { final SecurityManager sm = System.getSecurityManager(); if (sm != null) { sm.checkPermission(new VirtualFilePermission(getPathName(), "read")); } if (isDirectory()) { return new VirtualJarInputStream(this); ...
java
public File getPhysicalFile() throws IOException { final SecurityManager sm = System.getSecurityManager(); if (sm != null) { sm.checkPermission(new VirtualFilePermission(getPathName(), "getfile")); } final VFS.Mount mount = VFS.getMount(this); if (sm != null) { ...
java
public List<VirtualFile> getChildren() { // isDirectory does the read security check if (!isDirectory()) { return Collections.emptyList(); } final VFS.Mount mount = VFS.getMount(this); final Set<String> submounts = VFS.getSubmounts(this); final List<String> names = mount.getFileS...
java
public List<VirtualFile> getChildren(VirtualFileFilter filter) throws IOException { // isDirectory does the read security check if (!isDirectory()) { return Collections.emptyList(); } if (filter == null) { filter = MatchAllVirtualFileFilter.INSTANCE; } FilterVirtualFileVisitor visitor = ...
java
public VirtualFile getChild(String path) { if (path == null) { throw VFSMessages.MESSAGES.nullArgument("path"); } final List<String> pathParts = PathTokenizer.getTokens(path); VirtualFile current = this; for (String part : pathParts) { if (PathTokenizer.is...
java
public static List<String> getTokens(String path) { if (path == null) { throw MESSAGES.nullArgument("path"); } List<String> list = new ArrayList<String>(); getTokens(list, path); return list; }
java
public static void getTokens(List<String> list, String path) { int start = -1, length = path.length(), state = STATE_INITIAL; char ch; for (int index = 0; index < length; index++) { ch = path.charAt(index); switch (ch) { case '/': case '\\'...
java
public static String applySpecialPaths(String path) throws IllegalArgumentException { List<String> tokens = getTokens(path); if (tokens == null) { return null; } int i = 0; for (int j = 0; j < tokens.size(); j++) { String token = tokens.get(j); if (isCurrentToken(...
java
public static List<String> applySpecialPaths(List<String> pathTokens) throws IllegalArgumentException { final ArrayList<String> newTokens = new ArrayList<String>(); for (String pathToken : pathTokens) { if (isCurrentToken(pathToken)) { continue; } else if (isReverseToken(pathToken)) { ...
java
public static String getPathsString(Collection<VirtualFile> paths) { if (paths == null) { throw MESSAGES.nullArgument("paths"); } StringBuilder buffer = new StringBuilder(); boolean first = true; for (VirtualFile path : paths) { if (path == null) { throw n...
java
public static void addManifestLocations(VirtualFile file, List<VirtualFile> paths) throws IOException { if (file == null) { throw MESSAGES.nullArgument("file"); } if (paths == null) { throw MESSAGES.nullArgument("paths"); } boolean trace = VFSLogger.ROOT_L...
java
public static Manifest getManifest(VirtualFile archive) throws IOException { if (archive == null) { throw MESSAGES.nullArgument("archive"); } VirtualFile manifest = archive.getChild(JarFile.MANIFEST_NAME); if (manifest == null || !manifest.exists()) { if (VFSLogge...
java
public static Manifest readManifest(VirtualFile manifest) throws IOException { if (manifest == null) { throw MESSAGES.nullArgument("manifest file"); } InputStream stream = new PaddedManifestStream(manifest.openStream()); try { return new Manifest(stream); ...
java
public static String decode(String path, String encoding) { try { return URLDecoder.decode(path, encoding); } catch (UnsupportedEncodingException e) { throw MESSAGES.cannotDecode(path,encoding,e); } }
java
public static String getName(URI uri) { if (uri == null) { throw MESSAGES.nullArgument("uri"); } String name = uri.getPath(); if (name != null) { // TODO: Not correct for certain uris like jar:...!/ int lastSlash = name.lastIndexOf('/'); if...
java
public static URI toURI(URL url) throws URISyntaxException { if (url == null) { throw MESSAGES.nullArgument("url"); } try { return url.toURI(); } catch (URISyntaxException e) { String urispec = url.toExternalForm(); // Escape percent sign a...
java
public static void safeClose(final Iterable<? extends Closeable> ci) { if (ci != null) { for (Closeable closeable : ci) { safeClose(closeable); } } }
java
public static boolean exists(File file) { try { boolean fileExists = file.exists(); if(!forceCaseSensitive || !fileExists) { return fileExists; } String absPath = canonicalize(file.getAbsolutePath()); String canPath = canonicalize(file...
java
public static boolean recursiveDelete(VirtualFile root) { boolean ok = true; if (root.isDirectory()) { final List<VirtualFile> files = root.getChildren(); for (VirtualFile file : files) { ok &= recursiveDelete(file); } return ok && (root.de...
java
public static void recursiveCopy(File original, File destDir) throws IOException { final String name = original.getName(); final File destFile = new File(destDir, name); if (original.isDirectory()) { destFile.mkdir(); for (File file : original.listFiles()) { ...
java
public static void unzip(File zipFile, File destDir) throws IOException { final ZipFile zip = new ZipFile(zipFile); try { final Set<File> createdDirs = new HashSet<File>(); final Enumeration<? extends ZipEntry> entries = zip.entries(); FILES_LOOP: while (e...
java
public static File getMountSource(Closeable handle) { if (handle instanceof MountHandle) { return MountHandle.class.cast(handle).getMountSource(); } return null; }
java
private static VisitorAttributes checkAttributes(VirtualFileFilter filter, VisitorAttributes attributes) { if (filter == null) { throw MESSAGES.nullArgument("filter"); } // Specified if (attributes != null) { return attributes; } // From the filter if (filter ...
java
protected String getPathName(VirtualFile file) { try { // prefer the URI, as the pathName might // return an empty string for temp virtual files return file.toURI().toString(); } catch (Exception e) { return file.getPathName(); } }
java
private static MountConfig getMountConfig(MountOption[] mountOptions) { final MountConfig config = new MountConfig(); for (MountOption option : mountOptions) { option.applyTo(config); } return config; }
java
public static boolean addHandle(VirtualFile owner, Closeable handle) { RegistryEntry entry = getEntry(owner); return entry.handles.add(handle); }
java
public static boolean removeHandle(VirtualFile owner, Closeable handle) { RegistryEntry entry = getEntry(owner); return entry.handles.remove(handle); }
java
static RegistryEntry getEntry(VirtualFile virtualFile) { if (virtualFile == null) { throw MESSAGES.nullArgument("VirutalFile"); } return rootEntry.find(virtualFile); }
java
public static TempFileProvider create(final String providerType, final ScheduledExecutorService executor, final boolean cleanExisting) throws IOException { if (cleanExisting) { try { // The "clean existing" logic is as follows: // 1) Rename the root directory "foo" co...
java
public TempDir createTempDir(String originalName) throws IOException { if (!open.get()) { throw VFSMessages.MESSAGES.tempFileProviderClosed(); } final String name = createTempName(originalName + "-", ""); final File f = new File(providerRoot, name); for (int i = 0; i ...
java
private void openCurrent(VirtualFile current) throws IOException { if (current.isDirectory()) { currentEntryStream = VFSUtils.emptyStream(); } else { currentEntryStream = current.openStream(); } }
java