本文整理汇总了Java中de.lmu.ifi.dbs.elki.database.relation.RelationUtil.dimensionality方法的典型用法代码示例。如果您正苦于以下问题:Java RelationUtil.dimensionality方法的具体用法?Java RelationUtil.dimensionality怎么用?Java RelationUtil.dimensionality使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类de.lmu.ifi.dbs.elki.database.relation.RelationUtil
的用法示例。
在下文中一共展示了RelationUtil.dimensionality方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: make
import de.lmu.ifi.dbs.elki.database.relation.RelationUtil; //导入方法依赖的package包/类
/**
* Static constructor from an existing relation.
*
* @param relation Relation to use
* @param ids IDs to use
* @return Centroid
*/
public static Centroid make(Relation<? extends NumberVector> relation, DBIDs ids) {
final int dim = RelationUtil.dimensionality(relation);
Centroid c = new Centroid(dim);
double[] elems = c.elements;
int count = 0;
for(DBIDIter iter = ids.iter(); iter.valid(); iter.advance()) {
NumberVector v = relation.get(iter);
for(int i = 0; i < dim; i++) {
elems[i] += v.doubleValue(i);
}
count += 1;
}
if(count == 0) {
return c;
}
for(int i = 0; i < dim; i++) {
elems[i] /= count;
}
c.wsum = count;
return c;
}
示例2: splitCentroid
import de.lmu.ifi.dbs.elki.database.relation.RelationUtil; //导入方法依赖的package包/类
/**
* Split an existing centroid into two initial centers.
*
* @param parentCluster Existing cluster
* @param relation Data relation
* @return List of new centroids
*/
protected double[][] splitCentroid(Cluster<? extends MeanModel> parentCluster, Relation<V> relation) {
double[] parentCentroid = parentCluster.getModel().getMean();
// Compute size of cluster/region
double radius = 0.;
for(DBIDIter it = parentCluster.getIDs().iter(); it.valid(); it.advance()) {
double d = getDistanceFunction().distance(relation.get(it), DoubleVector.wrap(parentCentroid));
radius = (d > radius) ? d : radius;
}
// Choose random vector
Random random = rnd.getSingleThreadedRandom();
final int dim = RelationUtil.dimensionality(relation);
double[] randomVector = normalize(MathUtil.randomDoubleArray(dim, random));
timesEquals(randomVector, (.4 + random.nextDouble() * .5) * radius);
// Get the new centroids
double[][] vecs = new double[2][];
vecs[0] = minus(parentCentroid, randomVector);
vecs[1] = plusEquals(randomVector, parentCentroid);
return vecs;
}
示例3: ZCurveTransformer
import de.lmu.ifi.dbs.elki.database.relation.RelationUtil; //导入方法依赖的package包/类
/**
* Constructor.
*
* @param relation Relation to transform
* @param ids IDs subset to process
*/
public ZCurveTransformer(Relation<? extends NumberVector> relation, DBIDs ids) {
this.dimensionality = RelationUtil.dimensionality(relation);
this.minValues = new double[dimensionality];
this.maxValues = new double[dimensionality];
// Compute scaling of vector space
Arrays.fill(minValues, Double.POSITIVE_INFINITY);
Arrays.fill(maxValues, Double.NEGATIVE_INFINITY);
for (DBIDIter iter = ids.iter(); iter.valid(); iter.advance()) {
NumberVector vector = relation.get(iter);
for(int dim = 0; dim < dimensionality; ++dim) {
double dimValue = vector.doubleValue(dim);
minValues[dim] = Math.min(minValues[dim], dimValue);
maxValues[dim] = Math.max(maxValues[dim], dimValue);
}
}
}
示例4: run
import de.lmu.ifi.dbs.elki.database.relation.RelationUtil; //导入方法依赖的package包/类
/**
* Process a relation.
*
* @param relation Data relation
* @return Change points
*/
public ChangePoints run(Relation<NumberVector> relation) {
if(!(relation.getDBIDs() instanceof ArrayDBIDs)) {
throw new AbortException("This implementation may only be used on static databases, with ArrayDBIDs to provide a clear order.");
}
final ArrayDBIDs ids = (ArrayDBIDs) relation.getDBIDs();
final int dim = RelationUtil.dimensionality(relation);
ewma = new double[dim];
ewmv = new double[dim];
weight = 0.;
ChangePoints changepoints = new ChangePoints("Signi-Trend Changepoints", "signitrend-changepoints");
WritableDoubleDataStore vals = DataStoreUtil.makeDoubleStorage(ids, DataStoreFactory.HINT_DB | DataStoreFactory.HINT_SORTED | DataStoreFactory.HINT_STATIC);
DoubleMinMax mm = new DoubleMinMax();
for(DBIDIter iter = relation.iterDBIDs(); iter.valid(); iter.advance()) {
double absmax = processRow(iter, relation.get(iter), changepoints);
vals.putDouble(iter, absmax); // Store absolute maximum
mm.put(absmax);
}
OutlierScoreMeta meta = new BasicOutlierScoreMeta(mm.getMin(), mm.getMax(), 0, Double.POSITIVE_INFINITY, 0.);
DoubleRelation scores = new MaterializedDoubleRelation("Signi-Trend scores", "signitrend-scores", vals, relation.getDBIDs());
changepoints.addChildResult(new OutlierResult(meta, scores));
return changepoints;
}
示例5: testSorting
import de.lmu.ifi.dbs.elki.database.relation.RelationUtil; //导入方法依赖的package包/类
@Test
public void testSorting() {
Database db = AbstractSimpleAlgorithmTest.makeSimpleDatabase(filename, -1);
Relation<? extends NumberVector> rel = db.getRelation(TypeUtil.NUMBER_VECTOR_FIELD);
ArrayModifiableDBIDs ids = DBIDUtil.newArray(rel.getDBIDs());
final int size = rel.size();
int dims = RelationUtil.dimensionality(rel);
SortDBIDsBySingleDimension sorter = new VectorUtil.SortDBIDsBySingleDimension(rel);
for(int d = 0; d < dims; d++) {
sorter.setDimension(d);
ids.sort(sorter);
assertEquals("Lost some DBID during sorting?!?", size, DBIDUtil.newHashSet(ids).size());
DBIDArrayIter it = ids.iter();
double prev = rel.get(it).doubleValue(d);
for(it.advance(); it.valid(); it.advance()) {
double next = rel.get(it).doubleValue(d);
assertTrue("Not correctly sorted: " + prev + " > " + next + " at pos " + it.getOffset(), prev <= next);
prev = next;
}
}
}
示例6: run
import de.lmu.ifi.dbs.elki.database.relation.RelationUtil; //导入方法依赖的package包/类
/**
* Runs the VOV algorithm on the given database.
*
* @param database Database to query
* @param relation Data to process
* @return VOV outlier result
*/
public OutlierResult run(Database database, Relation<O> relation) {
StepProgress stepprog = LOG.isVerbose() ? new StepProgress("VOV", 3) : null;
DBIDs ids = relation.getDBIDs();
int dim = RelationUtil.dimensionality(relation);
LOG.beginStep(stepprog, 1, "Materializing nearest-neighbor sets.");
KNNQuery<O> knnq = DatabaseUtil.precomputedKNNQuery(database, relation, getDistanceFunction(), k);
// Compute Volumes
LOG.beginStep(stepprog, 2, "Computing Volumes.");
WritableDoubleDataStore vols = DataStoreUtil.makeDoubleStorage(ids, DataStoreFactory.HINT_HOT | DataStoreFactory.HINT_TEMP);
computeVolumes(knnq, dim, ids, vols);
// compute VOV of each object
LOG.beginStep(stepprog, 3, "Computing Variance of Volumes (VOV).");
WritableDoubleDataStore vovs = DataStoreUtil.makeDoubleStorage(ids, DataStoreFactory.HINT_HOT | DataStoreFactory.HINT_DB);
// track the maximum value for normalization.
DoubleMinMax vovminmax = new DoubleMinMax();
computeVOVs(knnq, ids, vols, vovs, vovminmax);
LOG.setCompleted(stepprog);
// Build result representation.
DoubleRelation scoreResult = new MaterializedDoubleRelation("Variance of Volume", "vov-outlier", vovs, ids);
OutlierScoreMeta scoreMeta = new BasicOutlierScoreMeta(vovminmax.getMin(), vovminmax.getMax(), 0.0, Double.POSITIVE_INFINITY, 0.0);
return new OutlierResult(scoreMeta, scoreResult);
}
示例7: initialize
import de.lmu.ifi.dbs.elki.database.relation.RelationUtil; //导入方法依赖的package包/类
@Override
public void initialize() {
sorted = DBIDUtil.newDistanceDBIDList(relation.size());
dims = RelationUtil.dimensionality(relation);
for(DBIDIter it = relation.iterDBIDs(); it.valid(); it.advance()) {
sorted.add(Double.NaN, it);
}
buildTree(0, sorted.size(), 0, sorted.iter());
}
示例8: KernelDensityEstimator
import de.lmu.ifi.dbs.elki.database.relation.RelationUtil; //导入方法依赖的package包/类
/**
* Constructor.
*
* @param relation Relation to apply to
*/
public KernelDensityEstimator(Relation<V> relation) {
super();
this.relation = relation;
dim = RelationUtil.dimensionality(relation);
hopttwo = optimalBandwidth(2);
epsilons = new double[dim + 1];
Arrays.fill(epsilons, Double.NEGATIVE_INFINITY);
epsilons[2] = OUTRES.this.eps;
}
示例9: logLikelihoodAlternate
import de.lmu.ifi.dbs.elki.database.relation.RelationUtil; //导入方法依赖的package包/类
/**
* Computes log likelihood of an entire clustering.
*
* Version as used by Zhao et al.
*
* @param relation Data relation
* @param clustering Clustering
* @param distanceFunction Distance function
* @param <V> Vector type
* @return Log Likelihood.
*/
@Reference(authors = "Q. Zhao, M. Xu, P. Fränti", //
title = "Knee Point Detection on Bayesian Information Criterion", //
booktitle = "20th IEEE International Conference on Tools with Artificial Intelligence", //
url = "http://dx.doi.org/10.1109/ICTAI.2008.154")
public static <V extends NumberVector> double logLikelihoodAlternate(Relation<V> relation, Clustering<? extends MeanModel> clustering, NumberVectorDistanceFunction<? super V> distanceFunction) {
List<? extends Cluster<? extends MeanModel>> clusters = clustering.getAllClusters();
// dimensionality of data points
final int dim = RelationUtil.dimensionality(relation);
// number of clusters
final int m = clusters.size();
// number of objects in the clustering
int n = 0;
// cluster sizes
int[] n_i = new int[m];
// variances
double[] d_i = new double[m];
// Iterate over clusters:
Iterator<? extends Cluster<? extends MeanModel>> it = clusters.iterator();
for(int i = 0; it.hasNext(); ++i) {
Cluster<? extends MeanModel> cluster = it.next();
n += n_i[i] = cluster.size();
d_i[i] = varianceOfCluster(cluster, distanceFunction, relation);
}
// log likelihood of this clustering
double logLikelihood = 0.;
// Aggregate
for(int i = 0; i < m; i++) {
logLikelihood += n_i[i] * FastMath.log(n_i[i] / (double) n) // ni log ni/n
- n_i[i] * dim * .5 * MathUtil.LOGTWOPI // ni*d/2 log2pi
- n_i[i] * .5 * FastMath.log(d_i[i]) // ni/2 log sigma_i
- (n_i[i] - m) * .5; // (ni-m)/2
}
return logLikelihood;
}
示例10: dimensionality
import de.lmu.ifi.dbs.elki.database.relation.RelationUtil; //导入方法依赖的package包/类
/**
* Ugly hack to allow using this implementation without having a well-defined
* dimensionality.
*
* @param rel Data relation
* @return Dimensionality
*/
private int dimensionality(Relation<O> rel) {
// Explicit:
if(idim >= 0) {
return idim;
}
// Cast to vector field relation.
@SuppressWarnings("unchecked")
final Relation<NumberVector> frel = (Relation<NumberVector>) rel;
int dim = RelationUtil.dimensionality(frel);
if(dim < 1) {
throw new AbortException("When using KDEOS with non-vectorspace data, the intrinsic dimensionality parameter must be set!");
}
return dim;
}
示例11: buildRanges
import de.lmu.ifi.dbs.elki.database.relation.RelationUtil; //导入方法依赖的package包/类
/**
* Grid discretization of the data:<br />
* Each attribute of data is divided into phi equi-depth ranges.<br />
* Each range contains a fraction f=1/phi of the records.
*
* @param relation Relation to process
* @return range map
*/
protected ArrayList<ArrayList<DBIDs>> buildRanges(Relation<V> relation) {
final int dim = RelationUtil.dimensionality(relation);
final int size = relation.size();
final ArrayList<ArrayList<DBIDs>> ranges = new ArrayList<>();
ArrayModifiableDBIDs ids = DBIDUtil.newArray(relation.getDBIDs());
SortDBIDsBySingleDimension sorter = new SortDBIDsBySingleDimension(relation);
// Split into cells
final double part = size * 1.0 / phi;
for(int d = 0; d < dim; d++) {
sorter.setDimension(d);
ids.sort(sorter);
ArrayList<DBIDs> dimranges = new ArrayList<>(phi + 1);
int start = 0;
DBIDArrayIter iter = ids.iter();
for(int r = 1; r <= phi; r++) {
int end = (r < phi) ? (int) (part * r) : size;
ArrayModifiableDBIDs currange = DBIDUtil.newArray(end - start);
for(iter.seek(start); iter.getOffset() < end; iter.advance()) {
currange.add(iter);
}
start = end;
dimranges.add(currange);
}
ranges.add(dimranges);
}
return ranges;
}
示例12: findDimensions
import de.lmu.ifi.dbs.elki.database.relation.RelationUtil; //导入方法依赖的package包/类
/**
* Refinement step that determines the set of correlated dimensions for each
* cluster centroid.
*
* @param clusters the list of clusters
* @param database the database containing the objects
* @return the set of correlated dimensions for each specified cluster
* centroid
*/
private List<Pair<double[], long[]>> findDimensions(ArrayList<PROCLUSCluster> clusters, Relation<V> database) {
// compute x_ij = avg distance from points in c_i to c_i.centroid
final int dim = RelationUtil.dimensionality(database);
final int numc = clusters.size();
double[][] averageDistances = new double[numc][];
for(int i = 0; i < numc; i++) {
PROCLUSCluster c_i = clusters.get(i);
double[] x_i = new double[dim];
for(DBIDIter iter = c_i.objectIDs.iter(); iter.valid(); iter.advance()) {
V o = database.get(iter);
for(int d = 0; d < dim; d++) {
x_i[d] += Math.abs(c_i.centroid[d] - o.doubleValue(d));
}
}
for(int d = 0; d < dim; d++) {
x_i[d] /= c_i.objectIDs.size();
}
averageDistances[i] = x_i;
}
List<DoubleIntInt> z_ijs = computeZijs(averageDistances, dim);
long[][] dimensionMap = computeDimensionMap(z_ijs, dim, numc);
// mapping cluster -> dimensions
List<Pair<double[], long[]>> result = new ArrayList<>(numc);
for(int i = 0; i < numc; i++) {
long[] dims_i = dimensionMap[i];
if(dims_i == null) {
continue;
}
result.add(new Pair<>(clusters.get(i).centroid, dims_i));
}
return result;
}
示例13: fullRedraw
import de.lmu.ifi.dbs.elki.database.relation.RelationUtil; //导入方法依赖的package包/类
@Override
public void fullRedraw() {
setupCanvas();
final StyleLibrary style = context.getStyleLibrary();
final StylingPolicy spol = context.getStylingPolicy();
final double size = style.getSize(StyleLibrary.MARKERPLOT);
final MarkerLibrary ml = style.markers();
// Only visualize cluster-based policies
if(!(spol instanceof ClusterStylingPolicy)) {
return;
}
ClusterStylingPolicy cspol = (ClusterStylingPolicy) spol;
Clustering<?> c = cspol.getClustering();
// If this is a sample from the uncertain database, it must have a parent
// relation containing vectors, which is a child to the uncertain
// database.
Relation<? extends NumberVector> srel = null;
boolean isChild = false;
for(It<Relation<?>> it = context.getHierarchy().iterAncestors(c).filter(Relation.class); it.valid(); it.advance()) {
Relation<?> r = it.get();
if(r == this.rel) {
isChild = true;
}
else {
final SimpleTypeInformation<?> type = r.getDataTypeInformation();
if(TypeUtil.NUMBER_VECTOR_FIELD.isAssignableFromType(type)) {
@SuppressWarnings("unchecked")
Relation<? extends NumberVector> vr = (Relation<? extends NumberVector>) r;
int dim = RelationUtil.dimensionality(vr);
if(dim == RelationUtil.dimensionality(this.rel)) {
srel = vr;
}
}
}
if(isChild && srel != null) {
break;
}
}
// Nothing found, probably in a different subtree.
if(!isChild || srel == null) {
return;
}
for(int cnum = cspol.getMinStyle(); cnum < cspol.getMaxStyle(); cnum++) {
for(DBIDIter iter = cspol.iterateClass(cnum); iter.valid(); iter.advance()) {
if(!sample.getSample().contains(iter)) {
continue; // TODO: can we test more efficiently than this?
}
try {
final NumberVector vec = srel.get(iter);
double[] v = proj.fastProjectDataToRenderSpace(vec);
if(v[0] != v[0] || v[1] != v[1]) {
continue; // NaN!
}
ml.useMarker(svgp, layer, v[0], v[1], cnum, size);
}
catch(ObjectNotFoundException e) {
// ignore.
}
}
}
}
示例14: initializeCapacities
import de.lmu.ifi.dbs.elki.database.relation.RelationUtil; //导入方法依赖的package包/类
@Override
protected void initializeCapacities(MTreeEntry exampleLeaf) {
int distanceSize = ByteArrayUtil.SIZE_DOUBLE; // exampleLeaf.getParentDistance().externalizableSize();
// FIXME: simulate a proper feature size!
@SuppressWarnings("unchecked")
Relation<? extends SpatialComparable> vrel = (Relation<? extends SpatialComparable>) relation;
final int dim = RelationUtil.dimensionality(vrel);
int featuresize = 8 * dim;
if(dim <= 0) {
getLogger().warning("Relation does not have a dimensionality -- simulating M-tree as external index!");
featuresize = 0;
}
// overhead = index(4), numEntries(4), id(4), isLeaf(0.125)
double overhead = 12.125;
if(getPageSize() - overhead < 0) {
throw new RuntimeException("Node size of " + getPageSize() + " Bytes is chosen too small!");
}
// dirCapacity = (pageSize - overhead) / (nodeID + objectID + coveringRadius
// + parentDistance) + 1
// dirCapacity = (int) (pageSize - overhead) / (4 + 4 + distanceSize +
// distanceSize) + 1;
// dirCapacity = (pageSize - overhead) / (nodeID + **object feature size** +
// coveringRadius + parentDistance) + 1
dirCapacity = (int) (getPageSize() - overhead) / (4 + featuresize + distanceSize + distanceSize) + 1;
if(dirCapacity <= 2) {
throw new RuntimeException("Node size of " + getPageSize() + " Bytes is chosen too small!");
}
if(dirCapacity < 10) {
getLogger().warning("Page size is choosen too small! Maximum number of entries " + "in a directory node = " + (dirCapacity - 1));
}
// leafCapacity = (pageSize - overhead) / (objectID + parentDistance) + 1
// leafCapacity = (int) (pageSize - overhead) / (4 + distanceSize) + 1;
// leafCapacity = (pageSize - overhead) / (objectID + ** object size ** +
// parentDistance) + 1
leafCapacity = (int) (getPageSize() - overhead) / (4 + featuresize + distanceSize) + 1;
if(leafCapacity <= 1) {
throw new RuntimeException("Node size of " + getPageSize() + " Bytes is chosen too small!");
}
if(leafCapacity < 10) {
getLogger().warning("Page size is choosen too small! Maximum number of entries " + "in a leaf node = " + (leafCapacity - 1));
}
}
示例15: run
import de.lmu.ifi.dbs.elki.database.relation.RelationUtil; //导入方法依赖的package包/类
/**
* Performs the ORCLUS algorithm on the given database.
*
* @param database Database
* @param relation Relation
*/
public Clustering<Model> run(Database database, Relation<V> relation) {
// current dimensionality associated with each seed
int dim_c = RelationUtil.dimensionality(relation);
if(dim_c < l) {
throw new IllegalStateException("Dimensionality of data < parameter l! " + "(" + dim_c + " < " + l + ")");
}
// current number of seeds
int k_c = Math.min(relation.size(), k_i * k);
// pick k0 > k points from the database
List<ORCLUSCluster> clusters = initialSeeds(relation, k_c);
double beta = FastMath.exp(-FastMath.log(dim_c / (double) l) * FastMath.log(1 / alpha) / FastMath.log(k_c / (double) k));
IndefiniteProgress cprogress = LOG.isVerbose() ? new IndefiniteProgress("Current number of clusters:", LOG) : null;
while(k_c > k) {
// find partitioning induced by the seeds of the clusters
assign(relation, clusters);
// determine current subspace associated with each cluster
for(ORCLUSCluster cluster : clusters) {
if(cluster.objectIDs.size() > 0) {
cluster.basis = findBasis(relation, cluster, dim_c);
}
}
// reduce number of seeds and dimensionality associated with
// each seed
k_c = (int) Math.max(k, k_c * alpha);
dim_c = (int) Math.max(l, dim_c * beta);
merge(relation, clusters, k_c, dim_c, cprogress);
if(cprogress != null) {
cprogress.setProcessed(clusters.size(), LOG);
}
}
assign(relation, clusters);
LOG.setCompleted(cprogress);
// get the result
Clustering<Model> r = new Clustering<>("ORCLUS clustering", "orclus-clustering");
for(ORCLUSCluster c : clusters) {
r.addToplevelCluster(new Cluster<Model>(c.objectIDs, ClusterModel.CLUSTER));
}
return r;
}