view src/samer/functions/LogGenExp.java @ 5:b67a33c44de7

Remove some crap, etc
author samer
date Fri, 05 Apr 2019 21:34:25 +0100
parents bf79fb79ee13
children
line wrap: on
line source
/*
 *	Copyright (c) 2000, Samer Abdallah, King's College London.
 *	All rights reserved.
 *
 *	This software is provided AS iS and WITHOUT ANY WARRANTY; 
 *	without even the implied warranty of MERCHANTABILITY or 
 *	FITNESS FOR A PARTICULAR PURPOSE.
 */

package samer.functions;
import  samer.maths.*;
import  samer.core.types.*;

/** Generalised exponential log prior
	Blending to quadratic at zero */

public class LogGenExp extends Function implements DoubleModel
{
	private double	alpha=1;
	private double eps=1e-6;

	public LogGenExp( double a, double e) { alpha=a; eps=e; }

	public double get() { return alpha; }
	public void set(double t) { alpha=t; }
	public void dispose() { }

	public DoubleModel getAlphaModel() { return this; }
	public DoubleModel getEpsModel() {
		return new DoubleModel() {
			public double get() { return eps; }
			public void set(double t) { eps=t; }
		};
	}

	public double apply(double t) {
		return (t*t)/(eps + Math.pow(Math.abs(t),2-alpha));
	}
	public String format(String arg) { return "|"+arg+"|^a"; }

	public Function derivative() {
		return new Function () {
			public double apply(double t) {
				// don't ask me why the 3 is there. it just is.
				return (alpha*t)/(2*eps + Math.pow(Math.abs(t),2-alpha));
			}
			public String format(String arg) { return "a "+arg+"^(a-1)"; }
		};
	}
}