예제 #1
0
 def testDivsLength(self):
     for m in range(2,self.m_max):
         pm = mfng.simpleProbMeasure(m=m)
         for K in range(1,self.K_max):
             ipm = pm.iterate(K=K, maxdivs=4100)
             length = len(ipm.divs)
             self.assertEqual(length, m**K)
예제 #2
0
 def testProbsShape(self):
     for m in range(2,self.m_max):
         pm = mfng.simpleProbMeasure(m=m)
         for K in range(1,self.K_max):
             ipm = pm.iterate(K=K, maxdivs=4100)
             shape = ipm.probs.shape
             self.assertEqual(shape, (m**K,m**K))
예제 #3
0
 def testDivsLength(self):
     for m in range(2, self.m_max):
         pm = mfng.simpleProbMeasure(m=m)
         for K in range(1, self.K_max):
             ipm = pm.iterate(K=K, maxdivs=4100)
             length = len(ipm.divs)
             self.assertEqual(length, m**K)
예제 #4
0
 def testProbsShape(self):
     for m in range(2, self.m_max):
         pm = mfng.simpleProbMeasure(m=m)
         for K in range(1, self.K_max):
             ipm = pm.iterate(K=K, maxdivs=4100)
             shape = ipm.probs.shape
             self.assertEqual(shape, (m**K, m**K))
예제 #5
0
 def testProbsValues(self):
     for m in range(2,self.m_max):
         prob = 1./m**2
         for i in range(m):
             for j in range(m):
                 pm = mfng.simpleProbMeasure(m=m)
                 p = pm.probs[i,j]
                 self.assertAlmostEqual(p, prob)
예제 #6
0
 def testMaxDivs(self):
     for m in range(2, self.m_max):
         pm = mfng.simpleProbMeasure(m=m)
         for K in range(1, self.K_max):
             self.assertRaises(ValueError,
                               pm.iterate,
                               K=K,
                               maxdivs=m**K - 1)
예제 #7
0
 def testProbsValues(self):
     for m in range(2, self.m_max):
         prob = 1. / m**2
         for i in range(m):
             for j in range(m):
                 pm = mfng.simpleProbMeasure(m=m)
                 p = pm.probs[i, j]
                 self.assertAlmostEqual(p, prob)
예제 #8
0
 def testDivsValues(self):
     for m in range(2,self.m_max):
         pm = mfng.simpleProbMeasure(m=m)
         divs = pm.divs
         value = 0.
         delta = 1./m
         for i in range(m):
             value += delta
             self.assertAlmostEqual(value, divs[i])
예제 #9
0
 def testDivsValues(self):
     for m in range(2, self.m_max):
         pm = mfng.simpleProbMeasure(m=m)
         divs = pm.divs
         value = 0.
         delta = 1. / m
         for i in range(m):
             value += delta
             self.assertAlmostEqual(value, divs[i])
예제 #10
0
 def testIteratedValue(self):
     for value in self.known_values:
         m = value["m"]
         K = value["K"]
         divs = value["divs"]
         pm = mfng.simpleProbMeasure(m=m)
         ipm = pm.iterate(K=K)
         for i, j in zip(ipm.divs, divs):
             self.assertAlmostEqual(i, j)
예제 #11
0
 def testIteratedValue(self):
     for value in self.known_values:
         m = value["m"]
         K = value["K"]
         divs = value["divs"]
         pm = mfng.simpleProbMeasure(m=m)
         ipm = pm.iterate(K=K)
         for i, j in zip(ipm.divs, divs):
             self.assertAlmostEqual(i, j)
예제 #12
0
    def probmeasure(self, iterated=True, initial=False, **kwargs):
        """Returns the link probability or the generator measure.

        It can be plotted then.

        Parameters:
            `iterated`: boolean
                If True it returns with the iterated measure.
                (with the link probability measure)
            `initial`: boolean
                If True it returns with the initial measure.
            `label`: string or None
                If string, it will use this as label.

        Example. In this example the link probability measure and the generator
        measure will be plotted. ::

            >>> pm=r.probmeasure()
            >>> pm.plot(ticklabels=False)
            <matplotlib.axes.AxesSubplot object at 0x8f05d0c>
            >>> pm=r.probmeasure(iterated=False)
            >>> pm.plot()
            <matplotlib.axes.AxesSubplot object at 0x9632eec>

        """
        label = kwargs.get("label")
        if not label and (not isinstance(self.labels, list)
                          or not self.labels):
            raise NoLabelsError
        if not label:
            label = self.labels[-1]
        run = self.runs[label]

        if initial:
            pm = mfng.simpleProbMeasure(m=run["m"])
        else:
            divs = run["divs"]
            probs = run["probs"]
            pm = ProbMeasure(divs, probs)

        if iterated:
            K = run.get("K") or run.get(
                "k")  # Older files have k instead of K.
            pm = pm.iterate(K)

        return pm
예제 #13
0
    def probmeasure(self, iterated=True, initial=False, **kwargs):
        """Returns the link probability or the generator measure.

        It can be plotted then.

        Parameters:
            `iterated`: boolean
                If True it returns with the iterated measure.
                (with the link probability measure)
            `initial`: boolean
                If True it returns with the initial measure.
            `label`: string or None
                If string, it will use this as label.

        Example. In this example the link probability measure and the generator
        measure will be plotted. ::

            >>> pm=r.probmeasure()
            >>> pm.plot(ticklabels=False)
            <matplotlib.axes.AxesSubplot object at 0x8f05d0c>
            >>> pm=r.probmeasure(iterated=False)
            >>> pm.plot()
            <matplotlib.axes.AxesSubplot object at 0x9632eec>

        """
        label = kwargs.get("label")
        if not label and (not isinstance(self.labels, list) or not self.labels):
            raise NoLabelsError
        if not label:
            label=self.labels[-1]
        run = self.runs[label]

        if initial:
            pm = mfng.simpleProbMeasure(m=run["m"])
        else:
            divs = run["divs"]
            probs = run["probs"]
            pm = ProbMeasure(divs, probs)

        if iterated:
            K = run.get("K") or run.get("k")  # Older files have k instead of K.
            pm = pm.iterate(K)

        return pm
예제 #14
0
 def testAvgDegree(self):
     pm = mfng.simpleProbMeasure(m=3)
     self.assertAlmostEqual(pm.avg_degree(9001), 1000)
예제 #15
0
 def testAvgDegree(self):
     pm = mfng.simpleProbMeasure(m=3)
     self.assertAlmostEqual(pm.avg_degree(9001), 1000)
예제 #16
0
 def testProbsShape(self):
     for m in range(2, self.m_max):
         pm = mfng.simpleProbMeasure(m=m)
         shape = pm.probs.shape
         self.assertEqual(shape, (m, m))
예제 #17
0
 def testDivsLength(self):
     for m in range(2, self.m_max):
         pm = mfng.simpleProbMeasure(m=m)
         length = len(pm.divs)
         self.assertEqual(length, m)
예제 #18
0
 def testMaxDivs(self):
     for m in range(2,self.m_max):
         pm = mfng.simpleProbMeasure(m=m)
         for K in range(1,self.K_max):
             self.assertRaises(ValueError, pm.iterate, K=K, maxdivs=m**K-1)
예제 #19
0
 def testTooManyDivs(self):
     m  = 4
     pm = mfng.simpleProbMeasure(m=m)
     K = 5
     # 4**4 = 216
     self.assertRaises(ValueError, pm.iterate, K=K)
예제 #20
0
 def testTooManyDivs(self):
     m = 4
     pm = mfng.simpleProbMeasure(m=m)
     K = 5
     # 4**4 = 216
     self.assertRaises(ValueError, pm.iterate, K=K)
예제 #21
0
 def testDivsLength(self):
     for m in range(2,self.m_max):
         pm = mfng.simpleProbMeasure(m=m)
         length = len(pm.divs)
         self.assertEqual(length, m)
예제 #22
0
 def testProbsShape(self):
     for m in range(2,self.m_max):
         pm = mfng.simpleProbMeasure(m=m)
         shape = pm.probs.shape
         self.assertEqual(shape, (m,m))