annotate src/samer/core_/util/LogMap.java @ 8:5e3cbbf173aa tip

Reorganise some more
author samer
date Fri, 05 Apr 2019 22:41:58 +0100
parents bf79fb79ee13
children
rev   line source
samer@0 1 /*
samer@0 2 * Copyright (c) 2000, Samer Abdallah, King's College London.
samer@0 3 * All rights reserved.
samer@0 4 *
samer@0 5 * This software is provided AS iS and WITHOUT ANY WARRANTY;
samer@0 6 * without even the implied warranty of MERCHANTABILITY or
samer@0 7 * FITNESS FOR A PARTICULAR PURPOSE.
samer@0 8 */
samer@0 9
samer@0 10 package samer.core.util;
samer@0 11
samer@0 12 /**
samer@0 13 This class maps a given interval of real numbers
samer@0 14 to the interval [0,1], returning either the real
samer@0 15 number, or converting it to an integer between 0
samer@0 16 and a given value (defaults to 256).
samer@0 17 */
samer@0 18
samer@0 19 public class LogMap extends IMap
samer@0 20 {
samer@0 21 public LogMap() { this(0.001,1.0,256); }
samer@0 22 public LogMap(int m) { this(0.001,1.0,m); }
samer@0 23 public LogMap(double t1, double t2) { this(t1,t2,256); }
samer@0 24 public LogMap(double t1, double t2, int m) { setDomain(t1,t2); setIntRange(m); }
samer@0 25
samer@0 26 public double getDomainMin() { return Math.exp(super.getDomainMin()); }
samer@0 27 public double getDomainMax() { return Math.exp(super.getDomainMax()); }
samer@0 28 public void setDomain( double t1, double t2) {
samer@0 29 if (t1<0 || t2<0) throw new Error("Bad domain for log map");
samer@0 30 super.setDomain( Math.log(t1), Math.log(t2));
samer@0 31 }
samer@0 32
samer@0 33 private static double log(double t) { return t>0 ? Math.log(t) : Double.NEGATIVE_INFINITY; }
samer@0 34 public final double map( double t) { return super.map(log(t)); }
samer@0 35 public final int clipInt( double t) { return super.clipInt(log(t)); }
samer@0 36 public final int toInt( double t) { return super.toInt(log(t)); }
samer@0 37 public double inverse(double t) { return Math.exp(super.inverse(t)); }
samer@0 38 public double inverseFromInt(int i) { return Math.exp(super.inverseFromInt(i)); }
samer@0 39 }
samer@0 40
samer@0 41
samer@0 42
samer@0 43
samer@0 44
samer@0 45
samer@0 46
samer@0 47