def test(self): numberOfBins = 4 multiplicity = 2 h = Histogram(numberOfBins, multiplicity) h.setCurrentToMinimum() h.accumulate(0, 1) h.accumulate(1, 2) h.accumulate(2, 2) h.accumulate(3, 1) frameTimes = [0, 1] recordedSpecies = [0, 1, 2] x = HistogramFrames(numberOfBins, multiplicity, recordedSpecies) x.setFrameTimes(frameTimes) for i in range(2): x.setCurrentToMinimum() for i in range(len(frameTimes)): for j in range(len(recordedSpecies)): x.histograms[i][j].merge(h) assert not x.hasErrors() stream = StringIO() writer = XmlWriter(stream) writer.beginDocument() x.writeXml(writer, 'model', 'method') writer.endDocument()
def writeMethodXml(simulation, out=None): if out: writer = XmlWriter(out) else: writer = XmlWriter() writer.beginDocument() simulation.writeXml(writer) writer.endDocument()
def writeModelSbml(model, out=None): if out: writer = XmlWriter(out) else: writer = XmlWriter() writer.beginDocument() model.writeSbml(writer, 3) writer.endDocument()
def test(self): trajectory = TimeSeriesFrames([0, 1]) trajectory.recordedSpecies = [0, 1] trajectory.recordedReactions = [0, 1] trajectory.appendPopulations([2, 3, 7, 11]) trajectory.appendReactionCounts([13, 17, 19, 23]) assert not trajectory.hasErrors() writer = XmlWriter(StringIO()) writer.beginDocument() trajectory.writeXml(writer, 'model', 'method') writer.endDocument()
def main(): import sys sys.path.insert(1, '..') from io.XmlWriter import XmlWriter recordedSpecies = [0, 1, 2] x = StatisticsAverage(recordedSpecies) x.setStatistics([1, 2, 3, 4, 5, 6]) writer = XmlWriter() writer.beginDocument() x.writeXml(writer, 'model', 'method') writer.endDocument()
def test(self): # One species, two reactions. trajectory = TimeSeriesAllReactions([0], [0, 1], 1., 5.) trajectory.appendInitialPopulations([7.]) trajectory.appendIndices([0, 1, 1, 0]) trajectory.appendTimes([1, 2, 3, 4]) assert not trajectory.hasErrors() writer = XmlWriter(StringIO()) writer.beginDocument() trajectory.writeXml(writer, 'model', 'method') writer.endDocument()
def test(self): recordedSpecies = [0, 1, 2] x = StatisticsAverage(recordedSpecies) x.setStatistics([1, 2, 3, 4, 5, 6]) assert x.statistics[0] == (1, 2) assert x.statistics[1] == (3, 4) assert x.statistics[2] == (5, 6) assert not x.hasErrors() writer = XmlWriter(StringIO()) writer.beginDocument() x.writeXml(writer, 'model', 'method') writer.endDocument()
def main(): import sys sys.path.insert(1, '..') from io.XmlWriter import XmlWriter trajectory = TimeSeriesFrames([0, 1]) trajectory.recordedSpecies = [0, 1] trajectory.recordedReactions = [0, 1] trajectory.appendPopulations([2, 3, 7, 11]) trajectory.appendReactionCounts([13, 17, 19, 23]) writer = XmlWriter() writer.beginDocument() trajectory.writeXml(writer, 'model', 'method') writer.endDocument()
def main(): import sys sys.path.insert(1, '..') from io.XmlWriter import XmlWriter frameTimes = [0, 1] recordedSpecies = [0, 1, 2] x = StatisticsFrames(recordedSpecies) x.setFrameTimes(frameTimes) x.setStatistics([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]) writer = XmlWriter() writer.beginDocument() x.writeXml(writer, 'model', 'method') writer.endDocument()
def main(): import sys sys.path.insert(1, '..') from io.XmlWriter import XmlWriter # One species, two reactions. trajectory = TimeSeriesAllReactions([0], [0, 1], 1., 5.) trajectory.appendInitialPopulations([7.]) trajectory.appendIndices([0, 1, 1, 0]) trajectory.appendTimes([1, 2, 3, 4]) writer = XmlWriter() writer.beginDocument() trajectory.writeXml(writer, 'model', 'method') writer.endDocument()
def test(self): frameTimes = [0, 1] recordedSpecies = [0, 1, 2] x = StatisticsFrames(recordedSpecies) x.setFrameTimes(frameTimes) x.setStatistics([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]) assert x.statistics[0][0] == (1, 2) assert x.statistics[0][1] == (3, 4) assert x.statistics[0][2] == (5, 6) assert x.statistics[1][0] == (7, 8) assert x.statistics[1][1] == (9, 10) assert x.statistics[1][2] == (11, 12) assert not x.hasErrors() writer = XmlWriter(StringIO()) writer.beginDocument() x.writeXml(writer, 'model', 'method') writer.endDocument()
def testPoisson1(self): # Poisson with mean 4. 20 bins. PMF = e^-lambda lambda^n / n! # Store in the first array of bins. lam = 4. size = 20 poisson = [math.exp(-lam)] for n in range(1, size): poisson.append(poisson[-1] * lam / n) cardinality = size sumOfWeights = sum(poisson) mean = 0. for i in range(size): mean += poisson[i] * i mean /= sumOfWeights summedSecondCenteredMoment = 0. for i in range(size): summedSecondCenteredMoment += poisson[i] * (i - mean)**2 stream = StringIO(repr(cardinality) + '\n' + repr(sumOfWeights) + '\n' + repr(mean) + '\n' + repr(summedSecondCenteredMoment) + '\n' + '0\n1\n' + ''.join([repr(_x) + ' ' for _x in poisson]) + '\n' + '0 ' * len(poisson) + '\n') x = Histogram() x.read(stream, 2) assert x.cardinality == cardinality assert x.sumOfWeights == sumOfWeights assert x.mean == mean assert x.summedSecondCenteredMoment == summedSecondCenteredMoment assert x.size() == len(poisson) self.assertAlmostEqual(sum(x.getProbabilities()), 1) stream = StringIO() writer = XmlWriter(stream) writer.beginDocument() x.writeXml(writer, 0, 0) writer.endDocument()