package genesom;

// eta control: f(span/2) = eta (from - to) + to    => eta in ]0:0.5[
// if eta == 0 -> eta is set to its canonic value without offset c
// !! offset c may become negative for x > span !

public class ExponentialDecayModel
  extends DecayModel
{

  protected double f;
  protected double c;
  protected double g;

  public boolean init() {

    if(to <= 0. || from <= 0. || to > from) return true;

    if(eta == 0.) eta = (g = Math.sqrt(to)) / (Math.sqrt(from) + g); // c == 0

// f(x) = exp(f * (g-x)) + c
// Solve[eta (from-to) + to == c + Exp[Log[from-c]-Log[(from-c)/(to-c)]/2],c]
    c = (eta * eta * (from - to) - to + 2. * eta * to) / (2. * eta - 1.);
    f = Math.log((from - c) / (to - c)) / span;
    g = Math.log(from - c) / f;

    return super.init();
  }

  protected double calcResult(double x) {
    return c + Math.exp(f * (g - x));
  }
}

