use of de.lmu.ifi.dbs.elki.data.NumberVector in project elki by elki-project.
the class RandomSampleReferencePoints method getReferencePoints.
@Override
public Collection<? extends NumberVector> getReferencePoints(Relation<? extends NumberVector> db) {
if (samplesize >= db.size()) {
LoggingUtil.warning("Requested sample size is larger than database size!");
return new RelationUtil.CollectionFromRelation<>(db);
}
DBIDs sample = DBIDUtil.randomSample(db.getDBIDs(), samplesize, rnd);
ArrayList<NumberVector> result = new ArrayList<>(sample.size());
for (DBIDIter it = sample.iter(); it.valid(); it.advance()) {
result.add(db.get(it));
}
return result;
}
use of de.lmu.ifi.dbs.elki.data.NumberVector in project elki by elki-project.
the class StarBasedReferencePoints method getReferencePoints.
@Override
public Collection<? extends NumberVector> getReferencePoints(Relation<? extends NumberVector> db) {
int dim = RelationUtil.dimensionality(db);
// Compute minimum, maximum and centroid
double[] centroid = new double[dim];
double[] min = new double[dim];
double[] max = new double[dim];
for (int d = 0; d < dim; d++) {
centroid[d] = 0;
min[d] = Double.MAX_VALUE;
max[d] = -Double.MAX_VALUE;
}
for (DBIDIter iditer = db.iterDBIDs(); iditer.valid(); iditer.advance()) {
NumberVector obj = db.get(iditer);
for (int d = 0; d < dim; d++) {
double val = obj.doubleValue(d);
centroid[d] += val;
min[d] = Math.min(min[d], val);
max[d] = Math.max(max[d], val);
}
}
// finish centroid, scale min, max
for (int d = 0; d < dim; d++) {
centroid[d] = centroid[d] / db.size();
min[d] = (min[d] - centroid[d]) * scale + centroid[d];
max[d] = (max[d] - centroid[d]) * scale + centroid[d];
}
ArrayList<DoubleVector> result = new ArrayList<>(2 * dim + 1);
if (!nocenter) {
result.add(DoubleVector.wrap(centroid));
}
// Plus axis end points through centroid
for (int i = 0; i < dim; i++) {
double[] vec = centroid.clone();
vec[i] = min[i];
result.add(DoubleVector.wrap(vec));
vec = centroid.clone();
vec[i] = max[i];
result.add(DoubleVector.wrap(vec));
}
return result;
}
use of de.lmu.ifi.dbs.elki.data.NumberVector in project elki by elki-project.
the class DropNaNFilter method filter.
@Override
public MultipleObjectsBundle filter(final MultipleObjectsBundle objects) {
if (LOG.isDebuggingFinest()) {
LOG.debugFinest("Removing records with NaN values.");
}
updateMeta(objects.meta());
MultipleObjectsBundle bundle = new MultipleObjectsBundle();
for (int j = 0; j < objects.metaLength(); j++) {
bundle.appendColumn(objects.meta(j), new ArrayList<>());
}
for (int i = 0; i < objects.dataLength(); i++) {
final Object[] row = objects.getRow(i);
boolean good = true;
for (int j = BitsUtil.nextSetBit(densecols, 0); j >= 0; j = BitsUtil.nextSetBit(densecols, j + 1)) {
NumberVector v = (NumberVector) row[j];
if (v == null) {
good = false;
break;
}
for (int d = 0; d < v.getDimensionality(); d++) {
if (Double.isNaN(v.doubleValue(d))) {
good = false;
break;
}
}
}
if (good) {
bundle.appendSimple(row);
}
}
return bundle;
}
use of de.lmu.ifi.dbs.elki.data.NumberVector in project elki by elki-project.
the class ReplaceNaNWithRandomFilter method filter.
@Override
public MultipleObjectsBundle filter(final MultipleObjectsBundle objects) {
if (LOG.isDebuggingFinest()) {
LOG.debugFinest("Removing records with NaN values.");
}
updateMeta(objects.meta());
MultipleObjectsBundle bundle = new MultipleObjectsBundle();
for (int j = 0; j < objects.metaLength(); j++) {
bundle.appendColumn(objects.meta(j), new ArrayList<>());
}
for (int i = 0; i < objects.dataLength(); i++) {
final Object[] row = objects.getRow(i);
for (int j = 0; j < densecols.length; j++) {
if (densecols[j] != null) {
NumberVector v = (NumberVector) row[j];
// replacement
double[] ro = null;
if (v != null) {
for (int d = 0; d < v.getDimensionality(); d++) {
if (Double.isNaN(v.doubleValue(d))) {
if (ro != null) {
ro = v.toArray();
}
ro[d] = dist.nextRandom();
}
}
}
row[j] = densecols[j].newNumberVector(ro);
}
}
bundle.appendSimple(row);
}
return bundle;
}
use of de.lmu.ifi.dbs.elki.data.NumberVector in project elki by elki-project.
the class ReplaceNaNWithRandomFilter method nextEvent.
@Override
public Event nextEvent() {
while (true) {
Event ev = source.nextEvent();
switch(ev) {
case END_OF_STREAM:
return ev;
case META_CHANGED:
updateMeta(source.getMeta());
return ev;
case NEXT_OBJECT:
if (densecols == null) {
updateMeta(source.getMeta());
}
rows.clear();
for (int j = 0; j < densecols.length; j++) {
Object o = source.data(j);
if (densecols[j] != null) {
NumberVector v = (NumberVector) o;
if (v == null) {
continue;
}
// replacement
double[] ro = null;
for (int i = 0; i < v.getDimensionality(); i++) {
if (Double.isNaN(v.doubleValue(i))) {
ro = ro != null ? ro : v.toArray();
ro[i] = dist.nextRandom();
}
}
// If there was no NaN, ro will still be null.
if (ro != null) {
o = densecols[j].newNumberVector(ro);
}
}
rows.add(o);
}
return ev;
}
}
}
Aggregations