nilsnevertree / kalman-reconstruction-partially-observed-systems

Data-driven Reconstruction of Partially Observed Dynamical Systems using Kalman Algorithms in an itterative way
GNU General Public License v3.0
1 stars 0 forks source link

Fix arguments of xarray wrapper for both Kalman_SEM versions. #54

Closed nilsnevertree closed 1 year ago

nilsnevertree commented 1 year ago

The argument random_variables is not very general.


def xarray_Kalman_SEM_time_dependent(
    ds: xr.Dataset,
    observation_variables: Iterable[str],
    random_variables: Iterable[str],
    nb_iter_SEM: int = 30,
    variance_obs_comp: float = 0.0001,
    sigma=10,
    suffix: str = "",
) -> xr.Dataset:

It might be better to use state_variables as this is the name used for most of the documentation

def xarray_Kalman_SEM_time_dependent(
    ds: xr.Dataset,
    observation_variables: Iterable[str],
    state_variables: Iterable[str],
#-- random_variables: Iterable[str],
    nb_iter_SEM: int = 30,
    variance_obs_comp: float = 0.0001,
    sigma=10,
    suffix: str = "",
) -> xr.Dataset:
nilsnevertree commented 1 year ago

With this the call of a function would change from


test = pipeline.xarray_Kalman_SEM(
    ds=data,
    observation_variables=["x2", "x3"],
    random_variables=["z1", "z2"],
    nb_iter_SEM=10,
    variance_obs_comp=0.0001,
)

to



test = pipeline.xarray_Kalman_SEM(
    ds=data,
    observation_variables=["x2", "x3", "z1", "z2"],
    state_variables=["x2", "x3"],
    nb_iter_SEM=10,
    variance_obs_comp=0.0001,
)
nilsnevertree commented 1 year ago

It would be applicable to arange that the same keys in the two arrays observations_varibles and state_variables are at same position.

Wrong order

pipeline.xarray_Kalman_SEM(
    ds=data,
    observation_variables=["x2", "x3"],
    state_variables=["x2", "z1", "x3", "z2"],
    nb_iter_SEM=10,
    variance_obs_comp=0.0001,
) 

Result Wrong_order


Correct Order

pipeline.xarray_Kalman_SEM(
    ds=data,
    observation_variables=["x2", "x3"],
    state_variables=["x2", "x3", "z1", "z2"],
    nb_iter_SEM=10,
    variance_obs_comp=0.0001,
)

Result

Correct_order

nilsnevertree commented 1 year ago

An option is to sort the arrays. This is implemented in commit #90e012e This solves the problem