package genesom;


public class SOMDecayFunction
{
  protected DecayModel decmo;
  protected SOM som;

  protected double from = Double.MAX_VALUE;
  protected double to = Double.MAX_VALUE;
  protected double eta = 0.; // read e[x]t[r]a -Additional general purpose param

  public SOMDecayFunction() { }

  public SOMDecayFunction(double from, double to) {
    this.from = from;
    this.to = to;
  }

  public SOMDecayFunction(double from, double to, double eta)
  {
    this(from, to);
    this.eta = eta;
  }

  /* THIS METHOD MUST BE CALLED */
  public void setSOMEnviroment(SOM som) {

    this.som = som;

    if(decmo == null)
      throw new RuntimeException("DecayModel not specified!");

    decmo.setFrom(from);
    decmo.setTo(to);
    decmo.setEta(eta);
    decmo.setSpan(som.maxcycles);

    if(decmo.init())
      throw new RuntimeException(this.getClass().getName() + " not properly inited!");
  }


  protected void setDecayModel(String dm) {

    try {
      decmo = (DecayModel)Class.forName(
       (dm.indexOf('.') < 0 ?
        this.getClass().getPackage().getName() + "." : "") + dm).newInstance();
    }
    catch(Exception e) { throw new RuntimeException(e); }

  }

  public DecayModel getDecayModel() { return decmo; }

  public double value(double x) { return decmo.get(x >= 0. ? x : -x); }

  public double value() { return decmo.get(som.cycles); }

  public double getFrom() { return from; }
  public double getTo() { return to; }
  public double getEta() { return eta; }

}

