本文整理汇总了Java中de.lmu.ifi.dbs.elki.database.relation.RelationUtil类的典型用法代码示例。如果您正苦于以下问题:Java RelationUtil类的具体用法?Java RelationUtil怎么用?Java RelationUtil使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RelationUtil类属于de.lmu.ifi.dbs.elki.database.relation包,在下文中一共展示了RelationUtil类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getReferencePoints
import de.lmu.ifi.dbs.elki.database.relation.RelationUtil; //导入依赖的package包/类
@Override
public Collection<? extends NumberVector> getReferencePoints(Relation<? extends NumberVector> db) {
double[][] minmax = RelationUtil.computeMinMax(db);
int dim = RelationUtil.dimensionality(db);
// Compute mean and extend from minmax.
double[] mean = minmax[0], delta = minmax[1];
for(int d = 0; d < dim; d++) {
delta[d] -= mean[d];
mean[d] -= delta[d] * .5;
}
Random rand = rnd.getSingleThreadedRandom();
ArrayList<DoubleVector> result = new ArrayList<>(samplesize);
for(int i = 0; i < samplesize; i++) {
double[] vec = new double[dim];
for(int d = 0; d < dim; d++) {
vec[d] = mean[d] + (rand.nextDouble() - 0.5) * scale * delta[d];
}
result.add(DoubleVector.wrap(vec));
}
return result;
}
示例2: 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;
}
示例3: run
import de.lmu.ifi.dbs.elki.database.relation.RelationUtil; //导入依赖的package包/类
/**
* Run the change point detection algorithm on a data relation.
*
* @param relation Data relation.
* @return Change points
*/
public ChangePoints run(Relation<DoubleVector> relation) {
final ArrayDBIDs ids = (ArrayDBIDs) relation.getDBIDs();
final int dim = RelationUtil.dimensionality(relation);
final int size = ids.size();
iter = ids.iter();
column = new double[size];
sums = new double[size];
bstrap = new double[size];
result = new ChangePoints("CUSUM Changepoints", "cusum-changepoints");
for(columnnr = 0; columnnr < dim; columnnr++) {
// Materialize one column of the data.
for(iter.seek(0); iter.valid(); iter.advance()) {
column[iter.getOffset()] = relation.get(iter).doubleValue(columnnr);
}
cusum(column, sums, 0, size);
multipleChangepointsWithConfidence(0, size);
}
return result;
}
示例4: chooseInitialMeans
import de.lmu.ifi.dbs.elki.database.relation.RelationUtil; //导入依赖的package包/类
@Override
public <T extends NumberVector> double[][] chooseInitialMeans(Database database, Relation<T> relation, int k, NumberVectorDistanceFunction<? super T> distanceFunction) {
final int dim = RelationUtil.dimensionality(relation);
double[][] minmax = RelationUtil.computeMinMax(relation);
double[] min = minmax[0], scale = minmax[1];
for(int d = 0; d < dim; d++) {
scale[d] = scale[d] - min[d];
}
double[][] means = new double[k][];
final Random random = rnd.getSingleThreadedRandom();
for(int i = 0; i < k; i++) {
double[] r = MathUtil.randomDoubleArray(dim, random);
// Rescale
for(int d = 0; d < dim; d++) {
r[d] = min[d] + scale[d] * r[d];
}
means[i] = r;
}
return means;
}
示例5: 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;
}
示例6: determinePreferenceVector
import de.lmu.ifi.dbs.elki.database.relation.RelationUtil; //导入依赖的package包/类
/**
* Determines the preference vector according to the specified neighbor ids.
*
* @param relation the database storing the objects
* @param id the id of the object for which the preference vector should be
* determined
* @param neighborIDs the ids of the neighbors
* @param msg a string buffer for debug messages
* @return the preference vector
*/
private long[] determinePreferenceVector(Relation<V> relation, DBIDRef id, DBIDs neighborIDs, StringBuilder msg) {
// variances
double[] variances = RelationUtil.variances(relation, relation.get(id), neighborIDs);
// preference vector
long[] preferenceVector = BitsUtil.zero(variances.length);
for(int d = 0; d < variances.length; d++) {
if(variances[d] < alpha) {
BitsUtil.setI(preferenceVector, d);
}
}
if(msg != null && LOG.isDebugging()) {
msg.append("\nalpha ").append(alpha);
msg.append("\nvariances ");
msg.append(FormatUtil.format(variances, ", ", FormatUtil.NF4));
msg.append("\npreference ");
msg.append(BitsUtil.toStringLow(preferenceVector, variances.length));
}
return preferenceVector;
}
示例7: computeSimilarityMatrix
import de.lmu.ifi.dbs.elki.database.relation.RelationUtil; //导入依赖的package包/类
/**
* Compute a column-wise dependency matrix for the given relation.
*
* @param sim Dependence measure
* @param rel Vector relation
* @return Similarity matrix (lower triangular form)
*/
public static double[] computeSimilarityMatrix(DependenceMeasure sim, Relation<? extends NumberVector> rel) {
final int dim = RelationUtil.dimensionality(rel);
final int size = rel.size();
// TODO: we could use less memory (no copy), but this would likely be
// slower. Maybe as a fallback option?
double[][] data = new double[dim][size];
int r = 0;
for(DBIDIter it = rel.iterDBIDs(); it.valid(); it.advance(), r++) {
NumberVector v = rel.get(it);
for(int d = 0; d < dim; d++) {
data[d][r] = v.doubleValue(d);
}
}
return sim.dependence(DoubleArrayAdapter.STATIC, Arrays.asList(data));
}
示例8: processNewResult
import de.lmu.ifi.dbs.elki.database.relation.RelationUtil; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public void processNewResult(VisualizerContext context, Object result) {
VisualizationTree.findNewResultVis(context, result, Relation.class, ScatterPlotProjector.class, (rel, p) -> {
if(!TypeUtil.POLYGON_TYPE.isAssignableFromType(rel.getDataTypeInformation())) {
return;
}
if(RelationUtil.dimensionality((Relation<? extends PolygonsObject>) rel) != 2) {
return;
}
// Assume that a 2d projector is using the same coordinates as the
// polygons.
final VisualizationTask task = new VisualizationTask(this, NAME, rel, rel) //
.level(VisualizationTask.LEVEL_DATA - 10) //
.with(UpdateFlag.ON_DATA);
context.addVis(rel, task);
context.addVis(p, task);
});
}
示例9: processNewResult
import de.lmu.ifi.dbs.elki.database.relation.RelationUtil; //导入依赖的package包/类
@Override
public void processNewResult(VisualizerContext context, Object start) {
VisualizationTree.findNewResults(context, start).filter(Relation.class).forEach(rel -> {
if(!TypeUtil.NUMBER_VECTOR_FIELD.isAssignableFromType(rel.getDataTypeInformation())) {
return;
}
// Do not enable nested relations by default:
for(It<Relation<?>> it2 = context.getHierarchy().iterAncestors(rel).filter(Relation.class); it2.valid(); it2.advance()) {
// Parent relation
final Relation<?> rel2 = it2.get();
if(TypeUtil.SPATIAL_OBJECT.isAssignableFromType(rel2.getDataTypeInformation())) {
return;
}
// TODO: add Actions instead.
}
@SuppressWarnings("unchecked")
Relation<NumberVector> vrel = (Relation<NumberVector>) rel;
final int dim = RelationUtil.dimensionality(vrel);
HistogramProjector<NumberVector> proj = new HistogramProjector<>(vrel, Math.min(dim, maxdim));
context.addVis(vrel, proj);
});
}
示例10: applyPrescaling
import de.lmu.ifi.dbs.elki.database.relation.RelationUtil; //导入依赖的package包/类
/**
* Prescale each vector (except when in {@code skip}) with the given scaling
* function.
*
* @param scaling Scaling function
* @param relation Relation to read
* @param skip DBIDs to pass unmodified
* @return New relation
*/
public static Relation<NumberVector> applyPrescaling(ScalingFunction scaling, Relation<NumberVector> relation, DBIDs skip) {
if(scaling == null) {
return relation;
}
NumberVector.Factory<NumberVector> factory = RelationUtil.getNumberVectorFactory(relation);
DBIDs ids = relation.getDBIDs();
WritableDataStore<NumberVector> contents = DataStoreUtil.makeStorage(ids, DataStoreFactory.HINT_HOT, NumberVector.class);
for(DBIDIter iter = ids.iter(); iter.valid(); iter.advance()) {
NumberVector v = relation.get(iter);
double[] raw = v.toArray();
if(!skip.contains(iter)) {
applyScaling(raw, scaling);
}
contents.put(iter, factory.newNumberVector(raw, ArrayLikeUtil.DOUBLEARRAYADAPTER));
}
return new MaterializedRelation<>(relation.getDataTypeInformation(), ids, "rescaled", contents);
}
示例11: run
import de.lmu.ifi.dbs.elki.database.relation.RelationUtil; //导入依赖的package包/类
/**
* Computes quantitatively linear dependencies among the attributes of the
* given database based on a linear correlation PCA.
*
* @param database the database to run this DependencyDerivator on
* @param relation the relation to use
* @return the CorrelationAnalysisSolution computed by this
* DependencyDerivator
*/
public CorrelationAnalysisSolution<V> run(Database database, Relation<V> relation) {
if(LOG.isVerbose()) {
LOG.verbose("retrieving database objects...");
}
Centroid centroid = Centroid.make(relation, relation.getDBIDs());
NumberVector.Factory<V> factory = RelationUtil.getNumberVectorFactory(relation);
V centroidDV = factory.newNumberVector(centroid.getArrayRef());
DBIDs ids;
if(this.sampleSize > 0) {
if(randomsample) {
ids = DBIDUtil.randomSample(relation.getDBIDs(), this.sampleSize, RandomFactory.DEFAULT);
}
else {
DistanceQuery<V> distanceQuery = database.getDistanceQuery(relation, getDistanceFunction());
KNNList queryResults = database.getKNNQuery(distanceQuery, this.sampleSize)//
.getKNNForObject(centroidDV, this.sampleSize);
ids = DBIDUtil.newHashSet(queryResults);
}
}
else {
ids = relation.getDBIDs();
}
return generateModel(relation, ids, centroid.getArrayRef());
}
示例12: run
import de.lmu.ifi.dbs.elki.database.relation.RelationUtil; //导入依赖的package包/类
/**
* Add scales to a single vector relation.
*
* @param rel Relation
* @return Scales
*/
private ScalesResult run(Relation<? extends NumberVector> rel) {
double[][] mms = RelationUtil.computeMinMax(rel);
int dim = mms[0].length;
double delta = 0.;
for(int d = 0; d < dim; d++) {
double del = mms[1][d] - mms[0][d];
delta = del > delta ? del : delta;
}
if(delta < Double.MIN_NORMAL) {
delta = 1.;
}
int log10res = (int) Math.ceil(Math.log10(delta / (LinearScale.MAXTICKS - 1)));
double res = MathUtil.powi(10, log10res);
double target = Math.ceil(delta / res) * res; // Target width
LinearScale[] scales = new LinearScale[dim];
for(int d = 0; d < dim; d++) {
double mid = (mms[0][d] + mms[1][d] - target) * .5;
double min = Math.floor(mid / res) * res;
double max = Math.ceil((mid + target) / res) * res;
scales[d] = new LinearScale(min, max);
}
return new ScalesResult(scales);
}
示例13: 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;
}
}
}
示例14: loglikelihoodNormal
import de.lmu.ifi.dbs.elki.database.relation.RelationUtil; //导入依赖的package包/类
/**
* Computes the loglikelihood of all normal objects. Gaussian model
*
* @param objids Object IDs for 'normal' objects.
* @param relation Database
* @return loglikelihood for normal objects
*/
private double loglikelihoodNormal(DBIDs objids, Relation<V> relation) {
if(objids.isEmpty()) {
return 0;
}
CovarianceMatrix builder = CovarianceMatrix.make(relation, objids);
double[] mean = builder.getMeanVector();
double[][] covarianceMatrix = builder.destroyToSampleMatrix();
// test singulaere matrix
double[][] covInv = inverse(covarianceMatrix);
double covarianceDet = new LUDecomposition(covarianceMatrix).det();
double fakt = 1.0 / FastMath.sqrt(MathUtil.powi(MathUtil.TWOPI, RelationUtil.dimensionality(relation)) * covarianceDet);
// for each object compute probability and sum
double prob = 0;
for(DBIDIter iter = objids.iter(); iter.valid(); iter.advance()) {
double[] x = minusEquals(relation.get(iter).toArray(), mean);
double mDist = transposeTimesTimes(x, covInv, x);
prob += FastMath.log(fakt * FastMath.exp(-mDist * .5));
}
return prob;
}
示例15: runOnlineLOF
import de.lmu.ifi.dbs.elki.database.relation.RelationUtil; //导入依赖的package包/类
/**
* Run OnlineLOF (with insertions and removals) on database.
*/
@SuppressWarnings("unchecked")
private static OutlierResult runOnlineLOF(UpdatableDatabase db) {
Relation<DoubleVector> rep = db.getRelation(TypeUtil.DOUBLE_VECTOR_FIELD);
// setup algorithm
OnlineLOF<DoubleVector> lof = new OnlineLOF<>(k, k, neighborhoodDistanceFunction, reachabilityDistanceFunction);
// run OnlineLOF on database
OutlierResult result = lof.run(db);
// insert new objects
ArrayList<DoubleVector> insertions = new ArrayList<>();
NumberVector.Factory<DoubleVector> o = RelationUtil.getNumberVectorFactory(rep);
int dim = RelationUtil.dimensionality(rep);
Random random = new Random(seed);
for(int i = 0; i < size; i++) {
DoubleVector obj = VectorUtil.randomVector(o, dim, random);
insertions.add(obj);
}
DBIDs deletions = db.insert(MultipleObjectsBundle.makeSimple(rep.getDataTypeInformation(), insertions));
// delete objects
db.delete(deletions);
return result;
}