Exemplo n.º 1
0
    def test_SW_nrj_2C_3C(self):
        size = 400
        shape = (int(size**.5), int(size**.5))
        mask = _np.ones(shape, dtype=int)  # full mask
        g = graph_from_lattice(mask, kerMask=kerMask2D_4n)
        betas = _np.arange(0, 2.7, .2)
        nitMC = 100
        mU2C = _np.zeros(len(betas))
        vU2C = _np.zeros(len(betas))
        mU3C = _np.zeros(len(betas))
        vU3C = _np.zeros(len(betas))

        nrjCalc = field_energy_calculator(g)

        # print "nbClasses = 2"
        for ib, b in enumerate(betas):
            # print '    MC for beta ', b
            pottsGen = potts_generator(graph=g,
                                       beta=b,
                                       nbLabels=2,
                                       method='SW')
            mU2C[ib], vU2C[ib] = montecarlo(pottsGen, nrjCalc, nbit=nitMC)

        # print '  mu2C=',mU2C
        # print '  vU2C=',vU2C

        # print "nbClasses = 3"
        for ib, b in enumerate(betas):
            # print '    MC for beta ', b
            pottsGen = potts_generator(graph=g,
                                       beta=b,
                                       nbLabels=3,
                                       method='SW')
            mU3C[ib], vU3C[ib] = montecarlo(pottsGen, nrjCalc, nbit=nitMC)

        # print '  mu3C=',mU3C
        # print '  vU3C=',vU3C

        if config.savePlots:
            import matplotlib.pyplot as plt
            plt.plot(betas, mU2C, 'b-', label="2C")
            plt.errorbar(betas, mU2C, vU2C**.5, fmt=None, ecolor='b')
            plt.plot(betas, mU3C, 'r-', label="3C")
            plt.errorbar(betas, mU3C, vU3C**.5, fmt=None, ecolor='r')
            plt.legend(loc='upper right')
            plt.title(
                'Mean energy in terms of beta \n for 2-color and 3-color Potts (SW sampling)'
            )
            plt.xlabel('beta')
            plt.ylabel('mean U per site')
            plt.xlim(betas[0] - .1, betas[-1] * 1.05)
            figFn = os.path.join(self.outDir, figfn('potts_energy_2C_3C'))
            # print figFn
            plt.savefig(figFn)
Exemplo n.º 2
0
    def test_SW_nrj_2C_3C(self):
        size = 400
        shape = (int(size ** .5), int(size ** .5))
        mask = _np.ones(shape, dtype=int)  # full mask
        g = graph_from_lattice(mask, kerMask=kerMask2D_4n)
        betas = _np.arange(0, 2.7, .2)
        nitMC = 100
        mU2C = _np.zeros(len(betas))
        vU2C = _np.zeros(len(betas))
        mU3C = _np.zeros(len(betas))
        vU3C = _np.zeros(len(betas))

        nrjCalc = field_energy_calculator(g)

        # print "nbClasses = 2"
        for ib, b in enumerate(betas):
            # print '    MC for beta ', b
            pottsGen = potts_generator(graph=g, beta=b, nbLabels=2,
                                       method='SW')
            mU2C[ib], vU2C[ib] = montecarlo(pottsGen, nrjCalc, nbit=nitMC)

        # print '  mu2C=',mU2C
        # print '  vU2C=',vU2C

        # print "nbClasses = 3"
        for ib, b in enumerate(betas):
            # print '    MC for beta ', b
            pottsGen = potts_generator(graph=g, beta=b, nbLabels=3,
                                       method='SW')
            mU3C[ib], vU3C[ib] = montecarlo(pottsGen, nrjCalc, nbit=nitMC)

        # print '  mu3C=',mU3C
        # print '  vU3C=',vU3C

        if config.savePlots:
            import matplotlib.pyplot as plt
            plt.plot(betas, mU2C, 'b-', label="2C")
            plt.errorbar(betas, mU2C, vU2C ** .5, fmt=None, ecolor='b')
            plt.plot(betas, mU3C, 'r-', label="3C")
            plt.errorbar(betas, mU3C, vU3C ** .5, fmt=None, ecolor='r')
            plt.legend(loc='upper right')
            plt.title(
                'Mean energy in terms of beta \n for 2-color and 3-color Potts (SW sampling)')
            plt.xlabel('beta')
            plt.ylabel('mean U per site')
            plt.xlim(betas[0] - .1, betas[-1] * 1.05)
            figFn = os.path.join(self.outDir, figfn('potts_energy_2C_3C'))
            # print figFn
            plt.savefig(figFn)
Exemplo n.º 3
0
    def test_sw_nrj(self):
        size = 100
        shape = (int(size**.5), int(size**.5))
        mask = _np.ones(shape, dtype=int) #full mask
        g = graph_from_lattice(mask, kerMask=kerMask2D_4n)
        nc = 2
        betas = _np.arange(0, 1.4, .2)
        mU = _np.zeros(len(betas))
        vU = _np.zeros(len(betas))

        nrjCalc = field_energy_calculator(g)
        
        for ib, b in enumerate(betas):
            #print 'MC for beta ', b
            pottsGen = potts_generator(graph=g, beta=b, nbLabels=nc,
                                       method='SW')
            mU[ib], vU[ib] = montecarlo(pottsGen, nrjCalc, nbit=40)
            
        if config.savePlots:
            import matplotlib.pyplot as plt
            plt.plot(betas, mU)
            plt.errorbar(betas, mU, vU**.5)
            plt.xlabel('beta')
            plt.ylabel('mean U per site')
            plt.show()
Exemplo n.º 4
0
    def test_sw_nrj(self):
        size = 100
        shape = (int(size**.5), int(size**.5))
        mask = _np.ones(shape, dtype=int)  # full mask
        g = graph_from_lattice(mask, kerMask=kerMask2D_4n)
        nc = 2
        betas = _np.arange(0, 1.4, .2)
        mU = _np.zeros(len(betas))
        vU = _np.zeros(len(betas))

        nrjCalc = field_energy_calculator(g)

        for ib, b in enumerate(betas):
            pottsGen = potts_generator(graph=g,
                                       beta=b,
                                       nbLabels=nc,
                                       method='SW')
            mU[ib], vU[ib] = montecarlo(pottsGen, nrjCalc, nbit=40)

        if config.savePlots:
            import matplotlib.pyplot as plt
            plt.plot(betas, mU)
            plt.errorbar(betas, mU, vU**.5)
            plt.xlabel('beta')
            plt.ylabel('mean U per site')
            plt.show()
Exemplo n.º 5
0
    def test_SW_nrj(self):
        size = 100
        shape = (int(size**.5), int(size**.5))
        mask = _np.ones(shape, dtype=int)  # full mask
        g = graph_from_lattice(mask, kerMask=kerMask2D_4n)
        nc = 2
        betas = _np.arange(0, 2.5, .2)
        mU = _np.zeros(len(betas))
        vU = _np.zeros(len(betas))

        nrjCalc = field_energy_calculator(g)

        for ib, b in enumerate(betas):
            # print 'MC for beta ', b
            pottsGen = potts_generator(graph=g,
                                       beta=b,
                                       nbLabels=nc,
                                       method='SW')
            mU[ib], vU[ib] = montecarlo(pottsGen, nrjCalc, nbit=5)

        if 0:
            import matplotlib.pyplot as plt
            plt.plot(betas, mU, 'b-')
            plt.errorbar(betas, mU, vU**.5, fmt=None, ecolor='b')

        for ib, b in enumerate(betas):
            # print 'MC for beta ', b
            pottsGen = potts_generator(graph=g,
                                       beta=b,
                                       nbLabels=3,
                                       method='SW')
            mU[ib], vU[ib] = montecarlo(pottsGen, nrjCalc, nbit=5)

        if config.savePlots:
            plt.plot(betas, mU, 'r-')
            plt.errorbar(betas, mU, vU**.5, fmt=None, ecolor='r')
            plt.xlabel('beta')
            plt.ylabel('mean U per site')
            plt.xlim(betas[0] - .1, betas[-1] * 1.05)
            plt.show()