code
stringlengths 11
173k
| docstring
stringlengths 2
593k
| func_name
stringlengths 2
189
| language
stringclasses 1
value | repo
stringclasses 844
values | path
stringlengths 11
294
| url
stringlengths 60
339
| license
stringclasses 4
values |
---|---|---|---|---|---|---|---|
public boolean isEmpty(F element){
if (isEmpty())
return true;
Counter<S> m = maps.get(element);
if (m == null)
return true;
else
return m.isEmpty();
} |
This method checks if this CounterMap has any values stored for a given first element
@param element
@return
| CounterMap::isEmpty | java | deeplearning4j/deeplearning4j | nd4j/nd4j-common/src/main/java/org/nd4j/common/primitives/CounterMap.java | https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/primitives/CounterMap.java | Apache-2.0 |
public void incrementAll(CounterMap<F, S> other) {
for (Map.Entry<F, Counter<S>> entry : other.maps.entrySet()) {
F key = entry.getKey();
Counter<S> innerCounter = entry.getValue();
for (Map.Entry<S, AtomicDouble> innerEntry : innerCounter.entrySet()) {
S value = innerEntry.getKey();
incrementCount(key, value, innerEntry.getValue().get());
}
}
} |
This method will increment values of this counter, by counts of other counter
@param other
| CounterMap::incrementAll | java | deeplearning4j/deeplearning4j | nd4j/nd4j-common/src/main/java/org/nd4j/common/primitives/CounterMap.java | https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/primitives/CounterMap.java | Apache-2.0 |
public void incrementCount(F first, S second, double inc) {
Counter<S> counter = maps.get(first);
if (counter == null) {
counter = new Counter<S>();
maps.put(first, counter);
}
counter.incrementCount(second, inc);
} |
This method will increment counts for a given first/second pair
@param first
@param second
@param inc
| CounterMap::incrementCount | java | deeplearning4j/deeplearning4j | nd4j/nd4j-common/src/main/java/org/nd4j/common/primitives/CounterMap.java | https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/primitives/CounterMap.java | Apache-2.0 |
public double getCount(F first, S second) {
Counter<S> counter = maps.get(first);
if (counter == null)
return 0.0;
return counter.getCount(second);
} |
This method returns counts for a given first/second pair
@param first
@param second
@return
| CounterMap::getCount | java | deeplearning4j/deeplearning4j | nd4j/nd4j-common/src/main/java/org/nd4j/common/primitives/CounterMap.java | https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/primitives/CounterMap.java | Apache-2.0 |
public double setCount(F first, S second, double value) {
Counter<S> counter = maps.get(first);
if (counter == null) {
counter = new Counter<S>();
maps.put(first, counter);
}
return counter.setCount(second, value);
} |
This method allows you to set counter value for a given first/second pair
@param first
@param second
@param value
@return
| CounterMap::setCount | java | deeplearning4j/deeplearning4j | nd4j/nd4j-common/src/main/java/org/nd4j/common/primitives/CounterMap.java | https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/primitives/CounterMap.java | Apache-2.0 |
public Pair<F, S> argMax() {
Double maxCount = -Double.MAX_VALUE;
Pair<F, S> maxKey = null;
for (Map.Entry<F, Counter<S>> entry : maps.entrySet()) {
Counter<S> counter = entry.getValue();
S localMax = counter.argMax();
if (counter.getCount(localMax) > maxCount || maxKey == null) {
maxKey = new Pair<F, S>(entry.getKey(), localMax);
maxCount = counter.getCount(localMax);
}
}
return maxKey;
} |
This method returns pair of elements with a max value
@return
| CounterMap::argMax | java | deeplearning4j/deeplearning4j | nd4j/nd4j-common/src/main/java/org/nd4j/common/primitives/CounterMap.java | https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/primitives/CounterMap.java | Apache-2.0 |
public void clear() {
maps.clear();
} |
This method purges all counters
| CounterMap::clear | java | deeplearning4j/deeplearning4j | nd4j/nd4j-common/src/main/java/org/nd4j/common/primitives/CounterMap.java | https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/primitives/CounterMap.java | Apache-2.0 |
public void clear(F element) {
Counter<S> s = maps.get(element);
if (s != null)
s.clear();
} |
This method purges counter for a given first element
@param element
| CounterMap::clear | java | deeplearning4j/deeplearning4j | nd4j/nd4j-common/src/main/java/org/nd4j/common/primitives/CounterMap.java | https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/primitives/CounterMap.java | Apache-2.0 |
public Set<F> keySet() {
return maps.keySet();
} |
This method returns Set of all first elements
@return
| CounterMap::keySet | java | deeplearning4j/deeplearning4j | nd4j/nd4j-common/src/main/java/org/nd4j/common/primitives/CounterMap.java | https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/primitives/CounterMap.java | Apache-2.0 |
public Counter<S> getCounter(F first) {
return maps.get(first);
} |
This method returns counter for a given first element
@param first
@return
| CounterMap::getCounter | java | deeplearning4j/deeplearning4j | nd4j/nd4j-common/src/main/java/org/nd4j/common/primitives/CounterMap.java | https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/primitives/CounterMap.java | Apache-2.0 |
public Iterator<Pair<F, S>> getIterator() {
return new Iterator<Pair<F, S>>() {
Iterator<F> outerIt;
Iterator<S> innerIt;
F curKey;
{
outerIt = keySet().iterator();
}
private boolean hasInside() {
if (innerIt == null || !innerIt.hasNext()) {
if (!outerIt.hasNext()) {
return false;
}
curKey = outerIt.next();
innerIt = getCounter(curKey).keySet().iterator();
}
return true;
}
public boolean hasNext() {
return hasInside();
}
public Pair<F, S> next() {
hasInside();
if (curKey == null)
throw new RuntimeException("Outer element can't be null");
return Pair.makePair(curKey, innerIt.next());
}
public void remove() {
//
}
};
} |
This method returns Iterator of all first/second pairs stored in this counter
@return
| CounterMap::getIterator | java | deeplearning4j/deeplearning4j | nd4j/nd4j-common/src/main/java/org/nd4j/common/primitives/CounterMap.java | https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/primitives/CounterMap.java | Apache-2.0 |
public int size() {
return maps.size();
} |
This method returns number of First elements in this CounterMap
@return
| CounterMap::size | java | deeplearning4j/deeplearning4j | nd4j/nd4j-common/src/main/java/org/nd4j/common/primitives/CounterMap.java | https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/primitives/CounterMap.java | Apache-2.0 |
public int totalSize() {
int size = 0;
for (F first: keySet()) {
size += getCounter(first).size();
}
return size;
} |
This method returns total number of elements in this CounterMap
@return
| CounterMap::totalSize | java | deeplearning4j/deeplearning4j | nd4j/nd4j-common/src/main/java/org/nd4j/common/primitives/CounterMap.java | https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/primitives/CounterMap.java | Apache-2.0 |
public void incrementAll(Collection<T> elements, double inc) {
for (T element: elements) {
incrementCount(element, inc);
}
} |
This method will increment all elements in collection
@param elements
@param inc
| Counter::incrementAll | java | deeplearning4j/deeplearning4j | nd4j/nd4j-common/src/main/java/org/nd4j/common/primitives/Counter.java | https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/primitives/Counter.java | Apache-2.0 |
public <T2 extends T> void incrementAll(Counter<T2> other) {
for (T2 element: other.keySet()) {
double cnt = other.getCount(element);
incrementCount(element, cnt);
}
} |
This method will increment counts of this counter by counts from other counter
@param other
| Counter::incrementAll | java | deeplearning4j/deeplearning4j | nd4j/nd4j-common/src/main/java/org/nd4j/common/primitives/Counter.java | https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/primitives/Counter.java | Apache-2.0 |
public double getProbability(T element) {
if (totalCount() <= 0.0)
throw new IllegalStateException("Can't calculate probability with empty counter");
return getCount(element) / totalCount();
} |
This method returns probability of given element
@param element
@return
| Counter::getProbability | java | deeplearning4j/deeplearning4j | nd4j/nd4j-common/src/main/java/org/nd4j/common/primitives/Counter.java | https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/primitives/Counter.java | Apache-2.0 |
public double setCount(T element, double count) {
AtomicDouble t = map.get(element);
if (t != null) {
double val = t.getAndSet(count);
dirty.set(true);
return val;
} else {
map.put(element, new AtomicDouble(count));
totalCount.addAndGet(count);
return 0;
}
} |
This method sets new counter value for given element
@param element element to be updated
@param count new counter value
@return previous value
| Counter::setCount | java | deeplearning4j/deeplearning4j | nd4j/nd4j-common/src/main/java/org/nd4j/common/primitives/Counter.java | https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/primitives/Counter.java | Apache-2.0 |
public Set<T> keySet() {
return map.keySet();
} |
This method returns Set of elements used in this counter
@return
| Counter::keySet | java | deeplearning4j/deeplearning4j | nd4j/nd4j-common/src/main/java/org/nd4j/common/primitives/Counter.java | https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/primitives/Counter.java | Apache-2.0 |
public boolean isEmpty() {
return map.size() == 0;
} |
This method returns TRUE if counter has no elements, FALSE otherwise
@return
| Counter::isEmpty | java | deeplearning4j/deeplearning4j | nd4j/nd4j-common/src/main/java/org/nd4j/common/primitives/Counter.java | https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/primitives/Counter.java | Apache-2.0 |
public Set<Map.Entry<T, AtomicDouble>> entrySet() {
return map.entrySet();
} |
This method returns Set<Entry> of this counter
@return
| Counter::entrySet | java | deeplearning4j/deeplearning4j | nd4j/nd4j-common/src/main/java/org/nd4j/common/primitives/Counter.java | https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/primitives/Counter.java | Apache-2.0 |
public List<T> keySetSorted() {
List<T> result = new ArrayList<>();
PriorityQueue<Pair<T, Double>> pq = asPriorityQueue();
while (!pq.isEmpty()) {
result.add(pq.poll().getFirst());
}
return result;
} |
This method returns List of elements, sorted by their counts
@return
| Counter::keySetSorted | java | deeplearning4j/deeplearning4j | nd4j/nd4j-common/src/main/java/org/nd4j/common/primitives/Counter.java | https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/primitives/Counter.java | Apache-2.0 |
public void normalize() {
for (T key : keySet()) {
setCount(key, getCount(key) / totalCount.get());
}
rebuildTotals();
} |
This method will apply normalization to counter values and totals.
| Counter::normalize | java | deeplearning4j/deeplearning4j | nd4j/nd4j-common/src/main/java/org/nd4j/common/primitives/Counter.java | https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/primitives/Counter.java | Apache-2.0 |
public double totalCount() {
if (dirty.get())
rebuildTotals();
return totalCount.get();
} |
This method returns total sum of counter values
@return
| Counter::totalCount | java | deeplearning4j/deeplearning4j | nd4j/nd4j-common/src/main/java/org/nd4j/common/primitives/Counter.java | https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/primitives/Counter.java | Apache-2.0 |
public double removeKey(T element) {
AtomicDouble v = map.remove(element);
dirty.set(true);
if (v != null)
return v.get();
else
return 0.0;
} |
This method removes given key from counter
@param element
@return counter value
| Counter::removeKey | java | deeplearning4j/deeplearning4j | nd4j/nd4j-common/src/main/java/org/nd4j/common/primitives/Counter.java | https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/primitives/Counter.java | Apache-2.0 |
public T argMax() {
double maxCount = -Double.MAX_VALUE;
T maxKey = null;
for (Map.Entry<T, AtomicDouble> entry : map.entrySet()) {
if (entry.getValue().get() > maxCount || maxKey == null) {
maxKey = entry.getKey();
maxCount = entry.getValue().get();
}
}
return maxKey;
} |
This method returns element with highest counter value
@return
| Counter::argMax | java | deeplearning4j/deeplearning4j | nd4j/nd4j-common/src/main/java/org/nd4j/common/primitives/Counter.java | https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/primitives/Counter.java | Apache-2.0 |
public void dropElementsBelowThreshold(double threshold) {
Iterator<T> iterator = keySet().iterator();
while (iterator.hasNext()) {
T element = iterator.next();
double val = map.get(element).get();
if (val < threshold) {
iterator.remove();
dirty.set(true);
}
}
} |
This method will remove all elements with counts below given threshold from counter
@param threshold
| Counter::dropElementsBelowThreshold | java | deeplearning4j/deeplearning4j | nd4j/nd4j-common/src/main/java/org/nd4j/common/primitives/Counter.java | https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/primitives/Counter.java | Apache-2.0 |
public boolean containsElement(T element) {
return map.containsKey(element);
} |
This method checks, if element exist in this counter
@param element
@return
| Counter::containsElement | java | deeplearning4j/deeplearning4j | nd4j/nd4j-common/src/main/java/org/nd4j/common/primitives/Counter.java | https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/primitives/Counter.java | Apache-2.0 |
public void clear() {
map.clear();
totalCount.set(0.0);
dirty.set(false);
} |
This method effectively resets counter to empty state
| Counter::clear | java | deeplearning4j/deeplearning4j | nd4j/nd4j-common/src/main/java/org/nd4j/common/primitives/Counter.java | https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/primitives/Counter.java | Apache-2.0 |
public int size() {
return map.size();
} |
Returns total number of tracked elements
@return
| Counter::size | java | deeplearning4j/deeplearning4j | nd4j/nd4j-common/src/main/java/org/nd4j/common/primitives/Counter.java | https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/primitives/Counter.java | Apache-2.0 |
public void keepTopNElements(int N){
PriorityQueue<Pair<T, Double>> queue = asPriorityQueue();
clear();
for (int e = 0; e < N; e++) {
Pair<T, Double> pair = queue.poll();
if (pair != null)
incrementCount(pair.getFirst(), pair.getSecond());
}
} |
This method removes all elements except of top N by counter values
@param N
| Counter::keepTopNElements | java | deeplearning4j/deeplearning4j | nd4j/nd4j-common/src/main/java/org/nd4j/common/primitives/Counter.java | https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/primitives/Counter.java | Apache-2.0 |
public void set(T value) {
try {
lock.writeLock().lock();
this.value = value;
} finally {
lock.writeLock().unlock();
}
} |
This method assigns new value
@param value
| Atomic::set | java | deeplearning4j/deeplearning4j | nd4j/nd4j-common/src/main/java/org/nd4j/common/primitives/Atomic.java | https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/primitives/Atomic.java | Apache-2.0 |
public T get() {
try {
lock.readLock().lock();
return this.value;
} finally {
lock.readLock().unlock();
}
} |
This method returns current value
@return
| Atomic::get | java | deeplearning4j/deeplearning4j | nd4j/nd4j-common/src/main/java/org/nd4j/common/primitives/Atomic.java | https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/primitives/Atomic.java | Apache-2.0 |
public boolean cas(T expected, T newValue) {
try {
lock.writeLock().lock();
if (Objects.equals(value, expected)) {
this.value = newValue;
return true;
} else
return false;
} finally {
lock.writeLock().unlock();
}
} |
This method implements compare-and-swap
@param expected
@param newValue
@return true if value was swapped, false otherwise
| Atomic::cas | java | deeplearning4j/deeplearning4j | nd4j/nd4j-common/src/main/java/org/nd4j/common/primitives/Atomic.java | https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/primitives/Atomic.java | Apache-2.0 |
public final T get() {
try {
lock.readLock().lock();
return value;
} finally {
lock.readLock().unlock();
}
} |
This method returns stored value via read lock
@return
| SynchronizedObject::get | java | deeplearning4j/deeplearning4j | nd4j/nd4j-common/src/main/java/org/nd4j/common/primitives/SynchronizedObject.java | https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/primitives/SynchronizedObject.java | Apache-2.0 |
public final void set(T value) {
try {
lock.writeLock().lock();
this.value = value;
} finally {
lock.writeLock().unlock();
}
} |
This method updates stored value via write lock
@param value
| SynchronizedObject::set | java | deeplearning4j/deeplearning4j | nd4j/nd4j-common/src/main/java/org/nd4j/common/primitives/SynchronizedObject.java | https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/primitives/SynchronizedObject.java | Apache-2.0 |
public static void unzipFileTo(String file, String dest) throws IOException {
unzipFileTo(file, dest, true);
} |
Extracts all files from the archive to the specified destination.<br>
Note: Logs the path of all extracted files by default. Use {@link #unzipFileTo(String, String, boolean)} if
logging is not desired.<br>
Can handle .zip, .jar, .tar.gz, .tgz, .tar, and .gz formats.
Format is interpreted from the filename
@param file the file to extract the files from
@param dest the destination directory. Will be created if it does not exist
@throws IOException If an error occurs accessing the files or extracting
| ArchiveUtils::unzipFileTo | java | deeplearning4j/deeplearning4j | nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArchiveUtils.java | https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArchiveUtils.java | Apache-2.0 |
public static void unzipFileTo(String file, String dest, boolean logFiles) throws IOException {
File target = new File(file);
if (!target.exists())
throw new IllegalArgumentException("Archive doesnt exist");
if (!new File(dest).exists())
new File(dest).mkdirs();
FileInputStream fin = new FileInputStream(target);
int BUFFER = 2048;
byte data[] = new byte[BUFFER];
if (file.endsWith(".zip") || file.endsWith(".jar")) {
try(ZipInputStream zis = new ZipInputStream(fin)) {
//get the zipped file list entry
ZipEntry ze = zis.getNextEntry();
while (ze != null) {
String fileName = ze.getName();
String canonicalDestinationDirPath = new File(dest).getCanonicalPath();
File newFile = new File(dest + File.separator + fileName);
String canonicalDestinationFile = newFile.getCanonicalPath();
if (!canonicalDestinationFile.startsWith(canonicalDestinationDirPath + File.separator)) {
log.debug("Attempt to unzip entry is outside of the target dir");
throw new IOException("Entry is outside of the target dir: ");
}
if (ze.isDirectory()) {
newFile.mkdirs();
zis.closeEntry();
ze = zis.getNextEntry();
continue;
}
FileOutputStream fos = new FileOutputStream(newFile);
int len;
while ((len = zis.read(data)) > 0) {
fos.write(data, 0, len);
}
fos.close();
ze = zis.getNextEntry();
if(logFiles) {
log.info("File extracted: " + newFile.getAbsoluteFile());
}
}
zis.closeEntry();
}
} else if (file.endsWith(".tar.gz") || file.endsWith(".tgz") || file.endsWith(".tar")) {
BufferedInputStream in = new BufferedInputStream(fin);
TarArchiveInputStream tarIn;
if(file.endsWith(".tar")){
//Not compressed
tarIn = new TarArchiveInputStream(in);
} else {
GzipCompressorInputStream gzIn = new GzipCompressorInputStream(in);
tarIn = new TarArchiveInputStream(gzIn);
}
TarArchiveEntry entry;
/* Read the tar entries using the getNextEntry method **/
while ((entry = (TarArchiveEntry) tarIn.getNextEntry()) != null) {
if(logFiles) {
log.info("Extracting: " + entry.getName());
}
/* If the entry is a directory, create the directory. */
if (entry.isDirectory()) {
File f = new File(dest + File.separator + entry.getName());
f.mkdirs();
}
/*
* If the entry is a file,write the decompressed file to the disk
* and close destination stream.
*/
else {
int count;
try(FileOutputStream fos = new FileOutputStream(dest + File.separator + entry.getName());
BufferedOutputStream destStream = new BufferedOutputStream(fos, BUFFER);) {
while ((count = tarIn.read(data, 0, BUFFER)) != -1) {
destStream.write(data, 0, count);
}
destStream.flush();
IOUtils.closeQuietly(destStream);
}
}
}
// Close the input stream
tarIn.close();
} else if (file.endsWith(".gz")) {
File extracted = new File(target.getParent(), target.getName().replace(".gz", ""));
if (extracted.exists())
extracted.delete();
extracted.createNewFile();
try (GZIPInputStream is2 = new GZIPInputStream(fin); OutputStream fos = FileUtils.openOutputStream(extracted)) {
IOUtils.copyLarge(is2, fos);
fos.flush();
}
} else {
throw new IllegalStateException("Unable to infer file type (compression format) from source file name: " +
file);
}
target.delete();
} |
Extracts all files from the archive to the specified destination, optionally logging the extracted file path.<br>
Can handle .zip, .jar, .tar.gz, .tgz, .tar, and .gz formats.
Format is interpreted from the filename
@param file the file to extract the files from
@param dest the destination directory. Will be created if it does not exist
@param logFiles If true: log the path of every extracted file; if false do not log
@throws IOException If an error occurs accessing the files or extracting
| ArchiveUtils::unzipFileTo | java | deeplearning4j/deeplearning4j | nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArchiveUtils.java | https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArchiveUtils.java | Apache-2.0 |
public static List<String> tarListFiles(File tarFile) throws IOException {
Preconditions.checkState(!tarFile.getPath().endsWith(".tar.gz"), ".tar.gz files should not use this method - use tarGzListFiles instead");
return tarGzListFiles(tarFile, false);
} |
List all of the files and directories in the specified tar.gz file
@param tarFile A .tar file
@return List of files and directories
| ArchiveUtils::tarListFiles | java | deeplearning4j/deeplearning4j | nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArchiveUtils.java | https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArchiveUtils.java | Apache-2.0 |
public static List<String> tarGzListFiles(File tarGzFile) throws IOException {
return tarGzListFiles(tarGzFile, true);
} |
List all of the files and directories in the specified tar.gz file
@param tarGzFile A tar.gz file
@return List of files and directories
| ArchiveUtils::tarGzListFiles | java | deeplearning4j/deeplearning4j | nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArchiveUtils.java | https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArchiveUtils.java | Apache-2.0 |
public static List<String> zipListFiles(File zipFile) throws IOException {
List<String> out = new ArrayList<>();
try (ZipFile zf = new ZipFile(zipFile)) {
Enumeration entries = zf.entries();
while (entries.hasMoreElements()) {
ZipEntry ze = (ZipEntry) entries.nextElement();
out.add(ze.getName());
}
}
return out;
} |
List all of the files and directories in the specified .zip file
@param zipFile Zip file
@return List of files and directories
| ArchiveUtils::zipListFiles | java | deeplearning4j/deeplearning4j | nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArchiveUtils.java | https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArchiveUtils.java | Apache-2.0 |
public static void zipExtractSingleFile(File zipFile, File destination, String pathInZip) throws IOException {
try (ZipFile zf = new ZipFile(zipFile); InputStream is = new BufferedInputStream(zf.getInputStream(zf.getEntry(pathInZip)));
OutputStream os = new BufferedOutputStream(new FileOutputStream(destination))) {
IOUtils.copy(is, os);
}
} |
Extract a single file from a .zip file. Does not support directories
@param zipFile Zip file to extract from
@param destination Destination file
@param pathInZip Path in the zip to extract
@throws IOException If exception occurs while reading/writing
| ArchiveUtils::zipExtractSingleFile | java | deeplearning4j/deeplearning4j | nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArchiveUtils.java | https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArchiveUtils.java | Apache-2.0 |
public static void tarGzExtractSingleFile(File tarGz, File destination, String pathInTarGz) throws IOException {
try(TarArchiveInputStream tin = new TarArchiveInputStream(new GZIPInputStream(new BufferedInputStream(new FileInputStream(tarGz))))) {
ArchiveEntry entry;
boolean extracted = false;
while((entry = tin.getNextTarEntry()) != null){
String name = entry.getName();
if(pathInTarGz.equals(name)){
try(OutputStream os = new BufferedOutputStream(new FileOutputStream(destination))){
IOUtils.copy(tin, os);
}
extracted = true;
}
}
Preconditions.checkState(extracted, "No file was extracted. File not found? %s", pathInTarGz);
}
} |
Extract a single file from a tar.gz file. Does not support directories.
NOTE: This should not be used for batch extraction of files, due to the need to iterate over the entries until the
specified entry is found. Use {@link #unzipFileTo(String, String)} for batch extraction instead
@param tarGz A tar.gz file
@param destination The destination file to extract to
@param pathInTarGz The path in the tar.gz file to extract
| ArchiveUtils::tarGzExtractSingleFile | java | deeplearning4j/deeplearning4j | nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArchiveUtils.java | https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ArchiveUtils.java | Apache-2.0 |
public static void copyAtStride(int n, BufferType bufferType, ByteBuffer from, int fromOffset, int fromStride,
ByteBuffer to, int toOffset, int toStride) {
// TODO: implement shape copy for cases where stride == 1
ByteBuffer fromView = from;
ByteBuffer toView = to;
fromView.order(ByteOrder.nativeOrder());
toView.order(ByteOrder.nativeOrder());
switch (bufferType) {
case INT:
IntBuffer fromInt = fromView.asIntBuffer();
IntBuffer toInt = toView.asIntBuffer();
for (int i = 0; i < n; i++) {
int put = fromInt.get(fromOffset + i * fromStride);
toInt.put(toOffset + i * toStride, put);
}
break;
case FLOAT:
FloatBuffer fromFloat = fromView.asFloatBuffer();
FloatBuffer toFloat = toView.asFloatBuffer();
for (int i = 0; i < n; i++) {
float put = fromFloat.get(fromOffset + i * fromStride);
toFloat.put(toOffset + i * toStride, put);
}
break;
case DOUBLE:
DoubleBuffer fromDouble = fromView.asDoubleBuffer();
DoubleBuffer toDouble = toView.asDoubleBuffer();
for (int i = 0; i < n; i++) {
toDouble.put(toOffset + i * toStride, fromDouble.get(fromOffset + i * fromStride));
}
break;
default:
throw new IllegalArgumentException("Only floats and double supported");
}
} |
Copy from the given from buffer
to the to buffer at the specified
offsets and strides
@param n
@param bufferType
@param from the origin buffer
@param fromOffset the starting offset
@param fromStride the stride at which to copy from the origin
@param to the destination buffer
@param toOffset the starting point
@param toStride the to stride
| BufferType::copyAtStride | java | deeplearning4j/deeplearning4j | nd4j/nd4j-common/src/main/java/org/nd4j/common/util/NioUtil.java | https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/NioUtil.java | Apache-2.0 |
public static byte[] toByteArray(Serializable toSave) {
try {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream os = new ObjectOutputStream(bos);
os.writeObject(toSave);
byte[] ret = bos.toByteArray();
os.close();
return ret;
} catch (Exception e) {
throw new RuntimeException(e);
}
} |
Converts the given object to a byte array
@param toSave the object to save
| SerializationUtils::toByteArray | java | deeplearning4j/deeplearning4j | nd4j/nd4j-common/src/main/java/org/nd4j/common/util/SerializationUtils.java | https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/SerializationUtils.java | Apache-2.0 |
public static <T> T fromByteArray(byte[] bytes) {
return readObject(new ByteArrayInputStream(bytes));
} |
Deserializes object from byte array
@param bytes
@param <T>
@return
| SerializationUtils::fromByteArray | java | deeplearning4j/deeplearning4j | nd4j/nd4j-common/src/main/java/org/nd4j/common/util/SerializationUtils.java | https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/SerializationUtils.java | Apache-2.0 |
public static <T> T deserialize(byte[] bytes) {
return fromByteArray(bytes);
} |
Deserializes object from byte array
@param bytes
@param <T>
@return
| SerializationUtils::deserialize | java | deeplearning4j/deeplearning4j | nd4j/nd4j-common/src/main/java/org/nd4j/common/util/SerializationUtils.java | https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/SerializationUtils.java | Apache-2.0 |
public static <T> T deserialize(InputStream is) {
return readObject(is);
} |
Deserializes object from InputStream
@param bytes
@param <T>
@return
| SerializationUtils::deserialize | java | deeplearning4j/deeplearning4j | nd4j/nd4j-common/src/main/java/org/nd4j/common/util/SerializationUtils.java | https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/SerializationUtils.java | Apache-2.0 |
public static void writeObject(Serializable toSave, OutputStream writeTo) {
try {
ObjectOutputStream os = new ObjectOutputStream(writeTo);
os.writeObject(toSave);
} catch (Exception e) {
throw new RuntimeException(e);
}
} |
Writes the object to the output stream
THIS DOES NOT FLUSH THE STREAM
@param toSave the object to save
@param writeTo the output stream to write to
| SerializationUtils::writeObject | java | deeplearning4j/deeplearning4j | nd4j/nd4j-common/src/main/java/org/nd4j/common/util/SerializationUtils.java | https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/SerializationUtils.java | Apache-2.0 |
public static void serialize(Serializable object, OutputStream os) {
writeObject(object, os);
} |
Writes the object to the output stream
THIS DOES NOT FLUSH THE STREAM
@param toSave the object to save
@param writeTo the output stream to write to
| SerializationUtils::serialize | java | deeplearning4j/deeplearning4j | nd4j/nd4j-common/src/main/java/org/nd4j/common/util/SerializationUtils.java | https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/SerializationUtils.java | Apache-2.0 |
public static File createTempFile(String prefix, String suffix) {
String p = System.getProperty(ND4JSystemProperties.ND4J_TEMP_DIR_PROPERTY);
try {
if (p == null || p.isEmpty()) {
return File.createTempFile(prefix, suffix);
} else {
return File.createTempFile(prefix, suffix, new File(p));
}
} catch (IOException e){
throw new RuntimeException("Error creating temporary file", e);
}
} |
Create a temporary file in the location specified by {@link ND4JSystemProperties#ND4J_TEMP_DIR_PROPERTY} if set,
or the default temporary directory (usually specified by java.io.tmpdir system property)
@param prefix Prefix for generating file's name; must be at least 3 characeters
@param suffix Suffix for generating file's name; may be null (".tmp" will be used if null)
@return A temporary file
| ND4JFileUtils::createTempFile | java | deeplearning4j/deeplearning4j | nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ND4JFileUtils.java | https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ND4JFileUtils.java | Apache-2.0 |
public static File getTempDir(){
String p = System.getProperty(ND4JSystemProperties.ND4J_TEMP_DIR_PROPERTY);
if(p == null || p.isEmpty()){
return new File(System.getProperty("java.io.tmpdir"));
} else {
return new File(p);
}
} |
Get the temporary directory. This is the location specified by {@link ND4JSystemProperties#ND4J_TEMP_DIR_PROPERTY} if set,
or the default temporary directory (usually specified by java.io.tmpdir system property)
@return Temporary directory
| ND4JFileUtils::getTempDir | java | deeplearning4j/deeplearning4j | nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ND4JFileUtils.java | https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/ND4JFileUtils.java | Apache-2.0 |
public static double normalize(double val, double min, double max) {
if (max < min)
throw new IllegalArgumentException("Max must be greather than min");
return (val - min) / (max - min);
} |
Normalize a value
(val - min) / (max - min)
@param val value to normalize
@param max max value
@param min min value
@return the normalized value
| MathUtils::normalize | java | deeplearning4j/deeplearning4j | nd4j/nd4j-common/src/main/java/org/nd4j/common/util/MathUtils.java | https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/MathUtils.java | Apache-2.0 |
public static int clamp(int value, int min, int max) {
if (value < min)
value = min;
if (value > max)
value = max;
return value;
} |
Clamps the value to a discrete value
@param value the value to clamp
@param min min for the probability distribution
@param max max for the probability distribution
@return the discrete value
| MathUtils::clamp | java | deeplearning4j/deeplearning4j | nd4j/nd4j-common/src/main/java/org/nd4j/common/util/MathUtils.java | https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/MathUtils.java | Apache-2.0 |
public static int discretize(double value, double min, double max, int binCount) {
int discreteValue = (int) (binCount * normalize(value, min, max));
return clamp(discreteValue, 0, binCount - 1);
} |
Discretize the given value
@param value the value to discretize
@param min the min of the distribution
@param max the max of the distribution
@param binCount the number of bins
@return the discretized value
| MathUtils::discretize | java | deeplearning4j/deeplearning4j | nd4j/nd4j-common/src/main/java/org/nd4j/common/util/MathUtils.java | https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/MathUtils.java | Apache-2.0 |
public static long nextPowOf2(long v) {
v--;
v |= v >> 1;
v |= v >> 2;
v |= v >> 4;
v |= v >> 8;
v |= v >> 16;
v++;
return v;
} |
See: <a href="https://stackoverflow.com/questions/466204/rounding-off-to-nearest-power-of-2">https://stackoverflow.com/questions/466204/rounding-off-to-nearest-power-of-2</a>
@param v the number to getFromOrigin the next power of 2 for
@return the next power of 2 for the passed in value
| MathUtils::nextPowOf2 | java | deeplearning4j/deeplearning4j | nd4j/nd4j-common/src/main/java/org/nd4j/common/util/MathUtils.java | https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/MathUtils.java | Apache-2.0 |
public static int binomial(RandomGenerator rng, int n, double p) {
if ((p < 0) || (p > 1)) {
return 0;
}
int c = 0;
for (int i = 0; i < n; i++) {
if (rng.nextDouble() < p) {
c++;
}
}
return c;
} |
Generates a binomial distributed number using
the given rng
@param rng
@param n
@param p
@return
| MathUtils::binomial | java | deeplearning4j/deeplearning4j | nd4j/nd4j-common/src/main/java/org/nd4j/common/util/MathUtils.java | https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/MathUtils.java | Apache-2.0 |
public static double uniform(Random rng, double min, double max) {
return rng.nextDouble() * (max - min) + min;
} |
Generate a uniform random number from the given rng
@param rng the rng to use
@param min the min num
@param max the max num
@return a number uniformly distributed between min and max
| MathUtils::uniform | java | deeplearning4j/deeplearning4j | nd4j/nd4j-common/src/main/java/org/nd4j/common/util/MathUtils.java | https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/MathUtils.java | Apache-2.0 |
public static double correlation(double[] residuals, double targetAttribute[]) {
double[] predictedValues = new double[residuals.length];
for (int i = 0; i < predictedValues.length; i++) {
predictedValues[i] = targetAttribute[i] - residuals[i];
}
double ssErr = ssError(predictedValues, targetAttribute);
double total = ssTotal(residuals, targetAttribute);
return 1 - (ssErr / total);
}//end correlation |
Returns the correlation coefficient of two double vectors.
@param residuals residuals
@param targetAttribute target attribute vector
@return the correlation coefficient or r
| MathUtils::correlation | java | deeplearning4j/deeplearning4j | nd4j/nd4j-common/src/main/java/org/nd4j/common/util/MathUtils.java | https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/MathUtils.java | Apache-2.0 |
public static double sigmoid(double x) {
return 1.0 / (1.0 + Math.pow(Math.E, -x));
} |
1 / 1 + exp(-x)
@param x
@return
| MathUtils::sigmoid | java | deeplearning4j/deeplearning4j | nd4j/nd4j-common/src/main/java/org/nd4j/common/util/MathUtils.java | https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/MathUtils.java | Apache-2.0 |
public static double ssReg(double[] residuals, double[] targetAttribute) {
double mean = sum(targetAttribute) / targetAttribute.length;
double ret = 0;
for (int i = 0; i < residuals.length; i++) {
ret += Math.pow(residuals[i] - mean, 2);
}
return ret;
} |
How much of the variance is explained by the regression
@param residuals error
@param targetAttribute data for target attribute
@return the sum squares of regression
| MathUtils::ssReg | java | deeplearning4j/deeplearning4j | nd4j/nd4j-common/src/main/java/org/nd4j/common/util/MathUtils.java | https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/MathUtils.java | Apache-2.0 |
public static double ssError(double[] predictedValues, double[] targetAttribute) {
double ret = 0;
for (int i = 0; i < predictedValues.length; i++) {
ret += Math.pow(targetAttribute[i] - predictedValues[i], 2);
}
return ret;
} |
How much of the variance is NOT explained by the regression
@param predictedValues predicted values
@param targetAttribute data for target attribute
@return the sum squares of regression
| MathUtils::ssError | java | deeplearning4j/deeplearning4j | nd4j/nd4j-common/src/main/java/org/nd4j/common/util/MathUtils.java | https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/MathUtils.java | Apache-2.0 |
public static double stringSimilarity(String... strings) {
if (strings == null)
return 0;
Counter<String> counter = new Counter<>();
Counter<String> counter2 = new Counter<>();
for (int i = 0; i < strings[0].length(); i++)
counter.incrementCount(String.valueOf(strings[0].charAt(i)), 1.0f);
for (int i = 0; i < strings[1].length(); i++)
counter2.incrementCount(String.valueOf(strings[1].charAt(i)), 1.0f);
Set<String> v1 = counter.keySet();
Set<String> v2 = counter2.keySet();
Set<String> both = SetUtils.intersection(v1, v2);
double sclar = 0, norm1 = 0, norm2 = 0;
for (String k : both)
sclar += counter.getCount(k) * counter2.getCount(k);
for (String k : v1)
norm1 += counter.getCount(k) * counter.getCount(k);
for (String k : v2)
norm2 += counter2.getCount(k) * counter2.getCount(k);
return sclar / Math.sqrt(norm1 * norm2);
} |
Calculate string similarity with tfidf weights relative to each character
frequency and how many times a character appears in a given string
@param strings the strings to calculate similarity for
@return the cosine similarity between the strings
| MathUtils::stringSimilarity | java | deeplearning4j/deeplearning4j | nd4j/nd4j-common/src/main/java/org/nd4j/common/util/MathUtils.java | https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/MathUtils.java | Apache-2.0 |
public static double vectorLength(double[] vector) {
double ret = 0;
if (vector == null)
return ret;
else {
for (int i = 0; i < vector.length; i++) {
ret += Math.pow(vector[i], 2);
}
}
return ret;
} |
Returns the vector length (sqrt(sum(x_i))
@param vector the vector to return the vector length for
@return the vector length of the passed in array
| MathUtils::vectorLength | java | deeplearning4j/deeplearning4j | nd4j/nd4j-common/src/main/java/org/nd4j/common/util/MathUtils.java | https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/MathUtils.java | Apache-2.0 |
public static double idf(double totalDocs, double numTimesWordAppearedInADocument) {
return totalDocs > 0 ? Math.log10(totalDocs / numTimesWordAppearedInADocument) : 0;
} |
Inverse document frequency: the total docs divided by the number of times the word
appeared in a document
@param totalDocs the total documents for the data applyTransformToDestination
@param numTimesWordAppearedInADocument the number of times the word occurred in a document
@return log(10) (totalDocs/numTImesWordAppearedInADocument)
| MathUtils::idf | java | deeplearning4j/deeplearning4j | nd4j/nd4j-common/src/main/java/org/nd4j/common/util/MathUtils.java | https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/MathUtils.java | Apache-2.0 |
public static double tf(int count) {
return count > 0 ? 1 + Math.log10(count) : 0;
} |
Term frequency: 1+ log10(count)
@param count the count of a word or character in a given string or document
@return 1+ log(10) count
| MathUtils::tf | java | deeplearning4j/deeplearning4j | nd4j/nd4j-common/src/main/java/org/nd4j/common/util/MathUtils.java | https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/MathUtils.java | Apache-2.0 |
public static double tfidf(double td, double idf) {
return td * idf;
} |
Return td * idf
@param td the term frequency (assumed calculated)
@param idf inverse document frequency (assumed calculated)
@return td * idf
| MathUtils::tfidf | java | deeplearning4j/deeplearning4j | nd4j/nd4j-common/src/main/java/org/nd4j/common/util/MathUtils.java | https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/MathUtils.java | Apache-2.0 |
public static double ssTotal(double[] residuals, double[] targetAttribute) {
return ssReg(residuals, targetAttribute) + ssError(residuals, targetAttribute);
} |
Total variance in target attribute
@param residuals error
@param targetAttribute data for target attribute
@return Total variance in target attribute
| MathUtils::ssTotal | java | deeplearning4j/deeplearning4j | nd4j/nd4j-common/src/main/java/org/nd4j/common/util/MathUtils.java | https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/MathUtils.java | Apache-2.0 |
public static double sum(double[] nums) {
double ret = 0;
for (double d : nums)
ret += d;
return ret;
}//end sum |
This returns the sum of the given array.
@param nums the array of numbers to sum
@return the sum of the given array
| MathUtils::sum | java | deeplearning4j/deeplearning4j | nd4j/nd4j-common/src/main/java/org/nd4j/common/util/MathUtils.java | https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/MathUtils.java | Apache-2.0 |
public static double[] mergeCoords(double[] x, double[] y) {
if (x.length != y.length)
throw new IllegalArgumentException(
"Sample sizes must be the same for each data applyTransformToDestination.");
double[] ret = new double[x.length + y.length];
for (int i = 0; i < x.length; i++) {
ret[i] = x[i];
ret[i + 1] = y[i];
}
return ret;
}//end mergeCoords |
This will merge the coordinates of the given coordinate system.
@param x the x coordinates
@param y the y coordinates
@return a vector such that each (x,y) pair is at ret[i],ret[i+1]
| MathUtils::mergeCoords | java | deeplearning4j/deeplearning4j | nd4j/nd4j-common/src/main/java/org/nd4j/common/util/MathUtils.java | https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/MathUtils.java | Apache-2.0 |
public static List<Double> mergeCoords(List<Double> x, List<Double> y) {
if (x.size() != y.size())
throw new IllegalArgumentException(
"Sample sizes must be the same for each data applyTransformToDestination.");
List<Double> ret = new ArrayList<Double>();
for (int i = 0; i < x.size(); i++) {
ret.add(x.get(i));
ret.add(y.get(i));
}
return ret;
}//end mergeCoords |
This will merge the coordinates of the given coordinate system.
@param x the x coordinates
@param y the y coordinates
@return a vector such that each (x,y) pair is at ret[i],ret[i+1]
| MathUtils::mergeCoords | java | deeplearning4j/deeplearning4j | nd4j/nd4j-common/src/main/java/org/nd4j/common/util/MathUtils.java | https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/MathUtils.java | Apache-2.0 |
public static double[] weightsFor(List<Double> vector) {
/* split coordinate system */
List<double[]> coords = coordSplit(vector);
/* x vals */
double[] x = coords.get(0);
/* y vals */
double[] y = coords.get(1);
double meanX = sum(x) / x.length;
double meanY = sum(y) / y.length;
double sumOfMeanDifferences = sumOfMeanDifferences(x, y);
double xDifferenceOfMean = sumOfMeanDifferencesOnePoint(x);
double w_1 = sumOfMeanDifferences / xDifferenceOfMean;
double w_0 = meanY - (w_1) * meanX;
//double w_1=(n*sumOfProducts(x,y) - sum(x) * sum(y))/(n*sumOfSquares(x) - Math.pow(sum(x),2));
// double w_0=(sum(y) - (w_1 * sum(x)))/n;
double[] ret = new double[vector.size()];
ret[0] = w_0;
ret[1] = w_1;
return ret;
}//end weightsFor |
This returns the minimized loss values for a given vector.
It is assumed that the x, y pairs are at
vector[i], vector[i+1]
@param vector the vector of numbers to getFromOrigin the weights for
@return a double array with w_0 and w_1 are the associated indices.
| MathUtils::weightsFor | java | deeplearning4j/deeplearning4j | nd4j/nd4j-common/src/main/java/org/nd4j/common/util/MathUtils.java | https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/MathUtils.java | Apache-2.0 |
public static double squaredLoss(double[] x, double[] y, double w_0, double w_1) {
double sum = 0;
for (int j = 0; j < x.length; j++) {
sum += Math.pow((y[j] - (w_1 * x[j] + w_0)), 2);
}
return sum;
}//end squaredLoss |
This will return the squared loss of the given
points
@param x the x coordinates to use
@param y the y coordinates to use
@param w_0 the first weight
@param w_1 the second weight
@return the squared loss of the given points
| MathUtils::squaredLoss | java | deeplearning4j/deeplearning4j | nd4j/nd4j-common/src/main/java/org/nd4j/common/util/MathUtils.java | https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/MathUtils.java | Apache-2.0 |
public static double[] weightsFor(double[] vector) {
/* split coordinate system */
List<double[]> coords = coordSplit(vector);
/* x vals */
double[] x = coords.get(0);
/* y vals */
double[] y = coords.get(1);
double meanX = sum(x) / x.length;
double meanY = sum(y) / y.length;
double sumOfMeanDifferences = sumOfMeanDifferences(x, y);
double xDifferenceOfMean = sumOfMeanDifferencesOnePoint(x);
double w_1 = sumOfMeanDifferences / xDifferenceOfMean;
double w_0 = meanY - (w_1) * meanX;
double[] ret = new double[vector.length];
ret[0] = w_0;
ret[1] = w_1;
return ret;
}//end weightsFor |
This returns the minimized loss values for a given vector.
It is assumed that the x, y pairs are at
vector[i], vector[i+1]
@param vector the vector of numbers to getFromOrigin the weights for
@return a double array with w_0 and w_1 are the associated indices.
| MathUtils::weightsFor | java | deeplearning4j/deeplearning4j | nd4j/nd4j-common/src/main/java/org/nd4j/common/util/MathUtils.java | https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/MathUtils.java | Apache-2.0 |
public static double sumOfMeanDifferences(double[] vector, double[] vector2) {
double mean = sum(vector) / vector.length;
double mean2 = sum(vector2) / vector2.length;
double ret = 0;
for (int i = 0; i < vector.length; i++) {
double vec1Diff = vector[i] - mean;
double vec2Diff = vector2[i] - mean2;
ret += vec1Diff * vec2Diff;
}
return ret;
}//end sumOfMeanDifferences |
Used for calculating top part of simple regression for
beta 1
@param vector the x coordinates
@param vector2 the y coordinates
@return the sum of mean differences for the input vectors
| MathUtils::sumOfMeanDifferences | java | deeplearning4j/deeplearning4j | nd4j/nd4j-common/src/main/java/org/nd4j/common/util/MathUtils.java | https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/MathUtils.java | Apache-2.0 |
public static double sumOfMeanDifferencesOnePoint(double[] vector) {
double mean = sum(vector) / vector.length;
double ret = 0;
for (int i = 0; i < vector.length; i++) {
double vec1Diff = Math.pow(vector[i] - mean, 2);
ret += vec1Diff;
}
return ret;
}//end sumOfMeanDifferences |
Used for calculating top part of simple regression for
beta 1
@param vector the x coordinates
@return the sum of mean differences for the input vectors
| MathUtils::sumOfMeanDifferencesOnePoint | java | deeplearning4j/deeplearning4j | nd4j/nd4j-common/src/main/java/org/nd4j/common/util/MathUtils.java | https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/MathUtils.java | Apache-2.0 |
public static double times(double[] nums) {
if (nums == null || nums.length == 0)
return 0;
double ret = 1;
for (int i = 0; i < nums.length; i++)
ret *= nums[i];
return ret;
}//end times |
This returns the product of all numbers in the given array.
@param nums the numbers to multiply over
@return the product of all numbers in the array, or 0
if the length is or or nums i null
| MathUtils::times | java | deeplearning4j/deeplearning4j | nd4j/nd4j-common/src/main/java/org/nd4j/common/util/MathUtils.java | https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/MathUtils.java | Apache-2.0 |
public static double sumOfProducts(double[]... nums) {
if (nums == null || nums.length < 1)
return 0;
double sum = 0;
for (int i = 0; i < nums.length; i++) {
/* The ith column for all of the rows */
double[] column = column(i, nums);
sum += times(column);
}
return sum;
}//end sumOfProducts |
This returns the sum of products for the given
numbers.
@param nums the sum of products for the give numbers
@return the sum of products for the given numbers
| MathUtils::sumOfProducts | java | deeplearning4j/deeplearning4j | nd4j/nd4j-common/src/main/java/org/nd4j/common/util/MathUtils.java | https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/MathUtils.java | Apache-2.0 |
private static double[] column(int column, double[]... nums) throws IllegalArgumentException {
double[] ret = new double[nums.length];
for (int i = 0; i < nums.length; i++) {
double[] curr = nums[i];
ret[i] = curr[column];
}
return ret;
}//end column |
This returns the given column over an n arrays
@param column the column to getFromOrigin values for
@param nums the arrays to extract values from
@return a double array containing all of the numbers in that column
for all of the arrays.
@throws IllegalArgumentException if the index is < 0
| MathUtils::column | java | deeplearning4j/deeplearning4j | nd4j/nd4j-common/src/main/java/org/nd4j/common/util/MathUtils.java | https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/MathUtils.java | Apache-2.0 |
public static List<double[]> coordSplit(double[] vector) {
if (vector == null)
return null;
List<double[]> ret = new ArrayList<double[]>();
/* x coordinates */
double[] xVals = new double[vector.length / 2];
/* y coordinates */
double[] yVals = new double[vector.length / 2];
/* current points */
int xTracker = 0;
int yTracker = 0;
for (int i = 0; i < vector.length; i++) {
//even value, x coordinate
if (i % 2 == 0)
xVals[xTracker++] = vector[i];
//y coordinate
else
yVals[yTracker++] = vector[i];
}
ret.add(xVals);
ret.add(yVals);
return ret;
}//end coordSplit |
This returns the coordinate split in a list of coordinates
such that the values for ret[0] are the x values
and ret[1] are the y values
@param vector the vector to split with x and y values/
@return a coordinate split for the given vector of values.
if null, is passed in null is returned
| MathUtils::coordSplit | java | deeplearning4j/deeplearning4j | nd4j/nd4j-common/src/main/java/org/nd4j/common/util/MathUtils.java | https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/MathUtils.java | Apache-2.0 |
public static List<List<Double>> partitionVariable(List<Double> arr, int chunk) {
int count = 0;
List<List<Double>> ret = new ArrayList<List<Double>>();
while (count < arr.size()) {
List<Double> sublist = arr.subList(count, count + chunk);
count += chunk;
ret.add(sublist);
}
//All data sets must be same size
for (List<Double> lists : ret) {
if (lists.size() < chunk)
ret.remove(lists);
}
return ret;
}//end partitionVariable |
This will partition the given whole variable data applyTransformToDestination in to the specified chunk number.
@param arr the data applyTransformToDestination to pass in
@param chunk the number to separate by
@return a partition data applyTransformToDestination relative to the passed in chunk number
| MathUtils::partitionVariable | java | deeplearning4j/deeplearning4j | nd4j/nd4j-common/src/main/java/org/nd4j/common/util/MathUtils.java | https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/MathUtils.java | Apache-2.0 |
public static List<double[]> coordSplit(List<Double> vector) {
if (vector == null)
return null;
List<double[]> ret = new ArrayList<double[]>();
/* x coordinates */
double[] xVals = new double[vector.size() / 2];
/* y coordinates */
double[] yVals = new double[vector.size() / 2];
/* current points */
int xTracker = 0;
int yTracker = 0;
for (int i = 0; i < vector.size(); i++) {
//even value, x coordinate
if (i % 2 == 0)
xVals[xTracker++] = vector.get(i);
//y coordinate
else
yVals[yTracker++] = vector.get(i);
}
ret.add(xVals);
ret.add(yVals);
return ret;
}//end coordSplit |
This returns the coordinate split in a list of coordinates
such that the values for ret[0] are the x values
and ret[1] are the y values
@param vector the vector to split with x and y values
Note that the list will be more stable due to the size operator.
The array version will have extraneous values if not monitored
properly.
@return a coordinate split for the given vector of values.
if null, is passed in null is returned
| MathUtils::coordSplit | java | deeplearning4j/deeplearning4j | nd4j/nd4j-common/src/main/java/org/nd4j/common/util/MathUtils.java | https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/MathUtils.java | Apache-2.0 |
public static double[] xVals(double[] vector) {
if (vector == null)
return null;
double[] x = new double[vector.length / 2];
int count = 0;
for (int i = 0; i < vector.length; i++) {
if (i % 2 != 0)
x[count++] = vector[i];
}
return x;
}//end xVals |
This returns the x values of the given vector.
These are assumed to be the even values of the vector.
@param vector the vector to getFromOrigin the values for
@return the x values of the given vector
| MathUtils::xVals | java | deeplearning4j/deeplearning4j | nd4j/nd4j-common/src/main/java/org/nd4j/common/util/MathUtils.java | https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/MathUtils.java | Apache-2.0 |
public static double[] yVals(double[] vector) {
double[] y = new double[vector.length / 2];
int count = 0;
for (int i = 0; i < vector.length; i++) {
if (i % 2 == 0)
y[count++] = vector[i];
}
return y;
}//end yVals |
This returns the odd indexed values for the given vector
@param vector the odd indexed values of rht egiven vector
@return the y values of the given vector
| MathUtils::yVals | java | deeplearning4j/deeplearning4j | nd4j/nd4j-common/src/main/java/org/nd4j/common/util/MathUtils.java | https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/MathUtils.java | Apache-2.0 |
public static double sumOfSquares(double[] vector) {
double ret = 0;
for (double d : vector)
ret += Math.pow(d, 2);
return ret;
} |
This returns the sum of squares for the given vector.
@param vector the vector to obtain the sum of squares for
@return the sum of squares for this vector
| MathUtils::sumOfSquares | java | deeplearning4j/deeplearning4j | nd4j/nd4j-common/src/main/java/org/nd4j/common/util/MathUtils.java | https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/MathUtils.java | Apache-2.0 |
public static double determinationCoefficient(double[] y1, double[] y2, int n) {
return Math.pow(correlation(y1, y2), 2);
} |
This returns the determination coefficient of two vectors given a length
@param y1 the first vector
@param y2 the second vector
@param n the length of both vectors
@return the determination coefficient or r^2
| MathUtils::determinationCoefficient | java | deeplearning4j/deeplearning4j | nd4j/nd4j-common/src/main/java/org/nd4j/common/util/MathUtils.java | https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/MathUtils.java | Apache-2.0 |
public static double log2(double a) {
if (a == 0)
return 0.0;
return Math.log(a) / log2;
} |
Returns the logarithm of a for base 2.
@param a a double
@return the logarithm for base 2
| MathUtils::log2 | java | deeplearning4j/deeplearning4j | nd4j/nd4j-common/src/main/java/org/nd4j/common/util/MathUtils.java | https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/MathUtils.java | Apache-2.0 |
public static double rootMeansSquaredError(double[] real, double[] predicted) {
double ret = 1 / real.length;
for (int i = 0; i < real.length; i++) {
ret += Math.pow((real[i] - predicted[i]), 2);
}
return Math.sqrt(ret);
}//end rootMeansSquaredError |
This returns the root mean squared error of two data sets
@param real the realComponent values
@param predicted the predicted values
@return the root means squared error for two data sets
| MathUtils::rootMeansSquaredError | java | deeplearning4j/deeplearning4j | nd4j/nd4j-common/src/main/java/org/nd4j/common/util/MathUtils.java | https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/MathUtils.java | Apache-2.0 |
public static double entropy(double[] vector) {
if (vector == null || vector.length == 0)
return 0;
else {
double ret = 0;
for (double d : vector)
ret += d * Math.log(d);
return -ret;
}
}//end entropy |
This returns the entropy (information gain, or uncertainty of a random variable): -sum(x*log(x))
@param vector the vector of values to getFromOrigin the entropy for
@return the entropy of the given vector
| MathUtils::entropy | java | deeplearning4j/deeplearning4j | nd4j/nd4j-common/src/main/java/org/nd4j/common/util/MathUtils.java | https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/MathUtils.java | Apache-2.0 |
public static int kroneckerDelta(double i, double j) {
return (i == j) ? 1 : 0;
} |
This returns the kronecker delta of two doubles.
@param i the first number to compare
@param j the second number to compare
@return 1 if they are equal, 0 otherwise
| MathUtils::kroneckerDelta | java | deeplearning4j/deeplearning4j | nd4j/nd4j-common/src/main/java/org/nd4j/common/util/MathUtils.java | https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/MathUtils.java | Apache-2.0 |
public static double adjustedrSquared(double rSquared, int numRegressors, int numDataPoints) {
double divide = (numDataPoints - 1) / (numDataPoints - numRegressors - 1);
double rSquaredDiff = 1 - rSquared;
return 1 - (rSquaredDiff * divide);
} |
This calculates the adjusted r^2 including degrees of freedom.
Also known as calculating "strength" of a regression
@param rSquared the r squared value to calculate
@param numRegressors number of variables
@param numDataPoints size of the data applyTransformToDestination
@return an adjusted r^2 for degrees of freedom
| MathUtils::adjustedrSquared | java | deeplearning4j/deeplearning4j | nd4j/nd4j-common/src/main/java/org/nd4j/common/util/MathUtils.java | https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/MathUtils.java | Apache-2.0 |
public static void normalize(double[] doubles, double sum) {
if (Double.isNaN(sum)) {
throw new IllegalArgumentException("Can't normalize array. Sum is NaN.");
}
if (sum == 0) {
// Maybe this should just be a return.
throw new IllegalArgumentException("Can't normalize array. Sum is zero.");
}
for (int i = 0; i < doubles.length; i++) {
doubles[i] /= sum;
}
}//end normalize |
Normalizes the doubles in the array using the given value.
@param doubles the array of double
@param sum the value by which the doubles are to be normalized
@throws IllegalArgumentException if sum is zero or NaN
| MathUtils::normalize | java | deeplearning4j/deeplearning4j | nd4j/nd4j-common/src/main/java/org/nd4j/common/util/MathUtils.java | https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/MathUtils.java | Apache-2.0 |
public static double[] logs2probs(double[] a) {
double max = a[maxIndex(a)];
double sum = 0.0;
double[] result = new double[a.length];
for (int i = 0; i < a.length; i++) {
result[i] = Math.exp(a[i] - max);
sum += result[i];
}
normalize(result, sum);
return result;
}//end logs2probs |
Converts an array containing the natural logarithms of
probabilities stored in a vector back into probabilities.
The probabilities are assumed to sum to one.
@param a an array holding the natural logarithms of the probabilities
@return the converted array
| MathUtils::logs2probs | java | deeplearning4j/deeplearning4j | nd4j/nd4j-common/src/main/java/org/nd4j/common/util/MathUtils.java | https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/MathUtils.java | Apache-2.0 |
public static double information(double[] probabilities) {
double total = 0.0;
for (double d : probabilities) {
total += (-1.0 * log2(d) * d);
}
return total;
}//end information |
This returns the entropy for a given vector of probabilities.
@param probabilities the probabilities to getFromOrigin the entropy for
@return the entropy of the given probabilities.
| MathUtils::information | java | deeplearning4j/deeplearning4j | nd4j/nd4j-common/src/main/java/org/nd4j/common/util/MathUtils.java | https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/MathUtils.java | Apache-2.0 |
public static /*@pure@*/ int maxIndex(double[] doubles) {
double maximum = 0;
int maxIndex = 0;
for (int i = 0; i < doubles.length; i++) {
if ((i == 0) || (doubles[i] > maximum)) {
maxIndex = i;
maximum = doubles[i];
}
}
return maxIndex;
}//end maxIndex |
Returns index of maximum element in a given
array of doubles. First maximum is returned.
@param doubles the array of doubles
@return the index of the maximum element
| MathUtils::maxIndex | java | deeplearning4j/deeplearning4j | nd4j/nd4j-common/src/main/java/org/nd4j/common/util/MathUtils.java | https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/MathUtils.java | Apache-2.0 |
public static double factorial(double n) {
if (n == 1 || n == 0)
return 1;
for (double i = n; i > 0; i--, n *= (i > 0 ? i : 1)) {
}
return n;
}//end factorial |
This will return the factorial of the given number n.
@param n the number to getFromOrigin the factorial for
@return the factorial for this number
| MathUtils::factorial | java | deeplearning4j/deeplearning4j | nd4j/nd4j-common/src/main/java/org/nd4j/common/util/MathUtils.java | https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/MathUtils.java | Apache-2.0 |
public static /*@pure@*/ double probToLogOdds(double prob) {
if (gr(prob, 1) || (sm(prob, 0))) {
throw new IllegalArgumentException("probToLogOdds: probability must " + "be in [0,1] " + prob);
}
double p = SMALL + (1.0 - 2 * SMALL) * prob;
return Math.log(p / (1 - p));
} |
Returns the log-odds for a given probability.
@param prob the probability
@return the log-odds after the probability has been mapped to
[Utils.SMALL, 1-Utils.SMALL]
| MathUtils::probToLogOdds | java | deeplearning4j/deeplearning4j | nd4j/nd4j-common/src/main/java/org/nd4j/common/util/MathUtils.java | https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/MathUtils.java | Apache-2.0 |
public static /*@pure@*/ int round(double value) {
int roundedValue = value > 0 ? (int) (value + 0.5) : -(int) (Math.abs(value) + 0.5);
return roundedValue;
}//end round |
Rounds a double to the next nearest integer value. The JDK version
of it doesn't work properly.
@param value the double value
@return the resulting integer value
| MathUtils::round | java | deeplearning4j/deeplearning4j | nd4j/nd4j-common/src/main/java/org/nd4j/common/util/MathUtils.java | https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/MathUtils.java | Apache-2.0 |
public static double permutation(double n, double r) {
double nFac = MathUtils.factorial(n);
double nMinusRFac = MathUtils.factorial((n - r));
return nFac / nMinusRFac;
}//end permutation |
This returns the permutation of n choose r.
@param n the n to choose
@param r the number of elements to choose
@return the permutation of these numbers
| MathUtils::permutation | java | deeplearning4j/deeplearning4j | nd4j/nd4j-common/src/main/java/org/nd4j/common/util/MathUtils.java | https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/MathUtils.java | Apache-2.0 |
public static double combination(double n, double r) {
double nFac = MathUtils.factorial(n);
double rFac = MathUtils.factorial(r);
double nMinusRFac = MathUtils.factorial((n - r));
return nFac / (rFac * nMinusRFac);
}//end combination |
This returns the combination of n choose r
@param n the number of elements overall
@param r the number of elements to choose
@return the amount of possible combinations for this applyTransformToDestination of elements
| MathUtils::combination | java | deeplearning4j/deeplearning4j | nd4j/nd4j-common/src/main/java/org/nd4j/common/util/MathUtils.java | https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/MathUtils.java | Apache-2.0 |
public static double hypotenuse(double a, double b) {
double r;
if (Math.abs(a) > Math.abs(b)) {
r = b / a;
r = Math.abs(a) * Math.sqrt(1 + r * r);
} else if (b != 0) {
r = a / b;
r = Math.abs(b) * Math.sqrt(1 + r * r);
} else {
r = 0.0;
}
return r;
}//end hypotenuse |
sqrt(a^2 + b^2) without under/overflow.
| MathUtils::hypotenuse | java | deeplearning4j/deeplearning4j | nd4j/nd4j-common/src/main/java/org/nd4j/common/util/MathUtils.java | https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-common/src/main/java/org/nd4j/common/util/MathUtils.java | Apache-2.0 |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.