示例#1
0
 def weighting_function(freq_vec, f_changeover, sharpness):
     """ another weighting function, using tanh to prevent exp. overflow """
     weight = .5 - .5 * tanh(
         (freq_vec.squeeze()[1:] - f_changeover) * sharpness)
     weight = (weight + weight[::-1]).squeeze()
     weight = np.hstack([1., weight])
     return weight
示例#2
0
    def feedforward(self):
        # 검색 단어가 유일한 입력임
        for i in range(len(self.wordids)):
            self.ai[i] = 1.0

        # 은닉 노드 활성화
        for j in range(len(self.hiddenids)):
            sum = 0.0
            for i in range(len(self.wordids)):
                sum = sum + self.ai[i] * self.wi[i][j]
            self.ah[j] = tanh(sum)

        # 출력 노드 활성화
        for k in range(len(self.urlids)):
            sum = 0.0
            for j in range(len(self.hiddenids)):
                sum = sum + self.ah[j] * self.wo[j][k]
            self.ao[k] = tanh(sum)

        return self.ao[:]
    def feedforward(self):
        # 검색 단어가 유일한 입력임
        for i in range(len(self.wordids)):
            self.ai[i] = 1.0

        # 은닉 노드 활성화
        for j in range(len(self.hiddenids)):
            sum = 0.0
            for i in range(len(self.wordids)):
                sum = sum + self.ai[i] * self.wi[i][j]
            self.ah[j] = tanh(sum)

        # 출력 노드 활성화
        for k in range(len(self.urlids)):
            sum = 0.0
            for j in range(len(self.hiddenids)):
                sum = sum + self.ah[j] * self.wo[j][k]
            self.ao[k] = tanh(sum)

        return self.ao[:]
 def f(x, amptan, ttan):
     return amptan * pl.tanh(2 * (x / ttan)**4)
示例#5
0
 def phiPrime2(self,t):
     return 0.5*M.pi*t*M.cosh(t)/M.cosh(0.5*M.pi*M.sinh(t))**2+M.tanh(0.5*M.pi*M.sinh(t))
示例#6
0
 def phi2(self,t):
     return t*M.tanh(0.5*M.pi*M.sinh(t))
示例#7
0
def main():

    args = aTools.parseCMD()
   
    # Check if our data file exists, if not: write one.
    # Otherwise, open the file and plot.
    check = glob.glob('*JackKnifeData_Cv.dat*')
    fileNames = args.fileNames
    skip = args.skip

    # check which ensemble
    canonical=True
    if fileNames[0][0]=='g':
        canonical=False

    print fileNames
    
    if check == []:
        
        temps,Cvs,CvsErr = pl.array([]),pl.array([]),pl.array([])
        Es, EsErr = pl.array([]), pl.array([])
        rhos_rhos, rhos_rhoErr = pl.array([]), pl.array([])
   
        # open energy/ specific heat data file, write headers
        fout = open('JackKnifeData_Cv.dat', 'w')
        fout.write('#%15s\t%16s\t%16s\t%16s\t%16s\n'% (
            'T', 'E', 'Eerr', 'Cv', 'CvErr'))
        
        # open superfluid stiffness data file, write headers
        foutSup = open('JackKnifeData_super.dat','w')
        foutSup.write('#%15s\t%16s\t%16s\n'%(
            'T', 'rho_s/rho', 'rho_s/rhoErr'))
        
        # perform jackknife analysis of data, writing to disk
        if args.Crunched:   # check if we have combined data
            tempList = aTools.getHeadersFromFile(fileNames[0])
            for temp in tempList:
                temps = pl.append(temps,float(temp))
            n,n2 = 0,0
            for fileName in fileNames:
                print '\n\n---',fileName,'---\n'
                for temp in tempList:
                    print n
                    if 'Estimator' in fileName:
                        E, EEcv, Ecv, dEdB = pl.loadtxt(fileName,\
                                unpack=True, usecols=(n,n+1,n+2,n+3), delimiter=',')
                        EAve, Eerr = aTools.jackknife(E[skip:])
                        jkAve, jkErr = aTools.jackknife(
                                EEcv[skip:],Ecv[skip:],dEdB[skip:])
                        print 'T = ',float(temp),':'
                        print '<E>  = ',EAve,' +/- ',Eerr
                        print '<Cv> = ',jkAve,' +/- ',jkErr
                        Es      = pl.append(Es, EAve)
                        Cvs     = pl.append(Cvs, jkAve)
                        EsErr   = pl.append(EsErr, Eerr)
                        CvsErr  = pl.append(CvsErr, jkErr)
                        fout.write('%16.8E\t%16.8E\t%16.8E\t%16.8E\t%16.8E\n' %(
                            float(temp), EAve, Eerr, jkAve, jkErr)) 
                        n += 4
                    elif 'Super' in fileName:
                        rhos_rho = pl.loadtxt(fileName, \
                                unpack=True, usecols=(n2,), delimiter=',')
                        superAve, superErr = aTools.jackknife(rhos_rho[skip:])
                        print 'rho_s/rho = ', superAve,' +/- ',superErr
                        rhos_rhos   = pl.append(rhos_rhos, superAve)
                        rhos_rhoErr = pl.append(rhos_rhoErr, superErr)
                        foutSup.write('%16.8E\t%16.8E\t%16.8E\n' %(
                            float(temp), superAve, superErr))
                        n2 += 1


        else:       # otherwise just read in individual (g)ce-estimator files
            for fileName in fileNames:
                if canonical: 
                    temp = float(fileName[13:19])
                else:
                    temp = float(fileName[14:20])
                temps = pl.append(temps, temp)
                E, EEcv, Ecv, dEdB = pl.loadtxt(fileName, unpack=True, 
                        usecols=(4,11,12,13))
                jkAve, jkErr = aTools.jackknife(
                        EEcv[skip:],Ecv[skip:],dEdB[skip:])
                EAve, Eerr = aTools.jackknife(E[skip:])
                print 'T = ',temp
                print '<Cv> = ',jkAve,' +/- ',jkErr
                print '<E>  = ',EAve,' +/- ',Eerr
                Es      = pl.append(Es, EAve)
                Cvs     = pl.append(Cvs, jkAve)
                EsErr   = pl.append(EsErr, Eerr)
                CvsErr  = pl.append(CvsErr, jkErr)
                fout.write('%16.8E\t%16.8E\t%16.8E\t%16.8E\t%16.8E\n' %(
                    float(temp), EAve, Eerr, jkAve, jkErr)) 
        
        fout.close()

    else:
        print 'Found existing data file in CWD.'
        temps, Es, EsErr, Cvs, CvsErr = pl.loadtxt('JackKnifeData_Cv.dat', 
                unpack=True)
        temps, rhos_rhos, rhos_rhoErr = pl.loadtxt('JackKnifeData_super.dat', 
                unpack=True)
   

    errCheck = False
    if errCheck:
        EsNorm, EsErrNorm = pl.array([]), pl.array([])
        for fileName in args.fileNames:
            #Ecv,Eth = pl.loadtxt(fileName, unpack=True, usecols=(4,-5))
            Ecv = pl.loadtxt(fileName, unpack=True, usecols=(4,))
            EsNorm = pl.append(EsNorm,pl.average(Ecv))
            #ET = pl.append(ET, pl.average(Eth))
            EsErrNorm = pl.append(EsErrNorm, pl.std(Ecv)/pl.sqrt(float(len(Ecv))))
            #ETerr = pl.append(ETerr, pl.std(Eth)/pl.sqrt(float(len(Eth))))

        pl.scatter(temps, EsErrNorm, label='Standard Error', color='Navy')
        pl.scatter(temps, EsErr, label='Jackknife Error', color='Orange')
        pl.grid()
        pl.legend()
        pl.show()

    QHO = False
    if QHO:
        # analytical solutions for 1D QHO with one particle
        tempRange = pl.arange(0.01,1.0,0.01)
        Eanalytic = 0.5/pl.tanh(1.0/(2.0*tempRange))
        CvAnalytic = 1.0/(4.0*(tempRange*pl.sinh(1.0/(2.0*tempRange)))**2)

    ShareAxis=True      # shared x-axis for Cv and Energy
    # plot the specific heat vs. temperature
    if ShareAxis:
        ax1 = pl.subplot(211)
    else:
        pl.figure(1)
    if QHO: # plot analytic result
        pl.plot(tempRange,CvAnalytic, label='Exact')
    pl.errorbar(temps,Cvs,CvsErr, label='PIMC',color='Violet',fmt='o')
    if not ShareAxis:
        pl.xlabel('Temperature [K]')
    pl.ylabel('Specific Heat', fontsize=20)
    pl.grid(True)
    pl.legend(loc=2)
    
    # plot the energy vs. temperature
    if ShareAxis:
        pl.setp(ax1.get_xticklabels(), visible=False)
        ax2 = pl.subplot(212, sharex=ax1)
    else:
        pl.figure(2)
    if QHO: # plot analytic result
        pl.plot(tempRange,Eanalytic, label='Exact')
    pl.errorbar(temps,Es,EsErr, label='PIMC virial',color='Lime',fmt='o')
    pl.xlabel('Temperature [K]', fontsize=20)
    pl.ylabel('Energy [K]', fontsize=20)
    pl.grid(True)
    pl.legend(loc=2)

    pl.savefig('Helium_critical_CVest.pdf', format='pdf',
            bbox_inches='tight')

    if ShareAxis:
        pl.figure(2)
    else:
        pl.figure(3)
    pl.errorbar(temps, rhos_rhos, rhos_rhoErr)
    pl.xlabel('Temperature [K]', fontsize=20)
    pl.ylabel('Superfluid Stiffness', fontsize=20)
    pl.grid(True)

    pl.show()
示例#8
0
def sigmoid(x, H=.5, Q=1, G=60, P=1, T=0.5):
    '''Sigmoidal thresholding function.'''
    return H * (Q + tanh(G * (P * x - T)))
示例#9
0
文件: FDatAn.py 项目: MMaus/mutils
 def weighting_function(freq_vec, f_changeover, sharpness):
     """ another weighting function, using tanh to prevent exp. overflow """
     weight = .5 - .5*tanh((freq_vec.squeeze()[1:] - f_changeover) * sharpness)
     weight = (weight + weight[::-1]).squeeze()
     weight = np.hstack([1., weight])
     return weight
示例#10
0
def hfunc(x):
    "Nonlinearity used for output."
    return tanh(x)
示例#11
0
def main():

    args = parseCMD()
   
    # Check if our data file exists, if not: write one.
    # Otherwise, open the file and plot.
    check = glob.glob('*JackKnifeData_Cv.dat*')
    
    if check == []:
        
        fileNames = args.fileNames
        skip = args.skip
        
        temps,Cvs,CvsErr = pl.array([]),pl.array([]),pl.array([])
        Es, EsErr = pl.array([]),pl.array([])
        ET, ETerr = pl.array([]),pl.array([])

  
        # open new data file, write headers
        fout = open('JackKnifeData_Cv.dat', 'w')
        fout.write('#%15s\t%16s\t%16s\t%16s\t%16s\t%16s\t%16s\n'% (
            'T', 'Ecv', 'EcvErr', 'Et', 'EtErr','Cv', 'CvErr'))

        # perform jackknife analysis of data, writing to disk
        for fileName in fileNames:
            temp = float(fileName[-40:-34])
            temps = pl.append(temps, temp)

            # grab and analyze energy data
            Ecv,Eth = pl.loadtxt(fileName, unpack=True, usecols=(4,-5))
            E = pl.average(Ecv)
            Et = pl.average(Eth)
            EErr = pl.std(Ecv)/pl.sqrt(float(len(Ecv)))
            EtErr = pl.std(Eth)/pl.sqrt(float(len(Eth)))
            Es = pl.append(Es,E)
            ET = pl.append(ET, Et)
            EsErr = pl.append(EsErr, EErr)
            ETerr = pl.append(ETerr, EtErr)
            
            # grab and analyze specific heat data
            EEcv, Ecv, dEdB = pl.loadtxt(fileName, unpack=True, usecols=(11,12,13))
            jkAve, jkErr = jk.jackknife(EEcv[skip:],Ecv[skip:],dEdB[skip:])
            Cvs = pl.append(Cvs,jkAve)
            CvsErr = pl.append(CvsErr,jkErr)
            
            fout.write('%16.8E\t%16.8E\t%16.8E\t%16.8E\t%16.8E\t%16.8E\t%16.8E\n' %(
                temp, E, EErr, Et, EtErr, jkAve, jkErr))
            print 'T = ',str(temp),' complete.'
        
        fout.close()

    else:
        print 'Found existing data file in CWD.'
        temps,Es,EsErr,ET,ETerr,Cvs,CvsErr = pl.loadtxt(
                'JackKnifeData_Cv.dat', unpack=True)

    # plot specific heat for QHO
    tempRange = pl.arange(0.01,1.0,0.01)
    Eanalytic = 0.5/pl.tanh(1.0/(2.0*tempRange))
    CvAnalytic = 1.0/(4.0*(tempRange*pl.sinh(1.0/(2.0*tempRange)))**2)

    pl.figure(1)
    ax1 = pl.subplot(211)
    pl.plot(tempRange,CvAnalytic, label='Exact')
    pl.errorbar(temps,Cvs,CvsErr, label='PIMC',color='Violet',fmt='o')
    pl.ylabel('Specific Heat',fontsize=20)
    pl.title('1D QHO -- 1 boson',fontsize=20)
    pl.legend(loc=2)

    pl.setp(ax1.get_xticklabels(), visible=False)
    ax2 = pl.subplot(212, sharex=ax1)
    pl.plot(tempRange,Eanalytic, label='Exact')
    pl.errorbar(temps,Es,EsErr, label='PIMC virial',color='Lime',fmt='o')
    pl.errorbar(temps,ET,ETerr, label='PIMC therm.',color='k',fmt='o')
    #pl.scatter(temps,Es, label='PIMC')
    pl.xlabel('Temperature [K]',fontsize=20)
    pl.ylabel('Energy [K]',fontsize=20)
    pl.legend(loc=2)

    pl.savefig('1Dqho_largerCOM_800000bins_CvANDenergy.pdf',
            format='pdf', bbox_inches='tight')

    pl.show()
示例#12
0
import pylab as pl

sr = 44100.
fc = 500.

t = pl.arange(0, sr)
w = 2 * pl.pi * fc * t / sr

k = 10000. / (fc * pl.log10(fc))
scal = 1. / pl.tanh(k)
s = scal * pl.tanh(k * pl.sin(w))

pl.figure(figsize=(8, 5))

pl.subplot(211)
pl.ylim(-1.1, 1.1)
pl.plot(t[0:440] / sr, s[0:440], 'k-')
pl.xlabel("time (s)")

sig = s
N = 32768
start = 0
x = pl.arange(0, N / 2)
bins = x * sr / N
win = pl.hanning(N)
scal = N * pl.sqrt(pl.mean(win**2))
sig1 = sig[start:N + start]
window = pl.fft(sig1 * win / max(sig1))
mags = abs(window / scal)
spec = 20 * pl.log10(mags / max(mags))
示例#13
0
def hprime(x, y=None):
    if y is None:
        y = tanh(x)
    return 1 - y**2
示例#14
0
def hfunc(x):
    return tanh(x)
示例#15
0
def gfunc(x):
    return tanh(x)
示例#16
0
 def thresholding(self, x):
     '''Thresholding definition depending on threshold_type: 0 for tanh ; 1 for Brunel's function.'''
     return 0.5 * (1. + tanh(self.gamma * (x - self.theta)))
示例#17
0
 def thresholding(self, x, theta):
     '''Thresholding definition depending on threshold_type: 0 for tanh ; 1 for Brunel's function.'''
     return 0.5 * (1. + tanh(self.G * (self.P * x - theta)))
示例#18
0
           'blue':  [(0.0,  0.0, 0.0),
                     (xlo,  0.1, 0.1),
                     ((1-whiterange)/gmax,  1.0, 1.0),
                     ((1+whiterange)/gmax,  1.0, 1.0),
                     (xhi,  1.0, 1.0),
                     (xhier,0.0, 0.0),
                     (1.0,  0.0, 0.0)]}
  cmap = matplotlib.colors.LinearSegmentedColormap('mine', cdict)
  return Z, R, g2mc, cmap, gmax

pylab.figure(figsize=(21,15 + 10*dx))
pylab.subplot(1,1,1).set_aspect('equal')

Z, R, g2mc, cmap, gmax = read_g2_and_prepare_plot(zmin, 21, 15.0)
rbins = Z.shape[0]
nrmin = round(rbins/2) + 10
levels = pylab.concatenate([pylab.linspace(0, .85, 10),
                            pylab.linspace(.855, 0.99, 10),
                            pylab.linspace(1.01, 1.15, 10),
                            pylab.linspace(1.2, gmax, 10)])
g2mc = (1+pylab.tanh((R+10)/2))/2*(g2mc-1) + 1
pylab.contourf(Z[:nrmin,:], R[:nrmin,:], g2mc[:nrmin,:], levels, vmax=gmax*.5, vmin=0, cmap=cmap)
pylab.axes().get_xaxis().set_visible(False)
pylab.axes().get_yaxis().set_visible(False)
pylab.title('')
pylab.subplots_adjust(left=-0.01, right=1.02, top=1.02, bottom=-0.02)
pylab.savefig("figs/pretty-%d.svg"  % (int(ff*10)))

pylab.show()

 def f(x, amptan, ttan, amplog, tlog, sigma):
     return amptan * pl.tanh(
         2 * (x / ttan)**4) + amplog * stats.lognorm.pdf(
             x, scale=pl.exp(tlog), s=sigma)
示例#20
0
def gfunc(x):
    "Nonlinearity used for input to state."
    return tanh(x)
示例#21
0
def gfunc(x):
    "Nonlinearity used for input to state."
    return tanh(x)
示例#22
0
def hfunc(x):
    "Nonlinearity used for output."
    return tanh(x)
示例#23
0
def main():

    args = parseCMD()

    # Check if our data file exists, if not: write one.
    # Otherwise, open the file and plot.
    check = glob.glob('*JackKnifeData_Cv.dat*')

    if check == []:

        fileNames = args.fileNames
        skip = args.skip
        temps, Cvs, CvsErr = pl.array([]), pl.array([]), pl.array([])
        timeSteps = pl.array([])

        # open new data file, write headers
        fout = open('JackKnifeData_Cv.dat', 'w')
        fout.write('#%09s\t%10s\t%10s\t%10s\n' % ('T', 'tau', 'Cv', 'CvErr'))

        # perform jackknife analysis of data, writing to disk
        for fileName in fileNames:
            tau = float(fileName[-21:-14])
            temp = float(fileName[-40:-34])
            timeSteps = pl.append(timeSteps, tau)
            temps = pl.append(temps, temp)
            EEcv, Ecv, dEdB = pl.loadtxt(fileName,
                                         unpack=True,
                                         usecols=(11, 12, 13))
            jkAve, jkErr = aTools.jackknife(EEcv[skip:], Ecv[skip:],
                                            dEdB[skip:])
            print '<est> = ', jkAve, ' +/- ', jkErr
            Cvs = pl.append(Cvs, jkAve)
            CvsErr = pl.append(CvsErr, jkErr)
            fout.write('%10s\t%10s\t%10s\t%10s\n' % (temp, tau, jkAve, jkErr))
        fout.close()

    else:
        print 'Found existing data file in CWD.'
        temps, timeSteps, Cvs, CvsErr = pl.loadtxt('JackKnifeData_Cv.dat',
                                                   unpack=True)

    # make array of energies
    Es, EsErr = pl.array([]), pl.array([])
    ET, ETerr = pl.array([]), pl.array([])

    for fileName in args.fileNames:
        Ecv, Eth = pl.loadtxt(fileName, unpack=True, usecols=(4, -5))
        Es = pl.append(Es, pl.average(Ecv))
        ET = pl.append(ET, pl.average(Eth))
        EsErr = pl.append(EsErr, pl.std(Ecv) / pl.sqrt(float(len(Ecv))))
        ETerr = pl.append(ETerr, pl.std(Eth) / pl.sqrt(float(len(Eth))))

    # plot specific heat for QHO
    tempRange = pl.arange(0.01, 1.0, 0.01)
    Eanalytic = 0.5 / pl.tanh(1.0 / (2.0 * tempRange))
    CvAnalytic = 1.0 / (4.0 * (tempRange * pl.sinh(1.0 /
                                                   (2.0 * tempRange)))**2)

    if args.timeStepScaling:
        pl.figure(1)
        pl.plot(timeSteps, 0.5 / pl.tanh(1.0 / (2.0 * (temps))), label='Exact')
        pl.errorbar(timeSteps,
                    Es,
                    EsErr,
                    label='PIMC virial',
                    color='Lime',
                    fmt='o')
        pl.errorbar(timeSteps,
                    ET,
                    ETerr,
                    label='PIMC therm.',
                    color='Navy',
                    fmt='o')
        pl.xlabel('Time Step [1/K]')
        pl.ylabel('Energy [K]')
        pl.title('1D QHO -- 1 boson -- T=%s' % temps[0])
        pl.legend(loc=1)

        pl.figure(2)
        pl.plot(timeSteps,
                1.0 / (4.0 * (temps * pl.sinh(1.0 / (2.0 * temps)))**2),
                label='Exact')
        pl.errorbar(timeSteps,
                    Cvs,
                    CvsErr,
                    label='PIMC virial',
                    color='Navy',
                    fmt='o')
        pl.xlabel('Time Step [1/K]')
        pl.ylabel('Specific Heat [K]')
        pl.title('1D QHO -- 1 boson -- T=%s' % temps[0])
        pl.legend(loc=1)

    else:
        pl.figure(1)
        pl.plot(tempRange, CvAnalytic, label='Exact')
        pl.errorbar(temps, Cvs, CvsErr, label='PIMC', color='Violet', fmt='o')
        pl.xlabel('Temperature [K]')
        pl.ylabel('Specific Heat')
        pl.title('1D QHO -- 1 boson')
        pl.legend(loc=2)

        pl.figure(2)
        pl.plot(tempRange, Eanalytic, label='Exact')
        pl.errorbar(temps,
                    Es,
                    EsErr,
                    label='PIMC virial',
                    color='Lime',
                    fmt='o')
        pl.errorbar(temps, ET, ETerr, label='PIMC therm.', color='k', fmt='o')
        #pl.scatter(temps,Es, label='PIMC')
        pl.xlabel('Temperature [K]')
        pl.ylabel('Energy [K]')
        pl.title('1D QHO -- 1 boson')
        pl.legend(loc=2)

    pl.show()
示例#24
0
           'blue':  [(0.0,  0.0, 0.0),
                     (xlo,  0.1, 0.1),
                     ((1-whiterange)/gmax,  1.0, 1.0),
                     ((1+whiterange)/gmax,  1.0, 1.0),
                     (xhi,  1.0, 1.0),
                     (xhier, 0.0, 0.0),
                     (1.0,  0.0, 0.0)]}
  cmap = matplotlib.colors.LinearSegmentedColormap('mine', cdict)
  return Z, R, g2mc, cmap, gmax

pylab.figure(figsize=(21, 15 + 10*dx))
pylab.subplot(1, 1, 1).set_aspect('equal')

Z, R, g2mc, cmap, gmax = read_g2_and_prepare_plot(zmin, 21, 15.0)
rbins = Z.shape[0]
nrmin = round(rbins/2) + 10
levels = pylab.concatenate([pylab.linspace(0, .85, 10),
                            pylab.linspace(.855, 0.99, 10),
                            pylab.linspace(1.01, 1.15, 10),
                            pylab.linspace(1.2, gmax, 10)])
g2mc = (1+pylab.tanh((R+10)/2))/2*(g2mc-1) + 1
pylab.contourf(Z[:nrmin,:], R[:nrmin,:], g2mc[:nrmin,:], levels, vmax=gmax*.5, vmin=0, cmap=cmap)
pylab.axes().get_xaxis().set_visible(False)
pylab.axes().get_yaxis().set_visible(False)
pylab.title('')
pylab.subplots_adjust(left=-0.01, right=1.02, top=1.02, bottom=-0.02)
pylab.savefig("figs/pretty-%d.svg"  % (int(ff*10)))

pylab.show()