Beispiel #1
0
def satWaterPressure(T, unit='kelvin'):
    """
    Returns the saturated water vapor pressure according eq (3.97) of Wallace and Hobbes, page 99.

    e0, b, T1 and T2 are constants specific for water vapor

    Parameters
    ----------
    T: float
        thermodynamic temperature

    Returns
    -------
        saturated vapor pressure of water (in kPa)
    """
    from np import exp
    e0=0.61094
    b=17.2694
    if unit=='kelvin':
        T1=273.16
        T2=35.86
    elif units=='celsius':
        T1=0.
        T2=243.04
    else:
        raise TypeError('Check your units')
    brackets=b*(T-T1)/(T-T2)
    return e0*exp(brackets)
Beispiel #2
0
def satWaterPressure(T, unit='kelvin'):
    """
    Returns the saturated water vapor pressure according eq (3.97) of Wallace and Hobbes, page 99.

    e0, b, T1 and T2 are constants specific for water vapor

    Parameters
    ----------
    T: float
        thermodynamic temperature

    Returns
    -------
        saturated vapor pressure of water (in kPa)
    """
    from np import exp
    e0 = 0.61094
    b = 17.2694
    if unit == 'kelvin':
        T1 = 273.16
        T2 = 35.86
    elif units == 'celsius':
        T1 = 0.
        T2 = 243.04
    else:
        raise TypeError('Check your units')
    brackets = b * (T - T1) / (T - T2)
    return e0 * exp(brackets)
Beispiel #3
0
def RHS(x, y, z):
    return -exp(-(x - 0.25)**2 - (y - 0.6)**2 - z**2)
Beispiel #4
0
def softmax(x):
    m = np.max(x)
    e = np.exp(x - m)
    return e / e.sum()
Beispiel #5
0
 def density(T):
     return 8.9975852012753705e3 * np.exp(
         -1.0e-6 *
         (+13.251 * T + 6.903e-3 / 2.0 * T**2 + 8.5306e-7 / 3.0 * T**3))
Beispiel #6
0
 def electrical_conductivity(T):
     return 1e6 / (28.9 - 18.8 * np.exp(-(np.log(T / 1023.0) / 2.37)**2))
Beispiel #7
0
def blurringkernel(shape, T, a, b):
    xx, yy = shape
    x, y = np.ogrid[(-xx / 2):(xx / 2), (-yy / 2):yy / 2]
    q = (np.pi * (x * a + y * b))
    q[np.where(q == 0)] = T
    return (T / q) * np.sin(q) * np.exp(-1j * q)
def f(x):
    return np.exp(-x) - x**2/2
def secDerf(x):
    return np.exp(-x) - 1
def derf(x):
    return - np.exp(-x) - x
Beispiel #11
0
    # Python实现正态分布
    import np
    import matplotlib.pyplot as plt
    import math
    # 绘制正态分布概率密度函数
    u = 0   # 均值μ
    u01 = -2
    sig = math.sqrt(0.2)  # 标准差δ
    sig01 = math.sqrt(1)
    sig02 = math.sqrt(5)
    sig_u01 = math.sqrt(0.5)
    x = np.linspace(u - 3*sig, u + 3*sig, 50)
    x_01 = np.linspace(u - 6 * sig, u + 6 * sig, 50)
    x_02 = np.linspace(u - 10 * sig, u + 10 * sig, 50)
    x_u01 = np.linspace(u - 10 * sig, u + 1 * sig, 50)
    y_sig = np.exp(-(x - u) ** 2 /(2* sig **2))/(math.sqrt(2*math.pi)*sig)
    y_sig01 = np.exp(-(x_01 - u) ** 2 /(2* sig01 **2))/(math.sqrt(2*math.pi)*sig01)
    y_sig02 = np.exp(-(x_02 - u) ** 2 / (2 * sig02 ** 2)) / (math.sqrt(2 * math.pi) * sig02)
    y_sig_u01 = np.exp(-(x_u01 - u01) ** 2 / (2 * sig_u01 ** 2)) / (math.sqrt(2 * math.pi) * sig_u01)
    plt.plot(x, y_sig, "r-", linewidth=2)
    plt.plot(x_01, y_sig01, "g-", linewidth=2)
    plt.plot(x_02, y_sig02, "b-", linewidth=2)
    plt.plot(x_u01, y_sig_u01, "m-", linewidth=2)
    # plt.plot(x, y, 'r-', x, y, 'go', linewidth=2,markersize=8)
    plt.grid(True)
    plt.show()
Beispiel #12
0
logProbability0[np.isinf(logProbability0)] = -100  # заменяем -бесконечность
logLikehood0 = logProbability0.sum()
#print(logLikehood0)

r = 1
kde1 = KernelDensity(kernel='gaussian', bandwidth=0.05)
kde1.fit(dataTrain.loc[dataTrain['Response'] == r,
                       'L1_S24_F1846'].values.reshape(-1, 1))
logProbability1 = kde1.score_samples(
    dataTest.loc[dataTest['Response'] == r,
                 'L1_S24_F1846'].values.reshape(-1, 1))
logProbability1[np.isinf(logProbability1)] = -100  # заменяем -бесконечность
logLikehood1 = logProbability1.sum()
#print(logLikehood1)

predictionProbXafter0 = np.exp(
    kde0.score_samples(dataTest['L1_S24_F1846'].values.reshape(-1, 1)))
predictionProbXafter1 = np.exp(
    kde1.score_samples(dataTest['L1_S24_F1846'].values.reshape(-1, 1)))

predictionProb0afterX = predictionProbXafter0  #тут должна быть формула Баеса
predictionProb1afterX = predictionProbXafter1  #тут должна быть формула Баеса

ind = np.argsort(
    predictionProb0afterX)  # сортировка, возвращающая индексы элементов
print(predictionProb0afterX[ind[-10:]])  # вывод последних 10 элементов
print(sum(dataTest.loc[ind[-100:], 'Response'])
      )  # количество бракованных среди 100 с максимальной вероятностью брака
ind1 = np.argsort(
    predictionProb1afterX)  # сортировка, возвращающая индексы элементов
print(predictionProb1afterX[ind1[-10:]])  # вывод последних 10 элементов
print(sum(dataTest.loc[ind1[-100:], 'Response'])
Beispiel #13
0
from django.test import TestCase
import np
# Create your tests here.
X = np.array([[0, 0, 1], [0, 1, 1], [1, 0, 1], [1, 1, 1]])
y = np.array([[0, 1, 1, 0]]).T
syn0 = 2 * np.random.random((3, 4)) - 1
syn1 = 2 * np.random.random((4, 1)) - 1
for j in xrange(60000):
    l1 = 1 / (1 + np.exp(-(np.dot(X, syn0))))
    l2 = 1 / (1 + np.exp(-(np.dot(l1, syn1))))
    l2_delta = (y - l2) * (l2 * (1 - l2))
    l1_delta = l2_delta.dot(syn1.T) * (l1 * (1 - l1))
    syn1 += l1.T.dot(l2_delta)
    syn0 += X.T.dot(l1_delta)
Beispiel #14
0
def gaussian_kernel_1d(sigma):
    kernel_radius = np.ceil(sigma) * 3
    kernel_size = kernel_radius * 2 + 1
    ax = np.arange(-kernel_radius, kernel_radius + 1., dtype=np.float32)
    kernel = np.exp(-(ax**2) / (2. * sigma**2))
    return (kernel / np.sum(kernel)).reshape(1, kernel.shape[0])
Beispiel #15
0
def sigmoid(x):
    # 應用sigmoid啟用函式
    return 1 / (1 + np.exp(-x))
 def boltzman_probability(loss1, loss2, temp):
     k = 1.
     return np.exp((loss1 - loss2) / (k * temp))