use of de.lmu.ifi.dbs.elki.math.scales.LinearScale in project elki by elki-project.
the class AddSingleScale method run.
/**
* Add scales to a single vector relation.
*
* @param rel Relation
* @return Scales
*/
private ScalesResult run(Relation<? extends NumberVector> rel) {
final int dim = RelationUtil.dimensionality(rel);
LinearScale[] scales = new LinearScale[dim];
if (minmax == null) {
DoubleMinMax mm = new DoubleMinMax();
for (DBIDIter iditer = rel.iterDBIDs(); iditer.valid(); iditer.advance()) {
NumberVector vec = rel.get(iditer);
for (int d = 0; d < dim; d++) {
final double val = vec.doubleValue(d);
if (val != val) {
// NaN
continue;
}
mm.put(val);
}
}
LinearScale scale = new LinearScale(mm.getMin(), mm.getMax());
for (int i = 0; i < dim; i++) {
scales[i] = scale;
}
} else {
// Use predefined.
LinearScale scale = new LinearScale(minmax[0], minmax[1]);
for (int i = 0; i < dim; i++) {
scales[i] = scale;
}
}
ScalesResult res = new ScalesResult(scales);
return res;
}
use of de.lmu.ifi.dbs.elki.math.scales.LinearScale in project elki by elki-project.
the class AddUniformScale method run.
/**
* 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);
// Target width
double target = Math.ceil(delta / res) * res;
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);
}
use of de.lmu.ifi.dbs.elki.math.scales.LinearScale in project elki by elki-project.
the class LongDynamicHistogram method materialize.
/**
* Materialize the histogram from the cache.
*/
void materialize() {
// already materialized?
if (cachefill < 0) {
return;
}
// Compute minimum and maximum
double min = Double.MAX_VALUE, max = Double.MIN_VALUE;
for (int i = 0; i < cachefill; i++) {
min = Math.min(min, cachec[i]);
max = Math.max(max, cachec[i]);
}
// use the LinearScale magic to round to "likely suiteable" step sizes.
// TODO: extract into a reusable function?
LinearScale scale = new LinearScale(min, max);
min = scale.getMin();
max = scale.getMax();
this.base = min;
this.max = max;
this.binsize = (max - min) / this.destsize;
// initialize array
this.data = new long[this.destsize << 1];
size = destsize;
// re-insert data we have
final int end = cachefill;
// So reinsert works!
cachefill = -1;
for (int i = 0; i < end; i++) {
increment(cachec[i], cachev[i]);
}
// delete cache, signal that we're initialized
cachec = null;
cachev = null;
}
use of de.lmu.ifi.dbs.elki.math.scales.LinearScale in project elki by elki-project.
the class OPTICSPlot method computeScale.
/**
* Compute the scale (value range)
*
* @param order Cluster order to process
* @return Scale for value range of cluster order
*/
protected LinearScale computeScale(ClusterOrder order) {
DoubleMinMax range = new DoubleMinMax();
// calculate range
for (DBIDIter it = order.iter(); it.valid(); it.advance()) {
final double reach = co.getReachability(it);
if (reach < Double.POSITIVE_INFINITY) {
range.put(reach);
}
}
// Ensure we have a valid range
if (!range.isValid()) {
range.put(0.0);
range.put(1.0);
}
return new LinearScale(range.getMin(), range.getMax());
}
use of de.lmu.ifi.dbs.elki.math.scales.LinearScale in project elki by elki-project.
the class XYCurveVisualization method makeVisualization.
@Override
public Visualization makeVisualization(VisualizerContext context, VisualizationTask task, VisualizationPlot plot, double width, double height, Projection proj) {
XYCurve curve = task.getResult();
setupCSS(context, plot);
final StyleLibrary style = context.getStyleLibrary();
final double sizex = StyleLibrary.SCALE;
final double sizey = StyleLibrary.SCALE * height / width;
final double margin = style.getSize(StyleLibrary.MARGIN);
Element layer = SVGUtil.svgElement(plot.getDocument(), SVGConstants.SVG_G_TAG);
final String transform = SVGUtil.makeMarginTransform(width, height, sizex, sizey, margin);
SVGUtil.setAtt(layer, SVGConstants.SVG_TRANSFORM_ATTRIBUTE, transform);
// determine scaling
LinearScale scalex = new LinearScale(curve.getMinx(), curve.getMaxx());
LinearScale scaley = new LinearScale(curve.getMiny(), curve.getMaxy());
// plot the line
SVGPath path = new SVGPath();
for (XYCurve.Itr iterator = curve.iterator(); iterator.valid(); iterator.advance()) {
final double x = scalex.getScaled(iterator.getX());
final double y = 1 - scaley.getScaled(iterator.getY());
path.drawTo(sizex * x, sizey * y);
}
Element line = path.makeElement(plot);
line.setAttribute(SVGConstants.SVG_CLASS_ATTRIBUTE, SERIESID);
// add axes
try {
SVGSimpleLinearAxis.drawAxis(plot, layer, scaley, 0, sizey, 0, 0, SVGSimpleLinearAxis.LabelStyle.LEFTHAND, style);
SVGSimpleLinearAxis.drawAxis(plot, layer, scalex, 0, sizey, sizex, sizey, SVGSimpleLinearAxis.LabelStyle.RIGHTHAND, style);
} catch (CSSNamingConflict e) {
LoggingUtil.exception(e);
}
// Add axis labels
{
Element labelx = plot.svgText(sizex * .5, sizey + margin * .9, curve.getLabelx());
SVGUtil.setCSSClass(labelx, CSS_AXIS_LABEL);
layer.appendChild(labelx);
Element labely = plot.svgText(margin * -.8, sizey * .5, curve.getLabely());
SVGUtil.setCSSClass(labely, CSS_AXIS_LABEL);
SVGUtil.setAtt(labely, SVGConstants.SVG_TRANSFORM_ATTRIBUTE, "rotate(-90," + FormatUtil.NF6.format(margin * -.8) + "," + FormatUtil.NF6.format(sizey * .5) + ")");
layer.appendChild(labely);
}
// Add AUC value when found
if (curve instanceof ROCResult) {
double rocauc = ((ROCResult) curve).getAUC();
String lt = OutlierROCCurve.ROCAUC_LABEL + ": " + FormatUtil.NF.format(rocauc);
if (rocauc <= 0.5) {
Element auclbl = plot.svgText(sizex * 0.5, sizey * 0.10, lt);
SVGUtil.setCSSClass(auclbl, CSS_AXIS_LABEL);
layer.appendChild(auclbl);
} else {
Element auclbl = plot.svgText(sizex * 0.5, sizey * 0.95, lt);
SVGUtil.setCSSClass(auclbl, CSS_AXIS_LABEL);
layer.appendChild(auclbl);
}
}
if (curve instanceof PRCurve) {
double prauc = ((PRCurve) curve).getAUC();
String lt = OutlierPrecisionRecallCurve.PRAUC_LABEL + ": " + FormatUtil.NF.format(prauc);
if (prauc <= 0.5) {
Element auclbl = plot.svgText(sizex * 0.5, sizey * 0.10, lt);
SVGUtil.setCSSClass(auclbl, CSS_AXIS_LABEL);
layer.appendChild(auclbl);
} else {
Element auclbl = plot.svgText(sizex * 0.5, sizey * 0.95, lt);
SVGUtil.setCSSClass(auclbl, CSS_AXIS_LABEL);
layer.appendChild(auclbl);
}
}
layer.appendChild(line);
return new StaticVisualizationInstance(context, task, plot, width, height, layer);
}
Aggregations