コード例 #1
0
ファイル: __init__.py プロジェクト: Rainbow1994/DAPPER
# "interaction" coefficients
A = np.array([
    [1,     1.09,  1.52,  0],
    [0,     1,     0.44,  1.36],
    [2.33,  0,     1,     0.47],
    [1.21,  0.51,  0.35,  1]
])

x0 = 0.25*np.ones(Nx)


def dxdt(x):
    return (r*x) * (1 - [email protected])


step = dpr.with_rk4(dxdt, autonom=True)

Tplot = 100


def d2x_dtdx(x):
    return np.diag(r - r*(A@x)) - (r*x)[:, None]*A


def dstep_dx(x, t, dt):
    return integrate_TLM(d2x_dtdx(x), dt, method='approx')


def LP_setup(jj): return LPs(jj, params=dict())
コード例 #2
0
ファイル: demo.py プロジェクト: Rainbow1994/DAPPER
"""Demonstrate the Lorenz two-speed/scale/layer model."""

import numpy as np
from matplotlib import pyplot as plt

import dapper as dpr
from dapper.mods.LorenzUV.lorenz96 import LUV
from dapper.tools.utils import progbar
from dapper.tools.viz import setup_wrapping

nU, J = LUV.nU, LUV.J

dt = 0.005
K  = int(4/dt)

step_1 = dpr.with_rk4(LUV.dxdt, autonom=True)
step_K = dpr.with_recursion(step_1, prog='Simulating')

xx = step_K(LUV.x0, K, np.nan, dt)

# Grab parts of state vector
ii, wrapU = setup_wrapping(nU)
jj, wrapV = setup_wrapping(nU*J)

# Animate linear
plt.figure()
lhU = plt.plot(ii,   wrapU(xx[-1, :nU]), 'b', lw=3)[0]
lhV = plt.plot(jj/J, wrapV(xx[-1, nU:]), 'g', lw=2)[0]
for k in progbar(range(K), 'Plotting'):
    lhU.set_ydata(wrapU(xx[k, :nU]))
    lhV.set_ydata(wrapV(xx[k, nU:]))
コード例 #3
0
ファイル: l2s_utils.py プロジェクト: brajard/reddaml
 def step(x0, t0, dt):
     physical_step = with_rk4(LUV.dxdt_trunc, autonom=True)
     ml_step = model_nn.predict
     output = physical_step(
         x0, t0, dt) + dt * ml_step(x0[..., np.newaxis]).squeeze()
     return output
コード例 #4
0
from dapper.mods.LorenzUV import model_instance

LUV = model_instance(nU=36, J=10, F=10)
nU = LUV.nU


################
# Full
################

t = dpr.Chronology(dt=0.005, dtObs=0.05, T=4**3, BurnIn=6)


Dyn = {
    'M': LUV.M,
    'model': dpr.with_rk4(LUV.dxdt, autonom=True),
    'noise': 0,
    'linear': LUV.dstep_dx,
}

X0 = dpr.GaussRV(mu=LUV.x0, C=0.01)

R = 1.0
jj = np.arange(nU)
Obs = dpr.partial_Id_Obs(LUV.M, jj)
Obs['noise'] = R

other = {'name': utils.rel2mods(__file__)+'_full'}
HMM_full = dpr.HiddenMarkovModel(Dyn, Obs, t, X0, **other)

コード例 #5
0
ファイル: l2s_utils.py プロジェクト: brajard/reddaml
                            vmax=vdelta)
    ax[0].set_ylabel(labels[0])
    ax[1].set_ylabel(labels[1])
    ax[2].set_ylabel(labels[1][:2] + ' - ' + labels[0][:2])
    for i in delta:
        fig.colorbar(delta[i], cax=cax[i], orientation='vertical')
    return fig, ax


def other():
    print()


# trunc HMM (no param)
HMM_trunc = copy.deepcopy(HMM_trunc_dapper)
HMM_trunc.Dyn.model = with_rk4(LUV.dxdt_trunc, autonom=True)

import numpy as np
from dapper import ens_compatible, Id_mat, GaussRV, Operator


#TODO: allow list of index instead of maxind
class Observator:
    """This class handles sparse observations. It allows to create a dapper-compatible observation operators
	"""
    def __init__(self,
                 t,
                 m,
                 max_ind=None,
                 std_o=1,
                 p=None,