code stringlengths 73 34.1k | label stringclasses 1
value |
|---|---|
public Object[] getRow(int row) {
Object[] ret = new Object[columns.size()];
for(int c = 0; c < columns.size(); c++) {
ret[c] = data(row, c);
}
return ret;
} | java |
protected void batchNN(AbstractRStarTreeNode<?, ?> node, Map<DBID, KNNHeap> knnLists) {
if(node.isLeaf()) {
for(int i = 0; i < node.getNumEntries(); i++) {
SpatialEntry p = node.getEntry(i);
for(Entry<DBID, KNNHeap> ent : knnLists.entrySet()) {
final DBID q = ent.getKey();
... | java |
protected List<DoubleDistanceEntry> getSortedEntries(AbstractRStarTreeNode<?, ?> node, DBIDs ids) {
List<DoubleDistanceEntry> result = new ArrayList<>();
for(int i = 0; i < node.getNumEntries(); i++) {
SpatialEntry entry = node.getEntry(i);
double minMinDist = Double.MAX_VALUE;
for(DBIDIter i... | java |
private boolean checkCandidateUpdate(double[] point) {
final double x = point[0], y = point[1];
if(points.isEmpty()) {
leftx = rightx = x;
topy = bottomy = y;
topleft = topright = bottomleft = bottomright = point;
return true;
}
// A non-regular diamond spanned by left, top, righ... | java |
static DBIDs randomSample(DBIDs ids, int samplesize, Random rnd, DBIDs previous) {
if(previous == null) {
return DBIDUtil.randomSample(ids, samplesize, rnd);
}
ModifiableDBIDs sample = DBIDUtil.newHashSet(samplesize);
sample.addDBIDs(previous);
sample.addDBIDs(DBIDUtil.randomSample(ids, sample... | java |
@Override
public void actionPerformed(ActionEvent e) {
// Use a new JFileChooser. Inconsistent behaviour otherwise!
final JFileChooser fc = new JFileChooser(new File("."));
if(param.isDefined()) {
fc.setSelectedFile(param.getValue());
}
if(e.getSource() == button) {
int returnVal = fc... | java |
protected Node inlineThumbnail(Document doc, ParsedURL urldata, Node eold) {
RenderableImage img = ThumbnailRegistryEntry.handleURL(urldata);
if(img == null) {
LoggingUtil.warning("Image not found in registry: " + urldata.toString());
return null;
}
ByteArrayOutputStream os = new ByteArrayOu... | java |
private static PrintStream openStream(File out) throws IOException {
OutputStream os = new FileOutputStream(out);
os = out.getName().endsWith(GZIP_POSTFIX) ? new GZIPOutputStream(os) : os;
return new PrintStream(os);
} | java |
@Override
public void setDimensionality(int dimensionality) throws IllegalArgumentException {
final int maxdim = getMaxDim();
if(maxdim > dimensionality) {
throw new IllegalArgumentException("Given dimensionality " + dimensionality + " is too small w.r.t. the given values (occurring maximum: " + maxdim ... | java |
protected IndexTreePath<E> findPathToObject(IndexTreePath<E> subtree, SpatialComparable mbr, DBIDRef id) {
N node = getNode(subtree.getEntry());
if(node.isLeaf()) {
for(int i = 0; i < node.getNumEntries(); i++) {
if(DBIDUtil.equal(((LeafEntry) node.getEntry(i)).getDBID(), id)) {
return n... | java |
protected void deletePath(IndexTreePath<E> deletionPath) {
N leaf = getNode(deletionPath.getParentPath().getEntry());
int index = deletionPath.getIndex();
// delete o
E entry = leaf.getEntry(index);
leaf.deleteEntry(index);
writeNode(leaf);
// condense the tree
Stack<N> stack = new Sta... | java |
protected List<E> createBulkLeafNodes(List<E> objects) {
int minEntries = leafMinimum;
int maxEntries = leafCapacity;
ArrayList<E> result = new ArrayList<>();
List<List<E>> partitions = settings.bulkSplitter.partition(objects, minEntries, maxEntries);
for(List<E> partition : partitions) {
//... | java |
protected IndexTreePath<E> choosePath(IndexTreePath<E> subtree, SpatialComparable mbr, int depth, int cur) {
if(getLogger().isDebuggingFiner()) {
getLogger().debugFiner("node " + subtree + ", depth " + depth);
}
N node = getNode(subtree.getEntry());
if(node == null) {
throw new RuntimeExcep... | java |
private N split(N node) {
// choose the split dimension and the split point
int minimum = node.isLeaf() ? leafMinimum : dirMinimum;
long[] split = settings.nodeSplitter.split(node, NodeArrayAdapter.STATIC, minimum);
// New node
final N newNode = node.isLeaf() ? createNewLeafNode() : createNewDirect... | java |
public void reInsert(N node, IndexTreePath<E> path, int[] offs) {
final int depth = path.getPathCount();
long[] remove = BitsUtil.zero(node.getCapacity());
List<E> reInsertEntries = new ArrayList<>(offs.length);
for(int i = 0; i < offs.length; i++) {
reInsertEntries.add(node.getEntry(offs[i]));
... | java |
private void condenseTree(IndexTreePath<E> subtree, Stack<N> stack) {
N node = getNode(subtree.getEntry());
// node is not root
if(!isRoot(node)) {
N parent = getNode(subtree.getParentPath().getEntry());
int index = subtree.getIndex();
if(hasUnderflow(node)) {
if(parent.deleteEntry... | java |
private void getLeafNodes(N node, List<E> result, int currentLevel) {
// Level 1 are the leaf nodes, Level 2 is the one atop!
if(currentLevel == 2) {
for(int i = 0; i < node.getNumEntries(); i++) {
result.add(node.getEntry(i));
}
}
else {
for(int i = 0; i < node.getNumEntries()... | java |
public static double angleDense(NumberVector v1, NumberVector v2) {
final int dim1 = v1.getDimensionality(), dim2 = v2.getDimensionality();
final int mindim = (dim1 <= dim2) ? dim1 : dim2;
// Essentially, we want to compute this:
// v1.transposeTimes(v2) / (v1.euclideanLength() * v2.euclideanLength());
... | java |
public static double angleSparse(SparseNumberVector v1, SparseNumberVector v2) {
// TODO: exploit precomputed length, when available?
double l1 = 0., l2 = 0., cross = 0.;
int i1 = v1.iter(), i2 = v2.iter();
while(v1.iterValid(i1) && v2.iterValid(i2)) {
final int d1 = v1.iterDim(i1), d2 = v2.iterDi... | java |
public static double angleSparseDense(SparseNumberVector v1, NumberVector v2) {
// TODO: exploit precomputed length, when available.
final int dim2 = v2.getDimensionality();
double l1 = 0., l2 = 0., cross = 0.;
int i1 = v1.iter(), d2 = 0;
while(v1.iterValid(i1)) {
final int d1 = v1.iterDim(i1)... | java |
public static double cosAngle(NumberVector v1, NumberVector v2) {
// Java Hotspot appears to optimize these better than if-then-else:
return v1 instanceof SparseNumberVector ? //
v2 instanceof SparseNumberVector ? //
angleSparse((SparseNumberVector) v1, (SparseNumberVector) v2) : //
... | java |
public static double minCosAngle(SpatialComparable v1, SpatialComparable v2) {
if(v1 instanceof NumberVector && v2 instanceof NumberVector) {
return cosAngle((NumberVector) v1, (NumberVector) v2);
}
final int dim1 = v1.getDimensionality(), dim2 = v2.getDimensionality();
final int mindim = (dim1 <=... | java |
public static double angle(NumberVector v1, NumberVector v2, NumberVector o) {
final int dim1 = v1.getDimensionality(), dim2 = v2.getDimensionality(),
dimo = o.getDimensionality();
final int mindim = (dim1 <= dim2) ? dim1 : dim2;
// Essentially, we want to compute this:
// v1' = v1 - o, v2' = v2... | java |
public static double dotDense(NumberVector v1, NumberVector v2) {
final int dim1 = v1.getDimensionality(), dim2 = v2.getDimensionality();
final int mindim = (dim1 <= dim2) ? dim1 : dim2;
double dot = 0;
for(int k = 0; k < mindim; k++) {
dot += v1.doubleValue(k) * v2.doubleValue(k);
}
retur... | java |
public static double dotSparse(SparseNumberVector v1, SparseNumberVector v2) {
double dot = 0.;
int i1 = v1.iter(), i2 = v2.iter();
while(v1.iterValid(i1) && v2.iterValid(i2)) {
final int d1 = v1.iterDim(i1), d2 = v2.iterDim(i2);
if(d1 < d2) {
i1 = v1.iterAdvance(i1);
}
else ... | java |
public static double dotSparseDense(SparseNumberVector v1, NumberVector v2) {
final int dim2 = v2.getDimensionality();
double dot = 0.;
for(int i1 = v1.iter(); v1.iterValid(i1);) {
final int d1 = v1.iterDim(i1);
if(d1 >= dim2) {
break;
}
dot += v1.iterDoubleValue(i1) * v2.dou... | java |
public static double dot(NumberVector v1, NumberVector v2) {
// Java Hotspot appears to optimize these better than if-then-else:
return v1 instanceof SparseNumberVector ? //
v2 instanceof SparseNumberVector ? //
dotSparse((SparseNumberVector) v1, (SparseNumberVector) v2) : //
dot... | java |
public static double minDot(SpatialComparable v1, SpatialComparable v2) {
if(v1 instanceof NumberVector && v2 instanceof NumberVector) {
return dot((NumberVector) v1, (NumberVector) v2);
}
final int dim1 = v1.getDimensionality(), dim2 = v2.getDimensionality();
final int mindim = (dim1 <= dim2) ? d... | java |
public static <V extends NumberVector> V project(V v, long[] selectedAttributes, NumberVector.Factory<V> factory) {
int card = BitsUtil.cardinality(selectedAttributes);
if(factory instanceof SparseNumberVector.Factory) {
final SparseNumberVector.Factory<?> sfactory = (SparseNumberVector.Factory<?>) factor... | java |
public void mergeWith(Core o) {
o.num = this.num = (num < o.num ? num : o.num);
} | java |
public Clustering<Model> run(Relation<?> relation) {
HashMap<String, DBIDs> labelMap = multiple ? multipleAssignment(relation) : singleAssignment(relation);
ModifiableDBIDs noiseids = DBIDUtil.newArray();
Clustering<Model> result = new Clustering<>("By Label Clustering", "bylabel-clustering");
for(Entr... | java |
private HashMap<String, DBIDs> singleAssignment(Relation<?> data) {
HashMap<String, DBIDs> labelMap = new HashMap<>();
for(DBIDIter iditer = data.iterDBIDs(); iditer.valid(); iditer.advance()) {
final Object val = data.get(iditer);
String label = (val != null) ? val.toString() : null;
assign(... | java |
private HashMap<String, DBIDs> multipleAssignment(Relation<?> data) {
HashMap<String, DBIDs> labelMap = new HashMap<>();
for(DBIDIter iditer = data.iterDBIDs(); iditer.valid(); iditer.advance()) {
String[] labels = data.get(iditer).toString().split(" ");
for(String label : labels) {
assign(... | java |
private void assign(HashMap<String, DBIDs> labelMap, String label, DBIDRef id) {
if(labelMap.containsKey(label)) {
DBIDs exist = labelMap.get(label);
if(exist instanceof DBID) {
ModifiableDBIDs n = DBIDUtil.newHashSet();
n.add((DBID) exist);
n.add(id);
labelMap.put(label,... | java |
public void put(double val) {
min = val < min ? val : min;
max = val > max ? val : max;
} | java |
public static void addShadowFilter(SVGPlot svgp) {
Element shadow = svgp.getIdElement(SHADOW_ID);
if(shadow == null) {
shadow = svgp.svgElement(SVGConstants.SVG_FILTER_TAG);
shadow.setAttribute(SVGConstants.SVG_ID_ATTRIBUTE, SHADOW_ID);
shadow.setAttribute(SVGConstants.SVG_WIDTH_ATTRIBUTE, "14... | java |
public static void addLightGradient(SVGPlot svgp) {
Element gradient = svgp.getIdElement(LIGHT_GRADIENT_ID);
if(gradient == null) {
gradient = svgp.svgElement(SVGConstants.SVG_LINEAR_GRADIENT_TAG);
gradient.setAttribute(SVGConstants.SVG_ID_ATTRIBUTE, LIGHT_GRADIENT_ID);
gradient.setAttribute(S... | java |
public static Element makeCheckmark(SVGPlot svgp) {
Element checkmark = svgp.svgElement(SVGConstants.SVG_PATH_TAG);
checkmark.setAttribute(SVGConstants.SVG_D_ATTRIBUTE, SVG_CHECKMARK_PATH);
checkmark.setAttribute(SVGConstants.SVG_FILL_ATTRIBUTE, SVGConstants.CSS_BLACK_VALUE);
checkmark.setAttribute(SVGC... | java |
public double continueToMargin(double[] origin, double[] delta) {
assert (delta.length == 2 && origin.length == 2);
double factor = Double.POSITIVE_INFINITY;
if(delta[0] > 0) {
factor = Math.min(factor, (maxx - origin[0]) / delta[0]);
}
else if(delta[0] < 0) {
factor = Math.min(factor, (... | java |
@Override
public void clear() {
try {
file.setLength(header.size());
}
catch(IOException e) {
throw new RuntimeException(e);
}
} | java |
private double deviation(double[] delta, double[][] beta) {
final double a = squareSum(delta);
final double b = squareSum(transposeTimes(beta, delta));
return (a > b) ? FastMath.sqrt(a - b) : 0.;
} | java |
private Separation findSeparation(Relation<NumberVector> relation, DBIDs currentids, int dimension, Random r) {
Separation separation = new Separation();
// determine the number of samples needed, to secure that with a specific
// probability
// in at least on sample every sampled point is from the same... | java |
public double getDistance(final DBIDRef o1, final DBIDRef o2) {
return FastMath.sqrt(getSquaredDistance(o1, o2));
} | java |
public double getSquaredDistance(final DBIDRef id1, final DBIDRef id2) {
final int o1 = idmap.getOffset(id1), o2 = idmap.getOffset(id2);
return kernel[o1][o1] + kernel[o2][o2] - 2 * kernel[o1][o2];
} | java |
public double getSimilarity(DBIDRef id1, DBIDRef id2) {
return kernel[idmap.getOffset(id1)][idmap.getOffset(id2)];
} | java |
protected double[][] initialMeans(Database database, Relation<V> relation) {
Duration inittime = getLogger().newDuration(initializer.getClass() + ".time").begin();
double[][] means = initializer.chooseInitialMeans(database, relation, k, getDistanceFunction());
getLogger().statistics(inittime.end());
ret... | java |
public static void plusEquals(double[] sum, NumberVector vec) {
for(int d = 0; d < sum.length; d++) {
sum[d] += vec.doubleValue(d);
}
} | java |
public static void minusEquals(double[] sum, NumberVector vec) {
for(int d = 0; d < sum.length; d++) {
sum[d] -= vec.doubleValue(d);
}
} | java |
public static void plusMinusEquals(double[] add, double[] sub, NumberVector vec) {
for(int d = 0; d < add.length; d++) {
final double v = vec.doubleValue(d);
add[d] += v;
sub[d] -= v;
}
} | java |
protected static void incrementalUpdateMean(double[] mean, NumberVector vec, int newsize, double op) {
if(newsize == 0) {
return; // Keep old mean
}
// Note: numerically stabilized version:
VMath.plusTimesEquals(mean, VMath.minusEquals(vec.toArray(), mean), op / newsize);
} | java |
public static int fastModPrime(long data) {
// Mix high and low 32 bit:
int high = (int) (data >>> 32);
// Use fast multiplication with 5 for high:
int alpha = ((int) data) + (high << 2 + high);
// Note that in Java, PRIME will be negative.
if(alpha < 0 && alpha > -5) {
alpha = alpha + 5;
... | java |
private void doRangeQuery(DBID o_p, AbstractMTreeNode<O, ?, ?> node, O q, double r_q, ModifiableDoubleDBIDList result) {
double d1 = 0.;
if(o_p != null) {
d1 = distanceQuery.distance(o_p, q);
index.statistics.countDistanceCalculation();
}
if(!node.isLeaf()) {
for(int i = 0; i < node.ge... | java |
public static double pdf(double x, double mu, double beta) {
final double z = (x - mu) / beta;
if(x == Double.NEGATIVE_INFINITY) {
return 0.;
}
return FastMath.exp(-z - FastMath.exp(-z)) / beta;
} | java |
public static double logpdf(double x, double mu, double beta) {
if(x == Double.NEGATIVE_INFINITY) {
return Double.NEGATIVE_INFINITY;
}
final double z = (x - mu) / beta;
return -z - FastMath.exp(-z) - FastMath.log(beta);
} | java |
public static double cdf(double val, double mu, double beta) {
return FastMath.exp(-FastMath.exp(-(val - mu) / beta));
} | java |
public static double quantile(double val, double mu, double beta) {
return mu - beta * FastMath.log(-FastMath.log(val));
} | java |
public void setPartitions(Relation<V> relation) throws IllegalArgumentException {
if((FastMath.log(partitions) / FastMath.log(2)) != (int) (FastMath.log(partitions) / FastMath.log(2))) {
throw new IllegalArgumentException("Number of partitions must be a power of 2!");
}
final int dimensions = Relatio... | java |
public long getScannedPages() {
int vacapacity = pageSize / VectorApproximation.byteOnDisk(splitPositions.length, partitions);
long vasize = (long) Math.ceil((vectorApprox.size()) / (1.0 * vacapacity));
return vasize * scans;
} | java |
private void hqr2BackTransformation(int nn, int low, int high) {
for(int j = nn - 1; j >= low; j--) {
final int last = j < high ? j : high;
for(int i = low; i <= high; i++) {
final double[] Vi = V[i];
double sum = 0.;
for(int k = low; k <= last; k++) {
sum += Vi[k] * H[... | java |
protected static double gammaQuantileNewtonRefinement(final double logpt, final double k, final double theta, final int maxit, double x) {
final double EPS_N = 1e-15; // Precision threshold
// 0 is not possible, try MIN_NORMAL instead
if(x <= 0) {
x = Double.MIN_NORMAL;
}
// Current estimation... | java |
@Override
public Element useMarker(SVGPlot plot, Element parent, double x, double y, int stylenr, double size) {
Element marker = plot.svgCircle(x, y, size * .5);
final String col;
if(stylenr == -1) {
col = dotcolor;
}
else if(stylenr == -2) {
col = greycolor;
}
else {
co... | java |
public Clustering<DendrogramModel> run(PointerHierarchyRepresentationResult pointerresult) {
Clustering<DendrogramModel> result = new Instance(pointerresult).run();
result.addChildResult(pointerresult);
return result;
} | java |
public static double erf(double x) {
final double w = x < 0 ? -x : x;
double y;
if(w < 2.2) {
double t = w * w;
int k = (int) t;
t -= k;
k *= 13;
y = ((((((((((((ERF_COEFF1[k] * t + ERF_COEFF1[k + 1]) * t + //
ERF_COEFF1[k + 2]) * t + ERF_COEFF1[k + 3]) * t + ERF_COEF... | java |
public static double standardNormalQuantile(double d) {
return (d == 0) ? Double.NEGATIVE_INFINITY : //
(d == 1) ? Double.POSITIVE_INFINITY : //
(Double.isNaN(d) || d < 0 || d > 1) ? Double.NaN //
: MathUtil.SQRT2 * -erfcinv(2 * d);
} | java |
@Override
public <N extends SpatialComparable> List<List<N>> partition(List<N> spatialObjects, int minEntries, int maxEntries) {
List<List<N>> partitions = new ArrayList<>();
List<N> objects = new ArrayList<>(spatialObjects);
while (!objects.isEmpty()) {
StringBuilder msg = new StringBuilder();
... | java |
private int chooseMaximalExtendedSplitAxis(List<? extends SpatialComparable> objects) {
// maximum and minimum value for the extension
int dimension = objects.get(0).getDimensionality();
double[] maxExtension = new double[dimension];
double[] minExtension = new double[dimension];
Arrays.fill(minExte... | java |
public void setTotal(int total) throws IllegalArgumentException {
if(getProcessed() > total) {
throw new IllegalArgumentException(getProcessed() + " exceeds total: " + total);
}
this.total = total;
} | java |
@SuppressWarnings("unchecked")
protected <T> T get(DBIDRef id, int index) {
Object[] d = data.get(DBIDUtil.deref(id));
if(d == null) {
return null;
}
return (T) d[index];
} | java |
@SuppressWarnings("unchecked")
protected <T> T set(DBIDRef id, int index, T value) {
Object[] d = data.get(DBIDUtil.deref(id));
if(d == null) {
d = new Object[rlen];
data.put(DBIDUtil.deref(id), d);
}
T ret = (T) d[index];
d[index] = value;
return ret;
} | java |
public UniformDistribution estimate(DoubleMinMax mm) {
return new UniformDistribution(Math.max(mm.getMin(), -Double.MAX_VALUE), Math.min(mm.getMax(), Double.MAX_VALUE));
} | java |
public static boolean canVisualize(Relation<?> rel, AbstractMTree<?, ?, ?, ?> tree) {
if(!TypeUtil.NUMBER_VECTOR_FIELD.isAssignableFromType(rel.getDataTypeInformation())) {
return false;
}
return getLPNormP(tree) > 0;
} | java |
void initializeRandomAttributes(SimpleTypeInformation<V> in) {
int d = ((VectorFieldTypeInformation<V>) in).getDimensionality();
selectedAttributes = BitsUtil.random(k, d, rnd.getSingleThreadedRandom());
} | java |
protected void singleEnsemble(final double[] ensemble, final NumberVector vec) {
double[] buf = new double[1];
for(int i = 0; i < ensemble.length; i++) {
buf[0] = vec.doubleValue(i);
ensemble[i] = voting.combine(buf, 1);
if(Double.isNaN(ensemble[i])) {
LOG.warning("NaN after combining:... | java |
public static String getFullDescription(Parameter<?> param) {
StringBuilder description = new StringBuilder(1000) //
.append(param.getShortDescription()).append(FormatUtil.NEWLINE);
param.describeValues(description);
if(!FormatUtil.endsWith(description, FormatUtil.NEWLINE)) {
description.appen... | java |
private static void println(StringBuilder buf, int width, String data) {
for(String line : FormatUtil.splitAtLastBlank(data, width)) {
buf.append(line);
if(!line.endsWith(FormatUtil.NEWLINE)) {
buf.append(FormatUtil.NEWLINE);
}
}
} | java |
public static int centroids(Relation<? extends NumberVector> rel, List<? extends Cluster<?>> clusters, NumberVector[] centroids, NoiseHandling noiseOption) {
assert (centroids.length == clusters.size());
int ignorednoise = 0;
Iterator<? extends Cluster<?>> ci = clusters.iterator();
for(int i = 0; ci.has... | java |
public static double cdf(double val, double rate) {
final double v = .5 * FastMath.exp(-rate * Math.abs(val));
return (v == Double.POSITIVE_INFINITY) ? ((val <= 0) ? 0 : 1) : //
(val < 0) ? v : 1 - v;
} | java |
protected double maxDistance(DoubleDBIDList elems) {
double max = 0;
for(DoubleDBIDListIter it = elems.iter(); it.valid(); it.advance()) {
final double v = it.doubleValue();
max = max > v ? max : v;
}
return max;
} | java |
protected void excludeNotCovered(ModifiableDoubleDBIDList candidates, double fmax, ModifiableDoubleDBIDList collect) {
for(DoubleDBIDListIter it = candidates.iter(); it.valid();) {
if(it.doubleValue() > fmax) {
collect.add(it.doubleValue(), it);
candidates.removeSwap(it.getOffset());
}
... | java |
protected void collectByCover(DBIDRef cur, ModifiableDoubleDBIDList candidates, double fmax, ModifiableDoubleDBIDList collect) {
assert (collect.size() == 0) : "Not empty";
DoubleDBIDListIter it = candidates.iter().advance(); // Except first = cur!
while(it.valid()) {
assert (!DBIDUtil.equal(cur, it))... | java |
private void process(double[] data, double min, double max, KernelDensityFunction kernel, int window, double epsilon) {
dens = new double[data.length];
var = new double[data.length];
// This is the desired bandwidth of the kernel.
double halfwidth = ((max - min) / window) * .5;
for (int current = ... | java |
public static double[] computeSimilarityMatrix(DependenceMeasure sim, Relation<? extends NumberVector> rel) {
final int dim = RelationUtil.dimensionality(rel);
// TODO: we could use less memory (no copy), but this would likely be
// slower. Maybe as a fallback option?
double[][] data = new double[dim][r... | java |
protected N buildSpanningTree(int dim, double[] mat, Layout layout) {
assert (layout.edges == null || layout.edges.size() == 0);
int[] iedges = PrimsMinimumSpanningTree.processDense(mat, new LowerTriangularAdapter(dim));
int root = findOptimalRoot(iedges);
// Convert edges:
ArrayList<Edge> edges = ... | java |
protected N buildTree(int[] msg, int cur, int parent, ArrayList<N> nodes) {
// Count the number of children:
int c = 0;
for(int i = 1; i < msg.length; i += 2) {
if((msg[i - 1] == cur && msg[i] != parent) || (msg[i] == cur && msg[i - 1] != parent)) {
c++;
}
}
// Build children:
... | java |
protected int maxDepth(Layout.Node node) {
int depth = 0;
for(int i = 0; i < node.numChildren(); i++) {
depth = Math.max(depth, maxDepth(node.getChild(i)));
}
return depth + 1;
} | java |
@Override
public void initialize() {
TreeIndexHeader header = createHeader();
if(this.file.initialize(header)) {
initializeFromFile(header, file);
}
rootEntry = createRootEntry();
} | java |
public N getNode(int nodeID) {
if(nodeID == getPageID(rootEntry)) {
return getRoot();
}
else {
return file.readPage(nodeID);
}
} | java |
public void initializeFromFile(TreeIndexHeader header, PageFile<N> file) {
this.dirCapacity = header.getDirCapacity();
this.leafCapacity = header.getLeafCapacity();
this.dirMinimum = header.getDirMinimum();
this.leafMinimum = header.getLeafMinimum();
if(getLogger().isDebugging()) {
StringBuil... | java |
protected final void initialize(E exampleLeaf) {
initializeCapacities(exampleLeaf);
// create empty root
createEmptyRoot(exampleLeaf);
final Logging log = getLogger();
if(log.isStatistics()) {
String cls = this.getClass().getName();
log.statistics(new LongStatistic(cls + ".directory.ca... | java |
public static MeanVarianceMinMax[] newArray(int dimensionality) {
MeanVarianceMinMax[] arr = new MeanVarianceMinMax[dimensionality];
for(int i = 0; i < dimensionality; i++) {
arr[i] = new MeanVarianceMinMax();
}
return arr;
} | java |
@Override
public double getWeight(double distance, double max, double stddev) {
if(stddev <= 0) {
return 1;
}
double scaleddistance = distance / stddev;
return stddev * FastMath.exp(-.5 * scaleddistance);
} | java |
protected static <A> int[] sortedIndex(final NumberArrayAdapter<?, A> adapter, final A data, int len) {
int[] s1 = MathUtil.sequence(0, len);
IntegerArrayQuickSort.sort(s1, (x, y) -> Double.compare(adapter.getDouble(data, x), adapter.getDouble(data, y)));
return s1;
} | java |
protected static <A> int[] discretize(NumberArrayAdapter<?, A> adapter, A data, final int len, final int bins) {
double min = adapter.getDouble(data, 0), max = min;
for(int i = 1; i < len; i++) {
double v = adapter.getDouble(data, i);
if(v < min) {
min = v;
}
else if(v > max) {
... | java |
protected void finishGridRow() {
GridBagConstraints constraints = new GridBagConstraints();
constraints.gridwidth = GridBagConstraints.REMAINDER;
constraints.weightx = 0;
final JLabel icon;
if(param.isOptional()) {
if(param.isDefined() && param.tookDefaultValue() && !(param instanceof Flag)) {... | java |
private double normalize(int d, double val) {
d = (mean.length == 1) ? 0 : d;
return (val - mean[d]) / stddev[d];
} | java |
private static EigenPair[] processDecomposition(EigenvalueDecomposition evd) {
double[] eigenvalues = evd.getRealEigenvalues();
double[][] eigenvectors = evd.getV();
EigenPair[] eigenPairs = new EigenPair[eigenvalues.length];
for(int i = 0; i < eigenvalues.length; i++) {
double e = Math.abs(eigen... | java |
public void nextIteration(double[][] means) {
this.means = means;
changed = false;
final int k = means.length;
final int dim = means[0].length;
centroids = new double[k][dim];
sizes = new int[k];
Arrays.fill(varsum, 0.);
} | java |
public double[][] getMeans() {
double[][] newmeans = new double[centroids.length][];
for(int i = 0; i < centroids.length; i++) {
if(sizes[i] == 0) {
newmeans[i] = means[i]; // Keep old mean.
continue;
}
newmeans[i] = centroids[i];
}
return newmeans;
} | java |
public static String format(double[] v, int w, int d) {
DecimalFormat format = new DecimalFormat();
format.setDecimalFormatSymbols(new DecimalFormatSymbols(Locale.US));
format.setMinimumIntegerDigits(1);
format.setMaximumFractionDigits(d);
format.setMinimumFractionDigits(d);
format.setGroupingUs... | java |
public static StringBuilder formatTo(StringBuilder buf, double[] d, String sep) {
if(d == null) {
return buf.append("null");
}
if(d.length == 0) {
return buf;
}
buf.append(d[0]);
for(int i = 1; i < d.length; i++) {
buf.append(sep).append(d[i]);
}
return buf;
} | java |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.