repo stringlengths 7 58 | path stringlengths 12 218 | func_name stringlengths 3 140 | original_string stringlengths 73 34.1k | language stringclasses 1 value | code stringlengths 73 34.1k | code_tokens list | docstring stringlengths 3 16k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 105 339 | partition stringclasses 1 value |
|---|---|---|---|---|---|---|---|---|---|---|---|
elki-project/elki | elki-core-util/src/main/java/de/lmu/ifi/dbs/elki/utilities/ELKIServiceScanner.java | ELKIServiceScanner.load | public static void load(Class<?> restrictionClass) {
if(MASTER_CACHE == null) {
initialize();
}
if(MASTER_CACHE.isEmpty()) {
return;
}
Iterator<Class<?>> iter = MASTER_CACHE.iterator();
while(iter.hasNext()) {
Class<?> clazz = iter.next();
// Skip other classes.
if(!restrictionClass.isAssignableFrom(clazz)) {
continue;
}
// skip abstract / private classes.
if(Modifier.isInterface(clazz.getModifiers()) || Modifier.isAbstract(clazz.getModifiers()) || Modifier.isPrivate(clazz.getModifiers())) {
continue;
}
boolean instantiable = false;
try {
instantiable = clazz.getConstructor() != null;
}
catch(Exception | Error e) {
// ignore
}
try {
instantiable = instantiable || ClassGenericsUtil.getParameterizer(clazz) != null;
}
catch(Exception | Error e) {
// ignore
}
if(!instantiable) {
continue;
}
ELKIServiceRegistry.register(restrictionClass, clazz);
}
} | java | public static void load(Class<?> restrictionClass) {
if(MASTER_CACHE == null) {
initialize();
}
if(MASTER_CACHE.isEmpty()) {
return;
}
Iterator<Class<?>> iter = MASTER_CACHE.iterator();
while(iter.hasNext()) {
Class<?> clazz = iter.next();
// Skip other classes.
if(!restrictionClass.isAssignableFrom(clazz)) {
continue;
}
// skip abstract / private classes.
if(Modifier.isInterface(clazz.getModifiers()) || Modifier.isAbstract(clazz.getModifiers()) || Modifier.isPrivate(clazz.getModifiers())) {
continue;
}
boolean instantiable = false;
try {
instantiable = clazz.getConstructor() != null;
}
catch(Exception | Error e) {
// ignore
}
try {
instantiable = instantiable || ClassGenericsUtil.getParameterizer(clazz) != null;
}
catch(Exception | Error e) {
// ignore
}
if(!instantiable) {
continue;
}
ELKIServiceRegistry.register(restrictionClass, clazz);
}
} | [
"public",
"static",
"void",
"load",
"(",
"Class",
"<",
"?",
">",
"restrictionClass",
")",
"{",
"if",
"(",
"MASTER_CACHE",
"==",
"null",
")",
"{",
"initialize",
"(",
")",
";",
"}",
"if",
"(",
"MASTER_CACHE",
".",
"isEmpty",
"(",
")",
")",
"{",
"return... | Load classes via linear scanning.
@param restrictionClass Class to find subclasses for. | [
"Load",
"classes",
"via",
"linear",
"scanning",
"."
] | b54673327e76198ecd4c8a2a901021f1a9174498 | https://github.com/elki-project/elki/blob/b54673327e76198ecd4c8a2a901021f1a9174498/elki-core-util/src/main/java/de/lmu/ifi/dbs/elki/utilities/ELKIServiceScanner.java#L76-L112 | train |
elki-project/elki | elki-core-util/src/main/java/de/lmu/ifi/dbs/elki/utilities/ELKIServiceScanner.java | ELKIServiceScanner.comparePackageClass | private static int comparePackageClass(Class<?> o1, Class<?> o2) {
return o1.getPackage() == o2.getPackage() ? //
o1.getCanonicalName().compareTo(o2.getCanonicalName()) //
: o1.getPackage() == null ? -1 : o2.getPackage() == null ? +1 //
: o1.getPackage().getName().compareTo(o2.getPackage().getName());
} | java | private static int comparePackageClass(Class<?> o1, Class<?> o2) {
return o1.getPackage() == o2.getPackage() ? //
o1.getCanonicalName().compareTo(o2.getCanonicalName()) //
: o1.getPackage() == null ? -1 : o2.getPackage() == null ? +1 //
: o1.getPackage().getName().compareTo(o2.getPackage().getName());
} | [
"private",
"static",
"int",
"comparePackageClass",
"(",
"Class",
"<",
"?",
">",
"o1",
",",
"Class",
"<",
"?",
">",
"o2",
")",
"{",
"return",
"o1",
".",
"getPackage",
"(",
")",
"==",
"o2",
".",
"getPackage",
"(",
")",
"?",
"//",
"o1",
".",
"getCanon... | Compare two classes, by package name first.
@param o1 First class
@param o2 Second class
@return Comparison result | [
"Compare",
"two",
"classes",
"by",
"package",
"name",
"first",
"."
] | b54673327e76198ecd4c8a2a901021f1a9174498 | https://github.com/elki-project/elki/blob/b54673327e76198ecd4c8a2a901021f1a9174498/elki-core-util/src/main/java/de/lmu/ifi/dbs/elki/utilities/ELKIServiceScanner.java#L274-L279 | train |
elki-project/elki | elki-core-util/src/main/java/de/lmu/ifi/dbs/elki/utilities/ELKIServiceScanner.java | ELKIServiceScanner.classPriority | private static int classPriority(Class<?> o1) {
Priority p = o1.getAnnotation(Priority.class);
if(p == null) {
Class<?> pa = o1.getDeclaringClass();
p = (pa != null) ? pa.getAnnotation(Priority.class) : null;
}
return p != null ? p.value() : Priority.DEFAULT;
} | java | private static int classPriority(Class<?> o1) {
Priority p = o1.getAnnotation(Priority.class);
if(p == null) {
Class<?> pa = o1.getDeclaringClass();
p = (pa != null) ? pa.getAnnotation(Priority.class) : null;
}
return p != null ? p.value() : Priority.DEFAULT;
} | [
"private",
"static",
"int",
"classPriority",
"(",
"Class",
"<",
"?",
">",
"o1",
")",
"{",
"Priority",
"p",
"=",
"o1",
".",
"getAnnotation",
"(",
"Priority",
".",
"class",
")",
";",
"if",
"(",
"p",
"==",
"null",
")",
"{",
"Class",
"<",
"?",
">",
"... | Get the priority of a class, or its outer class.
@param o1 Class
@return Priority | [
"Get",
"the",
"priority",
"of",
"a",
"class",
"or",
"its",
"outer",
"class",
"."
] | b54673327e76198ecd4c8a2a901021f1a9174498 | https://github.com/elki-project/elki/blob/b54673327e76198ecd4c8a2a901021f1a9174498/elki-core-util/src/main/java/de/lmu/ifi/dbs/elki/utilities/ELKIServiceScanner.java#L287-L294 | train |
elki-project/elki | elki-core/src/main/java/de/lmu/ifi/dbs/elki/utilities/datastructures/unionfind/WeightedQuickUnionInteger.java | WeightedQuickUnionInteger.nextIndex | public int nextIndex(int weight) {
if(used == parent.length) {
int nsize = used + (used >> 1);
this.weight = Arrays.copyOf(this.weight, nsize);
this.parent = Arrays.copyOf(this.parent, nsize);
}
this.weight[used] = weight;
this.parent[used] = used;
return used++;
} | java | public int nextIndex(int weight) {
if(used == parent.length) {
int nsize = used + (used >> 1);
this.weight = Arrays.copyOf(this.weight, nsize);
this.parent = Arrays.copyOf(this.parent, nsize);
}
this.weight[used] = weight;
this.parent[used] = used;
return used++;
} | [
"public",
"int",
"nextIndex",
"(",
"int",
"weight",
")",
"{",
"if",
"(",
"used",
"==",
"parent",
".",
"length",
")",
"{",
"int",
"nsize",
"=",
"used",
"+",
"(",
"used",
">>",
"1",
")",
";",
"this",
".",
"weight",
"=",
"Arrays",
".",
"copyOf",
"("... | Occupy the next unused index.
@param weight Initial weight.
@return Next unused index. | [
"Occupy",
"the",
"next",
"unused",
"index",
"."
] | b54673327e76198ecd4c8a2a901021f1a9174498 | https://github.com/elki-project/elki/blob/b54673327e76198ecd4c8a2a901021f1a9174498/elki-core/src/main/java/de/lmu/ifi/dbs/elki/utilities/datastructures/unionfind/WeightedQuickUnionInteger.java#L84-L93 | train |
elki-project/elki | elki-core/src/main/java/de/lmu/ifi/dbs/elki/utilities/datastructures/unionfind/WeightedQuickUnionInteger.java | WeightedQuickUnionInteger.find | public int find(int cur) {
assert (cur >= 0 && cur < parent.length);
int p = parent[cur], tmp;
while(cur != p) {
tmp = p;
p = parent[cur] = parent[p]; // Perform simple path compression.
cur = tmp;
}
return cur;
} | java | public int find(int cur) {
assert (cur >= 0 && cur < parent.length);
int p = parent[cur], tmp;
while(cur != p) {
tmp = p;
p = parent[cur] = parent[p]; // Perform simple path compression.
cur = tmp;
}
return cur;
} | [
"public",
"int",
"find",
"(",
"int",
"cur",
")",
"{",
"assert",
"(",
"cur",
">=",
"0",
"&&",
"cur",
"<",
"parent",
".",
"length",
")",
";",
"int",
"p",
"=",
"parent",
"[",
"cur",
"]",
",",
"tmp",
";",
"while",
"(",
"cur",
"!=",
"p",
")",
"{",... | Find the parent of an object.
@param cur Current entry
@return Parent entry | [
"Find",
"the",
"parent",
"of",
"an",
"object",
"."
] | b54673327e76198ecd4c8a2a901021f1a9174498 | https://github.com/elki-project/elki/blob/b54673327e76198ecd4c8a2a901021f1a9174498/elki-core/src/main/java/de/lmu/ifi/dbs/elki/utilities/datastructures/unionfind/WeightedQuickUnionInteger.java#L101-L110 | train |
elki-project/elki | elki-core/src/main/java/de/lmu/ifi/dbs/elki/utilities/datastructures/unionfind/WeightedQuickUnionInteger.java | WeightedQuickUnionInteger.union | public int union(int first, int second) {
int firstComponent = find(first), secondComponent = find(second);
if(firstComponent == secondComponent) {
return firstComponent;
}
final int w1 = weight[firstComponent], w2 = weight[secondComponent];
if(w1 > w2) {
parent[secondComponent] = firstComponent;
weight[firstComponent] += w2;
return firstComponent;
}
else {
parent[firstComponent] = secondComponent;
weight[secondComponent] += w1;
return secondComponent;
}
} | java | public int union(int first, int second) {
int firstComponent = find(first), secondComponent = find(second);
if(firstComponent == secondComponent) {
return firstComponent;
}
final int w1 = weight[firstComponent], w2 = weight[secondComponent];
if(w1 > w2) {
parent[secondComponent] = firstComponent;
weight[firstComponent] += w2;
return firstComponent;
}
else {
parent[firstComponent] = secondComponent;
weight[secondComponent] += w1;
return secondComponent;
}
} | [
"public",
"int",
"union",
"(",
"int",
"first",
",",
"int",
"second",
")",
"{",
"int",
"firstComponent",
"=",
"find",
"(",
"first",
")",
",",
"secondComponent",
"=",
"find",
"(",
"second",
")",
";",
"if",
"(",
"firstComponent",
"==",
"secondComponent",
")... | Join the components of elements p and q.
@param first First element
@param second Second element
@return Component id. | [
"Join",
"the",
"components",
"of",
"elements",
"p",
"and",
"q",
"."
] | b54673327e76198ecd4c8a2a901021f1a9174498 | https://github.com/elki-project/elki/blob/b54673327e76198ecd4c8a2a901021f1a9174498/elki-core/src/main/java/de/lmu/ifi/dbs/elki/utilities/datastructures/unionfind/WeightedQuickUnionInteger.java#L119-L135 | train |
elki-project/elki | elki-core/src/main/java/de/lmu/ifi/dbs/elki/utilities/datastructures/unionfind/WeightedQuickUnionInteger.java | WeightedQuickUnionInteger.getRoots | public IntList getRoots() {
IntList roots = new IntArrayList();
for(int i = 0; i < used; i++) {
// roots or one element in component
if(parent[i] == i) {
roots.add(i);
}
}
return roots;
} | java | public IntList getRoots() {
IntList roots = new IntArrayList();
for(int i = 0; i < used; i++) {
// roots or one element in component
if(parent[i] == i) {
roots.add(i);
}
}
return roots;
} | [
"public",
"IntList",
"getRoots",
"(",
")",
"{",
"IntList",
"roots",
"=",
"new",
"IntArrayList",
"(",
")",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"used",
";",
"i",
"++",
")",
"{",
"// roots or one element in component",
"if",
"(",
"parent... | Collect all component root elements.
@return Root elements | [
"Collect",
"all",
"component",
"root",
"elements",
"."
] | b54673327e76198ecd4c8a2a901021f1a9174498 | https://github.com/elki-project/elki/blob/b54673327e76198ecd4c8a2a901021f1a9174498/elki-core/src/main/java/de/lmu/ifi/dbs/elki/utilities/datastructures/unionfind/WeightedQuickUnionInteger.java#L153-L162 | train |
elki-project/elki | addons/xtree/src/main/java/de/lmu/ifi/dbs/elki/index/tree/spatial/rstarvariants/xtree/AbstractXTreeNode.java | AbstractXTreeNode.growSuperNode | public int growSuperNode() {
if(getNumEntries() < getCapacity()) {
throw new IllegalStateException("This node is not yet overflowing (only " + getNumEntries() + " of " + getCapacity() + " entries)");
}
Entry[] old_nodes = super.entries.clone();
assert old_nodes[old_nodes.length - 1] != null;
super.entries = (Entry[]) java.util.Arrays.copyOfRange(old_nodes, 0, getCapacity() * 2 - 1, entries.getClass());
assert super.entries.length == old_nodes.length * 2 - 1;
return getCapacity();
} | java | public int growSuperNode() {
if(getNumEntries() < getCapacity()) {
throw new IllegalStateException("This node is not yet overflowing (only " + getNumEntries() + " of " + getCapacity() + " entries)");
}
Entry[] old_nodes = super.entries.clone();
assert old_nodes[old_nodes.length - 1] != null;
super.entries = (Entry[]) java.util.Arrays.copyOfRange(old_nodes, 0, getCapacity() * 2 - 1, entries.getClass());
assert super.entries.length == old_nodes.length * 2 - 1;
return getCapacity();
} | [
"public",
"int",
"growSuperNode",
"(",
")",
"{",
"if",
"(",
"getNumEntries",
"(",
")",
"<",
"getCapacity",
"(",
")",
")",
"{",
"throw",
"new",
"IllegalStateException",
"(",
"\"This node is not yet overflowing (only \"",
"+",
"getNumEntries",
"(",
")",
"+",
"\" o... | Grows the supernode by duplicating its capacity.
@return the new page capacity of this node | [
"Grows",
"the",
"supernode",
"by",
"duplicating",
"its",
"capacity",
"."
] | b54673327e76198ecd4c8a2a901021f1a9174498 | https://github.com/elki-project/elki/blob/b54673327e76198ecd4c8a2a901021f1a9174498/addons/xtree/src/main/java/de/lmu/ifi/dbs/elki/index/tree/spatial/rstarvariants/xtree/AbstractXTreeNode.java#L90-L99 | train |
elki-project/elki | addons/xtree/src/main/java/de/lmu/ifi/dbs/elki/index/tree/spatial/rstarvariants/xtree/AbstractXTreeNode.java | AbstractXTreeNode.readSuperNode | public <T extends AbstractXTree<N>> void readSuperNode(ObjectInput in, T tree) throws IOException, ClassNotFoundException {
readExternal(in);
if(capacity_to_be_filled <= 0 || !isSuperNode()) {
throw new IllegalStateException("This node does not appear to be a supernode");
}
if(isLeaf) {
throw new IllegalStateException("A supernode is cannot be a leaf");
}
// TODO: verify
entries = new Entry[capacity_to_be_filled];
// old way:
// entries = (E[]) new XDirectoryEntry[capacity_to_be_filled];
capacity_to_be_filled = 0;
for(int i = 0; i < numEntries; i++) {
SpatialEntry s = new SpatialDirectoryEntry();
s.readExternal(in);
entries[i] = s;
}
N n = tree.getSupernodes().put((long) getPageID(), (N) this);
if(n != null) {
Logging.getLogger(this.getClass()).fine("Warning: this supernode should only be read once. Now a node of size " + entries.length + " has replaced a node of size " + n.entries.length + " for id " + getPageID());
}
} | java | public <T extends AbstractXTree<N>> void readSuperNode(ObjectInput in, T tree) throws IOException, ClassNotFoundException {
readExternal(in);
if(capacity_to_be_filled <= 0 || !isSuperNode()) {
throw new IllegalStateException("This node does not appear to be a supernode");
}
if(isLeaf) {
throw new IllegalStateException("A supernode is cannot be a leaf");
}
// TODO: verify
entries = new Entry[capacity_to_be_filled];
// old way:
// entries = (E[]) new XDirectoryEntry[capacity_to_be_filled];
capacity_to_be_filled = 0;
for(int i = 0; i < numEntries; i++) {
SpatialEntry s = new SpatialDirectoryEntry();
s.readExternal(in);
entries[i] = s;
}
N n = tree.getSupernodes().put((long) getPageID(), (N) this);
if(n != null) {
Logging.getLogger(this.getClass()).fine("Warning: this supernode should only be read once. Now a node of size " + entries.length + " has replaced a node of size " + n.entries.length + " for id " + getPageID());
}
} | [
"public",
"<",
"T",
"extends",
"AbstractXTree",
"<",
"N",
">",
">",
"void",
"readSuperNode",
"(",
"ObjectInput",
"in",
",",
"T",
"tree",
")",
"throws",
"IOException",
",",
"ClassNotFoundException",
"{",
"readExternal",
"(",
"in",
")",
";",
"if",
"(",
"capa... | Reads the id of this supernode, the numEntries and the entries array from
the specified stream.
@param in the stream to read data from in order to restore the object
@param tree the tree this supernode is to be assigned to
@throws java.io.IOException if I/O errors occur
@throws ClassNotFoundException If the class for an object being restored
cannot be found.
@throws IllegalStateException if the parameters of the file's supernode do
not match this | [
"Reads",
"the",
"id",
"of",
"this",
"supernode",
"the",
"numEntries",
"and",
"the",
"entries",
"array",
"from",
"the",
"specified",
"stream",
"."
] | b54673327e76198ecd4c8a2a901021f1a9174498 | https://github.com/elki-project/elki/blob/b54673327e76198ecd4c8a2a901021f1a9174498/addons/xtree/src/main/java/de/lmu/ifi/dbs/elki/index/tree/spatial/rstarvariants/xtree/AbstractXTreeNode.java#L238-L260 | train |
elki-project/elki | elki-core-dbids/src/main/java/de/lmu/ifi/dbs/elki/database/ids/DBIDUtil.java | DBIDUtil.compare | public static int compare(DBIDRef id1, DBIDRef id2) {
return DBIDFactory.FACTORY.compare(id1, id2);
} | java | public static int compare(DBIDRef id1, DBIDRef id2) {
return DBIDFactory.FACTORY.compare(id1, id2);
} | [
"public",
"static",
"int",
"compare",
"(",
"DBIDRef",
"id1",
",",
"DBIDRef",
"id2",
")",
"{",
"return",
"DBIDFactory",
".",
"FACTORY",
".",
"compare",
"(",
"id1",
",",
"id2",
")",
";",
"}"
] | Compare two DBIDs.
@param id1 First ID
@param id2 Second ID
@return Comparison result | [
"Compare",
"two",
"DBIDs",
"."
] | b54673327e76198ecd4c8a2a901021f1a9174498 | https://github.com/elki-project/elki/blob/b54673327e76198ecd4c8a2a901021f1a9174498/elki-core-dbids/src/main/java/de/lmu/ifi/dbs/elki/database/ids/DBIDUtil.java#L95-L97 | train |
elki-project/elki | elki-core-dbids/src/main/java/de/lmu/ifi/dbs/elki/database/ids/DBIDUtil.java | DBIDUtil.equal | public static boolean equal(DBIDRef id1, DBIDRef id2) {
return DBIDFactory.FACTORY.equal(id1, id2);
} | java | public static boolean equal(DBIDRef id1, DBIDRef id2) {
return DBIDFactory.FACTORY.equal(id1, id2);
} | [
"public",
"static",
"boolean",
"equal",
"(",
"DBIDRef",
"id1",
",",
"DBIDRef",
"id2",
")",
"{",
"return",
"DBIDFactory",
".",
"FACTORY",
".",
"equal",
"(",
"id1",
",",
"id2",
")",
";",
"}"
] | Test two DBIDs for equality.
@param id1 First ID
@param id2 Second ID
@return Comparison result | [
"Test",
"two",
"DBIDs",
"for",
"equality",
"."
] | b54673327e76198ecd4c8a2a901021f1a9174498 | https://github.com/elki-project/elki/blob/b54673327e76198ecd4c8a2a901021f1a9174498/elki-core-dbids/src/main/java/de/lmu/ifi/dbs/elki/database/ids/DBIDUtil.java#L106-L108 | train |
elki-project/elki | elki-core-dbids/src/main/java/de/lmu/ifi/dbs/elki/database/ids/DBIDUtil.java | DBIDUtil.deref | public static DBID deref(DBIDRef ref) {
return ref instanceof DBID ? (DBID) ref : importInteger(ref.internalGetIndex());
} | java | public static DBID deref(DBIDRef ref) {
return ref instanceof DBID ? (DBID) ref : importInteger(ref.internalGetIndex());
} | [
"public",
"static",
"DBID",
"deref",
"(",
"DBIDRef",
"ref",
")",
"{",
"return",
"ref",
"instanceof",
"DBID",
"?",
"(",
"DBID",
")",
"ref",
":",
"importInteger",
"(",
"ref",
".",
"internalGetIndex",
"(",
")",
")",
";",
"}"
] | Dereference a DBID reference.
@param ref DBID reference
@return DBID | [
"Dereference",
"a",
"DBID",
"reference",
"."
] | b54673327e76198ecd4c8a2a901021f1a9174498 | https://github.com/elki-project/elki/blob/b54673327e76198ecd4c8a2a901021f1a9174498/elki-core-dbids/src/main/java/de/lmu/ifi/dbs/elki/database/ids/DBIDUtil.java#L116-L118 | train |
elki-project/elki | elki-core-dbids/src/main/java/de/lmu/ifi/dbs/elki/database/ids/DBIDUtil.java | DBIDUtil.union | public static ModifiableDBIDs union(DBIDs ids1, DBIDs ids2) {
ModifiableDBIDs result = DBIDUtil.newHashSet(Math.max(ids1.size(), ids2.size()));
result.addDBIDs(ids1);
result.addDBIDs(ids2);
return result;
} | java | public static ModifiableDBIDs union(DBIDs ids1, DBIDs ids2) {
ModifiableDBIDs result = DBIDUtil.newHashSet(Math.max(ids1.size(), ids2.size()));
result.addDBIDs(ids1);
result.addDBIDs(ids2);
return result;
} | [
"public",
"static",
"ModifiableDBIDs",
"union",
"(",
"DBIDs",
"ids1",
",",
"DBIDs",
"ids2",
")",
"{",
"ModifiableDBIDs",
"result",
"=",
"DBIDUtil",
".",
"newHashSet",
"(",
"Math",
".",
"max",
"(",
"ids1",
".",
"size",
"(",
")",
",",
"ids2",
".",
"size",
... | Returns the union of the two specified collection of IDs.
@param ids1 the first collection
@param ids2 the second collection
@return the union of ids1 and ids2 without duplicates | [
"Returns",
"the",
"union",
"of",
"the",
"two",
"specified",
"collection",
"of",
"IDs",
"."
] | b54673327e76198ecd4c8a2a901021f1a9174498 | https://github.com/elki-project/elki/blob/b54673327e76198ecd4c8a2a901021f1a9174498/elki-core-dbids/src/main/java/de/lmu/ifi/dbs/elki/database/ids/DBIDUtil.java#L398-L403 | train |
elki-project/elki | elki-core-dbids/src/main/java/de/lmu/ifi/dbs/elki/database/ids/DBIDUtil.java | DBIDUtil.difference | public static ModifiableDBIDs difference(DBIDs ids1, DBIDs ids2) {
ModifiableDBIDs result = DBIDUtil.newHashSet(ids1);
result.removeDBIDs(ids2);
return result;
} | java | public static ModifiableDBIDs difference(DBIDs ids1, DBIDs ids2) {
ModifiableDBIDs result = DBIDUtil.newHashSet(ids1);
result.removeDBIDs(ids2);
return result;
} | [
"public",
"static",
"ModifiableDBIDs",
"difference",
"(",
"DBIDs",
"ids1",
",",
"DBIDs",
"ids2",
")",
"{",
"ModifiableDBIDs",
"result",
"=",
"DBIDUtil",
".",
"newHashSet",
"(",
"ids1",
")",
";",
"result",
".",
"removeDBIDs",
"(",
"ids2",
")",
";",
"return",
... | Returns the difference of the two specified collection of IDs.
@param ids1 the first collection
@param ids2 the second collection
@return the difference of ids1 minus ids2 | [
"Returns",
"the",
"difference",
"of",
"the",
"two",
"specified",
"collection",
"of",
"IDs",
"."
] | b54673327e76198ecd4c8a2a901021f1a9174498 | https://github.com/elki-project/elki/blob/b54673327e76198ecd4c8a2a901021f1a9174498/elki-core-dbids/src/main/java/de/lmu/ifi/dbs/elki/database/ids/DBIDUtil.java#L412-L416 | train |
elki-project/elki | elki-core-dbids/src/main/java/de/lmu/ifi/dbs/elki/database/ids/DBIDUtil.java | DBIDUtil.ensureArray | public static ArrayDBIDs ensureArray(DBIDs ids) {
return ids instanceof ArrayDBIDs ? (ArrayDBIDs) ids : newArray(ids);
} | java | public static ArrayDBIDs ensureArray(DBIDs ids) {
return ids instanceof ArrayDBIDs ? (ArrayDBIDs) ids : newArray(ids);
} | [
"public",
"static",
"ArrayDBIDs",
"ensureArray",
"(",
"DBIDs",
"ids",
")",
"{",
"return",
"ids",
"instanceof",
"ArrayDBIDs",
"?",
"(",
"ArrayDBIDs",
")",
"ids",
":",
"newArray",
"(",
"ids",
")",
";",
"}"
] | Ensure that the given DBIDs are array-indexable.
@param ids IDs
@return Array DBIDs. | [
"Ensure",
"that",
"the",
"given",
"DBIDs",
"are",
"array",
"-",
"indexable",
"."
] | b54673327e76198ecd4c8a2a901021f1a9174498 | https://github.com/elki-project/elki/blob/b54673327e76198ecd4c8a2a901021f1a9174498/elki-core-dbids/src/main/java/de/lmu/ifi/dbs/elki/database/ids/DBIDUtil.java#L434-L436 | train |
elki-project/elki | elki-core-dbids/src/main/java/de/lmu/ifi/dbs/elki/database/ids/DBIDUtil.java | DBIDUtil.ensureSet | public static SetDBIDs ensureSet(DBIDs ids) {
return ids instanceof SetDBIDs ? (SetDBIDs) ids : newHashSet(ids);
} | java | public static SetDBIDs ensureSet(DBIDs ids) {
return ids instanceof SetDBIDs ? (SetDBIDs) ids : newHashSet(ids);
} | [
"public",
"static",
"SetDBIDs",
"ensureSet",
"(",
"DBIDs",
"ids",
")",
"{",
"return",
"ids",
"instanceof",
"SetDBIDs",
"?",
"(",
"SetDBIDs",
")",
"ids",
":",
"newHashSet",
"(",
"ids",
")",
";",
"}"
] | Ensure that the given DBIDs support fast "contains" operations.
@param ids IDs
@return Set DBIDs. | [
"Ensure",
"that",
"the",
"given",
"DBIDs",
"support",
"fast",
"contains",
"operations",
"."
] | b54673327e76198ecd4c8a2a901021f1a9174498 | https://github.com/elki-project/elki/blob/b54673327e76198ecd4c8a2a901021f1a9174498/elki-core-dbids/src/main/java/de/lmu/ifi/dbs/elki/database/ids/DBIDUtil.java#L444-L446 | train |
elki-project/elki | elki-core-dbids/src/main/java/de/lmu/ifi/dbs/elki/database/ids/DBIDUtil.java | DBIDUtil.ensureModifiable | public static ModifiableDBIDs ensureModifiable(DBIDs ids) {
return ids instanceof ModifiableDBIDs ? (ModifiableDBIDs) ids : //
ids instanceof HashSetDBIDs ? newHashSet(ids) : newArray(ids);
} | java | public static ModifiableDBIDs ensureModifiable(DBIDs ids) {
return ids instanceof ModifiableDBIDs ? (ModifiableDBIDs) ids : //
ids instanceof HashSetDBIDs ? newHashSet(ids) : newArray(ids);
} | [
"public",
"static",
"ModifiableDBIDs",
"ensureModifiable",
"(",
"DBIDs",
"ids",
")",
"{",
"return",
"ids",
"instanceof",
"ModifiableDBIDs",
"?",
"(",
"ModifiableDBIDs",
")",
"ids",
":",
"//",
"ids",
"instanceof",
"HashSetDBIDs",
"?",
"newHashSet",
"(",
"ids",
")... | Ensure modifiable.
@param ids IDs
@return Modifiable DBIDs. | [
"Ensure",
"modifiable",
"."
] | b54673327e76198ecd4c8a2a901021f1a9174498 | https://github.com/elki-project/elki/blob/b54673327e76198ecd4c8a2a901021f1a9174498/elki-core-dbids/src/main/java/de/lmu/ifi/dbs/elki/database/ids/DBIDUtil.java#L454-L457 | train |
elki-project/elki | elki-core-dbids/src/main/java/de/lmu/ifi/dbs/elki/database/ids/DBIDUtil.java | DBIDUtil.newPair | public static DBIDPair newPair(DBIDRef id1, DBIDRef id2) {
return DBIDFactory.FACTORY.newPair(id1, id2);
} | java | public static DBIDPair newPair(DBIDRef id1, DBIDRef id2) {
return DBIDFactory.FACTORY.newPair(id1, id2);
} | [
"public",
"static",
"DBIDPair",
"newPair",
"(",
"DBIDRef",
"id1",
",",
"DBIDRef",
"id2",
")",
"{",
"return",
"DBIDFactory",
".",
"FACTORY",
".",
"newPair",
"(",
"id1",
",",
"id2",
")",
";",
"}"
] | Make a DBID pair.
@param id1 first ID
@param id2 second ID
@return DBID pair | [
"Make",
"a",
"DBID",
"pair",
"."
] | b54673327e76198ecd4c8a2a901021f1a9174498 | https://github.com/elki-project/elki/blob/b54673327e76198ecd4c8a2a901021f1a9174498/elki-core-dbids/src/main/java/de/lmu/ifi/dbs/elki/database/ids/DBIDUtil.java#L467-L469 | train |
elki-project/elki | elki-core-dbids/src/main/java/de/lmu/ifi/dbs/elki/database/ids/DBIDUtil.java | DBIDUtil.newPair | public static DoubleDBIDPair newPair(double val, DBIDRef id) {
return DBIDFactory.FACTORY.newPair(val, id);
} | java | public static DoubleDBIDPair newPair(double val, DBIDRef id) {
return DBIDFactory.FACTORY.newPair(val, id);
} | [
"public",
"static",
"DoubleDBIDPair",
"newPair",
"(",
"double",
"val",
",",
"DBIDRef",
"id",
")",
"{",
"return",
"DBIDFactory",
".",
"FACTORY",
".",
"newPair",
"(",
"val",
",",
"id",
")",
";",
"}"
] | Make a DoubleDBIDPair.
@param val double value
@param id ID
@return new pair | [
"Make",
"a",
"DoubleDBIDPair",
"."
] | b54673327e76198ecd4c8a2a901021f1a9174498 | https://github.com/elki-project/elki/blob/b54673327e76198ecd4c8a2a901021f1a9174498/elki-core-dbids/src/main/java/de/lmu/ifi/dbs/elki/database/ids/DBIDUtil.java#L478-L480 | train |
elki-project/elki | elki-core-dbids-int/src/main/java/de/lmu/ifi/dbs/elki/database/ids/integer/IntegerDBIDArrayQuickSort.java | IntegerDBIDArrayQuickSort.sort | public static void sort(int[] data, Comparator<? super DBIDRef> comp) {
sort(data, 0, data.length, comp);
} | java | public static void sort(int[] data, Comparator<? super DBIDRef> comp) {
sort(data, 0, data.length, comp);
} | [
"public",
"static",
"void",
"sort",
"(",
"int",
"[",
"]",
"data",
",",
"Comparator",
"<",
"?",
"super",
"DBIDRef",
">",
"comp",
")",
"{",
"sort",
"(",
"data",
",",
"0",
",",
"data",
".",
"length",
",",
"comp",
")",
";",
"}"
] | Sort the full array using the given comparator.
@param data Data to sort
@param comp Comparator | [
"Sort",
"the",
"full",
"array",
"using",
"the",
"given",
"comparator",
"."
] | b54673327e76198ecd4c8a2a901021f1a9174498 | https://github.com/elki-project/elki/blob/b54673327e76198ecd4c8a2a901021f1a9174498/elki-core-dbids-int/src/main/java/de/lmu/ifi/dbs/elki/database/ids/integer/IntegerDBIDArrayQuickSort.java#L68-L70 | train |
elki-project/elki | elki-core-dbids-int/src/main/java/de/lmu/ifi/dbs/elki/database/ids/integer/IntegerDBIDArrayQuickSort.java | IntegerDBIDArrayQuickSort.compare | private static int compare(IntegerDBIDVar i1, int p1, IntegerDBIDVar i2, int p2, Comparator<? super DBIDRef> comp) {
i1.internalSetIndex(p1);
i2.internalSetIndex(p2);
return comp.compare(i1, i2);
} | java | private static int compare(IntegerDBIDVar i1, int p1, IntegerDBIDVar i2, int p2, Comparator<? super DBIDRef> comp) {
i1.internalSetIndex(p1);
i2.internalSetIndex(p2);
return comp.compare(i1, i2);
} | [
"private",
"static",
"int",
"compare",
"(",
"IntegerDBIDVar",
"i1",
",",
"int",
"p1",
",",
"IntegerDBIDVar",
"i2",
",",
"int",
"p2",
",",
"Comparator",
"<",
"?",
"super",
"DBIDRef",
">",
"comp",
")",
"{",
"i1",
".",
"internalSetIndex",
"(",
"p1",
")",
... | Compare two elements.
@param i1 First scratch variable
@param p1 Value for first
@param i2 Second scratch variable
@param p2 Value for second
@param comp Comparator
@return Comparison result | [
"Compare",
"two",
"elements",
"."
] | b54673327e76198ecd4c8a2a901021f1a9174498 | https://github.com/elki-project/elki/blob/b54673327e76198ecd4c8a2a901021f1a9174498/elki-core-dbids-int/src/main/java/de/lmu/ifi/dbs/elki/database/ids/integer/IntegerDBIDArrayQuickSort.java#L256-L260 | train |
elki-project/elki | addons/xtree/src/main/java/de/lmu/ifi/dbs/elki/index/tree/spatial/rstarvariants/xtree/AbstractXTree.java | AbstractXTree.computeHeight | @Override
protected int computeHeight() {
N node = getRoot();
int tHeight = 1;
// compute height
while(!node.isLeaf() && node.getNumEntries() != 0) {
SpatialEntry entry = node.getEntry(0);
node = getNode(entry);
tHeight++;
}
return tHeight;
} | java | @Override
protected int computeHeight() {
N node = getRoot();
int tHeight = 1;
// compute height
while(!node.isLeaf() && node.getNumEntries() != 0) {
SpatialEntry entry = node.getEntry(0);
node = getNode(entry);
tHeight++;
}
return tHeight;
} | [
"@",
"Override",
"protected",
"int",
"computeHeight",
"(",
")",
"{",
"N",
"node",
"=",
"getRoot",
"(",
")",
";",
"int",
"tHeight",
"=",
"1",
";",
"// compute height",
"while",
"(",
"!",
"node",
".",
"isLeaf",
"(",
")",
"&&",
"node",
".",
"getNumEntries... | Computes the height of this XTree. Is called by the constructor. and should
be overwritten by subclasses if necessary.
@return the height of this XTree | [
"Computes",
"the",
"height",
"of",
"this",
"XTree",
".",
"Is",
"called",
"by",
"the",
"constructor",
".",
"and",
"should",
"be",
"overwritten",
"by",
"subclasses",
"if",
"necessary",
"."
] | b54673327e76198ecd4c8a2a901021f1a9174498 | https://github.com/elki-project/elki/blob/b54673327e76198ecd4c8a2a901021f1a9174498/addons/xtree/src/main/java/de/lmu/ifi/dbs/elki/index/tree/spatial/rstarvariants/xtree/AbstractXTree.java#L170-L182 | train |
elki-project/elki | addons/xtree/src/main/java/de/lmu/ifi/dbs/elki/index/tree/spatial/rstarvariants/xtree/AbstractXTree.java | AbstractXTree.commit | public long commit() throws IOException {
final PageFile<N> file = super.getFile();
if(!(file instanceof PersistentPageFile)) {
throw new IllegalStateException("Trying to commit a non-persistent XTree");
}
long npid = file.getNextPageID();
XTreeHeader ph = (XTreeHeader) ((PersistentPageFile<?>) file).getHeader();
long offset = (ph.getReservedPages() + npid) * ph.getPageSize();
ph.setSupernode_offset(npid * ph.getPageSize());
ph.setNumberOfElements(num_elements);
RandomAccessFile ra_file = ((PersistentPageFile<?>) file).getFile();
ph.writeHeader(ra_file);
ra_file.seek(offset);
long nBytes = 0;
for(Iterator<N> iterator = supernodes.values().iterator(); iterator.hasNext();) {
N supernode = iterator.next();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
supernode.writeSuperNode(oos);
oos.close();
baos.close();
byte[] array = baos.toByteArray();
byte[] sn_array = new byte[getPageSize() * (int) Math.ceil((double) supernode.getCapacity() / dirCapacity)];
if(array.length > sn_array.length) {
throw new IllegalStateException("Supernode is too large for fitting in " + ((int) Math.ceil((double) supernode.getCapacity() / dirCapacity)) + " pages of total size " + sn_array.length);
}
System.arraycopy(array, 0, sn_array, 0, array.length);
// file.countWrite();
ra_file.write(sn_array);
nBytes += sn_array.length;
}
return nBytes;
} | java | public long commit() throws IOException {
final PageFile<N> file = super.getFile();
if(!(file instanceof PersistentPageFile)) {
throw new IllegalStateException("Trying to commit a non-persistent XTree");
}
long npid = file.getNextPageID();
XTreeHeader ph = (XTreeHeader) ((PersistentPageFile<?>) file).getHeader();
long offset = (ph.getReservedPages() + npid) * ph.getPageSize();
ph.setSupernode_offset(npid * ph.getPageSize());
ph.setNumberOfElements(num_elements);
RandomAccessFile ra_file = ((PersistentPageFile<?>) file).getFile();
ph.writeHeader(ra_file);
ra_file.seek(offset);
long nBytes = 0;
for(Iterator<N> iterator = supernodes.values().iterator(); iterator.hasNext();) {
N supernode = iterator.next();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
supernode.writeSuperNode(oos);
oos.close();
baos.close();
byte[] array = baos.toByteArray();
byte[] sn_array = new byte[getPageSize() * (int) Math.ceil((double) supernode.getCapacity() / dirCapacity)];
if(array.length > sn_array.length) {
throw new IllegalStateException("Supernode is too large for fitting in " + ((int) Math.ceil((double) supernode.getCapacity() / dirCapacity)) + " pages of total size " + sn_array.length);
}
System.arraycopy(array, 0, sn_array, 0, array.length);
// file.countWrite();
ra_file.write(sn_array);
nBytes += sn_array.length;
}
return nBytes;
} | [
"public",
"long",
"commit",
"(",
")",
"throws",
"IOException",
"{",
"final",
"PageFile",
"<",
"N",
">",
"file",
"=",
"super",
".",
"getFile",
"(",
")",
";",
"if",
"(",
"!",
"(",
"file",
"instanceof",
"PersistentPageFile",
")",
")",
"{",
"throw",
"new",... | Writes all supernodes to the end of the file. This is only supposed to be
used for a final saving of an XTree. If another page is added to this tree,
the supernodes written to file by this operation are over-written.
@return the number of bytes written to file for this tree's supernodes
@throws IOException if there are any io problems when writing the tree's
supernodes | [
"Writes",
"all",
"supernodes",
"to",
"the",
"end",
"of",
"the",
"file",
".",
"This",
"is",
"only",
"supposed",
"to",
"be",
"used",
"for",
"a",
"final",
"saving",
"of",
"an",
"XTree",
".",
"If",
"another",
"page",
"is",
"added",
"to",
"this",
"tree",
... | b54673327e76198ecd4c8a2a901021f1a9174498 | https://github.com/elki-project/elki/blob/b54673327e76198ecd4c8a2a901021f1a9174498/addons/xtree/src/main/java/de/lmu/ifi/dbs/elki/index/tree/spatial/rstarvariants/xtree/AbstractXTree.java#L298-L330 | train |
elki-project/elki | elki-index-rtree/src/main/java/de/lmu/ifi/dbs/elki/index/tree/spatial/rstarvariants/deliclu/DeLiCluTree.java | DeLiCluTree.setExpanded | public void setExpanded(SpatialEntry entry1, SpatialEntry entry2) {
IntSet exp1 = expanded.get(getPageID(entry1));
if(exp1 == null) {
exp1 = new IntOpenHashSet();
expanded.put(getPageID(entry1), exp1);
}
exp1.add(getPageID(entry2));
} | java | public void setExpanded(SpatialEntry entry1, SpatialEntry entry2) {
IntSet exp1 = expanded.get(getPageID(entry1));
if(exp1 == null) {
exp1 = new IntOpenHashSet();
expanded.put(getPageID(entry1), exp1);
}
exp1.add(getPageID(entry2));
} | [
"public",
"void",
"setExpanded",
"(",
"SpatialEntry",
"entry1",
",",
"SpatialEntry",
"entry2",
")",
"{",
"IntSet",
"exp1",
"=",
"expanded",
".",
"get",
"(",
"getPageID",
"(",
"entry1",
")",
")",
";",
"if",
"(",
"exp1",
"==",
"null",
")",
"{",
"exp1",
"... | Marks the nodes with the specified ids as expanded.
@param entry1 the first node
@param entry2 the second node | [
"Marks",
"the",
"nodes",
"with",
"the",
"specified",
"ids",
"as",
"expanded",
"."
] | b54673327e76198ecd4c8a2a901021f1a9174498 | https://github.com/elki-project/elki/blob/b54673327e76198ecd4c8a2a901021f1a9174498/elki-index-rtree/src/main/java/de/lmu/ifi/dbs/elki/index/tree/spatial/rstarvariants/deliclu/DeLiCluTree.java#L72-L79 | train |
elki-project/elki | elki-index-rtree/src/main/java/de/lmu/ifi/dbs/elki/index/tree/spatial/rstarvariants/deliclu/DeLiCluTree.java | DeLiCluTree.getExpanded | public IntSet getExpanded(SpatialEntry entry) {
IntSet exp = expanded.get(getPageID(entry));
return (exp != null) ? exp : IntSets.EMPTY_SET;
} | java | public IntSet getExpanded(SpatialEntry entry) {
IntSet exp = expanded.get(getPageID(entry));
return (exp != null) ? exp : IntSets.EMPTY_SET;
} | [
"public",
"IntSet",
"getExpanded",
"(",
"SpatialEntry",
"entry",
")",
"{",
"IntSet",
"exp",
"=",
"expanded",
".",
"get",
"(",
"getPageID",
"(",
"entry",
")",
")",
";",
"return",
"(",
"exp",
"!=",
"null",
")",
"?",
"exp",
":",
"IntSets",
".",
"EMPTY_SET... | Returns the nodes which are already expanded with the specified node.
@param entry the id of the node for which the expansions should be returned
@return the nodes which are already expanded with the specified node | [
"Returns",
"the",
"nodes",
"which",
"are",
"already",
"expanded",
"with",
"the",
"specified",
"node",
"."
] | b54673327e76198ecd4c8a2a901021f1a9174498 | https://github.com/elki-project/elki/blob/b54673327e76198ecd4c8a2a901021f1a9174498/elki-index-rtree/src/main/java/de/lmu/ifi/dbs/elki/index/tree/spatial/rstarvariants/deliclu/DeLiCluTree.java#L87-L90 | train |
elki-project/elki | elki-core/src/main/java/de/lmu/ifi/dbs/elki/utilities/datastructures/histogram/DoubleHistogram.java | DoubleHistogram.increment | public void increment(double coord, double val) {
int bin = getBinNr(coord);
if (bin < 0) {
if (size - bin > data.length) {
// Reallocate. TODO: use an arraylist-like grow strategy!
double[] tmpdata = new double[growSize(data.length, size - bin)];
System.arraycopy(data, 0, tmpdata, -bin, size);
data = tmpdata;
} else {
// Shift in place and clear head
System.arraycopy(data, 0, data, -bin, size);
Arrays.fill(data, 0, -bin, (double) 0);
}
data[0] = val;
// Note that bin is negative, -bin is the shift offset!
assert (data.length >= size - bin);
offset -= bin;
size -= bin;
// TODO: modCounter++; and have iterators fast-fail
} else if (bin >= data.length) {
double[] tmpdata = new double[growSize(data.length, bin + 1)];
System.arraycopy(data, 0, tmpdata, 0, size);
tmpdata[bin] = val;
data = tmpdata;
size = bin + 1;
// TODO: modCounter++; and have iterators fast-fail
// Unset max value when resizing
max = Double.MAX_VALUE;
} else {
if (bin >= size) {
// TODO: reset bins to 0 first?
size = bin + 1;
}
data[bin] += val;
}
} | java | public void increment(double coord, double val) {
int bin = getBinNr(coord);
if (bin < 0) {
if (size - bin > data.length) {
// Reallocate. TODO: use an arraylist-like grow strategy!
double[] tmpdata = new double[growSize(data.length, size - bin)];
System.arraycopy(data, 0, tmpdata, -bin, size);
data = tmpdata;
} else {
// Shift in place and clear head
System.arraycopy(data, 0, data, -bin, size);
Arrays.fill(data, 0, -bin, (double) 0);
}
data[0] = val;
// Note that bin is negative, -bin is the shift offset!
assert (data.length >= size - bin);
offset -= bin;
size -= bin;
// TODO: modCounter++; and have iterators fast-fail
} else if (bin >= data.length) {
double[] tmpdata = new double[growSize(data.length, bin + 1)];
System.arraycopy(data, 0, tmpdata, 0, size);
tmpdata[bin] = val;
data = tmpdata;
size = bin + 1;
// TODO: modCounter++; and have iterators fast-fail
// Unset max value when resizing
max = Double.MAX_VALUE;
} else {
if (bin >= size) {
// TODO: reset bins to 0 first?
size = bin + 1;
}
data[bin] += val;
}
} | [
"public",
"void",
"increment",
"(",
"double",
"coord",
",",
"double",
"val",
")",
"{",
"int",
"bin",
"=",
"getBinNr",
"(",
"coord",
")",
";",
"if",
"(",
"bin",
"<",
"0",
")",
"{",
"if",
"(",
"size",
"-",
"bin",
">",
"data",
".",
"length",
")",
... | Increment the value of a bin.
@param coord Coordinate
@param val Value | [
"Increment",
"the",
"value",
"of",
"a",
"bin",
"."
] | b54673327e76198ecd4c8a2a901021f1a9174498 | https://github.com/elki-project/elki/blob/b54673327e76198ecd4c8a2a901021f1a9174498/elki-core/src/main/java/de/lmu/ifi/dbs/elki/utilities/datastructures/histogram/DoubleHistogram.java#L58-L93 | train |
elki-project/elki | elki-core/src/main/java/de/lmu/ifi/dbs/elki/utilities/datastructures/histogram/DoubleHistogram.java | DoubleHistogram.get | public double get(double coord) {
int bin = getBinNr(coord);
return (bin < 0 || bin >= size) ? 0 : data[bin];
} | java | public double get(double coord) {
int bin = getBinNr(coord);
return (bin < 0 || bin >= size) ? 0 : data[bin];
} | [
"public",
"double",
"get",
"(",
"double",
"coord",
")",
"{",
"int",
"bin",
"=",
"getBinNr",
"(",
"coord",
")",
";",
"return",
"(",
"bin",
"<",
"0",
"||",
"bin",
">=",
"size",
")",
"?",
"0",
":",
"data",
"[",
"bin",
"]",
";",
"}"
] | Get the value at a particular position.
@param coord Coordinate
@return Value | [
"Get",
"the",
"value",
"at",
"a",
"particular",
"position",
"."
] | b54673327e76198ecd4c8a2a901021f1a9174498 | https://github.com/elki-project/elki/blob/b54673327e76198ecd4c8a2a901021f1a9174498/elki-core/src/main/java/de/lmu/ifi/dbs/elki/utilities/datastructures/histogram/DoubleHistogram.java#L101-L104 | train |
elki-project/elki | elki-clustering/src/main/java/de/lmu/ifi/dbs/elki/algorithm/clustering/gdbscan/util/MultiBorder.java | MultiBorder.update | public Assignment update(Border border) {
Arrays.sort(cs);
int j = 1;
boolean found = (cs[0].core == border.core);
for(int i = 1; i < cs.length; i++) {
if(cs[i].core != cs[i - 1].core) {
cs[j++] = cs[i];
}
found |= (cs[i].core == border.core);
}
if(found) {
if(j == 1) {
Border r = cs[0];
cs = null; // Prevent further use
return r;
}
if(j < cs.length) {
cs = Arrays.copyOf(cs, j);
}
return this;
}
if(j + 1 != cs.length) {
cs = Arrays.copyOf(cs, j + 1);
}
cs[j] = border;
return this;
} | java | public Assignment update(Border border) {
Arrays.sort(cs);
int j = 1;
boolean found = (cs[0].core == border.core);
for(int i = 1; i < cs.length; i++) {
if(cs[i].core != cs[i - 1].core) {
cs[j++] = cs[i];
}
found |= (cs[i].core == border.core);
}
if(found) {
if(j == 1) {
Border r = cs[0];
cs = null; // Prevent further use
return r;
}
if(j < cs.length) {
cs = Arrays.copyOf(cs, j);
}
return this;
}
if(j + 1 != cs.length) {
cs = Arrays.copyOf(cs, j + 1);
}
cs[j] = border;
return this;
} | [
"public",
"Assignment",
"update",
"(",
"Border",
"border",
")",
"{",
"Arrays",
".",
"sort",
"(",
"cs",
")",
";",
"int",
"j",
"=",
"1",
";",
"boolean",
"found",
"=",
"(",
"cs",
"[",
"0",
"]",
".",
"core",
"==",
"border",
".",
"core",
")",
";",
"... | Add a new border to the existing borders.
@param border New border. | [
"Add",
"a",
"new",
"border",
"to",
"the",
"existing",
"borders",
"."
] | b54673327e76198ecd4c8a2a901021f1a9174498 | https://github.com/elki-project/elki/blob/b54673327e76198ecd4c8a2a901021f1a9174498/elki-clustering/src/main/java/de/lmu/ifi/dbs/elki/algorithm/clustering/gdbscan/util/MultiBorder.java#L53-L79 | train |
elki-project/elki | elki-clustering/src/main/java/de/lmu/ifi/dbs/elki/algorithm/clustering/gdbscan/util/MultiBorder.java | MultiBorder.getCore | public Core getCore() {
Core a = cs[0].core;
for(int i = 1; i < cs.length; i++) {
Core v = cs[i].core;
a = a.num > v.num ? a : v; // max, of negative values
}
return a;
} | java | public Core getCore() {
Core a = cs[0].core;
for(int i = 1; i < cs.length; i++) {
Core v = cs[i].core;
a = a.num > v.num ? a : v; // max, of negative values
}
return a;
} | [
"public",
"Core",
"getCore",
"(",
")",
"{",
"Core",
"a",
"=",
"cs",
"[",
"0",
"]",
".",
"core",
";",
"for",
"(",
"int",
"i",
"=",
"1",
";",
"i",
"<",
"cs",
".",
"length",
";",
"i",
"++",
")",
"{",
"Core",
"v",
"=",
"cs",
"[",
"i",
"]",
... | Get the core this is assigned to.
@return Core | [
"Get",
"the",
"core",
"this",
"is",
"assigned",
"to",
"."
] | b54673327e76198ecd4c8a2a901021f1a9174498 | https://github.com/elki-project/elki/blob/b54673327e76198ecd4c8a2a901021f1a9174498/elki-clustering/src/main/java/de/lmu/ifi/dbs/elki/algorithm/clustering/gdbscan/util/MultiBorder.java#L86-L93 | train |
elki-project/elki | elki-clustering/src/main/java/de/lmu/ifi/dbs/elki/algorithm/clustering/kmeans/KMedoidsPark.java | KMedoidsPark.currentCluster | protected int currentCluster(List<? extends ModifiableDBIDs> clusters, DBIDRef id) {
for(int i = 0; i < k; i++) {
if(clusters.get(i).contains(id)) {
return i;
}
}
return -1;
} | java | protected int currentCluster(List<? extends ModifiableDBIDs> clusters, DBIDRef id) {
for(int i = 0; i < k; i++) {
if(clusters.get(i).contains(id)) {
return i;
}
}
return -1;
} | [
"protected",
"int",
"currentCluster",
"(",
"List",
"<",
"?",
"extends",
"ModifiableDBIDs",
">",
"clusters",
",",
"DBIDRef",
"id",
")",
"{",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"k",
";",
"i",
"++",
")",
"{",
"if",
"(",
"clusters",
".",
... | Find the current cluster assignment.
@param clusters Clusters
@param id Current object
@return Current cluster assignment. | [
"Find",
"the",
"current",
"cluster",
"assignment",
"."
] | b54673327e76198ecd4c8a2a901021f1a9174498 | https://github.com/elki-project/elki/blob/b54673327e76198ecd4c8a2a901021f1a9174498/elki-clustering/src/main/java/de/lmu/ifi/dbs/elki/algorithm/clustering/kmeans/KMedoidsPark.java#L286-L293 | train |
elki-project/elki | elki-outlier/src/main/java/de/lmu/ifi/dbs/elki/algorithm/outlier/lof/INFLO.java | INFLO.computeINFLO | protected void computeINFLO(Relation<O> relation, ModifiableDBIDs pruned, KNNQuery<O> knnq, WritableDataStore<ModifiableDBIDs> rNNminuskNNs, WritableDoubleDataStore inflos, DoubleMinMax inflominmax) {
FiniteProgress prog = LOG.isVerbose() ? new FiniteProgress("Computing INFLOs", relation.size(), LOG) : null;
HashSetModifiableDBIDs set = DBIDUtil.newHashSet();
for(DBIDIter iter = relation.iterDBIDs(); iter.valid(); iter.advance()) {
if(pruned.contains(iter)) {
inflos.putDouble(iter, 1.);
inflominmax.put(1.);
LOG.incrementProcessed(prog);
continue;
}
final KNNList knn = knnq.getKNNForDBID(iter, kplus1);
if(knn.getKNNDistance() == 0.) {
inflos.putDouble(iter, 1.);
inflominmax.put(1.);
LOG.incrementProcessed(prog);
continue;
}
set.clear();
set.addDBIDs(knn);
set.addDBIDs(rNNminuskNNs.get(iter));
// Compute mean density of NN \cup RNN
double sum = 0.;
int c = 0;
for(DBIDIter niter = set.iter(); niter.valid(); niter.advance()) {
if(DBIDUtil.equal(iter, niter)) {
continue;
}
final double kdist = knnq.getKNNForDBID(niter, kplus1).getKNNDistance();
if(kdist <= 0) {
sum = Double.POSITIVE_INFINITY;
c++;
break;
}
sum += 1. / kdist;
c++;
}
sum *= knn.getKNNDistance();
final double inflo = sum == 0 ? 1. : sum / c;
inflos.putDouble(iter, inflo);
inflominmax.put(inflo);
LOG.incrementProcessed(prog);
}
LOG.ensureCompleted(prog);
} | java | protected void computeINFLO(Relation<O> relation, ModifiableDBIDs pruned, KNNQuery<O> knnq, WritableDataStore<ModifiableDBIDs> rNNminuskNNs, WritableDoubleDataStore inflos, DoubleMinMax inflominmax) {
FiniteProgress prog = LOG.isVerbose() ? new FiniteProgress("Computing INFLOs", relation.size(), LOG) : null;
HashSetModifiableDBIDs set = DBIDUtil.newHashSet();
for(DBIDIter iter = relation.iterDBIDs(); iter.valid(); iter.advance()) {
if(pruned.contains(iter)) {
inflos.putDouble(iter, 1.);
inflominmax.put(1.);
LOG.incrementProcessed(prog);
continue;
}
final KNNList knn = knnq.getKNNForDBID(iter, kplus1);
if(knn.getKNNDistance() == 0.) {
inflos.putDouble(iter, 1.);
inflominmax.put(1.);
LOG.incrementProcessed(prog);
continue;
}
set.clear();
set.addDBIDs(knn);
set.addDBIDs(rNNminuskNNs.get(iter));
// Compute mean density of NN \cup RNN
double sum = 0.;
int c = 0;
for(DBIDIter niter = set.iter(); niter.valid(); niter.advance()) {
if(DBIDUtil.equal(iter, niter)) {
continue;
}
final double kdist = knnq.getKNNForDBID(niter, kplus1).getKNNDistance();
if(kdist <= 0) {
sum = Double.POSITIVE_INFINITY;
c++;
break;
}
sum += 1. / kdist;
c++;
}
sum *= knn.getKNNDistance();
final double inflo = sum == 0 ? 1. : sum / c;
inflos.putDouble(iter, inflo);
inflominmax.put(inflo);
LOG.incrementProcessed(prog);
}
LOG.ensureCompleted(prog);
} | [
"protected",
"void",
"computeINFLO",
"(",
"Relation",
"<",
"O",
">",
"relation",
",",
"ModifiableDBIDs",
"pruned",
",",
"KNNQuery",
"<",
"O",
">",
"knnq",
",",
"WritableDataStore",
"<",
"ModifiableDBIDs",
">",
"rNNminuskNNs",
",",
"WritableDoubleDataStore",
"inflo... | Compute the final INFLO scores.
@param relation Data relation
@param pruned Pruned objects
@param knnq kNN query
@param rNNminuskNNs reverse kNN storage
@param inflos INFLO score storage
@param inflominmax Output of minimum and maximum | [
"Compute",
"the",
"final",
"INFLO",
"scores",
"."
] | b54673327e76198ecd4c8a2a901021f1a9174498 | https://github.com/elki-project/elki/blob/b54673327e76198ecd4c8a2a901021f1a9174498/elki-outlier/src/main/java/de/lmu/ifi/dbs/elki/algorithm/outlier/lof/INFLO.java#L225-L268 | train |
elki-project/elki | addons/tutorial/src/main/java/tutorial/outlier/ODIN.java | ODIN.run | public OutlierResult run(Database database, Relation<O> relation) {
// Get the query functions:
DistanceQuery<O> dq = database.getDistanceQuery(relation, getDistanceFunction());
KNNQuery<O> knnq = database.getKNNQuery(dq, k);
// Get the objects to process, and a data storage for counting and output:
DBIDs ids = relation.getDBIDs();
WritableDoubleDataStore scores = DataStoreUtil.makeDoubleStorage(ids, DataStoreFactory.HINT_DB, 0.);
// Process all objects
for(DBIDIter iter = ids.iter(); iter.valid(); iter.advance()) {
// Find the nearest neighbors (using an index, if available!)
KNNList neighbors = knnq.getKNNForDBID(iter, k);
// For each neighbor, except ourselves, increase the in-degree:
for(DBIDIter nei = neighbors.iter(); nei.valid(); nei.advance()) {
if(DBIDUtil.equal(iter, nei)) {
continue;
}
scores.put(nei, scores.doubleValue(nei) + 1);
}
}
// Compute maximum
double min = Double.POSITIVE_INFINITY, max = 0.0;
for(DBIDIter iter = ids.iter(); iter.valid(); iter.advance()) {
min = Math.min(min, scores.doubleValue(iter));
max = Math.max(max, scores.doubleValue(iter));
}
// Wrap the result and add metadata.
// By actually specifying theoretical min, max and baseline, we get a better
// visualization (try it out - or see the screenshots in the tutorial)!
OutlierScoreMeta meta = new InvertedOutlierScoreMeta(min, max, 0., ids.size() - 1, k);
DoubleRelation rel = new MaterializedDoubleRelation("ODIN In-Degree", "odin", scores, ids);
return new OutlierResult(meta, rel);
} | java | public OutlierResult run(Database database, Relation<O> relation) {
// Get the query functions:
DistanceQuery<O> dq = database.getDistanceQuery(relation, getDistanceFunction());
KNNQuery<O> knnq = database.getKNNQuery(dq, k);
// Get the objects to process, and a data storage for counting and output:
DBIDs ids = relation.getDBIDs();
WritableDoubleDataStore scores = DataStoreUtil.makeDoubleStorage(ids, DataStoreFactory.HINT_DB, 0.);
// Process all objects
for(DBIDIter iter = ids.iter(); iter.valid(); iter.advance()) {
// Find the nearest neighbors (using an index, if available!)
KNNList neighbors = knnq.getKNNForDBID(iter, k);
// For each neighbor, except ourselves, increase the in-degree:
for(DBIDIter nei = neighbors.iter(); nei.valid(); nei.advance()) {
if(DBIDUtil.equal(iter, nei)) {
continue;
}
scores.put(nei, scores.doubleValue(nei) + 1);
}
}
// Compute maximum
double min = Double.POSITIVE_INFINITY, max = 0.0;
for(DBIDIter iter = ids.iter(); iter.valid(); iter.advance()) {
min = Math.min(min, scores.doubleValue(iter));
max = Math.max(max, scores.doubleValue(iter));
}
// Wrap the result and add metadata.
// By actually specifying theoretical min, max and baseline, we get a better
// visualization (try it out - or see the screenshots in the tutorial)!
OutlierScoreMeta meta = new InvertedOutlierScoreMeta(min, max, 0., ids.size() - 1, k);
DoubleRelation rel = new MaterializedDoubleRelation("ODIN In-Degree", "odin", scores, ids);
return new OutlierResult(meta, rel);
} | [
"public",
"OutlierResult",
"run",
"(",
"Database",
"database",
",",
"Relation",
"<",
"O",
">",
"relation",
")",
"{",
"// Get the query functions:",
"DistanceQuery",
"<",
"O",
">",
"dq",
"=",
"database",
".",
"getDistanceQuery",
"(",
"relation",
",",
"getDistance... | Run the ODIN algorithm
Tutorial note: the <em>signature</em> of this method depends on the types
that we requested in the {@link #getInputTypeRestriction} method. Here we
requested a single relation of type {@code O} , the data type of our
distance function.
@param database Database to run on.
@param relation Relation to process.
@return ODIN outlier result. | [
"Run",
"the",
"ODIN",
"algorithm"
] | b54673327e76198ecd4c8a2a901021f1a9174498 | https://github.com/elki-project/elki/blob/b54673327e76198ecd4c8a2a901021f1a9174498/addons/tutorial/src/main/java/tutorial/outlier/ODIN.java#L107-L141 | train |
elki-project/elki | elki-gui-minigui/src/main/java/de/lmu/ifi/dbs/elki/gui/icons/StockIcon.java | StockIcon.getStockIcon | public static Icon getStockIcon(String name) {
SoftReference<Icon> ref = iconcache.get(name);
if(ref != null) {
Icon icon = ref.get();
if(icon != null) {
return icon;
}
}
java.net.URL imgURL = StockIcon.class.getResource(name + ".png");
if(imgURL != null) {
Icon icon = new ImageIcon(imgURL);
iconcache.put(name, new SoftReference<>(icon));
return icon;
}
LoggingUtil.warning("Could not find stock icon: " + name);
return null;
} | java | public static Icon getStockIcon(String name) {
SoftReference<Icon> ref = iconcache.get(name);
if(ref != null) {
Icon icon = ref.get();
if(icon != null) {
return icon;
}
}
java.net.URL imgURL = StockIcon.class.getResource(name + ".png");
if(imgURL != null) {
Icon icon = new ImageIcon(imgURL);
iconcache.put(name, new SoftReference<>(icon));
return icon;
}
LoggingUtil.warning("Could not find stock icon: " + name);
return null;
} | [
"public",
"static",
"Icon",
"getStockIcon",
"(",
"String",
"name",
")",
"{",
"SoftReference",
"<",
"Icon",
">",
"ref",
"=",
"iconcache",
".",
"get",
"(",
"name",
")",
";",
"if",
"(",
"ref",
"!=",
"null",
")",
"{",
"Icon",
"icon",
"=",
"ref",
".",
"... | Get a particular stock icon.
@param name Icon name
@return Icon | [
"Get",
"a",
"particular",
"stock",
"icon",
"."
] | b54673327e76198ecd4c8a2a901021f1a9174498 | https://github.com/elki-project/elki/blob/b54673327e76198ecd4c8a2a901021f1a9174498/elki-gui-minigui/src/main/java/de/lmu/ifi/dbs/elki/gui/icons/StockIcon.java#L109-L125 | train |
elki-project/elki | elki-index-rtree/src/main/java/de/lmu/ifi/dbs/elki/index/tree/spatial/rstarvariants/flat/FlatRStarTree.java | FlatRStarTree.initializeFromFile | @Override
public void initializeFromFile(TreeIndexHeader header, PageFile<FlatRStarTreeNode> file) {
super.initializeFromFile(header, file);
// reconstruct root
int nextPageID = file.getNextPageID();
dirCapacity = nextPageID;
root = createNewDirectoryNode();
for(int i = 1; i < nextPageID; i++) {
FlatRStarTreeNode node = getNode(i);
root.addDirectoryEntry(createNewDirectoryEntry(node));
}
if(LOG.isDebugging()) {
LOG.debugFine("root: " + root + " with " + nextPageID + " leafNodes.");
}
} | java | @Override
public void initializeFromFile(TreeIndexHeader header, PageFile<FlatRStarTreeNode> file) {
super.initializeFromFile(header, file);
// reconstruct root
int nextPageID = file.getNextPageID();
dirCapacity = nextPageID;
root = createNewDirectoryNode();
for(int i = 1; i < nextPageID; i++) {
FlatRStarTreeNode node = getNode(i);
root.addDirectoryEntry(createNewDirectoryEntry(node));
}
if(LOG.isDebugging()) {
LOG.debugFine("root: " + root + " with " + nextPageID + " leafNodes.");
}
} | [
"@",
"Override",
"public",
"void",
"initializeFromFile",
"(",
"TreeIndexHeader",
"header",
",",
"PageFile",
"<",
"FlatRStarTreeNode",
">",
"file",
")",
"{",
"super",
".",
"initializeFromFile",
"(",
"header",
",",
"file",
")",
";",
"// reconstruct root",
"int",
"... | Initializes the flat RTree from an existing persistent file. | [
"Initializes",
"the",
"flat",
"RTree",
"from",
"an",
"existing",
"persistent",
"file",
"."
] | b54673327e76198ecd4c8a2a901021f1a9174498 | https://github.com/elki-project/elki/blob/b54673327e76198ecd4c8a2a901021f1a9174498/elki-index-rtree/src/main/java/de/lmu/ifi/dbs/elki/index/tree/spatial/rstarvariants/flat/FlatRStarTree.java#L68-L84 | train |
elki-project/elki | elki-index-various/src/main/java/de/lmu/ifi/dbs/elki/index/tree/metrical/covertree/CoverTree.java | CoverTree.bulkConstruct | protected Node bulkConstruct(DBIDRef cur, int maxScale, double parentDist, ModifiableDoubleDBIDList elems) {
assert (!elems.contains(cur));
final double max = maxDistance(elems);
final int scale = Math.min(distToScale(max) - 1, maxScale);
final int nextScale = scale - 1;
// Leaf node, because points coincide, we are too deep, or have too few
// elements remaining:
if(max <= 0 || scale <= scaleBottom || elems.size() < truncate) {
return new Node(cur, max, parentDist, elems);
}
// Find neighbors in the cover of the current object:
ModifiableDoubleDBIDList candidates = DBIDUtil.newDistanceDBIDList();
excludeNotCovered(elems, scaleToDist(scale), candidates);
// If no elements were not in the cover, build a compact tree:
if(candidates.size() == 0) {
LOG.warning("Scale not chosen appropriately? " + max + " " + scaleToDist(scale));
return bulkConstruct(cur, nextScale, parentDist, elems);
}
// We will have at least one other child, so build the parent:
Node node = new Node(cur, max, parentDist);
// Routing element now is a singleton:
final boolean curSingleton = elems.size() == 0;
if(!curSingleton) {
// Add node for the routing object:
node.children.add(bulkConstruct(cur, nextScale, 0, elems));
}
final double fmax = scaleToDist(nextScale);
// Build additional cover nodes:
for(DoubleDBIDListIter it = candidates.iter(); it.valid();) {
assert (it.getOffset() == 0);
DBID t = DBIDUtil.deref(it);
elems.clear(); // Recycle.
collectByCover(it, candidates, fmax, elems);
assert (DBIDUtil.equal(t, it)) : "First element in candidates must not change!";
if(elems.size() == 0) { // Singleton
node.singletons.add(it.doubleValue(), it);
}
else {
// Build a full child node:
node.children.add(bulkConstruct(it, nextScale, it.doubleValue(), elems));
}
candidates.removeSwap(0);
}
assert (candidates.size() == 0);
// Routing object is not yet handled:
if(curSingleton) {
if(node.isLeaf()) {
node.children = null; // First in leaf is enough.
}
else {
node.singletons.add(parentDist, cur); // Add as regular singleton.
}
}
// TODO: improve recycling of lists?
return node;
} | java | protected Node bulkConstruct(DBIDRef cur, int maxScale, double parentDist, ModifiableDoubleDBIDList elems) {
assert (!elems.contains(cur));
final double max = maxDistance(elems);
final int scale = Math.min(distToScale(max) - 1, maxScale);
final int nextScale = scale - 1;
// Leaf node, because points coincide, we are too deep, or have too few
// elements remaining:
if(max <= 0 || scale <= scaleBottom || elems.size() < truncate) {
return new Node(cur, max, parentDist, elems);
}
// Find neighbors in the cover of the current object:
ModifiableDoubleDBIDList candidates = DBIDUtil.newDistanceDBIDList();
excludeNotCovered(elems, scaleToDist(scale), candidates);
// If no elements were not in the cover, build a compact tree:
if(candidates.size() == 0) {
LOG.warning("Scale not chosen appropriately? " + max + " " + scaleToDist(scale));
return bulkConstruct(cur, nextScale, parentDist, elems);
}
// We will have at least one other child, so build the parent:
Node node = new Node(cur, max, parentDist);
// Routing element now is a singleton:
final boolean curSingleton = elems.size() == 0;
if(!curSingleton) {
// Add node for the routing object:
node.children.add(bulkConstruct(cur, nextScale, 0, elems));
}
final double fmax = scaleToDist(nextScale);
// Build additional cover nodes:
for(DoubleDBIDListIter it = candidates.iter(); it.valid();) {
assert (it.getOffset() == 0);
DBID t = DBIDUtil.deref(it);
elems.clear(); // Recycle.
collectByCover(it, candidates, fmax, elems);
assert (DBIDUtil.equal(t, it)) : "First element in candidates must not change!";
if(elems.size() == 0) { // Singleton
node.singletons.add(it.doubleValue(), it);
}
else {
// Build a full child node:
node.children.add(bulkConstruct(it, nextScale, it.doubleValue(), elems));
}
candidates.removeSwap(0);
}
assert (candidates.size() == 0);
// Routing object is not yet handled:
if(curSingleton) {
if(node.isLeaf()) {
node.children = null; // First in leaf is enough.
}
else {
node.singletons.add(parentDist, cur); // Add as regular singleton.
}
}
// TODO: improve recycling of lists?
return node;
} | [
"protected",
"Node",
"bulkConstruct",
"(",
"DBIDRef",
"cur",
",",
"int",
"maxScale",
",",
"double",
"parentDist",
",",
"ModifiableDoubleDBIDList",
"elems",
")",
"{",
"assert",
"(",
"!",
"elems",
".",
"contains",
"(",
"cur",
")",
")",
";",
"final",
"double",
... | Bulk-load the cover tree.
This bulk-load is slightly simpler than the one used in the original
cover-tree source: We do not look back into the "far" set of candidates.
@param cur Current routing object
@param maxScale Maximum scale
@param elems Candidates
@return Root node of subtree | [
"Bulk",
"-",
"load",
"the",
"cover",
"tree",
"."
] | b54673327e76198ecd4c8a2a901021f1a9174498 | https://github.com/elki-project/elki/blob/b54673327e76198ecd4c8a2a901021f1a9174498/elki-index-various/src/main/java/de/lmu/ifi/dbs/elki/index/tree/metrical/covertree/CoverTree.java#L223-L278 | train |
elki-project/elki | elki-core-math/src/main/java/de/lmu/ifi/dbs/elki/math/linearalgebra/pca/weightfunctions/QuadraticWeight.java | QuadraticWeight.getWeight | @Override
public double getWeight(double distance, double max, double stddev) {
if(max <= 0) {
return 1.0;
}
double relativedistance = distance / max;
return 1.0 - 0.9 * relativedistance * relativedistance;
} | java | @Override
public double getWeight(double distance, double max, double stddev) {
if(max <= 0) {
return 1.0;
}
double relativedistance = distance / max;
return 1.0 - 0.9 * relativedistance * relativedistance;
} | [
"@",
"Override",
"public",
"double",
"getWeight",
"(",
"double",
"distance",
",",
"double",
"max",
",",
"double",
"stddev",
")",
"{",
"if",
"(",
"max",
"<=",
"0",
")",
"{",
"return",
"1.0",
";",
"}",
"double",
"relativedistance",
"=",
"distance",
"/",
... | Evaluate quadratic weight. stddev is ignored. | [
"Evaluate",
"quadratic",
"weight",
".",
"stddev",
"is",
"ignored",
"."
] | b54673327e76198ecd4c8a2a901021f1a9174498 | https://github.com/elki-project/elki/blob/b54673327e76198ecd4c8a2a901021f1a9174498/elki-core-math/src/main/java/de/lmu/ifi/dbs/elki/math/linearalgebra/pca/weightfunctions/QuadraticWeight.java#L36-L43 | train |
elki-project/elki | elki-core-distance/src/main/java/de/lmu/ifi/dbs/elki/distance/distancefunction/minkowski/EuclideanDistanceFunction.java | EuclideanDistanceFunction.maxDist | public double maxDist(SpatialComparable mbr1, SpatialComparable mbr2) {
final int dim1 = mbr1.getDimensionality(), dim2 = mbr2.getDimensionality();
final int mindim = dim1 < dim2 ? dim1 : dim2;
double agg = 0.;
for(int d = 0; d < mindim; d++) {
double d1 = mbr1.getMax(d) - mbr2.getMin(d);
double d2 = mbr2.getMax(d) - mbr1.getMin(d);
double delta = d1 > d2 ? d1 : d2;
agg += delta * delta;
}
for(int d = mindim; d < dim1; d++) {
double d1 = Math.abs(mbr1.getMin(d)), d2 = Math.abs(mbr1.getMax(d));
double delta = d1 > d2 ? d1 : d2;
agg += delta * delta;
}
for(int d = mindim; d < dim2; d++) {
double d1 = Math.abs(mbr2.getMin(d)), d2 = Math.abs(mbr2.getMax(d));
double delta = d1 > d2 ? d1 : d2;
agg += delta * delta;
}
return FastMath.sqrt(agg);
} | java | public double maxDist(SpatialComparable mbr1, SpatialComparable mbr2) {
final int dim1 = mbr1.getDimensionality(), dim2 = mbr2.getDimensionality();
final int mindim = dim1 < dim2 ? dim1 : dim2;
double agg = 0.;
for(int d = 0; d < mindim; d++) {
double d1 = mbr1.getMax(d) - mbr2.getMin(d);
double d2 = mbr2.getMax(d) - mbr1.getMin(d);
double delta = d1 > d2 ? d1 : d2;
agg += delta * delta;
}
for(int d = mindim; d < dim1; d++) {
double d1 = Math.abs(mbr1.getMin(d)), d2 = Math.abs(mbr1.getMax(d));
double delta = d1 > d2 ? d1 : d2;
agg += delta * delta;
}
for(int d = mindim; d < dim2; d++) {
double d1 = Math.abs(mbr2.getMin(d)), d2 = Math.abs(mbr2.getMax(d));
double delta = d1 > d2 ? d1 : d2;
agg += delta * delta;
}
return FastMath.sqrt(agg);
} | [
"public",
"double",
"maxDist",
"(",
"SpatialComparable",
"mbr1",
",",
"SpatialComparable",
"mbr2",
")",
"{",
"final",
"int",
"dim1",
"=",
"mbr1",
".",
"getDimensionality",
"(",
")",
",",
"dim2",
"=",
"mbr2",
".",
"getDimensionality",
"(",
")",
";",
"final",
... | Maximum distance of two objects.
@param mbr1 First object
@param mbr2 Second object | [
"Maximum",
"distance",
"of",
"two",
"objects",
"."
] | b54673327e76198ecd4c8a2a901021f1a9174498 | https://github.com/elki-project/elki/blob/b54673327e76198ecd4c8a2a901021f1a9174498/elki-core-distance/src/main/java/de/lmu/ifi/dbs/elki/distance/distancefunction/minkowski/EuclideanDistanceFunction.java#L160-L182 | train |
elki-project/elki | elki-gui-minigui/src/main/java/de/lmu/ifi/dbs/elki/gui/util/DynamicParameters.java | DynamicParameters.updateFromTrackParameters | public synchronized void updateFromTrackParameters(TrackParameters track) {
parameters.clear();
for(TrackedParameter p : track.getAllParameters()) {
Parameter<?> option = p.getParameter();
String value = null;
if(option.isDefined()) {
if(option.tookDefaultValue()) {
value = DynamicParameters.STRING_USE_DEFAULT + option.getDefaultValueAsString();
}
else {
value = option.getValueAsString();
}
}
if(value == null) {
value = (option instanceof Flag) ? Flag.NOT_SET : "";
}
int bits = 0;
if(option.isOptional()) {
bits |= BIT_OPTIONAL;
}
if(option.hasDefaultValue() && option.tookDefaultValue()) {
bits |= BIT_DEFAULT_VALUE;
}
if(value.length() <= 0) {
if((bits & BIT_DEFAULT_VALUE) == 0 && (bits & BIT_OPTIONAL) == 0) {
bits |= BIT_INCOMPLETE;
}
}
else {
try {
if(!option.tookDefaultValue() && !option.isValid(value)) {
bits |= BIT_INVALID;
}
}
catch(ParameterException e) {
bits |= BIT_INVALID;
}
}
int depth = 0;
{
Object pos = track.getParent(option);
while(pos != null) {
pos = track.getParent(pos);
depth += 1;
if(depth > 10) {
break;
}
}
}
parameters.add(new Node(option, value, bits, depth));
}
} | java | public synchronized void updateFromTrackParameters(TrackParameters track) {
parameters.clear();
for(TrackedParameter p : track.getAllParameters()) {
Parameter<?> option = p.getParameter();
String value = null;
if(option.isDefined()) {
if(option.tookDefaultValue()) {
value = DynamicParameters.STRING_USE_DEFAULT + option.getDefaultValueAsString();
}
else {
value = option.getValueAsString();
}
}
if(value == null) {
value = (option instanceof Flag) ? Flag.NOT_SET : "";
}
int bits = 0;
if(option.isOptional()) {
bits |= BIT_OPTIONAL;
}
if(option.hasDefaultValue() && option.tookDefaultValue()) {
bits |= BIT_DEFAULT_VALUE;
}
if(value.length() <= 0) {
if((bits & BIT_DEFAULT_VALUE) == 0 && (bits & BIT_OPTIONAL) == 0) {
bits |= BIT_INCOMPLETE;
}
}
else {
try {
if(!option.tookDefaultValue() && !option.isValid(value)) {
bits |= BIT_INVALID;
}
}
catch(ParameterException e) {
bits |= BIT_INVALID;
}
}
int depth = 0;
{
Object pos = track.getParent(option);
while(pos != null) {
pos = track.getParent(pos);
depth += 1;
if(depth > 10) {
break;
}
}
}
parameters.add(new Node(option, value, bits, depth));
}
} | [
"public",
"synchronized",
"void",
"updateFromTrackParameters",
"(",
"TrackParameters",
"track",
")",
"{",
"parameters",
".",
"clear",
"(",
")",
";",
"for",
"(",
"TrackedParameter",
"p",
":",
"track",
".",
"getAllParameters",
"(",
")",
")",
"{",
"Parameter",
"<... | Update the Parameter list from the collected options of an ELKI context
@param track Tracked Parameters | [
"Update",
"the",
"Parameter",
"list",
"from",
"the",
"collected",
"options",
"of",
"an",
"ELKI",
"context"
] | b54673327e76198ecd4c8a2a901021f1a9174498 | https://github.com/elki-project/elki/blob/b54673327e76198ecd4c8a2a901021f1a9174498/elki-gui-minigui/src/main/java/de/lmu/ifi/dbs/elki/gui/util/DynamicParameters.java#L137-L188 | train |
elki-project/elki | elki-gui-minigui/src/main/java/de/lmu/ifi/dbs/elki/gui/util/DynamicParameters.java | DynamicParameters.addParameter | public synchronized void addParameter(Parameter<?> option, String value, int bits, int depth) {
parameters.add(new Node(option, value, bits, depth));
} | java | public synchronized void addParameter(Parameter<?> option, String value, int bits, int depth) {
parameters.add(new Node(option, value, bits, depth));
} | [
"public",
"synchronized",
"void",
"addParameter",
"(",
"Parameter",
"<",
"?",
">",
"option",
",",
"String",
"value",
",",
"int",
"bits",
",",
"int",
"depth",
")",
"{",
"parameters",
".",
"add",
"(",
"new",
"Node",
"(",
"option",
",",
"value",
",",
"bit... | Add a single parameter to the list
@param option Option
@param value Value
@param bits Bits
@param depth Depth | [
"Add",
"a",
"single",
"parameter",
"to",
"the",
"list"
] | b54673327e76198ecd4c8a2a901021f1a9174498 | https://github.com/elki-project/elki/blob/b54673327e76198ecd4c8a2a901021f1a9174498/elki-gui-minigui/src/main/java/de/lmu/ifi/dbs/elki/gui/util/DynamicParameters.java#L198-L200 | train |
elki-project/elki | elki-clustering/src/main/java/de/lmu/ifi/dbs/elki/data/Clustering.java | Clustering.getClusteringResults | public static List<Clustering<? extends Model>> getClusteringResults(Result r) {
if(r instanceof Clustering<?>) {
List<Clustering<?>> crs = new ArrayList<>(1);
crs.add((Clustering<?>) r);
return crs;
}
if(r instanceof HierarchicalResult) {
return ResultUtil.filterResults(((HierarchicalResult) r).getHierarchy(), r, Clustering.class);
}
return Collections.emptyList();
} | java | public static List<Clustering<? extends Model>> getClusteringResults(Result r) {
if(r instanceof Clustering<?>) {
List<Clustering<?>> crs = new ArrayList<>(1);
crs.add((Clustering<?>) r);
return crs;
}
if(r instanceof HierarchicalResult) {
return ResultUtil.filterResults(((HierarchicalResult) r).getHierarchy(), r, Clustering.class);
}
return Collections.emptyList();
} | [
"public",
"static",
"List",
"<",
"Clustering",
"<",
"?",
"extends",
"Model",
">",
">",
"getClusteringResults",
"(",
"Result",
"r",
")",
"{",
"if",
"(",
"r",
"instanceof",
"Clustering",
"<",
"?",
">",
")",
"{",
"List",
"<",
"Clustering",
"<",
"?",
">",
... | Collect all clustering results from a Result
@param r Result
@return List of clustering results | [
"Collect",
"all",
"clustering",
"results",
"from",
"a",
"Result"
] | b54673327e76198ecd4c8a2a901021f1a9174498 | https://github.com/elki-project/elki/blob/b54673327e76198ecd4c8a2a901021f1a9174498/elki-clustering/src/main/java/de/lmu/ifi/dbs/elki/data/Clustering.java#L167-L177 | train |
elki-project/elki | addons/tutorial/src/main/java/tutorial/javaapi/GeoIndexing.java | GeoIndexing.randomLatitudeLongitude | private static double[] randomLatitudeLongitude(Random r) {
// Make marginally more realistic looking data by non-uniformly sampling
// latitude, since Earth is a sphere, and there is not much at the poles
double lat = Math.pow(1. - r.nextDouble() * 2., 2) / 2. * 180;
double lng = (.5 - r.nextDouble()) * 360.;
return new double[] { lat, lng };
} | java | private static double[] randomLatitudeLongitude(Random r) {
// Make marginally more realistic looking data by non-uniformly sampling
// latitude, since Earth is a sphere, and there is not much at the poles
double lat = Math.pow(1. - r.nextDouble() * 2., 2) / 2. * 180;
double lng = (.5 - r.nextDouble()) * 360.;
return new double[] { lat, lng };
} | [
"private",
"static",
"double",
"[",
"]",
"randomLatitudeLongitude",
"(",
"Random",
"r",
")",
"{",
"// Make marginally more realistic looking data by non-uniformly sampling",
"// latitude, since Earth is a sphere, and there is not much at the poles",
"double",
"lat",
"=",
"Math",
".... | Generate random coordinates.
@param r Random generator
@return Latitude, Longitude array. | [
"Generate",
"random",
"coordinates",
"."
] | b54673327e76198ecd4c8a2a901021f1a9174498 | https://github.com/elki-project/elki/blob/b54673327e76198ecd4c8a2a901021f1a9174498/addons/tutorial/src/main/java/tutorial/javaapi/GeoIndexing.java#L138-L144 | train |
elki-project/elki | elki-core-distance/src/main/java/de/lmu/ifi/dbs/elki/distance/distancefunction/correlation/AbsolutePearsonCorrelationDistanceFunction.java | AbsolutePearsonCorrelationDistanceFunction.distance | @Override
public double distance(NumberVector v1, NumberVector v2) {
return 1 - Math.abs(PearsonCorrelation.coefficient(v1, v2));
} | java | @Override
public double distance(NumberVector v1, NumberVector v2) {
return 1 - Math.abs(PearsonCorrelation.coefficient(v1, v2));
} | [
"@",
"Override",
"public",
"double",
"distance",
"(",
"NumberVector",
"v1",
",",
"NumberVector",
"v2",
")",
"{",
"return",
"1",
"-",
"Math",
".",
"abs",
"(",
"PearsonCorrelation",
".",
"coefficient",
"(",
"v1",
",",
"v2",
")",
")",
";",
"}"
] | Computes the absolute Pearson correlation distance for two given feature
vectors.
The absolute Pearson correlation distance is computed from the Pearson
correlation coefficient <code>r</code> as: <code>1-abs(r)</code>. Hence,
possible values of this distance are between 0 and 1.
@param v1 first feature vector
@param v2 second feature vector
@return the absolute Pearson correlation distance for two given feature
vectors v1 and v2 | [
"Computes",
"the",
"absolute",
"Pearson",
"correlation",
"distance",
"for",
"two",
"given",
"feature",
"vectors",
"."
] | b54673327e76198ecd4c8a2a901021f1a9174498 | https://github.com/elki-project/elki/blob/b54673327e76198ecd4c8a2a901021f1a9174498/elki-core-distance/src/main/java/de/lmu/ifi/dbs/elki/distance/distancefunction/correlation/AbsolutePearsonCorrelationDistanceFunction.java#L71-L74 | train |
elki-project/elki | elki-core-math/src/main/java/de/lmu/ifi/dbs/elki/math/statistics/distribution/HaltonUniformDistribution.java | HaltonUniformDistribution.inverse | private long inverse(double current) {
// Represent to base b.
short[] digits = new short[maxi];
for(int j = 0; j < maxi; j++) {
current *= base;
digits[j] = (short) current;
current -= digits[j];
if(current <= 1e-10) {
break;
}
}
long inv = 0;
for(int j = maxi - 1; j >= 0; j--) {
inv = inv * base + digits[j];
}
return inv;
} | java | private long inverse(double current) {
// Represent to base b.
short[] digits = new short[maxi];
for(int j = 0; j < maxi; j++) {
current *= base;
digits[j] = (short) current;
current -= digits[j];
if(current <= 1e-10) {
break;
}
}
long inv = 0;
for(int j = maxi - 1; j >= 0; j--) {
inv = inv * base + digits[j];
}
return inv;
} | [
"private",
"long",
"inverse",
"(",
"double",
"current",
")",
"{",
"// Represent to base b.",
"short",
"[",
"]",
"digits",
"=",
"new",
"short",
"[",
"maxi",
"]",
";",
"for",
"(",
"int",
"j",
"=",
"0",
";",
"j",
"<",
"maxi",
";",
"j",
"++",
")",
"{",... | Compute the inverse with respect to the given base.
@param current Current value
@return Integer inverse | [
"Compute",
"the",
"inverse",
"with",
"respect",
"to",
"the",
"given",
"base",
"."
] | b54673327e76198ecd4c8a2a901021f1a9174498 | https://github.com/elki-project/elki/blob/b54673327e76198ecd4c8a2a901021f1a9174498/elki-core-math/src/main/java/de/lmu/ifi/dbs/elki/math/statistics/distribution/HaltonUniformDistribution.java#L240-L256 | train |
elki-project/elki | elki-core-math/src/main/java/de/lmu/ifi/dbs/elki/math/statistics/distribution/HaltonUniformDistribution.java | HaltonUniformDistribution.radicalInverse | private double radicalInverse(long i) {
double digit = 1.0 / (double) base;
double radical = digit;
double inverse = 0.0;
while(i > 0) {
inverse += digit * (double) (i % base);
digit *= radical;
i /= base;
}
return inverse;
} | java | private double radicalInverse(long i) {
double digit = 1.0 / (double) base;
double radical = digit;
double inverse = 0.0;
while(i > 0) {
inverse += digit * (double) (i % base);
digit *= radical;
i /= base;
}
return inverse;
} | [
"private",
"double",
"radicalInverse",
"(",
"long",
"i",
")",
"{",
"double",
"digit",
"=",
"1.0",
"/",
"(",
"double",
")",
"base",
";",
"double",
"radical",
"=",
"digit",
";",
"double",
"inverse",
"=",
"0.0",
";",
"while",
"(",
"i",
">",
"0",
")",
... | Compute the radical inverse of i.
@param i Input long value
@return Double radical inverse | [
"Compute",
"the",
"radical",
"inverse",
"of",
"i",
"."
] | b54673327e76198ecd4c8a2a901021f1a9174498 | https://github.com/elki-project/elki/blob/b54673327e76198ecd4c8a2a901021f1a9174498/elki-core-math/src/main/java/de/lmu/ifi/dbs/elki/math/statistics/distribution/HaltonUniformDistribution.java#L264-L274 | train |
elki-project/elki | elki-core-math/src/main/java/de/lmu/ifi/dbs/elki/math/statistics/distribution/HaltonUniformDistribution.java | HaltonUniformDistribution.nextRadicalInverse | private double nextRadicalInverse() {
counter++;
// Do at most MAXFAST appromate steps
if(counter >= MAXFAST) {
counter = 0;
inverse += MAXFAST;
current = radicalInverse(inverse);
return current;
}
// Fast approximation:
double nextInverse = current + invbase;
if(nextInverse < ALMOST_ONE) {
current = nextInverse;
return current;
}
else {
double digit1 = invbase, digit2 = invbase * invbase;
while(current + digit2 >= ALMOST_ONE) {
digit1 = digit2;
digit2 *= invbase;
}
current += (digit1 - 1.0) + digit2;
return current;
}
} | java | private double nextRadicalInverse() {
counter++;
// Do at most MAXFAST appromate steps
if(counter >= MAXFAST) {
counter = 0;
inverse += MAXFAST;
current = radicalInverse(inverse);
return current;
}
// Fast approximation:
double nextInverse = current + invbase;
if(nextInverse < ALMOST_ONE) {
current = nextInverse;
return current;
}
else {
double digit1 = invbase, digit2 = invbase * invbase;
while(current + digit2 >= ALMOST_ONE) {
digit1 = digit2;
digit2 *= invbase;
}
current += (digit1 - 1.0) + digit2;
return current;
}
} | [
"private",
"double",
"nextRadicalInverse",
"(",
")",
"{",
"counter",
"++",
";",
"// Do at most MAXFAST appromate steps",
"if",
"(",
"counter",
">=",
"MAXFAST",
")",
"{",
"counter",
"=",
"0",
";",
"inverse",
"+=",
"MAXFAST",
";",
"current",
"=",
"radicalInverse",... | Compute the next radical inverse.
@return Next inverse | [
"Compute",
"the",
"next",
"radical",
"inverse",
"."
] | b54673327e76198ecd4c8a2a901021f1a9174498 | https://github.com/elki-project/elki/blob/b54673327e76198ecd4c8a2a901021f1a9174498/elki-core-math/src/main/java/de/lmu/ifi/dbs/elki/math/statistics/distribution/HaltonUniformDistribution.java#L281-L305 | train |
elki-project/elki | elki-clustering/src/main/java/de/lmu/ifi/dbs/elki/data/Subspace.java | Subspace.dimensonsToString | public String dimensonsToString(String sep) {
StringBuilder result = new StringBuilder(100).append('[');
for(int dim = BitsUtil.nextSetBit(dimensions, 0); dim >= 0; dim = BitsUtil.nextSetBit(dimensions, dim + 1)) {
result.append(dim + 1).append(sep);
}
if(result.length() > sep.length()) { // Un-append last separator
result.setLength(result.length() - sep.length());
}
return result.append(']').toString();
} | java | public String dimensonsToString(String sep) {
StringBuilder result = new StringBuilder(100).append('[');
for(int dim = BitsUtil.nextSetBit(dimensions, 0); dim >= 0; dim = BitsUtil.nextSetBit(dimensions, dim + 1)) {
result.append(dim + 1).append(sep);
}
if(result.length() > sep.length()) { // Un-append last separator
result.setLength(result.length() - sep.length());
}
return result.append(']').toString();
} | [
"public",
"String",
"dimensonsToString",
"(",
"String",
"sep",
")",
"{",
"StringBuilder",
"result",
"=",
"new",
"StringBuilder",
"(",
"100",
")",
".",
"append",
"(",
"'",
"'",
")",
";",
"for",
"(",
"int",
"dim",
"=",
"BitsUtil",
".",
"nextSetBit",
"(",
... | Returns a string representation of the dimensions of this subspace.
@param sep the separator between the dimensions
@return a string representation of the dimensions of this subspace | [
"Returns",
"a",
"string",
"representation",
"of",
"the",
"dimensions",
"of",
"this",
"subspace",
"."
] | b54673327e76198ecd4c8a2a901021f1a9174498 | https://github.com/elki-project/elki/blob/b54673327e76198ecd4c8a2a901021f1a9174498/elki-clustering/src/main/java/de/lmu/ifi/dbs/elki/data/Subspace.java#L129-L138 | train |
elki-project/elki | elki-clustering/src/main/java/de/lmu/ifi/dbs/elki/data/Subspace.java | Subspace.isSubspace | public boolean isSubspace(Subspace subspace) {
return this.dimensionality <= subspace.dimensionality && //
BitsUtil.intersectionSize(dimensions, subspace.dimensions) == dimensionality;
} | java | public boolean isSubspace(Subspace subspace) {
return this.dimensionality <= subspace.dimensionality && //
BitsUtil.intersectionSize(dimensions, subspace.dimensions) == dimensionality;
} | [
"public",
"boolean",
"isSubspace",
"(",
"Subspace",
"subspace",
")",
"{",
"return",
"this",
".",
"dimensionality",
"<=",
"subspace",
".",
"dimensionality",
"&&",
"//",
"BitsUtil",
".",
"intersectionSize",
"(",
"dimensions",
",",
"subspace",
".",
"dimensions",
")... | Returns true if this subspace is a subspace of the specified subspace, i.e.
if the set of dimensions building this subspace are contained in the set of
dimensions building the specified subspace.
@param subspace the subspace to test
@return true if this subspace is a subspace of the specified subspace,
false otherwise | [
"Returns",
"true",
"if",
"this",
"subspace",
"is",
"a",
"subspace",
"of",
"the",
"specified",
"subspace",
"i",
".",
"e",
".",
"if",
"the",
"set",
"of",
"dimensions",
"building",
"this",
"subspace",
"are",
"contained",
"in",
"the",
"set",
"of",
"dimensions"... | b54673327e76198ecd4c8a2a901021f1a9174498 | https://github.com/elki-project/elki/blob/b54673327e76198ecd4c8a2a901021f1a9174498/elki-clustering/src/main/java/de/lmu/ifi/dbs/elki/data/Subspace.java#L149-L152 | train |
elki-project/elki | elki-index-rtree/src/main/java/de/lmu/ifi/dbs/elki/index/tree/spatial/rstarvariants/strategies/split/AngTanLinearSplit.java | AngTanLinearSplit.computeOverlap | protected <E extends SpatialComparable, A> double computeOverlap(A entries, ArrayAdapter<E, A> getter, long[] assign) {
ModifiableHyperBoundingBox mbr1 = null, mbr2 = null;
for(int i = 0; i < getter.size(entries); i++) {
E e = getter.get(entries, i);
if(BitsUtil.get(assign, i)) {
if(mbr1 == null) {
mbr1 = new ModifiableHyperBoundingBox(e);
}
else {
mbr1.extend(e);
}
}
else {
if(mbr2 == null) {
mbr2 = new ModifiableHyperBoundingBox(e);
}
else {
mbr2.extend(e);
}
}
}
if(mbr1 == null || mbr2 == null) {
throw new AbortException("Invalid state in split: one of the sets is empty.");
}
return SpatialUtil.overlap(mbr1, mbr2);
} | java | protected <E extends SpatialComparable, A> double computeOverlap(A entries, ArrayAdapter<E, A> getter, long[] assign) {
ModifiableHyperBoundingBox mbr1 = null, mbr2 = null;
for(int i = 0; i < getter.size(entries); i++) {
E e = getter.get(entries, i);
if(BitsUtil.get(assign, i)) {
if(mbr1 == null) {
mbr1 = new ModifiableHyperBoundingBox(e);
}
else {
mbr1.extend(e);
}
}
else {
if(mbr2 == null) {
mbr2 = new ModifiableHyperBoundingBox(e);
}
else {
mbr2.extend(e);
}
}
}
if(mbr1 == null || mbr2 == null) {
throw new AbortException("Invalid state in split: one of the sets is empty.");
}
return SpatialUtil.overlap(mbr1, mbr2);
} | [
"protected",
"<",
"E",
"extends",
"SpatialComparable",
",",
"A",
">",
"double",
"computeOverlap",
"(",
"A",
"entries",
",",
"ArrayAdapter",
"<",
"E",
",",
"A",
">",
"getter",
",",
"long",
"[",
"]",
"assign",
")",
"{",
"ModifiableHyperBoundingBox",
"mbr1",
... | Compute overlap of assignment
@param entries Entries
@param getter Entry accessor
@param assign Assignment
@return Overlap amount | [
"Compute",
"overlap",
"of",
"assignment"
] | b54673327e76198ecd4c8a2a901021f1a9174498 | https://github.com/elki-project/elki/blob/b54673327e76198ecd4c8a2a901021f1a9174498/elki-index-rtree/src/main/java/de/lmu/ifi/dbs/elki/index/tree/spatial/rstarvariants/strategies/split/AngTanLinearSplit.java#L150-L175 | train |
elki-project/elki | elki-core-math/src/main/java/de/lmu/ifi/dbs/elki/math/spacefillingcurves/BinarySplitSpatialSorter.java | BinarySplitSpatialSorter.binarySplitSort | private void binarySplitSort(List<? extends SpatialComparable> objs, final int start, final int end, int depth, final int numdim, int[] dims, Sorter comp) {
final int mid = start + ((end - start) >>> 1);
// Make invariant
comp.setDimension(dims != null ? dims[depth] : depth);
QuickSelect.quickSelect(objs, comp, start, end, mid);
// Recurse
final int nextdim = (depth + 1) % numdim;
if(start < mid - 1) {
binarySplitSort(objs, start, mid, nextdim, numdim, dims, comp);
}
if(mid + 2 < end) {
binarySplitSort(objs, mid + 1, end, nextdim, numdim, dims, comp);
}
} | java | private void binarySplitSort(List<? extends SpatialComparable> objs, final int start, final int end, int depth, final int numdim, int[] dims, Sorter comp) {
final int mid = start + ((end - start) >>> 1);
// Make invariant
comp.setDimension(dims != null ? dims[depth] : depth);
QuickSelect.quickSelect(objs, comp, start, end, mid);
// Recurse
final int nextdim = (depth + 1) % numdim;
if(start < mid - 1) {
binarySplitSort(objs, start, mid, nextdim, numdim, dims, comp);
}
if(mid + 2 < end) {
binarySplitSort(objs, mid + 1, end, nextdim, numdim, dims, comp);
}
} | [
"private",
"void",
"binarySplitSort",
"(",
"List",
"<",
"?",
"extends",
"SpatialComparable",
">",
"objs",
",",
"final",
"int",
"start",
",",
"final",
"int",
"end",
",",
"int",
"depth",
",",
"final",
"int",
"numdim",
",",
"int",
"[",
"]",
"dims",
",",
"... | Sort the array using a binary split in dimension curdim, then recurse with
the next dimension.
@param objs List of objects
@param start Interval start
@param end Interval end (exclusive)
@param depth Recursion depth
@param numdim Number of dimensions
@param dims Dimension indexes to sort by.
@param comp Comparator to use | [
"Sort",
"the",
"array",
"using",
"a",
"binary",
"split",
"in",
"dimension",
"curdim",
"then",
"recurse",
"with",
"the",
"next",
"dimension",
"."
] | b54673327e76198ecd4c8a2a901021f1a9174498 | https://github.com/elki-project/elki/blob/b54673327e76198ecd4c8a2a901021f1a9174498/elki-core-math/src/main/java/de/lmu/ifi/dbs/elki/math/spacefillingcurves/BinarySplitSpatialSorter.java#L86-L99 | train |
elki-project/elki | addons/batikvis/src/main/java/de/lmu/ifi/dbs/elki/visualization/svg/SVGUtil.java | SVGUtil.svgElement | public static Element svgElement(Document document, String name) {
return document.createElementNS(SVGConstants.SVG_NAMESPACE_URI, name);
} | java | public static Element svgElement(Document document, String name) {
return document.createElementNS(SVGConstants.SVG_NAMESPACE_URI, name);
} | [
"public",
"static",
"Element",
"svgElement",
"(",
"Document",
"document",
",",
"String",
"name",
")",
"{",
"return",
"document",
".",
"createElementNS",
"(",
"SVGConstants",
".",
"SVG_NAMESPACE_URI",
",",
"name",
")",
";",
"}"
] | Create a SVG element in appropriate namespace
@param document containing document
@param name node name
@return new SVG element. | [
"Create",
"a",
"SVG",
"element",
"in",
"appropriate",
"namespace"
] | b54673327e76198ecd4c8a2a901021f1a9174498 | https://github.com/elki-project/elki/blob/b54673327e76198ecd4c8a2a901021f1a9174498/addons/batikvis/src/main/java/de/lmu/ifi/dbs/elki/visualization/svg/SVGUtil.java#L283-L285 | train |
elki-project/elki | addons/batikvis/src/main/java/de/lmu/ifi/dbs/elki/visualization/svg/SVGUtil.java | SVGUtil.setStyle | public static void setStyle(Element el, String d) {
el.setAttribute(SVGConstants.SVG_STYLE_ATTRIBUTE, d);
} | java | public static void setStyle(Element el, String d) {
el.setAttribute(SVGConstants.SVG_STYLE_ATTRIBUTE, d);
} | [
"public",
"static",
"void",
"setStyle",
"(",
"Element",
"el",
",",
"String",
"d",
")",
"{",
"el",
".",
"setAttribute",
"(",
"SVGConstants",
".",
"SVG_STYLE_ATTRIBUTE",
",",
"d",
")",
";",
"}"
] | Set a SVG style attribute
@param el element
@param d style value | [
"Set",
"a",
"SVG",
"style",
"attribute"
] | b54673327e76198ecd4c8a2a901021f1a9174498 | https://github.com/elki-project/elki/blob/b54673327e76198ecd4c8a2a901021f1a9174498/addons/batikvis/src/main/java/de/lmu/ifi/dbs/elki/visualization/svg/SVGUtil.java#L326-L328 | train |
elki-project/elki | addons/batikvis/src/main/java/de/lmu/ifi/dbs/elki/visualization/svg/SVGUtil.java | SVGUtil.addCSSClass | public static void addCSSClass(Element e, String cssclass) {
String oldval = e.getAttribute(SVGConstants.SVG_CLASS_ATTRIBUTE);
if(oldval == null || oldval.length() == 0) {
setAtt(e, SVGConstants.SVG_CLASS_ATTRIBUTE, cssclass);
return;
}
String[] classes = oldval.split(" ");
for(String c : classes) {
if(c.equals(cssclass)) {
return;
}
}
setAtt(e, SVGConstants.SVG_CLASS_ATTRIBUTE, oldval + " " + cssclass);
} | java | public static void addCSSClass(Element e, String cssclass) {
String oldval = e.getAttribute(SVGConstants.SVG_CLASS_ATTRIBUTE);
if(oldval == null || oldval.length() == 0) {
setAtt(e, SVGConstants.SVG_CLASS_ATTRIBUTE, cssclass);
return;
}
String[] classes = oldval.split(" ");
for(String c : classes) {
if(c.equals(cssclass)) {
return;
}
}
setAtt(e, SVGConstants.SVG_CLASS_ATTRIBUTE, oldval + " " + cssclass);
} | [
"public",
"static",
"void",
"addCSSClass",
"(",
"Element",
"e",
",",
"String",
"cssclass",
")",
"{",
"String",
"oldval",
"=",
"e",
".",
"getAttribute",
"(",
"SVGConstants",
".",
"SVG_CLASS_ATTRIBUTE",
")",
";",
"if",
"(",
"oldval",
"==",
"null",
"||",
"old... | Add a CSS class to an Element.
@param e Element
@param cssclass class to add. | [
"Add",
"a",
"CSS",
"class",
"to",
"an",
"Element",
"."
] | b54673327e76198ecd4c8a2a901021f1a9174498 | https://github.com/elki-project/elki/blob/b54673327e76198ecd4c8a2a901021f1a9174498/addons/batikvis/src/main/java/de/lmu/ifi/dbs/elki/visualization/svg/SVGUtil.java#L347-L360 | train |
elki-project/elki | addons/batikvis/src/main/java/de/lmu/ifi/dbs/elki/visualization/svg/SVGUtil.java | SVGUtil.removeCSSClass | public static void removeCSSClass(Element e, String cssclass) {
String oldval = e.getAttribute(SVGConstants.SVG_CLASS_ATTRIBUTE);
if(oldval == null) {
return;
}
String[] classes = oldval.split(" ");
if(classes.length == 1) {
if(cssclass.equals(classes[0])) {
e.removeAttribute(SVGConstants.SVG_CLASS_ATTRIBUTE);
}
}
else if(classes.length == 2) {
if(cssclass.equals(classes[0])) {
if(cssclass.equals(classes[1])) {
e.removeAttribute(SVGConstants.SVG_CLASS_ATTRIBUTE);
}
else {
e.setAttribute(SVGConstants.SVG_CLASS_ATTRIBUTE, classes[1]);
}
}
else if(cssclass.equals(classes[1])) {
e.setAttribute(SVGConstants.SVG_CLASS_ATTRIBUTE, classes[0]);
}
}
else {
StringBuilder joined = new StringBuilder();
for(String c : classes) {
if(!c.equals(cssclass)) {
if(joined.length() > 0) {
joined.append(' ');
}
joined.append(c);
}
}
e.setAttribute(SVGConstants.SVG_CLASS_ATTRIBUTE, joined.toString());
}
} | java | public static void removeCSSClass(Element e, String cssclass) {
String oldval = e.getAttribute(SVGConstants.SVG_CLASS_ATTRIBUTE);
if(oldval == null) {
return;
}
String[] classes = oldval.split(" ");
if(classes.length == 1) {
if(cssclass.equals(classes[0])) {
e.removeAttribute(SVGConstants.SVG_CLASS_ATTRIBUTE);
}
}
else if(classes.length == 2) {
if(cssclass.equals(classes[0])) {
if(cssclass.equals(classes[1])) {
e.removeAttribute(SVGConstants.SVG_CLASS_ATTRIBUTE);
}
else {
e.setAttribute(SVGConstants.SVG_CLASS_ATTRIBUTE, classes[1]);
}
}
else if(cssclass.equals(classes[1])) {
e.setAttribute(SVGConstants.SVG_CLASS_ATTRIBUTE, classes[0]);
}
}
else {
StringBuilder joined = new StringBuilder();
for(String c : classes) {
if(!c.equals(cssclass)) {
if(joined.length() > 0) {
joined.append(' ');
}
joined.append(c);
}
}
e.setAttribute(SVGConstants.SVG_CLASS_ATTRIBUTE, joined.toString());
}
} | [
"public",
"static",
"void",
"removeCSSClass",
"(",
"Element",
"e",
",",
"String",
"cssclass",
")",
"{",
"String",
"oldval",
"=",
"e",
".",
"getAttribute",
"(",
"SVGConstants",
".",
"SVG_CLASS_ATTRIBUTE",
")",
";",
"if",
"(",
"oldval",
"==",
"null",
")",
"{... | Remove a CSS class from an Element.
@param e Element
@param cssclass class to remove. | [
"Remove",
"a",
"CSS",
"class",
"from",
"an",
"Element",
"."
] | b54673327e76198ecd4c8a2a901021f1a9174498 | https://github.com/elki-project/elki/blob/b54673327e76198ecd4c8a2a901021f1a9174498/addons/batikvis/src/main/java/de/lmu/ifi/dbs/elki/visualization/svg/SVGUtil.java#L368-L404 | train |
elki-project/elki | addons/batikvis/src/main/java/de/lmu/ifi/dbs/elki/visualization/svg/SVGUtil.java | SVGUtil.makeStyleElement | public static Element makeStyleElement(Document document) {
Element style = SVGUtil.svgElement(document, SVGConstants.SVG_STYLE_TAG);
style.setAttribute(SVGConstants.SVG_TYPE_ATTRIBUTE, SVGConstants.CSS_MIME_TYPE);
return style;
} | java | public static Element makeStyleElement(Document document) {
Element style = SVGUtil.svgElement(document, SVGConstants.SVG_STYLE_TAG);
style.setAttribute(SVGConstants.SVG_TYPE_ATTRIBUTE, SVGConstants.CSS_MIME_TYPE);
return style;
} | [
"public",
"static",
"Element",
"makeStyleElement",
"(",
"Document",
"document",
")",
"{",
"Element",
"style",
"=",
"SVGUtil",
".",
"svgElement",
"(",
"document",
",",
"SVGConstants",
".",
"SVG_STYLE_TAG",
")",
";",
"style",
".",
"setAttribute",
"(",
"SVGConstant... | Make a new CSS style element for the given Document.
@param document document (factory)
@return new CSS style element. | [
"Make",
"a",
"new",
"CSS",
"style",
"element",
"for",
"the",
"given",
"Document",
"."
] | b54673327e76198ecd4c8a2a901021f1a9174498 | https://github.com/elki-project/elki/blob/b54673327e76198ecd4c8a2a901021f1a9174498/addons/batikvis/src/main/java/de/lmu/ifi/dbs/elki/visualization/svg/SVGUtil.java#L412-L416 | train |
elki-project/elki | addons/batikvis/src/main/java/de/lmu/ifi/dbs/elki/visualization/svg/SVGUtil.java | SVGUtil.svgRect | public static Element svgRect(Document document, double x, double y, double w, double h) {
Element rect = SVGUtil.svgElement(document, SVGConstants.SVG_RECT_TAG);
SVGUtil.setAtt(rect, SVGConstants.SVG_X_ATTRIBUTE, x);
SVGUtil.setAtt(rect, SVGConstants.SVG_Y_ATTRIBUTE, y);
SVGUtil.setAtt(rect, SVGConstants.SVG_WIDTH_ATTRIBUTE, w);
SVGUtil.setAtt(rect, SVGConstants.SVG_HEIGHT_ATTRIBUTE, h);
return rect;
} | java | public static Element svgRect(Document document, double x, double y, double w, double h) {
Element rect = SVGUtil.svgElement(document, SVGConstants.SVG_RECT_TAG);
SVGUtil.setAtt(rect, SVGConstants.SVG_X_ATTRIBUTE, x);
SVGUtil.setAtt(rect, SVGConstants.SVG_Y_ATTRIBUTE, y);
SVGUtil.setAtt(rect, SVGConstants.SVG_WIDTH_ATTRIBUTE, w);
SVGUtil.setAtt(rect, SVGConstants.SVG_HEIGHT_ATTRIBUTE, h);
return rect;
} | [
"public",
"static",
"Element",
"svgRect",
"(",
"Document",
"document",
",",
"double",
"x",
",",
"double",
"y",
",",
"double",
"w",
",",
"double",
"h",
")",
"{",
"Element",
"rect",
"=",
"SVGUtil",
".",
"svgElement",
"(",
"document",
",",
"SVGConstants",
"... | Create a SVG rectangle element.
@param document document to create in (factory)
@param x X coordinate
@param y Y coordinate
@param w Width
@param h Height
@return new element | [
"Create",
"a",
"SVG",
"rectangle",
"element",
"."
] | b54673327e76198ecd4c8a2a901021f1a9174498 | https://github.com/elki-project/elki/blob/b54673327e76198ecd4c8a2a901021f1a9174498/addons/batikvis/src/main/java/de/lmu/ifi/dbs/elki/visualization/svg/SVGUtil.java#L428-L435 | train |
elki-project/elki | addons/batikvis/src/main/java/de/lmu/ifi/dbs/elki/visualization/svg/SVGUtil.java | SVGUtil.svgCircle | public static Element svgCircle(Document document, double cx, double cy, double r) {
Element circ = SVGUtil.svgElement(document, SVGConstants.SVG_CIRCLE_TAG);
SVGUtil.setAtt(circ, SVGConstants.SVG_CX_ATTRIBUTE, cx);
SVGUtil.setAtt(circ, SVGConstants.SVG_CY_ATTRIBUTE, cy);
SVGUtil.setAtt(circ, SVGConstants.SVG_R_ATTRIBUTE, r);
return circ;
} | java | public static Element svgCircle(Document document, double cx, double cy, double r) {
Element circ = SVGUtil.svgElement(document, SVGConstants.SVG_CIRCLE_TAG);
SVGUtil.setAtt(circ, SVGConstants.SVG_CX_ATTRIBUTE, cx);
SVGUtil.setAtt(circ, SVGConstants.SVG_CY_ATTRIBUTE, cy);
SVGUtil.setAtt(circ, SVGConstants.SVG_R_ATTRIBUTE, r);
return circ;
} | [
"public",
"static",
"Element",
"svgCircle",
"(",
"Document",
"document",
",",
"double",
"cx",
",",
"double",
"cy",
",",
"double",
"r",
")",
"{",
"Element",
"circ",
"=",
"SVGUtil",
".",
"svgElement",
"(",
"document",
",",
"SVGConstants",
".",
"SVG_CIRCLE_TAG"... | Create a SVG circle element.
@param document document to create in (factory)
@param cx center X
@param cy center Y
@param r radius
@return new element | [
"Create",
"a",
"SVG",
"circle",
"element",
"."
] | b54673327e76198ecd4c8a2a901021f1a9174498 | https://github.com/elki-project/elki/blob/b54673327e76198ecd4c8a2a901021f1a9174498/addons/batikvis/src/main/java/de/lmu/ifi/dbs/elki/visualization/svg/SVGUtil.java#L446-L452 | train |
elki-project/elki | addons/batikvis/src/main/java/de/lmu/ifi/dbs/elki/visualization/svg/SVGUtil.java | SVGUtil.svgLine | public static Element svgLine(Document document, double x1, double y1, double x2, double y2) {
Element line = SVGUtil.svgElement(document, SVGConstants.SVG_LINE_TAG);
SVGUtil.setAtt(line, SVGConstants.SVG_X1_ATTRIBUTE, x1);
SVGUtil.setAtt(line, SVGConstants.SVG_Y1_ATTRIBUTE, y1);
SVGUtil.setAtt(line, SVGConstants.SVG_X2_ATTRIBUTE, x2);
SVGUtil.setAtt(line, SVGConstants.SVG_Y2_ATTRIBUTE, y2);
return line;
} | java | public static Element svgLine(Document document, double x1, double y1, double x2, double y2) {
Element line = SVGUtil.svgElement(document, SVGConstants.SVG_LINE_TAG);
SVGUtil.setAtt(line, SVGConstants.SVG_X1_ATTRIBUTE, x1);
SVGUtil.setAtt(line, SVGConstants.SVG_Y1_ATTRIBUTE, y1);
SVGUtil.setAtt(line, SVGConstants.SVG_X2_ATTRIBUTE, x2);
SVGUtil.setAtt(line, SVGConstants.SVG_Y2_ATTRIBUTE, y2);
return line;
} | [
"public",
"static",
"Element",
"svgLine",
"(",
"Document",
"document",
",",
"double",
"x1",
",",
"double",
"y1",
",",
"double",
"x2",
",",
"double",
"y2",
")",
"{",
"Element",
"line",
"=",
"SVGUtil",
".",
"svgElement",
"(",
"document",
",",
"SVGConstants",... | Create a SVG line element. Do not confuse this with path elements.
@param document document to create in (factory)
@param x1 first point x
@param y1 first point y
@param x2 second point x
@param y2 second point y
@return new element | [
"Create",
"a",
"SVG",
"line",
"element",
".",
"Do",
"not",
"confuse",
"this",
"with",
"path",
"elements",
"."
] | b54673327e76198ecd4c8a2a901021f1a9174498 | https://github.com/elki-project/elki/blob/b54673327e76198ecd4c8a2a901021f1a9174498/addons/batikvis/src/main/java/de/lmu/ifi/dbs/elki/visualization/svg/SVGUtil.java#L464-L471 | train |
elki-project/elki | addons/batikvis/src/main/java/de/lmu/ifi/dbs/elki/visualization/svg/SVGUtil.java | SVGUtil.stringToColor | public static Color stringToColor(String str) {
int icol = SVG_COLOR_NAMES.getInt(str.toLowerCase());
if(icol != NO_VALUE) {
return new Color(icol, false);
}
return colorLookupStylesheet.stringToColor(str);
} | java | public static Color stringToColor(String str) {
int icol = SVG_COLOR_NAMES.getInt(str.toLowerCase());
if(icol != NO_VALUE) {
return new Color(icol, false);
}
return colorLookupStylesheet.stringToColor(str);
} | [
"public",
"static",
"Color",
"stringToColor",
"(",
"String",
"str",
")",
"{",
"int",
"icol",
"=",
"SVG_COLOR_NAMES",
".",
"getInt",
"(",
"str",
".",
"toLowerCase",
"(",
")",
")",
";",
"if",
"(",
"icol",
"!=",
"NO_VALUE",
")",
"{",
"return",
"new",
"Col... | Convert a color name from SVG syntax to an AWT color object.
@param str Color name
@return Color value | [
"Convert",
"a",
"color",
"name",
"from",
"SVG",
"syntax",
"to",
"an",
"AWT",
"color",
"object",
"."
] | b54673327e76198ecd4c8a2a901021f1a9174498 | https://github.com/elki-project/elki/blob/b54673327e76198ecd4c8a2a901021f1a9174498/addons/batikvis/src/main/java/de/lmu/ifi/dbs/elki/visualization/svg/SVGUtil.java#L528-L534 | train |
elki-project/elki | addons/batikvis/src/main/java/de/lmu/ifi/dbs/elki/visualization/svg/SVGUtil.java | SVGUtil.colorToString | public static String colorToString(int col) {
final char[] buf = new char[] { '#', 'X', 'X', 'X', 'X', 'X', 'X' };
for(int i = 6; i > 0; i--) {
final int v = (col & 0xF);
buf[i] = (char) ((v < 10) ? ('0' + v) : ('a' + v - 10));
col >>>= 4;
}
return new String(buf);
} | java | public static String colorToString(int col) {
final char[] buf = new char[] { '#', 'X', 'X', 'X', 'X', 'X', 'X' };
for(int i = 6; i > 0; i--) {
final int v = (col & 0xF);
buf[i] = (char) ((v < 10) ? ('0' + v) : ('a' + v - 10));
col >>>= 4;
}
return new String(buf);
} | [
"public",
"static",
"String",
"colorToString",
"(",
"int",
"col",
")",
"{",
"final",
"char",
"[",
"]",
"buf",
"=",
"new",
"char",
"[",
"]",
"{",
"'",
"'",
",",
"'",
"'",
",",
"'",
"'",
",",
"'",
"'",
",",
"'",
"'",
",",
"'",
"'",
",",
"'",
... | Convert a color name from an integer RGB color to CSS syntax
Note: currently only RGB (from ARGB order) are supported. The alpha channel
will be ignored.
@param col Color value
@return Color string | [
"Convert",
"a",
"color",
"name",
"from",
"an",
"integer",
"RGB",
"color",
"to",
"CSS",
"syntax"
] | b54673327e76198ecd4c8a2a901021f1a9174498 | https://github.com/elki-project/elki/blob/b54673327e76198ecd4c8a2a901021f1a9174498/addons/batikvis/src/main/java/de/lmu/ifi/dbs/elki/visualization/svg/SVGUtil.java#L557-L565 | train |
elki-project/elki | addons/batikvis/src/main/java/de/lmu/ifi/dbs/elki/visualization/svg/SVGUtil.java | SVGUtil.elementCoordinatesFromEvent | public static SVGPoint elementCoordinatesFromEvent(Document doc, Element tag, Event evt) {
try {
DOMMouseEvent gnme = (DOMMouseEvent) evt;
SVGMatrix mat = ((SVGLocatable) tag).getScreenCTM();
SVGMatrix imat = mat.inverse();
SVGPoint cPt = ((SVGDocument) doc).getRootElement().createSVGPoint();
cPt.setX(gnme.getClientX());
cPt.setY(gnme.getClientY());
return cPt.matrixTransform(imat);
}
catch(Exception e) {
LoggingUtil.warning("Error getting coordinates from SVG event.", e);
return null;
}
} | java | public static SVGPoint elementCoordinatesFromEvent(Document doc, Element tag, Event evt) {
try {
DOMMouseEvent gnme = (DOMMouseEvent) evt;
SVGMatrix mat = ((SVGLocatable) tag).getScreenCTM();
SVGMatrix imat = mat.inverse();
SVGPoint cPt = ((SVGDocument) doc).getRootElement().createSVGPoint();
cPt.setX(gnme.getClientX());
cPt.setY(gnme.getClientY());
return cPt.matrixTransform(imat);
}
catch(Exception e) {
LoggingUtil.warning("Error getting coordinates from SVG event.", e);
return null;
}
} | [
"public",
"static",
"SVGPoint",
"elementCoordinatesFromEvent",
"(",
"Document",
"doc",
",",
"Element",
"tag",
",",
"Event",
"evt",
")",
"{",
"try",
"{",
"DOMMouseEvent",
"gnme",
"=",
"(",
"DOMMouseEvent",
")",
"evt",
";",
"SVGMatrix",
"mat",
"=",
"(",
"(",
... | Convert the coordinates of an DOM Event from screen into element
coordinates.
@param doc Document context
@param tag Element containing the coordinate system
@param evt Event to interpret
@return coordinates | [
"Convert",
"the",
"coordinates",
"of",
"an",
"DOM",
"Event",
"from",
"screen",
"into",
"element",
"coordinates",
"."
] | b54673327e76198ecd4c8a2a901021f1a9174498 | https://github.com/elki-project/elki/blob/b54673327e76198ecd4c8a2a901021f1a9174498/addons/batikvis/src/main/java/de/lmu/ifi/dbs/elki/visualization/svg/SVGUtil.java#L627-L641 | train |
elki-project/elki | addons/batikvis/src/main/java/de/lmu/ifi/dbs/elki/visualization/svg/SVGUtil.java | SVGUtil.removeLastChild | public static void removeLastChild(Element tag) {
final Node last = tag.getLastChild();
if(last != null) {
tag.removeChild(last);
}
} | java | public static void removeLastChild(Element tag) {
final Node last = tag.getLastChild();
if(last != null) {
tag.removeChild(last);
}
} | [
"public",
"static",
"void",
"removeLastChild",
"(",
"Element",
"tag",
")",
"{",
"final",
"Node",
"last",
"=",
"tag",
".",
"getLastChild",
"(",
")",
";",
"if",
"(",
"last",
"!=",
"null",
")",
"{",
"tag",
".",
"removeChild",
"(",
"last",
")",
";",
"}",... | Remove last child of an element, when present
@param tag Parent | [
"Remove",
"last",
"child",
"of",
"an",
"element",
"when",
"present"
] | b54673327e76198ecd4c8a2a901021f1a9174498 | https://github.com/elki-project/elki/blob/b54673327e76198ecd4c8a2a901021f1a9174498/addons/batikvis/src/main/java/de/lmu/ifi/dbs/elki/visualization/svg/SVGUtil.java#L648-L653 | train |
elki-project/elki | addons/batikvis/src/main/java/de/lmu/ifi/dbs/elki/visualization/svg/SVGUtil.java | SVGUtil.removeFromParent | public static void removeFromParent(Element elem) {
if(elem != null && elem.getParentNode() != null) {
elem.getParentNode().removeChild(elem);
}
} | java | public static void removeFromParent(Element elem) {
if(elem != null && elem.getParentNode() != null) {
elem.getParentNode().removeChild(elem);
}
} | [
"public",
"static",
"void",
"removeFromParent",
"(",
"Element",
"elem",
")",
"{",
"if",
"(",
"elem",
"!=",
"null",
"&&",
"elem",
".",
"getParentNode",
"(",
")",
"!=",
"null",
")",
"{",
"elem",
".",
"getParentNode",
"(",
")",
".",
"removeChild",
"(",
"e... | Remove an element from its parent, if defined.
@param elem Element to remove | [
"Remove",
"an",
"element",
"from",
"its",
"parent",
"if",
"defined",
"."
] | b54673327e76198ecd4c8a2a901021f1a9174498 | https://github.com/elki-project/elki/blob/b54673327e76198ecd4c8a2a901021f1a9174498/addons/batikvis/src/main/java/de/lmu/ifi/dbs/elki/visualization/svg/SVGUtil.java#L660-L664 | train |
elki-project/elki | addons/batikvis/src/main/java/de/lmu/ifi/dbs/elki/visualization/svg/SVGUtil.java | SVGUtil.svgCircleSegment | public static Element svgCircleSegment(SVGPlot svgp, double centerx, double centery, double angleStart, double angleDelta, double innerRadius, double outerRadius) {
final DoubleWrapper tmp = new DoubleWrapper(); // To return cosine
double sin1st = FastMath.sinAndCos(angleStart, tmp);
double cos1st = tmp.value;
double sin2nd = FastMath.sinAndCos(angleStart + angleDelta, tmp);
double cos2nd = tmp.value; // Note: tmp is modified!
double inner1stx = centerx + (innerRadius * sin1st);
double inner1sty = centery - (innerRadius * cos1st);
double outer1stx = centerx + (outerRadius * sin1st);
double outer1sty = centery - (outerRadius * cos1st);
double inner2ndx = centerx + (innerRadius * sin2nd);
double inner2ndy = centery - (innerRadius * cos2nd);
double outer2ndx = centerx + (outerRadius * sin2nd);
double outer2ndy = centery - (outerRadius * cos2nd);
double largeArc = angleDelta >= Math.PI ? 1 : 0;
SVGPath path = new SVGPath(inner1stx, inner1sty).lineTo(outer1stx, outer1sty) //
.ellipticalArc(outerRadius, outerRadius, 0, largeArc, 1, outer2ndx, outer2ndy) //
.lineTo(inner2ndx, inner2ndy);
if(innerRadius > 0) {
path.ellipticalArc(innerRadius, innerRadius, 0, largeArc, 0, inner1stx, inner1sty);
}
return path.makeElement(svgp);
} | java | public static Element svgCircleSegment(SVGPlot svgp, double centerx, double centery, double angleStart, double angleDelta, double innerRadius, double outerRadius) {
final DoubleWrapper tmp = new DoubleWrapper(); // To return cosine
double sin1st = FastMath.sinAndCos(angleStart, tmp);
double cos1st = tmp.value;
double sin2nd = FastMath.sinAndCos(angleStart + angleDelta, tmp);
double cos2nd = tmp.value; // Note: tmp is modified!
double inner1stx = centerx + (innerRadius * sin1st);
double inner1sty = centery - (innerRadius * cos1st);
double outer1stx = centerx + (outerRadius * sin1st);
double outer1sty = centery - (outerRadius * cos1st);
double inner2ndx = centerx + (innerRadius * sin2nd);
double inner2ndy = centery - (innerRadius * cos2nd);
double outer2ndx = centerx + (outerRadius * sin2nd);
double outer2ndy = centery - (outerRadius * cos2nd);
double largeArc = angleDelta >= Math.PI ? 1 : 0;
SVGPath path = new SVGPath(inner1stx, inner1sty).lineTo(outer1stx, outer1sty) //
.ellipticalArc(outerRadius, outerRadius, 0, largeArc, 1, outer2ndx, outer2ndy) //
.lineTo(inner2ndx, inner2ndy);
if(innerRadius > 0) {
path.ellipticalArc(innerRadius, innerRadius, 0, largeArc, 0, inner1stx, inner1sty);
}
return path.makeElement(svgp);
} | [
"public",
"static",
"Element",
"svgCircleSegment",
"(",
"SVGPlot",
"svgp",
",",
"double",
"centerx",
",",
"double",
"centery",
",",
"double",
"angleStart",
",",
"double",
"angleDelta",
",",
"double",
"innerRadius",
",",
"double",
"outerRadius",
")",
"{",
"final"... | Create a circle segment.
@param svgp Plot to draw to
@param centerx Center X position
@param centery Center Y position
@param angleStart Starting angle
@param angleDelta Angle delta
@param innerRadius inner radius
@param outerRadius outer radius
@return SVG element representing this circle segment | [
"Create",
"a",
"circle",
"segment",
"."
] | b54673327e76198ecd4c8a2a901021f1a9174498 | https://github.com/elki-project/elki/blob/b54673327e76198ecd4c8a2a901021f1a9174498/addons/batikvis/src/main/java/de/lmu/ifi/dbs/elki/visualization/svg/SVGUtil.java#L678-L705 | train |
elki-project/elki | elki-clustering/src/main/java/de/lmu/ifi/dbs/elki/algorithm/clustering/hierarchical/AbstractHDBSCAN.java | AbstractHDBSCAN.computeCoreDists | protected WritableDoubleDataStore computeCoreDists(DBIDs ids, KNNQuery<O> knnQ, int minPts) {
final Logging LOG = getLogger();
final WritableDoubleDataStore coredists = DataStoreUtil.makeDoubleStorage(ids, DataStoreFactory.HINT_HOT | DataStoreFactory.HINT_DB);
FiniteProgress cprog = LOG.isVerbose() ? new FiniteProgress("Computing core sizes", ids.size(), LOG) : null;
for(DBIDIter iter = ids.iter(); iter.valid(); iter.advance()) {
coredists.put(iter, knnQ.getKNNForDBID(iter, minPts).getKNNDistance());
LOG.incrementProcessed(cprog);
}
LOG.ensureCompleted(cprog);
return coredists;
} | java | protected WritableDoubleDataStore computeCoreDists(DBIDs ids, KNNQuery<O> knnQ, int minPts) {
final Logging LOG = getLogger();
final WritableDoubleDataStore coredists = DataStoreUtil.makeDoubleStorage(ids, DataStoreFactory.HINT_HOT | DataStoreFactory.HINT_DB);
FiniteProgress cprog = LOG.isVerbose() ? new FiniteProgress("Computing core sizes", ids.size(), LOG) : null;
for(DBIDIter iter = ids.iter(); iter.valid(); iter.advance()) {
coredists.put(iter, knnQ.getKNNForDBID(iter, minPts).getKNNDistance());
LOG.incrementProcessed(cprog);
}
LOG.ensureCompleted(cprog);
return coredists;
} | [
"protected",
"WritableDoubleDataStore",
"computeCoreDists",
"(",
"DBIDs",
"ids",
",",
"KNNQuery",
"<",
"O",
">",
"knnQ",
",",
"int",
"minPts",
")",
"{",
"final",
"Logging",
"LOG",
"=",
"getLogger",
"(",
")",
";",
"final",
"WritableDoubleDataStore",
"coredists",
... | Compute the core distances for all objects.
@param ids Objects
@param knnQ kNN query
@param minPts Minimum neighborhood size
@return Data store with core distances | [
"Compute",
"the",
"core",
"distances",
"for",
"all",
"objects",
"."
] | b54673327e76198ecd4c8a2a901021f1a9174498 | https://github.com/elki-project/elki/blob/b54673327e76198ecd4c8a2a901021f1a9174498/elki-clustering/src/main/java/de/lmu/ifi/dbs/elki/algorithm/clustering/hierarchical/AbstractHDBSCAN.java#L91-L101 | train |
elki-project/elki | elki-clustering/src/main/java/de/lmu/ifi/dbs/elki/algorithm/clustering/hierarchical/AbstractHDBSCAN.java | AbstractHDBSCAN.convertToPointerRepresentation | protected void convertToPointerRepresentation(ArrayDBIDs ids, DoubleLongHeap heap, WritableDBIDDataStore pi, WritableDoubleDataStore lambda) {
final Logging LOG = getLogger();
// Initialize parent array:
for(DBIDArrayIter iter = ids.iter(); iter.valid(); iter.advance()) {
pi.put(iter, iter); // Initialize
}
DBIDVar p = DBIDUtil.newVar(), q = DBIDUtil.newVar(), n = DBIDUtil.newVar();
FiniteProgress pprog = LOG.isVerbose() ? new FiniteProgress("Converting MST to pointer representation", heap.size(), LOG) : null;
while(!heap.isEmpty()) {
final double dist = heap.peekKey();
final long pair = heap.peekValue();
final int i = (int) (pair >>> 31), j = (int) (pair & 0x7FFFFFFFL);
ids.assignVar(i, p);
// Follow p to its parent.
while(!DBIDUtil.equal(p, pi.assignVar(p, n))) {
p.set(n);
}
// Follow q to its parent.
ids.assignVar(j, q);
while(!DBIDUtil.equal(q, pi.assignVar(q, n))) {
q.set(n);
}
// By definition of the pointer representation, the largest element in
// each cluster is the cluster lead.
// The extraction methods currently rely on this!
int c = DBIDUtil.compare(p, q);
if(c < 0) {
// p joins q:
pi.put(p, q);
lambda.put(p, dist);
}
else {
assert (c != 0) : "This should never happen!";
// q joins p:
pi.put(q, p);
lambda.put(q, dist);
}
heap.poll();
LOG.incrementProcessed(pprog);
}
LOG.ensureCompleted(pprog);
// Hack to ensure a valid pointer representation:
// If distances are tied, the heap may return edges such that the n-way join
// does not fulfill the property that the last element has the largest id.
for(DBIDArrayIter iter = ids.iter(); iter.valid(); iter.advance()) {
double d = lambda.doubleValue(iter);
// Parent:
pi.assignVar(iter, p);
q.set(p);
// Follow parent while tied.
while(d >= lambda.doubleValue(q) && !DBIDUtil.equal(q, pi.assignVar(q, n))) {
q.set(n);
}
if(!DBIDUtil.equal(p, q)) {
if(LOG.isDebuggingFinest()) {
LOG.finest("Correcting parent: " + p + " -> " + q);
}
pi.put(iter, q);
}
}
} | java | protected void convertToPointerRepresentation(ArrayDBIDs ids, DoubleLongHeap heap, WritableDBIDDataStore pi, WritableDoubleDataStore lambda) {
final Logging LOG = getLogger();
// Initialize parent array:
for(DBIDArrayIter iter = ids.iter(); iter.valid(); iter.advance()) {
pi.put(iter, iter); // Initialize
}
DBIDVar p = DBIDUtil.newVar(), q = DBIDUtil.newVar(), n = DBIDUtil.newVar();
FiniteProgress pprog = LOG.isVerbose() ? new FiniteProgress("Converting MST to pointer representation", heap.size(), LOG) : null;
while(!heap.isEmpty()) {
final double dist = heap.peekKey();
final long pair = heap.peekValue();
final int i = (int) (pair >>> 31), j = (int) (pair & 0x7FFFFFFFL);
ids.assignVar(i, p);
// Follow p to its parent.
while(!DBIDUtil.equal(p, pi.assignVar(p, n))) {
p.set(n);
}
// Follow q to its parent.
ids.assignVar(j, q);
while(!DBIDUtil.equal(q, pi.assignVar(q, n))) {
q.set(n);
}
// By definition of the pointer representation, the largest element in
// each cluster is the cluster lead.
// The extraction methods currently rely on this!
int c = DBIDUtil.compare(p, q);
if(c < 0) {
// p joins q:
pi.put(p, q);
lambda.put(p, dist);
}
else {
assert (c != 0) : "This should never happen!";
// q joins p:
pi.put(q, p);
lambda.put(q, dist);
}
heap.poll();
LOG.incrementProcessed(pprog);
}
LOG.ensureCompleted(pprog);
// Hack to ensure a valid pointer representation:
// If distances are tied, the heap may return edges such that the n-way join
// does not fulfill the property that the last element has the largest id.
for(DBIDArrayIter iter = ids.iter(); iter.valid(); iter.advance()) {
double d = lambda.doubleValue(iter);
// Parent:
pi.assignVar(iter, p);
q.set(p);
// Follow parent while tied.
while(d >= lambda.doubleValue(q) && !DBIDUtil.equal(q, pi.assignVar(q, n))) {
q.set(n);
}
if(!DBIDUtil.equal(p, q)) {
if(LOG.isDebuggingFinest()) {
LOG.finest("Correcting parent: " + p + " -> " + q);
}
pi.put(iter, q);
}
}
} | [
"protected",
"void",
"convertToPointerRepresentation",
"(",
"ArrayDBIDs",
"ids",
",",
"DoubleLongHeap",
"heap",
",",
"WritableDBIDDataStore",
"pi",
",",
"WritableDoubleDataStore",
"lambda",
")",
"{",
"final",
"Logging",
"LOG",
"=",
"getLogger",
"(",
")",
";",
"// In... | Convert spanning tree to a pointer representation.
Note: the heap must use the correct encoding of indexes.
@param ids IDs indexed
@param heap Heap
@param pi Parent array
@param lambda Distance array | [
"Convert",
"spanning",
"tree",
"to",
"a",
"pointer",
"representation",
"."
] | b54673327e76198ecd4c8a2a901021f1a9174498 | https://github.com/elki-project/elki/blob/b54673327e76198ecd4c8a2a901021f1a9174498/elki-clustering/src/main/java/de/lmu/ifi/dbs/elki/algorithm/clustering/hierarchical/AbstractHDBSCAN.java#L214-L275 | train |
elki-project/elki | elki-core-dbids-int/src/main/java/de/lmu/ifi/dbs/elki/database/ids/integer/DoubleIntegerDBIDKNNHeap.java | DoubleIntegerDBIDKNNHeap.updateHeap | private void updateHeap(final double distance, final int iid) {
final double prevdist = kdist;
final int previd = heap.peekValue();
heap.replaceTopElement(distance, iid);
kdist = heap.peekKey();
// If the kdist improved, zap ties.
if(kdist < prevdist) {
numties = 0;
}
else {
addToTies(previd);
}
} | java | private void updateHeap(final double distance, final int iid) {
final double prevdist = kdist;
final int previd = heap.peekValue();
heap.replaceTopElement(distance, iid);
kdist = heap.peekKey();
// If the kdist improved, zap ties.
if(kdist < prevdist) {
numties = 0;
}
else {
addToTies(previd);
}
} | [
"private",
"void",
"updateHeap",
"(",
"final",
"double",
"distance",
",",
"final",
"int",
"iid",
")",
"{",
"final",
"double",
"prevdist",
"=",
"kdist",
";",
"final",
"int",
"previd",
"=",
"heap",
".",
"peekValue",
"(",
")",
";",
"heap",
".",
"replaceTopE... | Do a full update for the heap.
@param distance
Distance
@param iid
Object id | [
"Do",
"a",
"full",
"update",
"for",
"the",
"heap",
"."
] | b54673327e76198ecd4c8a2a901021f1a9174498 | https://github.com/elki-project/elki/blob/b54673327e76198ecd4c8a2a901021f1a9174498/elki-core-dbids-int/src/main/java/de/lmu/ifi/dbs/elki/database/ids/integer/DoubleIntegerDBIDKNNHeap.java#L145-L157 | train |
elki-project/elki | elki-core-dbids-int/src/main/java/de/lmu/ifi/dbs/elki/database/ids/integer/DoubleIntegerDBIDKNNHeap.java | DoubleIntegerDBIDKNNHeap.addToTies | private void addToTies(int id) {
if(ties.length == numties) {
ties = Arrays.copyOf(ties, (ties.length << 1) + 1); // grow.
}
ties[numties] = id;
++numties;
} | java | private void addToTies(int id) {
if(ties.length == numties) {
ties = Arrays.copyOf(ties, (ties.length << 1) + 1); // grow.
}
ties[numties] = id;
++numties;
} | [
"private",
"void",
"addToTies",
"(",
"int",
"id",
")",
"{",
"if",
"(",
"ties",
".",
"length",
"==",
"numties",
")",
"{",
"ties",
"=",
"Arrays",
".",
"copyOf",
"(",
"ties",
",",
"(",
"ties",
".",
"length",
"<<",
"1",
")",
"+",
"1",
")",
";",
"//... | Ensure the ties array has capacity for at least one more element.
@param id
Id to add | [
"Ensure",
"the",
"ties",
"array",
"has",
"capacity",
"for",
"at",
"least",
"one",
"more",
"element",
"."
] | b54673327e76198ecd4c8a2a901021f1a9174498 | https://github.com/elki-project/elki/blob/b54673327e76198ecd4c8a2a901021f1a9174498/elki-core-dbids-int/src/main/java/de/lmu/ifi/dbs/elki/database/ids/integer/DoubleIntegerDBIDKNNHeap.java#L165-L171 | train |
elki-project/elki | elki-clustering/src/main/java/de/lmu/ifi/dbs/elki/algorithm/clustering/kmeans/quality/AbstractKMeansQualityMeasure.java | AbstractKMeansQualityMeasure.numberOfFreeParameters | public static int numberOfFreeParameters(Relation<? extends NumberVector> relation, Clustering<? extends MeanModel> clustering) {
// number of clusters
int m = clustering.getAllClusters().size(); // num_ctrs
// dimensionality of data points
int dim = RelationUtil.dimensionality(relation); // num_dims
// number of free parameters
return (m - 1) + m * dim + m;
} | java | public static int numberOfFreeParameters(Relation<? extends NumberVector> relation, Clustering<? extends MeanModel> clustering) {
// number of clusters
int m = clustering.getAllClusters().size(); // num_ctrs
// dimensionality of data points
int dim = RelationUtil.dimensionality(relation); // num_dims
// number of free parameters
return (m - 1) + m * dim + m;
} | [
"public",
"static",
"int",
"numberOfFreeParameters",
"(",
"Relation",
"<",
"?",
"extends",
"NumberVector",
">",
"relation",
",",
"Clustering",
"<",
"?",
"extends",
"MeanModel",
">",
"clustering",
")",
"{",
"// number of clusters",
"int",
"m",
"=",
"clustering",
... | Compute the number of free parameters.
@param relation Data relation (for dimensionality)
@param clustering Set of clusters
@return Number of free parameters | [
"Compute",
"the",
"number",
"of",
"free",
"parameters",
"."
] | b54673327e76198ecd4c8a2a901021f1a9174498 | https://github.com/elki-project/elki/blob/b54673327e76198ecd4c8a2a901021f1a9174498/elki-clustering/src/main/java/de/lmu/ifi/dbs/elki/algorithm/clustering/kmeans/quality/AbstractKMeansQualityMeasure.java#L181-L190 | train |
elki-project/elki | elki-clustering/src/main/java/de/lmu/ifi/dbs/elki/result/ClusteringVectorDumper.java | ClusteringVectorDumper.dumpClusteringOutput | protected void dumpClusteringOutput(PrintStream writer, ResultHierarchy hierarchy, Clustering<?> c) {
DBIDRange ids = null;
for(It<Relation<?>> iter = hierarchy.iterParents(c).filter(Relation.class); iter.valid(); iter.advance()) {
DBIDs pids = iter.get().getDBIDs();
if(pids instanceof DBIDRange) {
ids = (DBIDRange) pids;
break;
}
LOG.warning("Parent result " + iter.get().getLongName() + " has DBID type " + pids.getClass());
}
// Fallback: try to locate a database.
if(ids == null) {
for(It<Database> iter = hierarchy.iterAll().filter(Database.class); iter.valid(); iter.advance()) {
DBIDs pids = iter.get().getRelation(TypeUtil.ANY).getDBIDs();
if(pids instanceof DBIDRange) {
ids = (DBIDRange) pids;
break;
}
LOG.warning("Parent result " + iter.get().getLongName() + " has DBID type " + pids.getClass());
}
}
if(ids == null) {
LOG.warning("Cannot dump cluster assignment, as I do not have a well-defined DBIDRange to use for a unique column assignment. DBIDs must be a continuous range.");
return;
}
WritableIntegerDataStore map = DataStoreUtil.makeIntegerStorage(ids, DataStoreFactory.HINT_TEMP);
int cnum = 0;
for(Cluster<?> clu : c.getAllClusters()) {
for(DBIDIter iter = clu.getIDs().iter(); iter.valid(); iter.advance()) {
map.putInt(iter, cnum);
}
++cnum;
}
for(DBIDArrayIter iter = ids.iter(); iter.valid(); iter.advance()) {
if(iter.getOffset() > 0) {
writer.append(' ');
}
writer.append(Integer.toString(map.intValue(iter)));
}
if(forceLabel != null) {
if(forceLabel.length() > 0) {
writer.append(' ').append(forceLabel);
}
}
else {
writer.append(' ').append(c.getLongName());
}
writer.append('\n');
} | java | protected void dumpClusteringOutput(PrintStream writer, ResultHierarchy hierarchy, Clustering<?> c) {
DBIDRange ids = null;
for(It<Relation<?>> iter = hierarchy.iterParents(c).filter(Relation.class); iter.valid(); iter.advance()) {
DBIDs pids = iter.get().getDBIDs();
if(pids instanceof DBIDRange) {
ids = (DBIDRange) pids;
break;
}
LOG.warning("Parent result " + iter.get().getLongName() + " has DBID type " + pids.getClass());
}
// Fallback: try to locate a database.
if(ids == null) {
for(It<Database> iter = hierarchy.iterAll().filter(Database.class); iter.valid(); iter.advance()) {
DBIDs pids = iter.get().getRelation(TypeUtil.ANY).getDBIDs();
if(pids instanceof DBIDRange) {
ids = (DBIDRange) pids;
break;
}
LOG.warning("Parent result " + iter.get().getLongName() + " has DBID type " + pids.getClass());
}
}
if(ids == null) {
LOG.warning("Cannot dump cluster assignment, as I do not have a well-defined DBIDRange to use for a unique column assignment. DBIDs must be a continuous range.");
return;
}
WritableIntegerDataStore map = DataStoreUtil.makeIntegerStorage(ids, DataStoreFactory.HINT_TEMP);
int cnum = 0;
for(Cluster<?> clu : c.getAllClusters()) {
for(DBIDIter iter = clu.getIDs().iter(); iter.valid(); iter.advance()) {
map.putInt(iter, cnum);
}
++cnum;
}
for(DBIDArrayIter iter = ids.iter(); iter.valid(); iter.advance()) {
if(iter.getOffset() > 0) {
writer.append(' ');
}
writer.append(Integer.toString(map.intValue(iter)));
}
if(forceLabel != null) {
if(forceLabel.length() > 0) {
writer.append(' ').append(forceLabel);
}
}
else {
writer.append(' ').append(c.getLongName());
}
writer.append('\n');
} | [
"protected",
"void",
"dumpClusteringOutput",
"(",
"PrintStream",
"writer",
",",
"ResultHierarchy",
"hierarchy",
",",
"Clustering",
"<",
"?",
">",
"c",
")",
"{",
"DBIDRange",
"ids",
"=",
"null",
";",
"for",
"(",
"It",
"<",
"Relation",
"<",
"?",
">",
">",
... | Dump a single clustering result.
@param writer Output writer
@param hierarchy Cluster hierarchy to process
@param c Clustering result | [
"Dump",
"a",
"single",
"clustering",
"result",
"."
] | b54673327e76198ecd4c8a2a901021f1a9174498 | https://github.com/elki-project/elki/blob/b54673327e76198ecd4c8a2a901021f1a9174498/elki-clustering/src/main/java/de/lmu/ifi/dbs/elki/result/ClusteringVectorDumper.java#L145-L194 | train |
elki-project/elki | elki-core-math/src/main/java/de/lmu/ifi/dbs/elki/math/linearalgebra/CovarianceMatrix.java | CovarianceMatrix.getMeanVector | public <F extends NumberVector> F getMeanVector(Relation<? extends F> relation) {
return RelationUtil.getNumberVectorFactory(relation).newNumberVector(mean);
} | java | public <F extends NumberVector> F getMeanVector(Relation<? extends F> relation) {
return RelationUtil.getNumberVectorFactory(relation).newNumberVector(mean);
} | [
"public",
"<",
"F",
"extends",
"NumberVector",
">",
"F",
"getMeanVector",
"(",
"Relation",
"<",
"?",
"extends",
"F",
">",
"relation",
")",
"{",
"return",
"RelationUtil",
".",
"getNumberVectorFactory",
"(",
"relation",
")",
".",
"newNumberVector",
"(",
"mean",
... | Get the mean as vector.
@param relation Data relation
@param <F> vector type
@return Mean vector | [
"Get",
"the",
"mean",
"as",
"vector",
"."
] | b54673327e76198ecd4c8a2a901021f1a9174498 | https://github.com/elki-project/elki/blob/b54673327e76198ecd4c8a2a901021f1a9174498/elki-core-math/src/main/java/de/lmu/ifi/dbs/elki/math/linearalgebra/CovarianceMatrix.java#L258-L260 | train |
elki-project/elki | elki-core-math/src/main/java/de/lmu/ifi/dbs/elki/math/linearalgebra/CovarianceMatrix.java | CovarianceMatrix.reset | public void reset() {
Arrays.fill(mean, 0.);
Arrays.fill(nmea, 0.);
if(elements != null) {
for(int i = 0; i < elements.length; i++) {
Arrays.fill(elements[i], 0.);
}
}
else {
elements = new double[mean.length][mean.length];
}
wsum = 0.;
} | java | public void reset() {
Arrays.fill(mean, 0.);
Arrays.fill(nmea, 0.);
if(elements != null) {
for(int i = 0; i < elements.length; i++) {
Arrays.fill(elements[i], 0.);
}
}
else {
elements = new double[mean.length][mean.length];
}
wsum = 0.;
} | [
"public",
"void",
"reset",
"(",
")",
"{",
"Arrays",
".",
"fill",
"(",
"mean",
",",
"0.",
")",
";",
"Arrays",
".",
"fill",
"(",
"nmea",
",",
"0.",
")",
";",
"if",
"(",
"elements",
"!=",
"null",
")",
"{",
"for",
"(",
"int",
"i",
"=",
"0",
";",
... | Reset the covariance matrix.
This function <em>may</em> be called after a "destroy". | [
"Reset",
"the",
"covariance",
"matrix",
"."
] | b54673327e76198ecd4c8a2a901021f1a9174498 | https://github.com/elki-project/elki/blob/b54673327e76198ecd4c8a2a901021f1a9174498/elki-core-math/src/main/java/de/lmu/ifi/dbs/elki/math/linearalgebra/CovarianceMatrix.java#L335-L347 | train |
elki-project/elki | elki-core-math/src/main/java/de/lmu/ifi/dbs/elki/math/linearalgebra/CovarianceMatrix.java | CovarianceMatrix.make | public static CovarianceMatrix make(Relation<? extends NumberVector> relation) {
int dim = RelationUtil.dimensionality(relation);
CovarianceMatrix c = new CovarianceMatrix(dim);
double[] mean = c.mean;
int count = 0;
// Compute mean first:
for(DBIDIter iditer = relation.iterDBIDs(); iditer.valid(); iditer.advance()) {
NumberVector vec = relation.get(iditer);
for(int i = 0; i < dim; i++) {
mean[i] += vec.doubleValue(i);
}
count++;
}
if(count == 0) {
return c;
}
// Normalize mean
for(int i = 0; i < dim; i++) {
mean[i] /= count;
}
// Compute covariances second
// Two-pass approach is numerically okay and fast, when possible.
double[] tmp = c.nmea; // Scratch space
double[][] elems = c.elements;
for(DBIDIter iditer = relation.iterDBIDs(); iditer.valid(); iditer.advance()) {
NumberVector vec = relation.get(iditer);
for(int i = 0; i < dim; i++) {
tmp[i] = vec.doubleValue(i) - mean[i];
}
for(int i = 0; i < dim; i++) {
for(int j = i; j < dim; j++) {
elems[i][j] += tmp[i] * tmp[j];
}
}
}
// Restore symmetry.
for(int i = 0; i < dim; i++) {
for(int j = i + 1; j < dim; j++) {
elems[j][i] = elems[i][j];
}
}
c.wsum = count;
return c;
} | java | public static CovarianceMatrix make(Relation<? extends NumberVector> relation) {
int dim = RelationUtil.dimensionality(relation);
CovarianceMatrix c = new CovarianceMatrix(dim);
double[] mean = c.mean;
int count = 0;
// Compute mean first:
for(DBIDIter iditer = relation.iterDBIDs(); iditer.valid(); iditer.advance()) {
NumberVector vec = relation.get(iditer);
for(int i = 0; i < dim; i++) {
mean[i] += vec.doubleValue(i);
}
count++;
}
if(count == 0) {
return c;
}
// Normalize mean
for(int i = 0; i < dim; i++) {
mean[i] /= count;
}
// Compute covariances second
// Two-pass approach is numerically okay and fast, when possible.
double[] tmp = c.nmea; // Scratch space
double[][] elems = c.elements;
for(DBIDIter iditer = relation.iterDBIDs(); iditer.valid(); iditer.advance()) {
NumberVector vec = relation.get(iditer);
for(int i = 0; i < dim; i++) {
tmp[i] = vec.doubleValue(i) - mean[i];
}
for(int i = 0; i < dim; i++) {
for(int j = i; j < dim; j++) {
elems[i][j] += tmp[i] * tmp[j];
}
}
}
// Restore symmetry.
for(int i = 0; i < dim; i++) {
for(int j = i + 1; j < dim; j++) {
elems[j][i] = elems[i][j];
}
}
c.wsum = count;
return c;
} | [
"public",
"static",
"CovarianceMatrix",
"make",
"(",
"Relation",
"<",
"?",
"extends",
"NumberVector",
">",
"relation",
")",
"{",
"int",
"dim",
"=",
"RelationUtil",
".",
"dimensionality",
"(",
"relation",
")",
";",
"CovarianceMatrix",
"c",
"=",
"new",
"Covarian... | Static Constructor from a full relation.
@param relation Relation to use.
@return Covariance matrix | [
"Static",
"Constructor",
"from",
"a",
"full",
"relation",
"."
] | b54673327e76198ecd4c8a2a901021f1a9174498 | https://github.com/elki-project/elki/blob/b54673327e76198ecd4c8a2a901021f1a9174498/elki-core-math/src/main/java/de/lmu/ifi/dbs/elki/math/linearalgebra/CovarianceMatrix.java#L355-L398 | train |
elki-project/elki | elki-logging/src/main/java/de/lmu/ifi/dbs/elki/logging/progress/FiniteProgress.java | FiniteProgress.appendToBuffer | @Override
public StringBuilder appendToBuffer(StringBuilder buf) {
String processedString = Integer.toString(getProcessed());
int percentage = (int) (getProcessed() * 100.0 / total);
buf.append(getTask());
buf.append(": ");
for(int i = 0; i < totalLength - processedString.length(); i++) {
buf.append(' ');
}
buf.append(getProcessed());
buf.append(" [");
if(percentage < 100) {
buf.append(' ');
}
if(percentage < 10) {
buf.append(' ');
}
buf.append(percentage);
buf.append("%]");
if(ratems > 0. && getProcessed() < total) {
buf.append(' ');
int secs = (int) Math.round((total - getProcessed()) / ratems / 1000. + .2);
if(secs > 300) {
buf.append(secs / 60);
buf.append(" min remaining");
}
else {
buf.append(secs);
buf.append(" sec remaining");
}
}
return buf;
} | java | @Override
public StringBuilder appendToBuffer(StringBuilder buf) {
String processedString = Integer.toString(getProcessed());
int percentage = (int) (getProcessed() * 100.0 / total);
buf.append(getTask());
buf.append(": ");
for(int i = 0; i < totalLength - processedString.length(); i++) {
buf.append(' ');
}
buf.append(getProcessed());
buf.append(" [");
if(percentage < 100) {
buf.append(' ');
}
if(percentage < 10) {
buf.append(' ');
}
buf.append(percentage);
buf.append("%]");
if(ratems > 0. && getProcessed() < total) {
buf.append(' ');
int secs = (int) Math.round((total - getProcessed()) / ratems / 1000. + .2);
if(secs > 300) {
buf.append(secs / 60);
buf.append(" min remaining");
}
else {
buf.append(secs);
buf.append(" sec remaining");
}
}
return buf;
} | [
"@",
"Override",
"public",
"StringBuilder",
"appendToBuffer",
"(",
"StringBuilder",
"buf",
")",
"{",
"String",
"processedString",
"=",
"Integer",
".",
"toString",
"(",
"getProcessed",
"(",
")",
")",
";",
"int",
"percentage",
"=",
"(",
"int",
")",
"(",
"getPr... | Append a string representation of the progress to the given string buffer.
@param buf Buffer to serialize to
@return Buffer the data was serialized to. | [
"Append",
"a",
"string",
"representation",
"of",
"the",
"progress",
"to",
"the",
"given",
"string",
"buffer",
"."
] | b54673327e76198ecd4c8a2a901021f1a9174498 | https://github.com/elki-project/elki/blob/b54673327e76198ecd4c8a2a901021f1a9174498/elki-logging/src/main/java/de/lmu/ifi/dbs/elki/logging/progress/FiniteProgress.java#L97-L129 | train |
elki-project/elki | elki-logging/src/main/java/de/lmu/ifi/dbs/elki/logging/progress/FiniteProgress.java | FiniteProgress.ensureCompleted | public void ensureCompleted(Logging logger) {
if(!isComplete()) {
logger.warning("Progress had not completed automatically as expected: " + getProcessed() + "/" + total, new Throwable());
setProcessed(getTotal());
logger.progress(this);
}
} | java | public void ensureCompleted(Logging logger) {
if(!isComplete()) {
logger.warning("Progress had not completed automatically as expected: " + getProcessed() + "/" + total, new Throwable());
setProcessed(getTotal());
logger.progress(this);
}
} | [
"public",
"void",
"ensureCompleted",
"(",
"Logging",
"logger",
")",
"{",
"if",
"(",
"!",
"isComplete",
"(",
")",
")",
"{",
"logger",
".",
"warning",
"(",
"\"Progress had not completed automatically as expected: \"",
"+",
"getProcessed",
"(",
")",
"+",
"\"/\"",
"... | Ensure that the progress was completed, to make progress bars disappear
@param logger Logger to report to. | [
"Ensure",
"that",
"the",
"progress",
"was",
"completed",
"to",
"make",
"progress",
"bars",
"disappear"
] | b54673327e76198ecd4c8a2a901021f1a9174498 | https://github.com/elki-project/elki/blob/b54673327e76198ecd4c8a2a901021f1a9174498/elki-logging/src/main/java/de/lmu/ifi/dbs/elki/logging/progress/FiniteProgress.java#L153-L159 | train |
elki-project/elki | elki-outlier/src/main/java/de/lmu/ifi/dbs/elki/algorithm/outlier/DWOF.java | DWOF.clusterData | private void clusterData(DBIDs ids, RangeQuery<O> rnnQuery, WritableDoubleDataStore radii, WritableDataStore<ModifiableDBIDs> labels) {
FiniteProgress clustProg = LOG.isVerbose() ? new FiniteProgress("Density-Based Clustering", ids.size(), LOG) : null;
// Iterate over all objects
for(DBIDIter iter = ids.iter(); iter.valid(); iter.advance()) {
if(labels.get(iter) != null) {
continue;
}
ModifiableDBIDs newCluster = DBIDUtil.newArray();
newCluster.add(iter);
labels.put(iter, newCluster);
LOG.incrementProcessed(clustProg);
// container of the points to be added and their radii neighbors to the
// cluster
ModifiableDBIDs nChain = DBIDUtil.newArray();
nChain.add(iter);
// iterate over nChain
for(DBIDIter toGetNeighbors = nChain.iter(); toGetNeighbors.valid(); toGetNeighbors.advance()) {
double range = radii.doubleValue(toGetNeighbors);
DoubleDBIDList nNeighbors = rnnQuery.getRangeForDBID(toGetNeighbors, range);
for(DoubleDBIDListIter iter2 = nNeighbors.iter(); iter2.valid(); iter2.advance()) {
if(DBIDUtil.equal(toGetNeighbors, iter2)) {
continue;
}
if(labels.get(iter2) == null) {
newCluster.add(iter2);
labels.put(iter2, newCluster);
nChain.add(iter2);
LOG.incrementProcessed(clustProg);
}
else if(labels.get(iter2) != newCluster) {
ModifiableDBIDs toBeDeleted = labels.get(iter2);
newCluster.addDBIDs(toBeDeleted);
for(DBIDIter iter3 = toBeDeleted.iter(); iter3.valid(); iter3.advance()) {
labels.put(iter3, newCluster);
}
toBeDeleted.clear();
}
}
}
}
LOG.ensureCompleted(clustProg);
} | java | private void clusterData(DBIDs ids, RangeQuery<O> rnnQuery, WritableDoubleDataStore radii, WritableDataStore<ModifiableDBIDs> labels) {
FiniteProgress clustProg = LOG.isVerbose() ? new FiniteProgress("Density-Based Clustering", ids.size(), LOG) : null;
// Iterate over all objects
for(DBIDIter iter = ids.iter(); iter.valid(); iter.advance()) {
if(labels.get(iter) != null) {
continue;
}
ModifiableDBIDs newCluster = DBIDUtil.newArray();
newCluster.add(iter);
labels.put(iter, newCluster);
LOG.incrementProcessed(clustProg);
// container of the points to be added and their radii neighbors to the
// cluster
ModifiableDBIDs nChain = DBIDUtil.newArray();
nChain.add(iter);
// iterate over nChain
for(DBIDIter toGetNeighbors = nChain.iter(); toGetNeighbors.valid(); toGetNeighbors.advance()) {
double range = radii.doubleValue(toGetNeighbors);
DoubleDBIDList nNeighbors = rnnQuery.getRangeForDBID(toGetNeighbors, range);
for(DoubleDBIDListIter iter2 = nNeighbors.iter(); iter2.valid(); iter2.advance()) {
if(DBIDUtil.equal(toGetNeighbors, iter2)) {
continue;
}
if(labels.get(iter2) == null) {
newCluster.add(iter2);
labels.put(iter2, newCluster);
nChain.add(iter2);
LOG.incrementProcessed(clustProg);
}
else if(labels.get(iter2) != newCluster) {
ModifiableDBIDs toBeDeleted = labels.get(iter2);
newCluster.addDBIDs(toBeDeleted);
for(DBIDIter iter3 = toBeDeleted.iter(); iter3.valid(); iter3.advance()) {
labels.put(iter3, newCluster);
}
toBeDeleted.clear();
}
}
}
}
LOG.ensureCompleted(clustProg);
} | [
"private",
"void",
"clusterData",
"(",
"DBIDs",
"ids",
",",
"RangeQuery",
"<",
"O",
">",
"rnnQuery",
",",
"WritableDoubleDataStore",
"radii",
",",
"WritableDataStore",
"<",
"ModifiableDBIDs",
">",
"labels",
")",
"{",
"FiniteProgress",
"clustProg",
"=",
"LOG",
".... | This method applies a density based clustering algorithm.
It looks for an unclustered object and builds a new cluster for it, then
adds all the points within its radius to that cluster.
nChain represents the points to be added to the cluster and its
radius-neighbors
@param ids Database IDs to process
@param rnnQuery Data to process
@param radii Radii to cluster accordingly
@param labels Label storage. | [
"This",
"method",
"applies",
"a",
"density",
"based",
"clustering",
"algorithm",
"."
] | b54673327e76198ecd4c8a2a901021f1a9174498 | https://github.com/elki-project/elki/blob/b54673327e76198ecd4c8a2a901021f1a9174498/elki-outlier/src/main/java/de/lmu/ifi/dbs/elki/algorithm/outlier/DWOF.java#L242-L283 | train |
elki-project/elki | elki-outlier/src/main/java/de/lmu/ifi/dbs/elki/algorithm/outlier/DWOF.java | DWOF.updateSizes | private int updateSizes(DBIDs ids, WritableDataStore<ModifiableDBIDs> labels, WritableIntegerDataStore newSizes) {
// to count the unclustered all over
int countUnmerged = 0;
for(DBIDIter iter = ids.iter(); iter.valid(); iter.advance()) {
// checking the point's new cluster size after the clustering step
int newClusterSize = labels.get(iter).size();
newSizes.putInt(iter, newClusterSize);
// the point is alone in the cluster --> not merged with other points
if(newClusterSize == 1) {
countUnmerged++;
}
}
return countUnmerged;
} | java | private int updateSizes(DBIDs ids, WritableDataStore<ModifiableDBIDs> labels, WritableIntegerDataStore newSizes) {
// to count the unclustered all over
int countUnmerged = 0;
for(DBIDIter iter = ids.iter(); iter.valid(); iter.advance()) {
// checking the point's new cluster size after the clustering step
int newClusterSize = labels.get(iter).size();
newSizes.putInt(iter, newClusterSize);
// the point is alone in the cluster --> not merged with other points
if(newClusterSize == 1) {
countUnmerged++;
}
}
return countUnmerged;
} | [
"private",
"int",
"updateSizes",
"(",
"DBIDs",
"ids",
",",
"WritableDataStore",
"<",
"ModifiableDBIDs",
">",
"labels",
",",
"WritableIntegerDataStore",
"newSizes",
")",
"{",
"// to count the unclustered all over",
"int",
"countUnmerged",
"=",
"0",
";",
"for",
"(",
"... | This method updates each object's cluster size after the clustering step.
@param ids Object IDs to process
@param labels references for each object's cluster
@param newSizes the sizes container to be updated
@return the number of unclustered objects | [
"This",
"method",
"updates",
"each",
"object",
"s",
"cluster",
"size",
"after",
"the",
"clustering",
"step",
"."
] | b54673327e76198ecd4c8a2a901021f1a9174498 | https://github.com/elki-project/elki/blob/b54673327e76198ecd4c8a2a901021f1a9174498/elki-outlier/src/main/java/de/lmu/ifi/dbs/elki/algorithm/outlier/DWOF.java#L293-L306 | train |
elki-project/elki | elki-clustering/src/main/java/de/lmu/ifi/dbs/elki/algorithm/clustering/hierarchical/SLINK.java | SLINK.run | public PointerHierarchyRepresentationResult run(Database database, Relation<O> relation) {
DBIDs ids = relation.getDBIDs();
WritableDBIDDataStore pi = DataStoreUtil.makeDBIDStorage(ids, DataStoreFactory.HINT_HOT | DataStoreFactory.HINT_STATIC);
WritableDoubleDataStore lambda = DataStoreUtil.makeDoubleStorage(ids, DataStoreFactory.HINT_HOT | DataStoreFactory.HINT_STATIC, Double.POSITIVE_INFINITY);
// Temporary storage for m.
WritableDoubleDataStore m = DataStoreUtil.makeDoubleStorage(ids, DataStoreFactory.HINT_HOT | DataStoreFactory.HINT_TEMP);
final Logging log = getLogger(); // To allow CLINK logger override
FiniteProgress progress = log.isVerbose() ? new FiniteProgress("Running SLINK", ids.size(), log) : null;
ArrayDBIDs aids = DBIDUtil.ensureArray(ids);
// First element is trivial/special:
DBIDArrayIter id = aids.iter(), it = aids.iter();
// Step 1: initialize
for(; id.valid(); id.advance()) {
// P(n+1) = n+1:
pi.put(id, id);
// L(n+1) = infinity already.
}
// First element is finished already (start at seek(1) below!)
log.incrementProcessed(progress);
// Optimized branch
if(getDistanceFunction() instanceof PrimitiveDistanceFunction) {
PrimitiveDistanceFunction<? super O> distf = (PrimitiveDistanceFunction<? super O>) getDistanceFunction();
for(id.seek(1); id.valid(); id.advance()) {
step2primitive(id, it, id.getOffset(), relation, distf, m);
process(id, aids, it, id.getOffset(), pi, lambda, m); // SLINK or CLINK
log.incrementProcessed(progress);
}
}
else {
// Fallback branch
DistanceQuery<O> distQ = database.getDistanceQuery(relation, getDistanceFunction());
for(id.seek(1); id.valid(); id.advance()) {
step2(id, it, id.getOffset(), distQ, m);
process(id, aids, it, id.getOffset(), pi, lambda, m); // SLINK or CLINK
log.incrementProcessed(progress);
}
}
log.ensureCompleted(progress);
// We don't need m anymore.
m.destroy();
m = null;
return new PointerHierarchyRepresentationResult(ids, pi, lambda, getDistanceFunction().isSquared());
} | java | public PointerHierarchyRepresentationResult run(Database database, Relation<O> relation) {
DBIDs ids = relation.getDBIDs();
WritableDBIDDataStore pi = DataStoreUtil.makeDBIDStorage(ids, DataStoreFactory.HINT_HOT | DataStoreFactory.HINT_STATIC);
WritableDoubleDataStore lambda = DataStoreUtil.makeDoubleStorage(ids, DataStoreFactory.HINT_HOT | DataStoreFactory.HINT_STATIC, Double.POSITIVE_INFINITY);
// Temporary storage for m.
WritableDoubleDataStore m = DataStoreUtil.makeDoubleStorage(ids, DataStoreFactory.HINT_HOT | DataStoreFactory.HINT_TEMP);
final Logging log = getLogger(); // To allow CLINK logger override
FiniteProgress progress = log.isVerbose() ? new FiniteProgress("Running SLINK", ids.size(), log) : null;
ArrayDBIDs aids = DBIDUtil.ensureArray(ids);
// First element is trivial/special:
DBIDArrayIter id = aids.iter(), it = aids.iter();
// Step 1: initialize
for(; id.valid(); id.advance()) {
// P(n+1) = n+1:
pi.put(id, id);
// L(n+1) = infinity already.
}
// First element is finished already (start at seek(1) below!)
log.incrementProcessed(progress);
// Optimized branch
if(getDistanceFunction() instanceof PrimitiveDistanceFunction) {
PrimitiveDistanceFunction<? super O> distf = (PrimitiveDistanceFunction<? super O>) getDistanceFunction();
for(id.seek(1); id.valid(); id.advance()) {
step2primitive(id, it, id.getOffset(), relation, distf, m);
process(id, aids, it, id.getOffset(), pi, lambda, m); // SLINK or CLINK
log.incrementProcessed(progress);
}
}
else {
// Fallback branch
DistanceQuery<O> distQ = database.getDistanceQuery(relation, getDistanceFunction());
for(id.seek(1); id.valid(); id.advance()) {
step2(id, it, id.getOffset(), distQ, m);
process(id, aids, it, id.getOffset(), pi, lambda, m); // SLINK or CLINK
log.incrementProcessed(progress);
}
}
log.ensureCompleted(progress);
// We don't need m anymore.
m.destroy();
m = null;
return new PointerHierarchyRepresentationResult(ids, pi, lambda, getDistanceFunction().isSquared());
} | [
"public",
"PointerHierarchyRepresentationResult",
"run",
"(",
"Database",
"database",
",",
"Relation",
"<",
"O",
">",
"relation",
")",
"{",
"DBIDs",
"ids",
"=",
"relation",
".",
"getDBIDs",
"(",
")",
";",
"WritableDBIDDataStore",
"pi",
"=",
"DataStoreUtil",
".",... | Performs the SLINK algorithm on the given database.
@param database Database to process
@param relation Data relation to use | [
"Performs",
"the",
"SLINK",
"algorithm",
"on",
"the",
"given",
"database",
"."
] | b54673327e76198ecd4c8a2a901021f1a9174498 | https://github.com/elki-project/elki/blob/b54673327e76198ecd4c8a2a901021f1a9174498/elki-clustering/src/main/java/de/lmu/ifi/dbs/elki/algorithm/clustering/hierarchical/SLINK.java#L101-L149 | train |
elki-project/elki | elki-clustering/src/main/java/de/lmu/ifi/dbs/elki/algorithm/clustering/hierarchical/SLINK.java | SLINK.process | protected void process(DBIDRef id, ArrayDBIDs ids, DBIDArrayIter it, int n, WritableDBIDDataStore pi, WritableDoubleDataStore lambda, WritableDoubleDataStore m) {
slinkstep3(id, it, n, pi, lambda, m);
slinkstep4(id, it, n, pi, lambda);
} | java | protected void process(DBIDRef id, ArrayDBIDs ids, DBIDArrayIter it, int n, WritableDBIDDataStore pi, WritableDoubleDataStore lambda, WritableDoubleDataStore m) {
slinkstep3(id, it, n, pi, lambda, m);
slinkstep4(id, it, n, pi, lambda);
} | [
"protected",
"void",
"process",
"(",
"DBIDRef",
"id",
",",
"ArrayDBIDs",
"ids",
",",
"DBIDArrayIter",
"it",
",",
"int",
"n",
",",
"WritableDBIDDataStore",
"pi",
",",
"WritableDoubleDataStore",
"lambda",
",",
"WritableDoubleDataStore",
"m",
")",
"{",
"slinkstep3",
... | SLINK main loop.
@param id Current object
@param ids All objects
@param it Array iterator
@param n Last object to process at this run
@param pi Parent
@param lambda Height
@param m Distance | [
"SLINK",
"main",
"loop",
"."
] | b54673327e76198ecd4c8a2a901021f1a9174498 | https://github.com/elki-project/elki/blob/b54673327e76198ecd4c8a2a901021f1a9174498/elki-clustering/src/main/java/de/lmu/ifi/dbs/elki/algorithm/clustering/hierarchical/SLINK.java#L200-L203 | train |
elki-project/elki | elki-clustering/src/main/java/de/lmu/ifi/dbs/elki/algorithm/clustering/optics/ClusterOrder.java | ClusterOrder.add | public void add(DBIDRef id, double reach, DBIDRef pre) {
ids.add(id);
reachability.putDouble(id, reach);
if(pre == null || pre instanceof DBIDVar && !((DBIDVar) pre).isSet()) {
return;
}
predecessor.putDBID(id, pre);
} | java | public void add(DBIDRef id, double reach, DBIDRef pre) {
ids.add(id);
reachability.putDouble(id, reach);
if(pre == null || pre instanceof DBIDVar && !((DBIDVar) pre).isSet()) {
return;
}
predecessor.putDBID(id, pre);
} | [
"public",
"void",
"add",
"(",
"DBIDRef",
"id",
",",
"double",
"reach",
",",
"DBIDRef",
"pre",
")",
"{",
"ids",
".",
"add",
"(",
"id",
")",
";",
"reachability",
".",
"putDouble",
"(",
"id",
",",
"reach",
")",
";",
"if",
"(",
"pre",
"==",
"null",
"... | Add an object to the cluster order.
@param id Object id
@param reach Reachability
@param pre Predecessor | [
"Add",
"an",
"object",
"to",
"the",
"cluster",
"order",
"."
] | b54673327e76198ecd4c8a2a901021f1a9174498 | https://github.com/elki-project/elki/blob/b54673327e76198ecd4c8a2a901021f1a9174498/elki-clustering/src/main/java/de/lmu/ifi/dbs/elki/algorithm/clustering/optics/ClusterOrder.java#L111-L118 | train |
elki-project/elki | elki-clustering/src/main/java/de/lmu/ifi/dbs/elki/algorithm/clustering/optics/ClusterOrder.java | ClusterOrder.order | @Override
public ArrayModifiableDBIDs order(DBIDs ids) {
ArrayModifiableDBIDs res = DBIDUtil.newArray(ids.size());
for(DBIDIter it = this.ids.iter(); it.valid(); it.advance()) {
if(ids.contains(it)) {
res.add(it);
}
}
return res;
} | java | @Override
public ArrayModifiableDBIDs order(DBIDs ids) {
ArrayModifiableDBIDs res = DBIDUtil.newArray(ids.size());
for(DBIDIter it = this.ids.iter(); it.valid(); it.advance()) {
if(ids.contains(it)) {
res.add(it);
}
}
return res;
} | [
"@",
"Override",
"public",
"ArrayModifiableDBIDs",
"order",
"(",
"DBIDs",
"ids",
")",
"{",
"ArrayModifiableDBIDs",
"res",
"=",
"DBIDUtil",
".",
"newArray",
"(",
"ids",
".",
"size",
"(",
")",
")",
";",
"for",
"(",
"DBIDIter",
"it",
"=",
"this",
".",
"ids"... | Use the cluster order to sort the given collection ids.
Implementation of the {@link OrderingResult} interface. | [
"Use",
"the",
"cluster",
"order",
"to",
"sort",
"the",
"given",
"collection",
"ids",
"."
] | b54673327e76198ecd4c8a2a901021f1a9174498 | https://github.com/elki-project/elki/blob/b54673327e76198ecd4c8a2a901021f1a9174498/elki-clustering/src/main/java/de/lmu/ifi/dbs/elki/algorithm/clustering/optics/ClusterOrder.java#L137-L146 | train |
elki-project/elki | elki-clustering/src/main/java/de/lmu/ifi/dbs/elki/algorithm/clustering/optics/ClusterOrder.java | ClusterOrder.getPredecessor | public void getPredecessor(DBIDRef id, DBIDVar out) {
if(predecessor == null) {
out.unset();
return;
}
predecessor.assignVar(id, out);
} | java | public void getPredecessor(DBIDRef id, DBIDVar out) {
if(predecessor == null) {
out.unset();
return;
}
predecessor.assignVar(id, out);
} | [
"public",
"void",
"getPredecessor",
"(",
"DBIDRef",
"id",
",",
"DBIDVar",
"out",
")",
"{",
"if",
"(",
"predecessor",
"==",
"null",
")",
"{",
"out",
".",
"unset",
"(",
")",
";",
"return",
";",
"}",
"predecessor",
".",
"assignVar",
"(",
"id",
",",
"out... | Get the predecessor.
@param id Current id.
@param out Output variable to store the predecessor. | [
"Get",
"the",
"predecessor",
"."
] | b54673327e76198ecd4c8a2a901021f1a9174498 | https://github.com/elki-project/elki/blob/b54673327e76198ecd4c8a2a901021f1a9174498/elki-clustering/src/main/java/de/lmu/ifi/dbs/elki/algorithm/clustering/optics/ClusterOrder.java#L173-L179 | train |
elki-project/elki | elki-outlier/src/main/java/de/lmu/ifi/dbs/elki/algorithm/outlier/lof/COF.java | COF.run | public OutlierResult run(Database database, Relation<O> relation) {
StepProgress stepprog = LOG.isVerbose() ? new StepProgress("COF", 3) : null;
DistanceQuery<O> dq = database.getDistanceQuery(relation, getDistanceFunction());
LOG.beginStep(stepprog, 1, "Materializing COF neighborhoods.");
KNNQuery<O> knnq = DatabaseUtil.precomputedKNNQuery(database, relation, dq, k);
DBIDs ids = relation.getDBIDs();
LOG.beginStep(stepprog, 2, "Computing Average Chaining Distances.");
WritableDoubleDataStore acds = DataStoreUtil.makeDoubleStorage(ids, DataStoreFactory.HINT_HOT | DataStoreFactory.HINT_TEMP);
computeAverageChainingDistances(knnq, dq, ids, acds);
// compute COF_SCORE of each db object
LOG.beginStep(stepprog, 3, "Computing Connectivity-based Outlier Factors.");
WritableDoubleDataStore cofs = DataStoreUtil.makeDoubleStorage(ids, DataStoreFactory.HINT_HOT | DataStoreFactory.HINT_DB);
// track the maximum value for normalization.
DoubleMinMax cofminmax = new DoubleMinMax();
computeCOFScores(knnq, ids, acds, cofs, cofminmax);
LOG.setCompleted(stepprog);
// Build result representation.
DoubleRelation scoreResult = new MaterializedDoubleRelation("Connectivity-Based Outlier Factor", "cof-outlier", cofs, ids);
OutlierScoreMeta scoreMeta = new QuotientOutlierScoreMeta(cofminmax.getMin(), cofminmax.getMax(), 0.0, Double.POSITIVE_INFINITY, 1.0);
return new OutlierResult(scoreMeta, scoreResult);
} | java | public OutlierResult run(Database database, Relation<O> relation) {
StepProgress stepprog = LOG.isVerbose() ? new StepProgress("COF", 3) : null;
DistanceQuery<O> dq = database.getDistanceQuery(relation, getDistanceFunction());
LOG.beginStep(stepprog, 1, "Materializing COF neighborhoods.");
KNNQuery<O> knnq = DatabaseUtil.precomputedKNNQuery(database, relation, dq, k);
DBIDs ids = relation.getDBIDs();
LOG.beginStep(stepprog, 2, "Computing Average Chaining Distances.");
WritableDoubleDataStore acds = DataStoreUtil.makeDoubleStorage(ids, DataStoreFactory.HINT_HOT | DataStoreFactory.HINT_TEMP);
computeAverageChainingDistances(knnq, dq, ids, acds);
// compute COF_SCORE of each db object
LOG.beginStep(stepprog, 3, "Computing Connectivity-based Outlier Factors.");
WritableDoubleDataStore cofs = DataStoreUtil.makeDoubleStorage(ids, DataStoreFactory.HINT_HOT | DataStoreFactory.HINT_DB);
// track the maximum value for normalization.
DoubleMinMax cofminmax = new DoubleMinMax();
computeCOFScores(knnq, ids, acds, cofs, cofminmax);
LOG.setCompleted(stepprog);
// Build result representation.
DoubleRelation scoreResult = new MaterializedDoubleRelation("Connectivity-Based Outlier Factor", "cof-outlier", cofs, ids);
OutlierScoreMeta scoreMeta = new QuotientOutlierScoreMeta(cofminmax.getMin(), cofminmax.getMax(), 0.0, Double.POSITIVE_INFINITY, 1.0);
return new OutlierResult(scoreMeta, scoreResult);
} | [
"public",
"OutlierResult",
"run",
"(",
"Database",
"database",
",",
"Relation",
"<",
"O",
">",
"relation",
")",
"{",
"StepProgress",
"stepprog",
"=",
"LOG",
".",
"isVerbose",
"(",
")",
"?",
"new",
"StepProgress",
"(",
"\"COF\"",
",",
"3",
")",
":",
"null... | Runs the COF algorithm on the given database.
@param database Database to query
@param relation Data to process
@return COF outlier result | [
"Runs",
"the",
"COF",
"algorithm",
"on",
"the",
"given",
"database",
"."
] | b54673327e76198ecd4c8a2a901021f1a9174498 | https://github.com/elki-project/elki/blob/b54673327e76198ecd4c8a2a901021f1a9174498/elki-outlier/src/main/java/de/lmu/ifi/dbs/elki/algorithm/outlier/lof/COF.java#L104-L128 | train |
elki-project/elki | elki-outlier/src/main/java/de/lmu/ifi/dbs/elki/algorithm/outlier/lof/COF.java | COF.computeCOFScores | private void computeCOFScores(KNNQuery<O> knnq, DBIDs ids, DoubleDataStore acds, WritableDoubleDataStore cofs, DoubleMinMax cofminmax) {
FiniteProgress progressCOFs = LOG.isVerbose() ? new FiniteProgress("COF for objects", ids.size(), LOG) : null;
for(DBIDIter iter = ids.iter(); iter.valid(); iter.advance()) {
final KNNList neighbors = knnq.getKNNForDBID(iter, k);
// Aggregate the average chaining distances of all neighbors:
double sum = 0.;
for(DBIDIter neighbor = neighbors.iter(); neighbor.valid(); neighbor.advance()) {
// skip the point itself
if(DBIDUtil.equal(neighbor, iter)) {
continue;
}
sum += acds.doubleValue(neighbor);
}
final double cof = (sum > 0.) ? (acds.doubleValue(iter) * k / sum) : (acds.doubleValue(iter) > 0. ? Double.POSITIVE_INFINITY : 1.);
cofs.putDouble(iter, cof);
// update minimum and maximum
cofminmax.put(cof);
LOG.incrementProcessed(progressCOFs);
}
LOG.ensureCompleted(progressCOFs);
} | java | private void computeCOFScores(KNNQuery<O> knnq, DBIDs ids, DoubleDataStore acds, WritableDoubleDataStore cofs, DoubleMinMax cofminmax) {
FiniteProgress progressCOFs = LOG.isVerbose() ? new FiniteProgress("COF for objects", ids.size(), LOG) : null;
for(DBIDIter iter = ids.iter(); iter.valid(); iter.advance()) {
final KNNList neighbors = knnq.getKNNForDBID(iter, k);
// Aggregate the average chaining distances of all neighbors:
double sum = 0.;
for(DBIDIter neighbor = neighbors.iter(); neighbor.valid(); neighbor.advance()) {
// skip the point itself
if(DBIDUtil.equal(neighbor, iter)) {
continue;
}
sum += acds.doubleValue(neighbor);
}
final double cof = (sum > 0.) ? (acds.doubleValue(iter) * k / sum) : (acds.doubleValue(iter) > 0. ? Double.POSITIVE_INFINITY : 1.);
cofs.putDouble(iter, cof);
// update minimum and maximum
cofminmax.put(cof);
LOG.incrementProcessed(progressCOFs);
}
LOG.ensureCompleted(progressCOFs);
} | [
"private",
"void",
"computeCOFScores",
"(",
"KNNQuery",
"<",
"O",
">",
"knnq",
",",
"DBIDs",
"ids",
",",
"DoubleDataStore",
"acds",
",",
"WritableDoubleDataStore",
"cofs",
",",
"DoubleMinMax",
"cofminmax",
")",
"{",
"FiniteProgress",
"progressCOFs",
"=",
"LOG",
... | Compute Connectivity outlier factors.
@param knnq KNN query
@param ids IDs to process
@param acds Average chaining distances
@param cofs Connectivity outlier factor storage
@param cofminmax Score minimum/maximum tracker | [
"Compute",
"Connectivity",
"outlier",
"factors",
"."
] | b54673327e76198ecd4c8a2a901021f1a9174498 | https://github.com/elki-project/elki/blob/b54673327e76198ecd4c8a2a901021f1a9174498/elki-outlier/src/main/java/de/lmu/ifi/dbs/elki/algorithm/outlier/lof/COF.java#L203-L224 | train |
elki-project/elki | addons/batikvis/src/main/java/de/lmu/ifi/dbs/elki/visualization/svg/UpdateRunner.java | UpdateRunner.invokeLater | public void invokeLater(Runnable r) {
queue.add(r);
synchronized(this) {
if(synchronizer == null) {
runQueue();
}
else {
synchronizer.activate();
}
}
} | java | public void invokeLater(Runnable r) {
queue.add(r);
synchronized(this) {
if(synchronizer == null) {
runQueue();
}
else {
synchronizer.activate();
}
}
} | [
"public",
"void",
"invokeLater",
"(",
"Runnable",
"r",
")",
"{",
"queue",
".",
"add",
"(",
"r",
")",
";",
"synchronized",
"(",
"this",
")",
"{",
"if",
"(",
"synchronizer",
"==",
"null",
")",
"{",
"runQueue",
"(",
")",
";",
"}",
"else",
"{",
"synchr... | Add a new update to run at any appropriate time.
@param r New runnable to perform the update | [
"Add",
"a",
"new",
"update",
"to",
"run",
"at",
"any",
"appropriate",
"time",
"."
] | b54673327e76198ecd4c8a2a901021f1a9174498 | https://github.com/elki-project/elki/blob/b54673327e76198ecd4c8a2a901021f1a9174498/addons/batikvis/src/main/java/de/lmu/ifi/dbs/elki/visualization/svg/UpdateRunner.java#L67-L77 | train |
elki-project/elki | addons/batikvis/src/main/java/de/lmu/ifi/dbs/elki/visualization/svg/UpdateRunner.java | UpdateRunner.runQueue | public void runQueue() {
synchronized(sync) {
while(!queue.isEmpty()) {
Runnable r = queue.poll();
if(r != null) {
try {
r.run();
}
catch(Exception e) {
// Alternatively, we could allow the specification of exception
// handlers for each runnable in the API. For now we'll just log.
// TODO: handle exceptions here better!
LoggingUtil.exception(e);
}
}
else {
LoggingUtil.warning("Tried to run a 'null' Object.");
}
}
}
} | java | public void runQueue() {
synchronized(sync) {
while(!queue.isEmpty()) {
Runnable r = queue.poll();
if(r != null) {
try {
r.run();
}
catch(Exception e) {
// Alternatively, we could allow the specification of exception
// handlers for each runnable in the API. For now we'll just log.
// TODO: handle exceptions here better!
LoggingUtil.exception(e);
}
}
else {
LoggingUtil.warning("Tried to run a 'null' Object.");
}
}
}
} | [
"public",
"void",
"runQueue",
"(",
")",
"{",
"synchronized",
"(",
"sync",
")",
"{",
"while",
"(",
"!",
"queue",
".",
"isEmpty",
"(",
")",
")",
"{",
"Runnable",
"r",
"=",
"queue",
".",
"poll",
"(",
")",
";",
"if",
"(",
"r",
"!=",
"null",
")",
"{... | Run the processing queue now. This should usually be only invoked by the
UpdateSynchronizer | [
"Run",
"the",
"processing",
"queue",
"now",
".",
"This",
"should",
"usually",
"be",
"only",
"invoked",
"by",
"the",
"UpdateSynchronizer"
] | b54673327e76198ecd4c8a2a901021f1a9174498 | https://github.com/elki-project/elki/blob/b54673327e76198ecd4c8a2a901021f1a9174498/addons/batikvis/src/main/java/de/lmu/ifi/dbs/elki/visualization/svg/UpdateRunner.java#L83-L103 | train |
elki-project/elki | addons/batikvis/src/main/java/de/lmu/ifi/dbs/elki/visualization/svg/UpdateRunner.java | UpdateRunner.synchronizeWith | public synchronized void synchronizeWith(UpdateSynchronizer newsync) {
// LoggingUtil.warning("Synchronizing: " + sync + " " + newsync, new
// Throwable());
if(synchronizer == newsync) {
LoggingUtil.warning("Double-synced to the same plot!", new Throwable());
return;
}
if(synchronizer != null) {
LoggingUtil.warning("Attempting to synchronize to more than one synchronizer.");
return;
}
synchronizer = newsync;
newsync.addUpdateRunner(this);
} | java | public synchronized void synchronizeWith(UpdateSynchronizer newsync) {
// LoggingUtil.warning("Synchronizing: " + sync + " " + newsync, new
// Throwable());
if(synchronizer == newsync) {
LoggingUtil.warning("Double-synced to the same plot!", new Throwable());
return;
}
if(synchronizer != null) {
LoggingUtil.warning("Attempting to synchronize to more than one synchronizer.");
return;
}
synchronizer = newsync;
newsync.addUpdateRunner(this);
} | [
"public",
"synchronized",
"void",
"synchronizeWith",
"(",
"UpdateSynchronizer",
"newsync",
")",
"{",
"// LoggingUtil.warning(\"Synchronizing: \" + sync + \" \" + newsync, new",
"// Throwable());",
"if",
"(",
"synchronizer",
"==",
"newsync",
")",
"{",
"LoggingUtil",
".",
"warn... | Set a new update synchronizer.
@param newsync Update synchronizer | [
"Set",
"a",
"new",
"update",
"synchronizer",
"."
] | b54673327e76198ecd4c8a2a901021f1a9174498 | https://github.com/elki-project/elki/blob/b54673327e76198ecd4c8a2a901021f1a9174498/addons/batikvis/src/main/java/de/lmu/ifi/dbs/elki/visualization/svg/UpdateRunner.java#L126-L139 | train |
elki-project/elki | addons/batikvis/src/main/java/de/lmu/ifi/dbs/elki/visualization/svg/UpdateRunner.java | UpdateRunner.unsynchronizeWith | public synchronized void unsynchronizeWith(UpdateSynchronizer oldsync) {
if(synchronizer == null) {
LoggingUtil.warning("Warning: was not synchronized.");
return;
}
if(synchronizer != oldsync) {
LoggingUtil.warning("Warning: was synchronized differently!");
return;
}
// LoggingUtil.warning("Unsynchronizing: " + sync + " " + oldsync);
synchronizer = null;
runQueue();
} | java | public synchronized void unsynchronizeWith(UpdateSynchronizer oldsync) {
if(synchronizer == null) {
LoggingUtil.warning("Warning: was not synchronized.");
return;
}
if(synchronizer != oldsync) {
LoggingUtil.warning("Warning: was synchronized differently!");
return;
}
// LoggingUtil.warning("Unsynchronizing: " + sync + " " + oldsync);
synchronizer = null;
runQueue();
} | [
"public",
"synchronized",
"void",
"unsynchronizeWith",
"(",
"UpdateSynchronizer",
"oldsync",
")",
"{",
"if",
"(",
"synchronizer",
"==",
"null",
")",
"{",
"LoggingUtil",
".",
"warning",
"(",
"\"Warning: was not synchronized.\"",
")",
";",
"return",
";",
"}",
"if",
... | Remove an update synchronizer
@param oldsync Update synchronizer to remove | [
"Remove",
"an",
"update",
"synchronizer"
] | b54673327e76198ecd4c8a2a901021f1a9174498 | https://github.com/elki-project/elki/blob/b54673327e76198ecd4c8a2a901021f1a9174498/addons/batikvis/src/main/java/de/lmu/ifi/dbs/elki/visualization/svg/UpdateRunner.java#L146-L158 | train |
elki-project/elki | elki/src/main/java/de/lmu/ifi/dbs/elki/algorithm/projection/PerplexityAffinityMatrixBuilder.java | PerplexityAffinityMatrixBuilder.estimateInitialBeta | protected static double estimateInitialBeta(double[] dist_i, double perplexity) {
double sum = 0.;
for(double d : dist_i) {
double d2 = d * d;
sum += d2 < Double.POSITIVE_INFINITY ? d2 : 0.;
}
return sum > 0 && sum < Double.POSITIVE_INFINITY ? .5 / sum * perplexity * (dist_i.length - 1.) : 1.;
} | java | protected static double estimateInitialBeta(double[] dist_i, double perplexity) {
double sum = 0.;
for(double d : dist_i) {
double d2 = d * d;
sum += d2 < Double.POSITIVE_INFINITY ? d2 : 0.;
}
return sum > 0 && sum < Double.POSITIVE_INFINITY ? .5 / sum * perplexity * (dist_i.length - 1.) : 1.;
} | [
"protected",
"static",
"double",
"estimateInitialBeta",
"(",
"double",
"[",
"]",
"dist_i",
",",
"double",
"perplexity",
")",
"{",
"double",
"sum",
"=",
"0.",
";",
"for",
"(",
"double",
"d",
":",
"dist_i",
")",
"{",
"double",
"d2",
"=",
"d",
"*",
"d",
... | Estimate beta from the distances in a row.
This lacks a mathematical argument, but is a handcrafted heuristic to avoid
numerical problems. The average distance is usually too large, so we scale
the average distance by 2*N/perplexity. Then estimate beta as 1/x.
@param dist_i Distances
@param perplexity Desired perplexity
@return Estimated beta. | [
"Estimate",
"beta",
"from",
"the",
"distances",
"in",
"a",
"row",
"."
] | b54673327e76198ecd4c8a2a901021f1a9174498 | https://github.com/elki-project/elki/blob/b54673327e76198ecd4c8a2a901021f1a9174498/elki/src/main/java/de/lmu/ifi/dbs/elki/algorithm/projection/PerplexityAffinityMatrixBuilder.java#L206-L213 | train |
elki-project/elki | elki-core/src/main/java/de/lmu/ifi/dbs/elki/result/ResultUtil.java | ResultUtil.getRelations | public static List<Relation<?>> getRelations(Result r) {
if(r instanceof Relation<?>) {
List<Relation<?>> anns = new ArrayList<>(1);
anns.add((Relation<?>) r);
return anns;
}
if(r instanceof HierarchicalResult) {
return filterResults(((HierarchicalResult) r).getHierarchy(), r, Relation.class);
}
return Collections.emptyList();
} | java | public static List<Relation<?>> getRelations(Result r) {
if(r instanceof Relation<?>) {
List<Relation<?>> anns = new ArrayList<>(1);
anns.add((Relation<?>) r);
return anns;
}
if(r instanceof HierarchicalResult) {
return filterResults(((HierarchicalResult) r).getHierarchy(), r, Relation.class);
}
return Collections.emptyList();
} | [
"public",
"static",
"List",
"<",
"Relation",
"<",
"?",
">",
">",
"getRelations",
"(",
"Result",
"r",
")",
"{",
"if",
"(",
"r",
"instanceof",
"Relation",
"<",
"?",
">",
")",
"{",
"List",
"<",
"Relation",
"<",
"?",
">",
">",
"anns",
"=",
"new",
"Ar... | Collect all Annotation results from a Result
@param r Result
@return List of all annotation results | [
"Collect",
"all",
"Annotation",
"results",
"from",
"a",
"Result"
] | b54673327e76198ecd4c8a2a901021f1a9174498 | https://github.com/elki-project/elki/blob/b54673327e76198ecd4c8a2a901021f1a9174498/elki-core/src/main/java/de/lmu/ifi/dbs/elki/result/ResultUtil.java#L53-L63 | train |
elki-project/elki | elki-core/src/main/java/de/lmu/ifi/dbs/elki/result/ResultUtil.java | ResultUtil.getOrderingResults | public static List<OrderingResult> getOrderingResults(Result r) {
if(r instanceof OrderingResult) {
List<OrderingResult> ors = new ArrayList<>(1);
ors.add((OrderingResult) r);
return ors;
}
if(r instanceof HierarchicalResult) {
return filterResults(((HierarchicalResult) r).getHierarchy(), r, OrderingResult.class);
}
return Collections.emptyList();
} | java | public static List<OrderingResult> getOrderingResults(Result r) {
if(r instanceof OrderingResult) {
List<OrderingResult> ors = new ArrayList<>(1);
ors.add((OrderingResult) r);
return ors;
}
if(r instanceof HierarchicalResult) {
return filterResults(((HierarchicalResult) r).getHierarchy(), r, OrderingResult.class);
}
return Collections.emptyList();
} | [
"public",
"static",
"List",
"<",
"OrderingResult",
">",
"getOrderingResults",
"(",
"Result",
"r",
")",
"{",
"if",
"(",
"r",
"instanceof",
"OrderingResult",
")",
"{",
"List",
"<",
"OrderingResult",
">",
"ors",
"=",
"new",
"ArrayList",
"<>",
"(",
"1",
")",
... | Collect all ordering results from a Result
@param r Result
@return List of ordering results | [
"Collect",
"all",
"ordering",
"results",
"from",
"a",
"Result"
] | b54673327e76198ecd4c8a2a901021f1a9174498 | https://github.com/elki-project/elki/blob/b54673327e76198ecd4c8a2a901021f1a9174498/elki-core/src/main/java/de/lmu/ifi/dbs/elki/result/ResultUtil.java#L71-L81 | train |
elki-project/elki | elki-core/src/main/java/de/lmu/ifi/dbs/elki/result/ResultUtil.java | ResultUtil.getCollectionResults | public static List<CollectionResult<?>> getCollectionResults(Result r) {
if(r instanceof CollectionResult<?>) {
List<CollectionResult<?>> crs = new ArrayList<>(1);
crs.add((CollectionResult<?>) r);
return crs;
}
if(r instanceof HierarchicalResult) {
return filterResults(((HierarchicalResult) r).getHierarchy(), r, CollectionResult.class);
}
return Collections.emptyList();
} | java | public static List<CollectionResult<?>> getCollectionResults(Result r) {
if(r instanceof CollectionResult<?>) {
List<CollectionResult<?>> crs = new ArrayList<>(1);
crs.add((CollectionResult<?>) r);
return crs;
}
if(r instanceof HierarchicalResult) {
return filterResults(((HierarchicalResult) r).getHierarchy(), r, CollectionResult.class);
}
return Collections.emptyList();
} | [
"public",
"static",
"List",
"<",
"CollectionResult",
"<",
"?",
">",
">",
"getCollectionResults",
"(",
"Result",
"r",
")",
"{",
"if",
"(",
"r",
"instanceof",
"CollectionResult",
"<",
"?",
">",
")",
"{",
"List",
"<",
"CollectionResult",
"<",
"?",
">",
">",... | Collect all collection results from a Result
@param r Result
@return List of collection results | [
"Collect",
"all",
"collection",
"results",
"from",
"a",
"Result"
] | b54673327e76198ecd4c8a2a901021f1a9174498 | https://github.com/elki-project/elki/blob/b54673327e76198ecd4c8a2a901021f1a9174498/elki-core/src/main/java/de/lmu/ifi/dbs/elki/result/ResultUtil.java#L89-L99 | train |
elki-project/elki | elki-core/src/main/java/de/lmu/ifi/dbs/elki/result/ResultUtil.java | ResultUtil.getIterableResults | public static List<IterableResult<?>> getIterableResults(Result r) {
if(r instanceof IterableResult<?>) {
List<IterableResult<?>> irs = new ArrayList<>(1);
irs.add((IterableResult<?>) r);
return irs;
}
if(r instanceof HierarchicalResult) {
return filterResults(((HierarchicalResult) r).getHierarchy(), r, IterableResult.class);
}
return Collections.emptyList();
} | java | public static List<IterableResult<?>> getIterableResults(Result r) {
if(r instanceof IterableResult<?>) {
List<IterableResult<?>> irs = new ArrayList<>(1);
irs.add((IterableResult<?>) r);
return irs;
}
if(r instanceof HierarchicalResult) {
return filterResults(((HierarchicalResult) r).getHierarchy(), r, IterableResult.class);
}
return Collections.emptyList();
} | [
"public",
"static",
"List",
"<",
"IterableResult",
"<",
"?",
">",
">",
"getIterableResults",
"(",
"Result",
"r",
")",
"{",
"if",
"(",
"r",
"instanceof",
"IterableResult",
"<",
"?",
">",
")",
"{",
"List",
"<",
"IterableResult",
"<",
"?",
">",
">",
"irs"... | Return all Iterable results
@param r Result
@return List of iterable results | [
"Return",
"all",
"Iterable",
"results"
] | b54673327e76198ecd4c8a2a901021f1a9174498 | https://github.com/elki-project/elki/blob/b54673327e76198ecd4c8a2a901021f1a9174498/elki-core/src/main/java/de/lmu/ifi/dbs/elki/result/ResultUtil.java#L107-L117 | train |
elki-project/elki | elki-core/src/main/java/de/lmu/ifi/dbs/elki/result/ResultUtil.java | ResultUtil.filterResults | public static <C extends Result> ArrayList<C> filterResults(ResultHierarchy hier, Result r, Class<? super C> restrictionClass) {
ArrayList<C> res = new ArrayList<>();
final It<C> it = hier.iterDescendantsSelf(r).filter(restrictionClass);
it.forEach(res::add);
return res;
} | java | public static <C extends Result> ArrayList<C> filterResults(ResultHierarchy hier, Result r, Class<? super C> restrictionClass) {
ArrayList<C> res = new ArrayList<>();
final It<C> it = hier.iterDescendantsSelf(r).filter(restrictionClass);
it.forEach(res::add);
return res;
} | [
"public",
"static",
"<",
"C",
"extends",
"Result",
">",
"ArrayList",
"<",
"C",
">",
"filterResults",
"(",
"ResultHierarchy",
"hier",
",",
"Result",
"r",
",",
"Class",
"<",
"?",
"super",
"C",
">",
"restrictionClass",
")",
"{",
"ArrayList",
"<",
"C",
">",
... | Return only results of the given restriction class
@param <C> Class type
@param hier Result hierarchy
@param r Starting position
@param restrictionClass Class restriction
@return filtered results list | [
"Return",
"only",
"results",
"of",
"the",
"given",
"restriction",
"class"
] | b54673327e76198ecd4c8a2a901021f1a9174498 | https://github.com/elki-project/elki/blob/b54673327e76198ecd4c8a2a901021f1a9174498/elki-core/src/main/java/de/lmu/ifi/dbs/elki/result/ResultUtil.java#L128-L133 | train |
elki-project/elki | elki-core/src/main/java/de/lmu/ifi/dbs/elki/result/ResultUtil.java | ResultUtil.addChildResult | public static void addChildResult(HierarchicalResult parent, Result child) {
parent.getHierarchy().add(parent, child);
} | java | public static void addChildResult(HierarchicalResult parent, Result child) {
parent.getHierarchy().add(parent, child);
} | [
"public",
"static",
"void",
"addChildResult",
"(",
"HierarchicalResult",
"parent",
",",
"Result",
"child",
")",
"{",
"parent",
".",
"getHierarchy",
"(",
")",
".",
"add",
"(",
"parent",
",",
"child",
")",
";",
"}"
] | Add a child result.
@param parent Parent
@param child Child | [
"Add",
"a",
"child",
"result",
"."
] | b54673327e76198ecd4c8a2a901021f1a9174498 | https://github.com/elki-project/elki/blob/b54673327e76198ecd4c8a2a901021f1a9174498/elki-core/src/main/java/de/lmu/ifi/dbs/elki/result/ResultUtil.java#L156-L158 | train |
elki-project/elki | elki-core/src/main/java/de/lmu/ifi/dbs/elki/result/ResultUtil.java | ResultUtil.findDatabase | public static Database findDatabase(ResultHierarchy hier, Result baseResult) {
final List<Database> dbs = filterResults(hier, baseResult, Database.class);
return (!dbs.isEmpty()) ? dbs.get(0) : null;
} | java | public static Database findDatabase(ResultHierarchy hier, Result baseResult) {
final List<Database> dbs = filterResults(hier, baseResult, Database.class);
return (!dbs.isEmpty()) ? dbs.get(0) : null;
} | [
"public",
"static",
"Database",
"findDatabase",
"(",
"ResultHierarchy",
"hier",
",",
"Result",
"baseResult",
")",
"{",
"final",
"List",
"<",
"Database",
">",
"dbs",
"=",
"filterResults",
"(",
"hier",
",",
"baseResult",
",",
"Database",
".",
"class",
")",
";"... | Find the first database result in the tree.
@param baseResult Result tree base.
@return Database | [
"Find",
"the",
"first",
"database",
"result",
"in",
"the",
"tree",
"."
] | b54673327e76198ecd4c8a2a901021f1a9174498 | https://github.com/elki-project/elki/blob/b54673327e76198ecd4c8a2a901021f1a9174498/elki-core/src/main/java/de/lmu/ifi/dbs/elki/result/ResultUtil.java#L166-L169 | train |
elki-project/elki | elki-core/src/main/java/de/lmu/ifi/dbs/elki/result/ResultUtil.java | ResultUtil.removeRecursive | public static void removeRecursive(ResultHierarchy hierarchy, Result child) {
for(It<Result> iter = hierarchy.iterParents(child); iter.valid(); iter.advance()) {
hierarchy.remove(iter.get(), child);
}
for(It<Result> iter = hierarchy.iterChildren(child); iter.valid(); iter.advance()) {
removeRecursive(hierarchy, iter.get());
}
} | java | public static void removeRecursive(ResultHierarchy hierarchy, Result child) {
for(It<Result> iter = hierarchy.iterParents(child); iter.valid(); iter.advance()) {
hierarchy.remove(iter.get(), child);
}
for(It<Result> iter = hierarchy.iterChildren(child); iter.valid(); iter.advance()) {
removeRecursive(hierarchy, iter.get());
}
} | [
"public",
"static",
"void",
"removeRecursive",
"(",
"ResultHierarchy",
"hierarchy",
",",
"Result",
"child",
")",
"{",
"for",
"(",
"It",
"<",
"Result",
">",
"iter",
"=",
"hierarchy",
".",
"iterParents",
"(",
"child",
")",
";",
"iter",
".",
"valid",
"(",
"... | Recursively remove a result and its children.
@param hierarchy Result hierarchy
@param child Result to remove | [
"Recursively",
"remove",
"a",
"result",
"and",
"its",
"children",
"."
] | b54673327e76198ecd4c8a2a901021f1a9174498 | https://github.com/elki-project/elki/blob/b54673327e76198ecd4c8a2a901021f1a9174498/elki-core/src/main/java/de/lmu/ifi/dbs/elki/result/ResultUtil.java#L188-L195 | train |
elki-project/elki | elki-input/src/main/java/de/lmu/ifi/dbs/elki/datasource/filter/transform/FastMultidimensionalScalingTransform.java | FastMultidimensionalScalingTransform.findEigenVectors | protected void findEigenVectors(double[][] imat, double[][] evs, double[] lambda) {
final int size = imat.length;
Random rnd = random.getSingleThreadedRandom();
double[] tmp = new double[size];
FiniteProgress prog = LOG.isVerbose() ? new FiniteProgress("Learning projections", tdim, LOG) : null;
for(int d = 0; d < tdim;) {
final double[] cur = evs[d];
randomInitialization(cur, rnd);
double l = multiply(imat, cur, tmp);
for(int iter = 0; iter < 100; iter++) {
// This will scale "tmp" to unit length, and copy it to cur:
double delta = updateEigenvector(tmp, cur, l);
if(delta < 1e-10) {
break;
}
l = multiply(imat, cur, tmp);
}
lambda[d++] = l = estimateEigenvalue(imat, cur);
LOG.incrementProcessed(prog);
if(d == tdim) {
break;
}
// Update matrix
updateMatrix(imat, cur, l);
}
LOG.ensureCompleted(prog);
} | java | protected void findEigenVectors(double[][] imat, double[][] evs, double[] lambda) {
final int size = imat.length;
Random rnd = random.getSingleThreadedRandom();
double[] tmp = new double[size];
FiniteProgress prog = LOG.isVerbose() ? new FiniteProgress("Learning projections", tdim, LOG) : null;
for(int d = 0; d < tdim;) {
final double[] cur = evs[d];
randomInitialization(cur, rnd);
double l = multiply(imat, cur, tmp);
for(int iter = 0; iter < 100; iter++) {
// This will scale "tmp" to unit length, and copy it to cur:
double delta = updateEigenvector(tmp, cur, l);
if(delta < 1e-10) {
break;
}
l = multiply(imat, cur, tmp);
}
lambda[d++] = l = estimateEigenvalue(imat, cur);
LOG.incrementProcessed(prog);
if(d == tdim) {
break;
}
// Update matrix
updateMatrix(imat, cur, l);
}
LOG.ensureCompleted(prog);
} | [
"protected",
"void",
"findEigenVectors",
"(",
"double",
"[",
"]",
"[",
"]",
"imat",
",",
"double",
"[",
"]",
"[",
"]",
"evs",
",",
"double",
"[",
"]",
"lambda",
")",
"{",
"final",
"int",
"size",
"=",
"imat",
".",
"length",
";",
"Random",
"rnd",
"="... | Find the first eigenvectors and eigenvalues using power iterations.
@param imat Matrix (will be modified!)
@param evs Eigenvectors output
@param lambda Eigenvalues output | [
"Find",
"the",
"first",
"eigenvectors",
"and",
"eigenvalues",
"using",
"power",
"iterations",
"."
] | b54673327e76198ecd4c8a2a901021f1a9174498 | https://github.com/elki-project/elki/blob/b54673327e76198ecd4c8a2a901021f1a9174498/elki-input/src/main/java/de/lmu/ifi/dbs/elki/datasource/filter/transform/FastMultidimensionalScalingTransform.java#L178-L204 | train |
elki-project/elki | elki-input/src/main/java/de/lmu/ifi/dbs/elki/datasource/filter/transform/FastMultidimensionalScalingTransform.java | FastMultidimensionalScalingTransform.randomInitialization | protected void randomInitialization(double[] out, Random rnd) {
double l2 = 0.;
while(!(l2 > 0)) {
for(int d = 0; d < out.length; d++) {
final double val = rnd.nextDouble();
out[d] = val;
l2 += val * val;
}
}
// Standardize:
final double s = 1. / FastMath.sqrt(l2);
for(int d = 0; d < out.length; d++) {
out[d] *= s;
}
} | java | protected void randomInitialization(double[] out, Random rnd) {
double l2 = 0.;
while(!(l2 > 0)) {
for(int d = 0; d < out.length; d++) {
final double val = rnd.nextDouble();
out[d] = val;
l2 += val * val;
}
}
// Standardize:
final double s = 1. / FastMath.sqrt(l2);
for(int d = 0; d < out.length; d++) {
out[d] *= s;
}
} | [
"protected",
"void",
"randomInitialization",
"(",
"double",
"[",
"]",
"out",
",",
"Random",
"rnd",
")",
"{",
"double",
"l2",
"=",
"0.",
";",
"while",
"(",
"!",
"(",
"l2",
">",
"0",
")",
")",
"{",
"for",
"(",
"int",
"d",
"=",
"0",
";",
"d",
"<",... | Choose a random vector of unit norm for power iterations.
@param out Output storage
@param rnd Random source. | [
"Choose",
"a",
"random",
"vector",
"of",
"unit",
"norm",
"for",
"power",
"iterations",
"."
] | b54673327e76198ecd4c8a2a901021f1a9174498 | https://github.com/elki-project/elki/blob/b54673327e76198ecd4c8a2a901021f1a9174498/elki-input/src/main/java/de/lmu/ifi/dbs/elki/datasource/filter/transform/FastMultidimensionalScalingTransform.java#L212-L226 | train |
elki-project/elki | elki-input/src/main/java/de/lmu/ifi/dbs/elki/datasource/filter/transform/FastMultidimensionalScalingTransform.java | FastMultidimensionalScalingTransform.updateEigenvector | protected double updateEigenvector(double[] in, double[] out, double l) {
double s = 1. / (l > 0. ? l : l < 0. ? -l : 1.);
s = (in[0] > 0.) ? s : -s; // Reduce flipping vectors
double diff = 0.;
for(int d = 0; d < in.length; d++) {
in[d] *= s; // Scale to unit length
// Compute change from previous iteration:
double delta = in[d] - out[d];
diff += delta * delta;
out[d] = in[d]; // Update output storage
}
return diff;
} | java | protected double updateEigenvector(double[] in, double[] out, double l) {
double s = 1. / (l > 0. ? l : l < 0. ? -l : 1.);
s = (in[0] > 0.) ? s : -s; // Reduce flipping vectors
double diff = 0.;
for(int d = 0; d < in.length; d++) {
in[d] *= s; // Scale to unit length
// Compute change from previous iteration:
double delta = in[d] - out[d];
diff += delta * delta;
out[d] = in[d]; // Update output storage
}
return diff;
} | [
"protected",
"double",
"updateEigenvector",
"(",
"double",
"[",
"]",
"in",
",",
"double",
"[",
"]",
"out",
",",
"double",
"l",
")",
"{",
"double",
"s",
"=",
"1.",
"/",
"(",
"l",
">",
"0.",
"?",
"l",
":",
"l",
"<",
"0.",
"?",
"-",
"l",
":",
"1... | Compute the change in the eigenvector, and normalize the output vector
while doing so.
@param in Input vector
@param out Output vector
@param l Eigenvalue
@return Change | [
"Compute",
"the",
"change",
"in",
"the",
"eigenvector",
"and",
"normalize",
"the",
"output",
"vector",
"while",
"doing",
"so",
"."
] | b54673327e76198ecd4c8a2a901021f1a9174498 | https://github.com/elki-project/elki/blob/b54673327e76198ecd4c8a2a901021f1a9174498/elki-input/src/main/java/de/lmu/ifi/dbs/elki/datasource/filter/transform/FastMultidimensionalScalingTransform.java#L260-L272 | train |
elki-project/elki | elki-input/src/main/java/de/lmu/ifi/dbs/elki/datasource/filter/transform/FastMultidimensionalScalingTransform.java | FastMultidimensionalScalingTransform.updateMatrix | protected void updateMatrix(double[][] mat, final double[] evec, double eval) {
final int size = mat.length;
for(int i = 0; i < size; i++) {
final double[] mati = mat[i];
final double eveci = evec[i];
for(int j = 0; j < size; j++) {
mati[j] -= eval * eveci * evec[j];
}
}
} | java | protected void updateMatrix(double[][] mat, final double[] evec, double eval) {
final int size = mat.length;
for(int i = 0; i < size; i++) {
final double[] mati = mat[i];
final double eveci = evec[i];
for(int j = 0; j < size; j++) {
mati[j] -= eval * eveci * evec[j];
}
}
} | [
"protected",
"void",
"updateMatrix",
"(",
"double",
"[",
"]",
"[",
"]",
"mat",
",",
"final",
"double",
"[",
"]",
"evec",
",",
"double",
"eval",
")",
"{",
"final",
"int",
"size",
"=",
"mat",
".",
"length",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";... | Update matrix, by removing the effects of a known Eigenvector.
@param mat Matrix
@param evec Known normalized Eigenvector
@param eval Eigenvalue | [
"Update",
"matrix",
"by",
"removing",
"the",
"effects",
"of",
"a",
"known",
"Eigenvector",
"."
] | b54673327e76198ecd4c8a2a901021f1a9174498 | https://github.com/elki-project/elki/blob/b54673327e76198ecd4c8a2a901021f1a9174498/elki-input/src/main/java/de/lmu/ifi/dbs/elki/datasource/filter/transform/FastMultidimensionalScalingTransform.java#L304-L313 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.