本文整理汇总了Java中de.lmu.ifi.dbs.elki.data.NumberVector类的典型用法代码示例。如果您正苦于以下问题:Java NumberVector类的具体用法?Java NumberVector怎么用?Java NumberVector使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
NumberVector类属于de.lmu.ifi.dbs.elki.data包,在下文中一共展示了NumberVector类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: minDist
import de.lmu.ifi.dbs.elki.data.NumberVector; //导入依赖的package包/类
@Override
@Reference(authors = "Erich Schubert, Arthur Zimek and Hans-Peter Kriegel", //
title = "Geodetic Distance Queries on R-Trees for Indexing Geographic Data", //
booktitle = "13th Int. Symposium on Advances in Spatial and Temporal Databases", //
url = "http://dx.doi.org/10.1007/978-3-642-40235-7_9")
public double minDist(SpatialComparable mbr1, SpatialComparable mbr2) {
if(mbr1 instanceof NumberVector) {
if(mbr2 instanceof NumberVector) {
return distance((NumberVector) mbr1, (NumberVector) mbr2);
}
else {
NumberVector o1 = (NumberVector) mbr1;
return model.minDistDeg(o1.doubleValue(dimlat), o1.doubleValue(dimlng), mbr2.getMin(dimlat), mbr2.getMin(dimlng), mbr2.getMax(dimlat), mbr2.getMax(dimlng));
}
}
else {
if(mbr2 instanceof NumberVector) {
NumberVector o2 = (NumberVector) mbr2;
return model.minDistDeg(o2.doubleValue(dimlat), o2.doubleValue(dimlng), mbr1.getMin(dimlat), mbr1.getMin(dimlng), mbr1.getMax(dimlat), mbr1.getMax(dimlng));
}
else {
throw new NotImplementedException("This distance function cannot - yet - be used with this algorithm, as the lower bound rectangle to rectangle distances have not yet been formalized for geodetic data.");
}
}
}
示例2: getVisibleEdges
import de.lmu.ifi.dbs.elki.data.NumberVector; //导入依赖的package包/类
/**
* Get the visible (non-0) edges of a hypercube
*
* @param proj Projection
* @param s_min Minimum value (in data space)
* @param s_max Maximum value (in data space)
* @return Edge list
*/
private static ArrayList<double[]> getVisibleEdges(Projection2D proj, NumberVector s_min, NumberVector s_max) {
final int dim = s_min.getDimensionality();
double[] s_deltas = new double[dim];
for(int i = 0; i < dim; i++) {
s_deltas[i] = s_max.doubleValue(i) - s_min.doubleValue(i);
}
ArrayList<double[]> r_edges = new ArrayList<>(dim);
for(int i = 0; i < dim; i++) {
double[] delta = new double[dim];
delta[i] = s_deltas[i];
double[] deltas = proj.fastProjectRelativeDataToRenderSpace(delta);
if(deltas[0] != 0 || deltas[1] != 0) {
r_edges.add(deltas);
}
}
return r_edges;
}
示例3: computeNNForUniformData
import de.lmu.ifi.dbs.elki.data.NumberVector; //导入依赖的package包/类
/**
* Search nearest neighbors for <em>artificial, uniform</em> data.
*
* @param knnQuery KNN query
* @param min Data minima
* @param extend Data extend
* @return Aggregated 1NN distances
*/
protected double computeNNForUniformData(final KNNQuery<NumberVector> knnQuery, final double[] min, final double[] extend) {
final Random rand = random.getSingleThreadedRandom();
final int dim = min.length;
double[] buf = new double[dim];
double u = 0.;
for(int i = 0; i < sampleSize; i++) {
// New random vector
for(int d = 0; d < buf.length; d++) {
buf[d] = min[d] + (rand.nextDouble() * extend[d]);
}
double kdist = knnQuery.getKNNForObject(DoubleVector.wrap(buf), k).getKNNDistance();
u += MathUtil.powi(kdist, dim);
}
return u;
}
示例4: naiveQueryDense
import de.lmu.ifi.dbs.elki.data.NumberVector; //导入依赖的package包/类
/**
* Query the most similar objects, dense version.
*
* @param obj Query object
* @param scores Score storage
* @param cands Non-zero objects set
* @return Result
*/
private double naiveQueryDense(NumberVector obj, WritableDoubleDataStore scores, HashSetModifiableDBIDs cands) {
double len = 0.; // Length of query object, for final normalization
for(int dim = 0, max = obj.getDimensionality(); dim < max; dim++) {
final double val = obj.doubleValue(dim);
if(val == 0. || val != val) {
continue;
}
len += val * val;
// No matching documents in index:
if(dim >= index.size()) {
continue;
}
ModifiableDoubleDBIDList column = index.get(dim);
for(DoubleDBIDListIter n = column.iter(); n.valid(); n.advance()) {
scores.increment(n, n.doubleValue() * val);
cands.add(n);
}
}
return FastMath.sqrt(len);
}
示例5: minDistObject
import de.lmu.ifi.dbs.elki.data.NumberVector; //导入依赖的package包/类
protected double minDistObject(SpatialComparable mbr, NumberVector v) {
double sqrDist = 0;
for(int d = BitsUtil.nextSetBit(dimensions, 0); d >= 0; d = BitsUtil.nextSetBit(dimensions, d + 1)) {
final double delta;
final double value = v.doubleValue(d);
final double omin = mbr.getMin(d);
if(value < omin) {
delta = omin - value;
}
else {
final double omax = mbr.getMax(d);
if(value > omax) {
delta = value - omax;
}
else {
continue;
}
}
sqrDist += FastMath.pow(delta, p);
}
return FastMath.pow(sqrDist, 1. / p);
}
示例6: updateE
import de.lmu.ifi.dbs.elki.data.NumberVector; //导入依赖的package包/类
@Override
public void updateE(NumberVector vec, double wei) {
assert (vec.getDimensionality() == mean.length);
final double nwsum = wsum + wei;
// Compute new means
for(int i = 0; i < mean.length; i++) {
final double delta = vec.doubleValue(i) - mean[i];
final double rval = delta * wei / nwsum;
nmea[i] = mean[i] + rval;
}
// Update variances
for(int i = 0; i < mean.length; i++) {
// We DO want to use the new mean once and the old mean once!
// It does not matter which one is which.
double vi = vec.doubleValue(i);
variances[i] += (vi - nmea[i]) * (vi - mean[i]) * wei;
}
// Use new values.
wsum = nwsum;
System.arraycopy(nmea, 0, mean, 0, nmea.length);
}
示例7: projectDense
import de.lmu.ifi.dbs.elki.data.NumberVector; //导入依赖的package包/类
/**
* Slower version, for dense multiplication.
*
* @param in Input vector
* @return Projected data.
*/
private double[] projectDense(NumberVector in, double[] ret) {
final int k = this.k;
final double dim = MathUtil.min(buf.length, in.getDimensionality());
for(int i = 0; i < dim; i++) {
final boolean[] row = mat[i];
double vali = in.doubleValue(i);
for(int o = 0; o < k; o++) {
if(row[o]) {
ret[o] += vali;
}
else {
ret[o] -= vali;
}
}
}
return ret;
}
示例8: minDist
import de.lmu.ifi.dbs.elki.data.NumberVector; //导入依赖的package包/类
@Override
public double minDist(SpatialComparable mbr1, SpatialComparable mbr2) {
final int dim1 = mbr1.getDimensionality(), dim2 = mbr2.getDimensionality();
final int mindim = (dim1 < dim2) ? dim1 : dim2;
final NumberVector v1 = (mbr1 instanceof NumberVector) ? (NumberVector) mbr1 : null;
final NumberVector v2 = (mbr2 instanceof NumberVector) ? (NumberVector) mbr2 : null;
double agg = (v1 != null) //
? (v2 != null) ? preDistance(v1, v2, 0, mindim) : preDistanceVM(v1, mbr2, 0, mindim) //
: (v2 != null) ? preDistanceVM(v2, mbr1, 0, mindim) : preDistanceMBR(mbr1, mbr2, 0, mindim);
// first object has more dimensions.
if(dim1 > mindim) {
agg += (v1 != null) ? preNorm(v1, mindim, dim1) : preNormMBR(mbr1, mindim, dim1);
}
// second object has more dimensions.
if(dim2 > mindim) {
agg += (v2 != null) ? preNorm(v2, mindim, dim2) : preNormMBR(mbr2, mindim, dim2);
}
return agg;
}
示例9: assignProbabilitiesToInstances
import de.lmu.ifi.dbs.elki.data.NumberVector; //导入依赖的package包/类
/**
* Assigns the current probability values to the instances in the database and
* compute the expectation value of the current mixture of distributions.
*
* Computed as the sum of the logarithms of the prior probability of each
* instance.
*
* @param relation the database used for assignment to instances
* @param models Cluster models
* @param probClusterIGivenX Output storage for cluster probabilities
* @return the expectation value of the current mixture of distributions
*/
public static double assignProbabilitiesToInstances(Relation<? extends NumberVector> relation, List<? extends EMClusterModel<?>> models, WritableDataStore<double[]> probClusterIGivenX) {
final int k = models.size();
double emSum = 0.;
for(DBIDIter iditer = relation.iterDBIDs(); iditer.valid(); iditer.advance()) {
NumberVector vec = relation.get(iditer);
double[] probs = new double[k];
for(int i = 0; i < k; i++) {
probs[i] = models.get(i).estimateLogDensity(vec);
}
double logP = logSumExp(probs);
emSum += logP > MIN_LOGLIKELIHOOD ? logP : MIN_LOGLIKELIHOOD;
for(int i = 0; i < k; i++) {
probs[i] = FastMath.exp(probs[i] - logP);
}
probClusterIGivenX.put(iditer, probs);
}
return emSum / relation.size();
}
示例10: guessFactory
import de.lmu.ifi.dbs.elki.data.NumberVector; //导入依赖的package包/类
/**
* Try to guess the appropriate factory.
*
* @param in Input type
* @param <V> Vector type
* @return Factory
*/
@SuppressWarnings("unchecked")
public static <V extends NumberVector> NumberVector.Factory<V> guessFactory(SimpleTypeInformation<V> in) {
NumberVector.Factory<V> factory = null;
if(in instanceof VectorTypeInformation) {
factory = (NumberVector.Factory<V>) ((VectorTypeInformation<V>) in).getFactory();
}
if(factory == null) {
// FIXME: hack. Add factories to simple type information, too?
try {
Field f = in.getRestrictionClass().getField("FACTORY");
factory = (NumberVector.Factory<V>) f.get(null);
}
catch(Exception e) {
LoggingUtil.warning("Cannot determine factory for type " + in.getRestrictionClass(), e);
}
}
return factory;
}
示例11: run
import de.lmu.ifi.dbs.elki.data.NumberVector; //导入依赖的package包/类
/**
* Run the actual algorithm.
*
* @param relation Relation
* @return Result
*/
public OutlierResult run(Relation<? extends NumberVector> relation) {
WritableDoubleDataStore scores = DataStoreUtil.makeDoubleStorage(relation.getDBIDs(), DataStoreFactory.HINT_HOT);
DoubleMinMax minmax = new DoubleMinMax();
Mean m = new Mean();
for(DBIDIter iditer = relation.iterDBIDs(); iditer.valid(); iditer.advance()) {
m.reset();
NumberVector nv = relation.get(iditer);
for (int i = 0; i < nv.getDimensionality(); i++) {
m.put(nv.doubleValue(i));
}
final double score = m.getMean();
scores.putDouble(iditer, score);
minmax.put(score);
}
DoubleRelation scoreres = new MaterializedDoubleRelation("Trivial mean score", "mean-outlier", scores, relation.getDBIDs());
OutlierScoreMeta meta = new BasicOutlierScoreMeta(minmax.getMin(), minmax.getMax());
return new OutlierResult(meta, scoreres);
}
示例12: logLikelihoodAlternate
import de.lmu.ifi.dbs.elki.data.NumberVector; //导入依赖的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;
}
示例13: findParent
import de.lmu.ifi.dbs.elki.data.NumberVector; //导入依赖的package包/类
/**
* Returns the parent of the specified cluster
*
* @param relation the relation storing the objects
* @param child the child to search the parent for
* @param clustersMap the map containing the clusters
* @return the parent of the specified cluster
*/
private Pair<long[], ArrayModifiableDBIDs> findParent(Relation<V> relation, Pair<long[], ArrayModifiableDBIDs> child, Object2ObjectMap<long[], List<ArrayModifiableDBIDs>> clustersMap) {
Centroid child_centroid = ProjectedCentroid.make(child.first, relation, child.second);
Pair<long[], ArrayModifiableDBIDs> result = null;
int resultCardinality = -1;
long[] childPV = child.first;
int childCardinality = BitsUtil.cardinality(childPV);
for(long[] parentPV : clustersMap.keySet()) {
int parentCardinality = BitsUtil.cardinality(parentPV);
if(parentCardinality >= childCardinality) {
continue;
}
if(resultCardinality != -1 && parentCardinality <= resultCardinality) {
continue;
}
long[] pv = BitsUtil.andCMin(childPV, parentPV);
if(BitsUtil.equal(pv, parentPV)) {
List<ArrayModifiableDBIDs> parentList = clustersMap.get(parentPV);
for(ArrayModifiableDBIDs parent : parentList) {
NumberVector parent_centroid = ProjectedCentroid.make(parentPV, relation, parent);
double d = weightedDistance(child_centroid, parent_centroid, parentPV);
if(d <= 2 * epsilon) {
result = new Pair<>(parentPV, parent);
resultCardinality = parentCardinality;
break;
}
}
}
}
return result;
}
示例14: distance
import de.lmu.ifi.dbs.elki.data.NumberVector; //导入依赖的package包/类
@Override
public double distance(NumberVector v1, NumberVector v2) {
final int dim1 = v1.getDimensionality(), dim2 = v2.getDimensionality();
final int mindim = (dim1 < dim2) ? dim1 : dim2;
double agg = preDistance(v1, v2, 0, mindim);
if(dim1 > mindim) {
agg += preNorm(v1, mindim, dim1);
}
else if(dim2 > mindim) {
agg += preNorm(v2, mindim, dim2);
}
return agg;
}
示例15: buildHullsRecursively
import de.lmu.ifi.dbs.elki.data.NumberVector; //导入依赖的package包/类
/**
* Recursively step through the clusters to build the hulls.
*
* @param clu Current cluster
* @param hier Clustering hierarchy
* @param hulls Hull map
*/
private DoubleObjPair<Polygon> buildHullsRecursively(Cluster<Model> clu, Hierarchy<Cluster<Model>> hier, Map<Object, DoubleObjPair<Polygon>> hulls, Relation<? extends NumberVector> coords) {
final DBIDs ids = clu.getIDs();
GrahamScanConvexHull2D hull = new GrahamScanConvexHull2D();
for(DBIDIter iter = ids.iter(); iter.valid(); iter.advance()) {
hull.add(coords.get(iter).toArray());
}
double weight = ids.size();
if(hier != null && hulls != null) {
final int numc = hier.numChildren(clu);
if(numc > 0) {
for(It<Cluster<Model>> iter = hier.iterChildren(clu); iter.valid(); iter.advance()) {
final Cluster<Model> iclu = iter.get();
DoubleObjPair<Polygon> poly = hulls.get(iclu);
if(poly == null) {
poly = buildHullsRecursively(iclu, hier, hulls, coords);
}
// Add inner convex hull to outer convex hull.
for(ArrayListIter<double[]> vi = poly.second.iter(); vi.valid(); vi.advance()) {
hull.add(vi.get());
}
weight += poly.first / numc;
}
}
}
DoubleObjPair<Polygon> pair = new DoubleObjPair<>(weight, hull.getHull());
hulls.put(clu, pair);
return pair;
}