本文整理汇总了Java中de.lmu.ifi.dbs.elki.database.relation.Relation类的典型用法代码示例。如果您正苦于以下问题:Java Relation类的具体用法?Java Relation怎么用?Java Relation使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Relation类属于de.lmu.ifi.dbs.elki.database.relation包,在下文中一共展示了Relation类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testVariance
import de.lmu.ifi.dbs.elki.database.relation.Relation; //导入依赖的package包/类
/**
* Test cluster variance.
*/
@Test
public void testVariance() {
Database db = makeSimpleDatabase(UNITTEST + "quality-measure-test.csv", 7);
Relation<DoubleVector> rel = db.getRelation(TypeUtil.DOUBLE_VECTOR_FIELD);
// Setup algorithm
KMeansLloyd<DoubleVector> kmeans = new ELKIBuilder<KMeansLloyd<DoubleVector>>(KMeansLloyd.class) //
.with(KMeans.K_ID, 2) //
.with(KMeans.INIT_ID, FirstKInitialMeans.class) //
.build();
// run KMeans on database
Clustering<KMeansModel> result = kmeans.run(db);
// Test Cluster Variance
KMeansQualityMeasure<? super DoubleVector> variance = new WithinClusterVarianceQualityMeasure();
final NumberVectorDistanceFunction<? super DoubleVector> dist = kmeans.getDistanceFunction();
final double quality = variance.quality(result, dist, rel);
assertEquals("Within cluster variance incorrect", 3.16666666666, quality, 1e-10);
}
示例2: runDBSCAN
import de.lmu.ifi.dbs.elki.database.relation.Relation; //导入依赖的package包/类
/**
* Run the DBSCAN algorithm
*
* @param relation Data relation
* @param rangeQuery Range query class
*/
protected void runDBSCAN(Relation<O> relation, RangeQuery<O> rangeQuery) {
final int size = relation.size();
FiniteProgress objprog = LOG.isVerbose() ? new FiniteProgress("Processing objects", size, LOG) : null;
IndefiniteProgress clusprog = LOG.isVerbose() ? new IndefiniteProgress("Number of clusters", LOG) : null;
processedIDs = DBIDUtil.newHashSet(size);
ArrayModifiableDBIDs seeds = DBIDUtil.newArray();
for(DBIDIter iditer = relation.iterDBIDs(); iditer.valid(); iditer.advance()) {
if(!processedIDs.contains(iditer)) {
expandCluster(relation, rangeQuery, iditer, seeds, objprog, clusprog);
}
if(objprog != null && clusprog != null) {
objprog.setProcessed(processedIDs.size(), LOG);
clusprog.setProcessed(resultList.size(), LOG);
}
if(processedIDs.size() == size) {
break;
}
}
// Finish progress logging
LOG.ensureCompleted(objprog);
LOG.setCompleted(clusprog);
}
示例3: buildDB
import de.lmu.ifi.dbs.elki.database.relation.Relation; //导入依赖的package包/类
/**
* Builds a dim-1 dimensional database where the objects are projected into
* the specified subspace.
*
* @param dim the dimensionality of the database
* @param basis the basis defining the subspace
* @param ids the ids for the new database
* @param relation the database storing the parameterization functions
* @return a dim-1 dimensional database where the objects are projected into
* the specified subspace
*/
private MaterializedRelation<ParameterizationFunction> buildDB(int dim, double[][] basis, DBIDs ids, Relation<ParameterizationFunction> relation) {
ProxyDatabase proxy = new ProxyDatabase(ids);
SimpleTypeInformation<ParameterizationFunction> type = new SimpleTypeInformation<>(ParameterizationFunction.class);
WritableDataStore<ParameterizationFunction> prep = DataStoreUtil.makeStorage(ids, DataStoreFactory.HINT_HOT, ParameterizationFunction.class);
// Project
for(DBIDIter iter = ids.iter(); iter.valid(); iter.advance()) {
prep.put(iter, project(basis, relation.get(iter)));
}
if(LOG.isDebugging()) {
LOG.debugFine("db fuer dim " + (dim - 1) + ": " + ids.size());
}
MaterializedRelation<ParameterizationFunction> prel = new MaterializedRelation<>(type, ids, null, prep);
proxy.addRelation(prel);
return prel;
}
示例4: processNewResult
import de.lmu.ifi.dbs.elki.database.relation.Relation; //导入依赖的package包/类
@Override
public void processNewResult(ResultHierarchy hier, Result newResult) {
boolean nonefound = true;
List<Relation<?>> rels = ResultUtil.getRelations(newResult);
for(Relation<?> rel : rels) {
if(!TypeUtil.NUMBER_VECTOR_FIELD.isAssignableFromType(rel.getDataTypeInformation())) {
continue;
}
@SuppressWarnings("unchecked")
Relation<? extends O> vrel = (Relation<? extends O>) rel;
ScalesResult scales = ScalesResult.getScalesResult(vrel);
ProjectionParallel proj = new SimpleParallel(null, scales.getScales());
PropertiesBasedStyleLibrary stylelib = new PropertiesBasedStyleLibrary();
StylingPolicy stylepol = getStylePolicy(hier, stylelib);
new Instance<>(vrel, proj, settings, stylepol, stylelib).run();
nonefound = false;
}
if(nonefound && hier.equals(newResult)) {
LOG.warning("3DPC did not find a number vector field relation to visualize!");
}
}
示例5: updateDistances
import de.lmu.ifi.dbs.elki.database.relation.Relation; //导入依赖的package包/类
/**
* Compute the distances of each object to all means. Update
* {@link Meta#secondary} to point to the best cluster number except the
* current cluster assignment
*
* @param relation Data relation
* @param means Means
* @param metas Metadata storage
* @param df Distance function
*/
protected void updateDistances(Relation<V> relation, double[][] means, final WritableDataStore<Meta> metas, NumberVectorDistanceFunction<? super V> df) {
for(DBIDIter id = relation.iterDBIDs(); id.valid(); id.advance()) {
Meta c = metas.get(id);
V fv = relation.get(id);
// Update distances to means.
c.secondary = -1;
for(int i = 0; i < k; i++) {
c.dists[i] = df.distance(fv, DoubleVector.wrap(means[i]));
if(c.primary != i) {
if(c.secondary < 0 || c.dists[i] < c.dists[c.secondary]) {
c.secondary = i;
}
}
}
metas.put(id, c); // Changed.
}
}
示例6: run
import de.lmu.ifi.dbs.elki.database.relation.Relation; //导入依赖的package包/类
public Result run(Database database, Relation<V> relation) {
DistanceQuery<V> distQuery = database.getDistanceQuery(relation, getDistanceFunction());
RangeQuery<V> rangeQuery = database.getRangeQuery(distQuery, radius);
MeanVariance numres = new MeanVariance();
final DBIDs ids = DBIDUtil.randomSample(relation.getDBIDs(), sampling, random);
FiniteProgress prog = LOG.isVerbose() ? new FiniteProgress("Performing range queries", ids.size(), LOG) : null;
for(DBIDIter iter = ids.iter(); iter.valid(); iter.advance()) {
numres.put(rangeQuery.getRangeForDBID(iter, radius).size());
LOG.incrementProcessed(prog);
}
LOG.ensureCompleted(prog);
final String prefix = this.getClass().getName();
LOG.statistics(new DoubleStatistic(prefix + ".mean", numres.getMean()));
LOG.statistics(new DoubleStatistic(prefix + ".std", numres.getSampleStddev()));
LOG.statistics(new DoubleStatistic(prefix + ".norm.mean", numres.getMean() / relation.size()));
LOG.statistics(new DoubleStatistic(prefix + ".norm.std", numres.getSampleStddev() / relation.size()));
LOG.statistics(new LongStatistic(prefix + ".samplesize", ids.size()));
return null;
}
示例7: run
import de.lmu.ifi.dbs.elki.database.relation.Relation; //导入依赖的package包/类
/**
* Performs the Generalized LOF_SCORE algorithm on the given database by
* calling {@code #doRunInTime(Database)} and adds a {@link LOFKNNListener} to
* the preprocessors.
*/
@Override
public OutlierResult run(Database database, Relation<O> relation) {
StepProgress stepprog = LOG.isVerbose() ? new StepProgress("OnlineLOF", 3) : null;
Pair<Pair<KNNQuery<O>, KNNQuery<O>>, Pair<RKNNQuery<O>, RKNNQuery<O>>> queries = getKNNAndRkNNQueries(database, relation, stepprog);
KNNQuery<O> kNNRefer = queries.getFirst().getFirst();
KNNQuery<O> kNNReach = queries.getFirst().getSecond();
RKNNQuery<O> rkNNRefer = queries.getSecond().getFirst();
RKNNQuery<O> rkNNReach = queries.getSecond().getSecond();
LOFResult<O> lofResult = super.doRunInTime(relation.getDBIDs(), kNNRefer, kNNReach, stepprog);
lofResult.setRkNNRefer(rkNNRefer);
lofResult.setRkNNReach(rkNNReach);
// add listener
KNNListener l = new LOFKNNListener(lofResult);
((MaterializeKNNPreprocessor<O>) ((PreprocessorKNNQuery<O>) lofResult.getKNNRefer()).getPreprocessor()).addKNNListener(l);
((MaterializeKNNPreprocessor<O>) ((PreprocessorKNNQuery<O>) lofResult.getKNNReach()).getPreprocessor()).addKNNListener(l);
return lofResult.getResult();
}
示例8: computeOutlierScores
import de.lmu.ifi.dbs.elki.database.relation.Relation; //导入依赖的package包/类
@Override
protected DoubleDataStore computeOutlierScores(Database database, Relation<O> relation, double d) {
DistanceQuery<O> distFunc = database.getDistanceQuery(relation, getDistanceFunction());
RangeQuery<O> rangeQuery = database.getRangeQuery(distFunc);
final double size = distFunc.getRelation().size();
WritableDoubleDataStore scores = DataStoreUtil.makeDoubleStorage(distFunc.getRelation().getDBIDs(), DataStoreFactory.HINT_STATIC);
FiniteProgress prog = LOG.isVerbose() ? new FiniteProgress("DBOutlier scores", distFunc.getRelation().size(), LOG) : null;
// TODO: use bulk when implemented.
for(DBIDIter iditer = distFunc.getRelation().iterDBIDs(); iditer.valid(); iditer.advance()) {
// compute percentage of neighbors in the given neighborhood with size d
double n = rangeQuery.getRangeForDBID(iditer, d).size() / size;
scores.putDouble(iditer, 1.0 - n);
LOG.incrementProcessed(prog);
}
LOG.ensureCompleted(prog);
return scores;
}
示例9: exactMinMax
import de.lmu.ifi.dbs.elki.database.relation.Relation; //导入依赖的package包/类
/**
* Compute the exact maximum and minimum.
*
* @param relation Relation to process
* @param distFunc Distance function
* @return Exact maximum and minimum
*/
private DoubleMinMax exactMinMax(Relation<O> relation, DistanceQuery<O> distFunc) {
final FiniteProgress progress = LOG.isVerbose() ? new FiniteProgress("Exact fitting distance computations", relation.size(), LOG) : null;
DoubleMinMax minmax = new DoubleMinMax();
// find exact minimum and maximum first.
for(DBIDIter iditer = relation.iterDBIDs(); iditer.valid(); iditer.advance()) {
for(DBIDIter iditer2 = relation.iterDBIDs(); iditer2.valid(); iditer2.advance()) {
// skip the point itself.
if(DBIDUtil.equal(iditer, iditer2)) {
continue;
}
double d = distFunc.distance(iditer, iditer2);
minmax.put(d);
}
LOG.incrementProcessed(progress);
}
LOG.ensureCompleted(progress);
return minmax;
}
示例10: getBundle
import de.lmu.ifi.dbs.elki.database.relation.Relation; //导入依赖的package包/类
@Override
public SingleObjectBundle getBundle(DBIDRef id) {
assert (id != null);
// TODO: ensure that the ID actually exists in the database?
try {
// Build an object package
SingleObjectBundle ret = new SingleObjectBundle();
for(Relation<?> relation : relations) {
ret.append(relation.getDataTypeInformation(), relation.get(id));
}
return ret;
}
catch(RuntimeException e) {
if(id == null) {
throw new UnsupportedOperationException("AbstractDatabase.getPackage(null) called!");
}
// throw e upwards.
throw e;
}
}
示例11: projectedEnergy
import de.lmu.ifi.dbs.elki.database.relation.Relation; //导入依赖的package包/类
/**
* Computes the projected energy of the specified clusters. The projected
* energy is given by the mean square distance of the points to the centroid
* of the union cluster c, when all points in c are projected to the subspace
* of c.
*
* @param relation the relation holding the objects
* @param c_i the first cluster
* @param c_j the second cluster
* @param i the index of cluster c_i in the cluster list
* @param j the index of cluster c_j in the cluster list
* @param dim the dimensionality of the clusters
* @return the projected energy of the specified cluster
*/
private ProjectedEnergy projectedEnergy(Relation<V> relation, ORCLUSCluster c_i, ORCLUSCluster c_j, int i, int j, int dim) {
NumberVectorDistanceFunction<? super V> distFunc = SquaredEuclideanDistanceFunction.STATIC;
// union of cluster c_i and c_j
ORCLUSCluster c_ij = union(relation, c_i, c_j, dim);
double sum = 0.;
NumberVector c_proj = DoubleVector.wrap(project(c_ij, c_ij.centroid));
for(DBIDIter iter = c_ij.objectIDs.iter(); iter.valid(); iter.advance()) {
NumberVector o_proj = DoubleVector.wrap(project(c_ij, relation.get(iter).toArray()));
sum += distFunc.distance(o_proj, c_proj);
}
sum /= c_ij.objectIDs.size();
return new ProjectedEnergy(i, j, c_ij, sum);
}
示例12: evaluateClusters
import de.lmu.ifi.dbs.elki.database.relation.Relation; //导入依赖的package包/类
/**
* Evaluates the quality of the clusters.
*
* @param clusters the clusters to be evaluated
* @param dimensions the dimensions associated with each cluster
* @param database the database holding the objects
* @return a measure for the cluster quality
*/
private double evaluateClusters(ArrayList<PROCLUSCluster> clusters, long[][] dimensions, Relation<V> database) {
double result = 0;
for(int i = 0; i < dimensions.length; i++) {
PROCLUSCluster c_i = clusters.get(i);
double[] centroid_i = c_i.centroid;
long[] dims_i = dimensions[i];
double w_i = 0;
for(int d = BitsUtil.nextSetBit(dims_i, 0); d >= 0; d = BitsUtil.nextSetBit(dims_i, d + 1)) {
w_i += avgDistance(centroid_i, c_i.objectIDs, database, d);
}
w_i /= dimensions.length;
result += c_i.objectIDs.size() * w_i;
}
return result / database.size();
}
示例13: computeNeighborhoods
import de.lmu.ifi.dbs.elki.database.relation.Relation; //导入依赖的package包/类
/**
* Compute neighborhoods
*
* @param relation
* @param knnQuery
* @param pruned
* @param knns
* @param rnns
* @param density
*/
protected void computeNeighborhoods(Relation<O> relation, KNNQuery<O> knnQuery, ModifiableDBIDs pruned, WritableDataStore<ModifiableDBIDs> knns, WritableDataStore<ModifiableDBIDs> rnns, WritableDoubleDataStore density) {
for(DBIDIter iter = relation.iterDBIDs(); iter.valid(); iter.advance()) {
// if not visited count=0
int count = rnns.get(iter).size();
DBIDs knn = getKNN(iter, knnQuery, knns, density);
for(DBIDIter niter = knn.iter(); niter.valid(); niter.advance()) {
// Ignore the query point itself.
if(DBIDUtil.equal(iter, niter)) {
continue;
}
if(getKNN(niter, knnQuery, knns, density).contains(iter)) {
rnns.get(niter).add(iter);
rnns.get(iter).add(niter);
count++;
}
}
if(count >= knn.size() * m) {
pruned.add(iter);
}
}
}
示例14: newContext
import de.lmu.ifi.dbs.elki.database.relation.Relation; //导入依赖的package包/类
/**
* Make a new visualization context
*
* @param hier Result hierarchy
* @param start Starting result
* @return New context
*/
public VisualizerContext newContext(ResultHierarchy hier, Result start) {
Collection<Relation<?>> rels = ResultUtil.filterResults(hier, Relation.class);
for(Relation<?> rel : rels) {
if(samplesize == 0) {
continue;
}
if(!ResultUtil.filterResults(hier, rel, SamplingResult.class).isEmpty()) {
continue;
}
if(rel.size() > samplesize) {
SamplingResult sample = new SamplingResult(rel);
sample.setSample(DBIDUtil.randomSample(sample.getSample(), samplesize, rnd));
ResultUtil.addChildResult(rel, sample);
}
}
return new VisualizerContext(hier, start, stylelib, factories);
}
示例15: run
import de.lmu.ifi.dbs.elki.database.relation.Relation; //导入依赖的package包/类
/**
* Run CASH on the relation.
*
* @param database Database
* @param vrel Relation
* @return Clustering result
*/
public Clustering<Model> run(Database database, Relation<V> vrel) {
fulldatabase = preprocess(database, vrel);
processedIDs = DBIDUtil.newHashSet(fulldatabase.size());
noiseDim = dimensionality(fulldatabase);
FiniteProgress progress = LOG.isVerbose() ? new FiniteProgress("CASH Clustering", fulldatabase.size(), LOG) : null;
Clustering<Model> result = doRun(fulldatabase, progress);
LOG.ensureCompleted(progress);
if(LOG.isVerbose()) {
StringBuilder msg = new StringBuilder(1000);
for(Cluster<Model> c : result.getAllClusters()) {
if(c.getModel() instanceof LinearEquationModel) {
LinearEquationModel s = (LinearEquationModel) c.getModel();
msg.append("\n Cluster: Dim: " + s.getLes().subspacedim() + " size: " + c.size());
}
else {
msg.append("\n Cluster: " + c.getModel().getClass().getName() + " size: " + c.size());
}
}
LOG.verbose(msg.toString());
}
return result;
}