Exemple #1
0
 def objf(a, b, c):
     gcpsf = lambda ps: a*np.exp(-(ps/c)**b)
     try:
         res = simf(gcpsf, r0=r0, r1=r1, t0=t0, t1=t1)
     except ValueError:
         res = 0
     return res
Exemple #2
0
def f(r0=0.3, r1=0, t0=100, t1=1):
    # objective function
    def objf(a, b, c):
        gcpsf = lambda ps: a*np.exp(-(ps/c)**b)
        try:
            res = simf(gcpsf, r0=r0, r1=r1, t0=t0, t1=t1)
        except ValueError:
            res = 0
        return res

    # parameter space
    pbounds = {'a': (0, 1), 'b': (0, 10), 'c': (-1, -0.01)}
    
    # bayesian optimization
    optimizer = BayesianOptimization(
        f=objf,
        pbounds=pbounds,
        verbose=1,
        random_state=1
        )
    
    # # prior
    # optimizer.probe(
    #     params={'a': 0.4, 'b': 1, 'c': -1},
    #     lazy=True
    #     )
    
    # reiterate
    optimizer.set_bounds(new_bounds={'a': (0, 1)})
    optimizer.maximize(
        init_points=10,
        n_iter=100,
        )
    return optimizer.max['target'], simf(eller, r0=r0, r1=r1, t0=t0, t1=t1)
Exemple #3
0
from Functions import gcmaxf, net_gainf, simf
from scipy import optimize
import numpy as np
import matplotlib.pyplot as plt


def eller(ps):
    gcmax = gcmaxf(ps)
    f1 = lambda gc: -net_gainf(gc, ps)
    gc = optimize.minimize_scalar(f1, bounds=(0, gcmax), method='bounded')
    return gc.x


if __name__ == "__main__":
    total_net_gain = simf(eller)
    print(total_net_gain)

    x = np.linspace(-2, 0, 100)
    y = [eller(i) for i in x]
    y2 = [0.4 * np.exp(i) for i in x]
    plt.plot(x, y)
    plt.plot(x, y2, color='red')
Exemple #4
0
from Functions import simf
import matplotlib.pyplot as plt

s0, t = 1, 100
a, D, l, n, Z = 1.6, 0.005, 1.8 * 10**-5, 0.43, 0.8
PLC, s = simf(s0, t, a, D, l, n, Z)

# figure
fig, ax = plt.subplots()
ax.plot(PLC[0::24], color='black')
ax.set_xlabel('Days', fontsize=14)
ax.set_ylabel('Permanent PLC', fontsize=14)
ax.set_ylim(0, 1)
ax2 = ax.twinx()
ax2.plot(s[:-1][0::24], color='blue')
ax2.set_ylabel('Relative soil water availability', color='blue', fontsize=14)
ax2.set_ylim(0, 1)