view src/samer/functions/HybridFunction.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.*;

/**
	Piecewise function made of two other functions, f and g.
	If argument>threshold, return g(t), otherwise return f(t)
	Implements double model for setting the threshold or
	cross-over point, which defaults to zero.
	*/

public class HybridFunction extends Function implements DoubleModel
{
	double theta=0;
	Function f, g;

	public HybridFunction( Function f, Function g) { this(f,g,0); }
	public HybridFunction( Function f, Function g, double th)
	{
		this.f=f;
		this.g=g;
		theta=th;
	}

	/** DoubleModel implementation: set crossover point */
	public void set(double t) { theta=t; }

	/** DoubleModel implementation: get crossover point */
	public double get() { return theta; }

	public void dispose() { f.dispose(); g.dispose(); }
	public double apply(double t) { return t<0 ? f.apply(t) : g.apply(t); }

	public Function derivative() {
		return new HybridFunction(f.derivative(),g.derivative(),theta);
	}

	public String format(String arg) {
		return "t>=0 ? "+g.format(arg)+" : " +f.format(arg);
	}
}