public double getValue(double time) { double x; double localLambda; if (lambdaTableEnabled) { localLambda = lambdaTable.getValue(time); } else { localLambda = lambda; } if (direction == BILATERAL) { double e; do { x = 2.0 * Math.random(); if (x > 1.0) { x = 2.0 - x; e = -Math.log(x); } else e = Math.log(x); e = (e / 14.0 / localLambda) + 0.5; } while ((e > 1.0) || (e < 0.0)); x = e; } else { do { while ((x = Math.random()) == 0) {} x = -Math.log(x) / 7.0 / localLambda; } while (x > 1.0); if (direction == INCREASING) { x = 1.0 - x; } } return x; }
public Element saveAsXML() { Element retVal = new Element("probabilityGenerator"); retVal.setAttribute("type", getClass().getName()); retVal.addElement(XMLUtilities.writeInt("direction", direction)); retVal.addElement(XMLUtilities.writeDouble("lambda", lambda)); retVal.addElement(XMLUtilities.writeBoolean("lambdaTableEnabled", lambdaTableEnabled)); retVal.addElement(lambdaTable.saveAsXML()); return retVal; }
public static ProbabilityGenerator loadFromXML(Element data) { Exponential retVal = new Exponential(); Elements nodes = data.getElements(); while (nodes.hasMoreElements()) { Element node = nodes.next(); String nodeName = node.getName(); if (nodeName.equals("direction")) { retVal.direction = XMLUtilities.readInt(node); } else if (nodeName.equals("lambda")) { retVal.lambda = XMLUtilities.readDouble(node); } else if (nodeName.equals("lambdaTableEnabled")) { retVal.lambdaTableEnabled = XMLUtilities.readBoolean(node); } else if (nodeName.equals("table")) { retVal.lambdaTable = Table.loadFromXML(node); } } return retVal; }
public Exponential() { lambdaTable.setMin(.0001, false); }