use of cbit.vcell.math.GaussianDistribution in project vcell by virtualcell.
the class XmlReader method getGaussianDistribution.
private GaussianDistribution getGaussianDistribution(Element distElement) {
Element element = distElement.getChild(XMLTags.GaussianDistributionMeanTag, vcNamespace);
Expression mu = unMangleExpression(element.getText());
element = distElement.getChild(XMLTags.GaussianDistributionStandardDeviationTag, vcNamespace);
Expression sigma = unMangleExpression(element.getText());
return new GaussianDistribution(mu, sigma);
}
use of cbit.vcell.math.GaussianDistribution in project vcell by virtualcell.
the class Xmlproducer method getXML.
private Element getXML(RandomVariable var) {
Element randomVariableElement = null;
if (var instanceof VolumeRandomVariable) {
randomVariableElement = new Element(XMLTags.VolumeRandomVariableTag);
} else {
randomVariableElement = new Element(XMLTags.MembraneRandomVariableTag);
}
randomVariableElement.setAttribute(XMLTags.NameAttrTag, mangle(var.getName()));
Element seedElement = new Element(XMLTags.RandomVariableSeedTag);
seedElement.addContent(mangleExpression(var.getSeed()));
randomVariableElement.addContent(seedElement);
if (var.getDomain() != null) {
randomVariableElement.setAttribute(XMLTags.DomainAttrTag, mangle(var.getDomain().getName()));
}
Element distElement = null;
if (var.getDistribution() instanceof UniformDistribution) {
distElement = getXML((UniformDistribution) var.getDistribution());
} else if (var.getDistribution() instanceof GaussianDistribution) {
distElement = getXML((GaussianDistribution) var.getDistribution());
}
randomVariableElement.addContent(distElement);
return randomVariableElement;
}
use of cbit.vcell.math.GaussianDistribution in project vcell by virtualcell.
the class FiniteVolumeFileWriter method generateRandomNumbers.
private double[] generateRandomNumbers(RandomVariable rv, int numRandomNumbers) throws ExpressionException {
VariableDomain variableDomain = (rv instanceof VolumeRandomVariable) ? VariableDomain.VARIABLEDOMAIN_VOLUME : VariableDomain.VARIABLEDOMAIN_MEMBRANE;
Expression seedExpr = subsituteExpression(rv.getSeed(), variableDomain);
if (!seedExpr.isNumeric()) {
throw new ExpressionException("Seed for RandomVariable '" + rv.getName() + " is not Constant!");
}
int seed = (int) rv.getSeed().evaluateConstant();
Distribution distribution = rv.getDistribution();
double[] randomNumbers = new double[numRandomNumbers];
Random random = new Random(seed);
if (distribution instanceof UniformDistribution) {
UniformDistribution ud = (UniformDistribution) distribution;
Expression minFlattened = subsituteExpression(ud.getMinimum(), variableDomain);
Expression maxFlattened = subsituteExpression(ud.getMaximum(), variableDomain);
if (!minFlattened.isNumeric()) {
throw new ExpressionException("For RandomVariable '" + rv.getName() + "', minimum for UniformDistribution is not Constant!");
}
if (!maxFlattened.isNumeric()) {
throw new ExpressionException("For RandomVariable '" + rv.getName() + "', maximum for UniformDistribution is not Constant!");
}
double minVal = minFlattened.evaluateConstant();
double maxVal = maxFlattened.evaluateConstant();
for (int i = 0; i < numRandomNumbers; i++) {
double r = random.nextDouble();
randomNumbers[i] = (maxVal - minVal) * r + minVal;
}
} else if (distribution instanceof GaussianDistribution) {
GaussianDistribution gd = (GaussianDistribution) distribution;
Expression meanFlattened = subsituteExpression(gd.getMean(), variableDomain);
Expression sdFlattened = subsituteExpression(gd.getStandardDeviation(), variableDomain);
if (!meanFlattened.isNumeric()) {
throw new ExpressionException("For RandomVariable '" + rv.getName() + "', mean for GaussianDistribution is not Constant!");
}
if (!sdFlattened.isNumeric()) {
throw new ExpressionException("For RandomVariable '" + rv.getName() + "', standard deviation for GaussianDistribution is not Constant!");
}
double muVal = meanFlattened.evaluateConstant();
double sigmaVal = sdFlattened.evaluateConstant();
for (int i = 0; i < numRandomNumbers; i++) {
double r = random.nextGaussian();
randomNumbers[i] = sigmaVal * r + muVal;
}
}
return randomNumbers;
}
Aggregations