package ec.gp.semantic.initialization;

import ec.*;
import ec.util.*;

/**
 * Probabilistic Geometric Semantic Initializer with exponential distribution.
 * 
 * @author Tomasz Pawlak
 * 
 */
public class ExponentialPGSI extends PGSI {

	private final static Parameter DEFAULT_BASE = new Parameter("ExponentialPGSI");
	private final static String LAMBDA = "lambda";

	protected double lambda = 1.0;

	@Override
	public Parameter defaultBase() {
		return DEFAULT_BASE;
	}

	@Override
	public void setup(EvolutionState state, Parameter base) {
		super.setup(state, base);

		ParameterDatabase db = state.parameters;

		this.lambda = db.getDouble(base.push(LAMBDA), defaultBase().push(LAMBDA));
	}

	@Override
	protected double probability(double distance) {
		assert distance >= 0.0;

		return this.lambda * Math.exp(-this.lambda * distance);
	}

}
