예제 #1
0
 def inc_normal(self, D, weight, var):
     # probability being normal
     A = abs(self.D - D) - 0.5
     B = A + 1
     probability = 0.5 * (utils.erf(B / var / math.sqrt(2)) -
                          utils.erf(A / var / math.sqrt(2)))
     self.prd_support += probability * weight
예제 #2
0
def phig(y):
    """
    Modified error function
    
    erf(y) - chandrasekhar(y)
    
    """
    return erf(y) - chandrasekhar(y)
예제 #3
0
def chandrasekhar(y):
    """ Chandrasekhar function for dynamical friction
    
    """
    
    if abs(y) < 1e-3:
        return  (2./sqrt(pi)) * y/3.
    
    return (erf(y) - (2./sqrt(pi))*y*exp(-y*y)) / (2.*y*y)
예제 #4
0
 def inverse(self, x):
     #print('sigma:' + str(self.sig))
     #print('inner_erf:', x/(np.sqrt(2)*self.sig))
     #print('erf:',utils.erf( x/(np.sqrt(2)*self.sig) ))
     #print('inverse:',-(1/self.lambd) * np.log( 0.5 - 0.5 *  utils.erf( x/(np.sqrt(2)*self.sig) ) ))
     res = np.maximum(
         -(1 / self.lambd) *
         np.log(0.5 - 0.5 * utils.erf(x / (np.sqrt(2) * self.sig)) + 1e-14),
         0)
     return np.nan_to_num(res)
예제 #5
0
 def expected_improvement(self, t):
   """Computes the expected improvement at position ``t`` under the current
   GP model.
   
   Reference "current best" is the observed ``t`` with minimal posterior
   mean."""
   
   assert isinstance(t, (float, np.float32, np.float64))
   
   # Find the observation with minimal posterior mean, if it has not yet been
   # computed by a previous call to this method
   if self.min_obs is None:
     self.min_obs = min(self.mu(tt) for tt in self.ts)
   
   # Compute posterior mean and variance at t
   m, v = self.mu(t), self.V(t)
   
   # Compute the two terms in the formula for EI and return the sum
   t1 = 0.5 * (self.min_obs-m) * (1 + erf((self.min_obs-m)/np.sqrt(2.*v)))
   t2 = np.sqrt(0.5*v/np.pi) * np.exp(-0.5*(self.min_obs-m)**2/v)
   
   return t1 + t2
예제 #6
0
파일: diagonal.py 프로젝트: Brainiarc7/TS
 def inc_normal(self, D, weight, var):
     # probability being normal
     A = abs(self.D - D) - 0.5
     B = A + 1
     probability = 0.5 * (utils.erf(B / var / math.sqrt(2)) - utils.erf(A / var / math.sqrt(2)))
     self.prd_support += probability * weight
예제 #7
0
def viscosity(surf, spec, vmax=5., nv=500, colldamping=0.):
    """
    Neoclassical viscosity calculation
    
    Parameters
    ----------

    surf  = Flux surface object (see equilibrium.py)
        .aspectRatio    = aspect ratio a/R
        .Bsqav() # < B^2 > flux-surface average
        .average( func(theta) )
        .deriv( func(theta) )
        .B(theta)
        .Bp(theta)
        
    spec  = list of Species
    
    Optional inputs
    ---------------
    
    vmax (=5.)  Maximum velocity to consider (units of vth)
    nv (=500)   Number of velocity grid points
    
    colldamping (=0.) determines collisional suppression:
       ]0,1[   Collisional suppression
       None    Shiang's result that a=1 experiences no collisional suppression
    
    """
    
    conl = connectionLength(surf)
    ft   = trappedFraction(surf)

    Bsq = surf.Bsqav() # < B^2 > flux-surface average
    
    # < (dB/dl)^2 Bp^2 / B^2 >
    dotav = surf.average(lambda x: ( surf.deriv(surf.B)(x) * surf.Bp(x) / surf.B(x) )**2 )
    
    ns = size(spec) # Number of species

    nv = 500 # Number of velocity points
    dv=vmax/(nv-1.)
    
    vd   = zeros([ns, nv])
    vt   = zeros([ns, nv])
    vtot = zeros([ns, nv])
    
    # Calculate collision times
    coltau = collisionTimes(spec)

    # Populate velocity mesh values
    # This code really needs some love
    
    for i, si in enumerate(spec):
        vtha = si.Vth # Thermal speed
        omta = vtha / conl
        vsttau = 8./(3.*pi) * ft*omta*Bsq / (dotav * vtha**2)
        
        for n in range(nv):
            vv = (n+0.5)*dv
            
            for j, sj in enumerate(spec):
                y    = vv * si.Vth / sj.Vth
                
                vdij = phig(y) / (coltau[i,j]*vv**3)
                vd[i,n] += vdij
                
                vtij = (((erf(y) - 3.*chandrasekhar(y)) / vv**3) + 4.*(si.T/sj.T + (si.Vth/sj.Vth)**2)*chandrasekhar(y)/vv)/coltau[i,j]
                vt[i,n] += vtij
            
            vd[i,n] *= 3.*sqrt(pi)/4.
            vt[i,n] *= 3.*sqrt(pi)/4.
            
            if colldamping == None:
                # Shiang's result
                fac1=1.+(1.- surf.aspectRatio**2)*vsttau*vd[i,n]/vv
                fac2=1.+5.*pi*vt[i,n]/(8.*vv*omta)
            else:
                fac1=1.+colldamping*vsttau*vd[i,n]/vv
                fac2=1.+colldamping*5.*pi*vt[i,n]/(8.*vv*omta)
            vtot[i,n] = vd[i,n] / (fac1 * fac2)
    
    # perform velocity integrals to calculate k's
    # No need to store vd,vt,vtot arrays
    rk11 = zeros(ns)
    rk12 = zeros(ns)
    rk22 = zeros(ns)

    vis = zeros([ns, 3])
    
    for i, si in enumerate(spec):
        for n in range(nv):
            vv = (n+0.5)*dv
            arg=(vv**4)*exp(-vv**2)*vtot[i,n]*dv
            rk11[i] += arg
            rk12[i] += arg*vv**2
            rk22[i] += arg*vv**4
        
        rk11[i] *= ft*8./(3.*(1.-ft)*sqrt(pi))
        rk12[i] *= ft*8./(3.*(1.-ft)*sqrt(pi))
        rk22[i] *= ft*8./(3.*(1.-ft)*sqrt(pi))
        
        print "viscosity: ", rk11[i], rk12[i], rk22[i]
        
        vis[i,0] = rk11[i]*si.density*si.mass
        vis[i,1] = (rk12[i] - 2.5*rk11[i])*si.density*si.mass
        vis[i,2] = (rk22[i] - 5.*rk12[i] + 6.25*rk11[i])*si.density*si.mass
        
    return vis
예제 #8
0
 def inverse(self, x):
     return np.sqrt(2) * self.s * utils.inv_erf(
         0.5 + 0.5 * utils.erf(x / (np.sqrt(2) * self.sig)))