Beispiel #1
0
def getV(lam, tau):
    n = len(lam)
    V = np.zeros((n, n))
    ones = np.ones((n, n))
    delta = tau * (lam - lam[:, np.newaxis])  # delta_ij = lam_j-lam_i
    positive = delta >= 0
    negative = delta < 0
    a1 = tau * np.exp(tau * lam)[:, np.newaxis] * ones  # tau*e^l_i
    b1 = exprel(delta)
    V[negative] = a1[negative] * b1[negative]
    a2 = tau * np.exp(tau * lam)[np.newaxis, :] * ones  # tau*e^l_j *
    b2 = exprel(-delta)
    V[positive] = a2[positive] * b2[positive]
    return V
Beispiel #2
0
def pexpunif(t, tau, T):
    """
    Convolution of an exponential with scale tau and a uniform in (0, T).
    """
    if t <= 0:
        return 0
    elif 0 < t <= T:
        return -np.expm1(-t / tau) / T
    else:
        return np.exp(-(t - T) / tau) * special.exprel(-T / tau) / tau
def test_dwell():
    d = copy.deepcopy(D)
    s = arbplf_dwell(json.dumps(d))
    df = pd.read_json(StringIO(s), orient='split', precise_float=True)
    actual = df.pivot('edge', 'state', 'value').values
    # compute the desired closed form solution
    u = np.cumsum([0] + rates)
    a, b = u[:-1], u[1:]
    v = exprel(b - a) * exp(-b)
    desired = np.vstack([v, 1-v]).T
    # compare actual and desired result
    assert_allclose(actual, desired)
def test_truncated_dwell():
    d = copy.deepcopy(D)
    d['model_and_data']['probability_array'][0][-1] = [0, 1]
    s = arbplf_dwell(json.dumps(d))
    df = pd.read_json(StringIO(s), orient='split', precise_float=True)
    actual = df.pivot('edge', 'state', 'value').values
    # compute the desired closed form solution
    u = np.cumsum([0] + rates)
    a, b = u[:-1], u[1:]
    T = u[-1]
    # this way is not robust when a == b.
    def F(x):
        return -(exp(T - x) + x) / expm1(T)
    v = (F(b) - F(a)) / (b - a)
    desired = np.vstack([v, 1-v]).T
    # this way is better
    v = (exprel(b-a)*exp(T-b) - 1) / expm1(T)
    desired = np.vstack([v, 1-v]).T
    # compare actual and desired result
    assert_allclose(actual, desired)
Beispiel #5
0
def gen(x, name):
    """Generate fixture data and write to file.

    # Arguments

    * `x`: domain
    * `name::str`: output filename

    # Examples

    ``` python
    python> x = linspace(-1000, 1000, 2001)
    python> gen(x, './data.json')
    ```
    """
    y = exprel(x)
    data = {"x": x.tolist(), "expected": y.tolist()}

    # Based on the script directory, create an output filepath:
    filepath = os.path.join(DIR, name)

    # Write the data to the output filepath as JSON:
    with open(filepath, "w") as outfile:
        json.dump(data, outfile)
Beispiel #6
0
    def XfPar (self, fin, ini):
        r  = log( fin["Lambda"] / ini["Lambda"] )
        yc = log( fin["Alpha"]  / ini["Alpha"] )
        ys = -fin["Alpha"] * r / exprel(yc)

        return { "Alpha": yc, "Lambda": ys }
Beispiel #7
0
def lam(eps):
    ''' Calculates lambda eps (used for Jaakola & Jordan local bound) '''
    eps = -abs(eps)
    return 0.25 * exprel(eps) / (np.exp(eps) + 1)