@@ -1,6 +1,6 @@
Loading
1 1
"""Discrete transitions."""
2 2
import typing
3 -
from typing import Callable, Optional
3 +
from typing import Callable, Optional, Tuple
4 4
5 5
import numpy as np
6 6
import scipy.linalg
@@ -146,15 +146,16 @@
Loading
146 146
    ):
147 147
148 148
        if rv_forwarded is None or gain is None:
149 -
            rv_forwarded, info = self.forward_rv(
149 +
            rv_forwarded, info_forwarded = self.forward_rv(
150 150
                rv,
151 151
                t=t,
152 152
                compute_gain=True,
153 153
                _diffusion=_diffusion,
154 154
                _linearise_at=_linearise_at,
155 155
            )
156 -
            gain = info["gain"]
157 -
        return condition_state_on_rv(rv_obtained, rv_forwarded, rv, gain), {}
156 +
            gain = info_forwarded["gain"]
157 +
        info = {"rv_forwarded": rv_forwarded}
158 +
        return condition_state_on_rv(rv_obtained, rv_forwarded, rv, gain), info
158 159
159 160
    @lru_cache(maxsize=None)
160 161
    def proc_noise_cov_cholesky_fun(self, t):
@@ -323,7 +324,7 @@
Loading
323 324
324 325
    def _forward_rv_classic(
325 326
        self, rv, t, compute_gain=False, _diffusion=1.0
326 -
    ) -> (randvars.RandomVariable, typing.Dict):
327 +
    ) -> Tuple[randvars.RandomVariable, typing.Dict]:
327 328
        H = self.state_trans_mat_fun(t)
328 329
        R = self.proc_noise_cov_mat_fun(t)
329 330
        shift = self.shift_vec_fun(t)
@@ -339,7 +340,7 @@
Loading
339 340
340 341
    def _forward_rv_sqrt(
341 342
        self, rv, t, compute_gain=False, _diffusion=1.0
342 -
    ) -> (randvars.RandomVariable, typing.Dict):
343 +
    ) -> Tuple[randvars.RandomVariable, typing.Dict]:
343 344
344 345
        H = self.state_trans_mat_fun(t)
345 346
        SR = self.proc_noise_cov_cholesky_fun(t)
@@ -369,7 +370,7 @@
Loading
369 370
        gain=None,
370 371
        t=None,
371 372
        _diffusion=1.0,
372 -
    ):
373 +
    ) -> Tuple[randvars.RandomVariable, typing.Dict]:
373 374
        """See Section 4.1f of:
374 375
375 376
        ``https://www.sciencedirect.com/science/article/abs/pii/S0005109805001810``.
@@ -382,10 +383,10 @@
Loading
382 383
        # make an extra prediction to compute the gain.
383 384
        if gain is None:
384 385
            if np.linalg.norm(rv_obtained.cov) > 0:
385 -
                _, info = self.forward_rv(
386 +
                rv_forwarded, info_forwarded = self.forward_rv(
386 387
                    rv, t=t, compute_gain=True, _diffusion=_diffusion
387 388
                )
388 -
                gain = info["gain"]
389 +
                gain = info_forwarded["gain"]
389 390
            else:
390 391
                gain = np.zeros((len(rv.mean), len(rv_obtained.mean)))
391 392
@@ -427,7 +428,8 @@
Loading
427 428
        new_cov_cholesky = tril_to_positive_tril(new_chol_triu.T)
428 429
        new_cov = new_cov_cholesky @ new_cov_cholesky.T
429 430
430 -
        return randvars.Normal(new_mean, new_cov, cov_cholesky=new_cov_cholesky), {}
431 +
        info = {"rv_forwarded": rv_forwarded}
432 +
        return randvars.Normal(new_mean, new_cov, cov_cholesky=new_cov_cholesky), info
431 433
432 434
    def _backward_rv_joseph(
433 435
        self,
@@ -437,12 +439,14 @@
Loading
437 439
        gain=None,
438 440
        t=None,
439 441
        _diffusion=None,
440 -
    ):
442 +
    ) -> Tuple[randvars.RandomVariable, typing.Dict]:
441 443
        # forwarded_rv is ignored in Joseph updates.
442 444
443 445
        if gain is None:
444 -
            _, info = self.forward_rv(rv, t=t, compute_gain=True, _diffusion=_diffusion)
445 -
            gain = info["gain"]
446 +
            rv_forwarded, info_forwarded = self.forward_rv(
447 +
                rv, t=t, compute_gain=True, _diffusion=_diffusion
448 +
            )
449 +
            gain = info_forwarded["gain"]
446 450
447 451
        H = self.state_trans_mat_fun(t)
448 452
        R = _diffusion * self.proc_noise_cov_mat_fun(t)
@@ -455,7 +459,9 @@
Loading
455 459
            + gain @ R @ gain.T
456 460
            + gain @ rv_obtained.cov @ gain.T
457 461
        )
458 -
        return randvars.Normal(new_mean, new_cov), {}
462 +
463 +
        info = {"rv_forwarded": rv_forwarded}
464 +
        return randvars.Normal(new_mean, new_cov), info
459 465
460 466
461 467
class DiscreteLTIGaussian(DiscreteLinearGaussian):

@@ -292,9 +292,6 @@
Loading
292 292
            t=t,
293 293
            _diffusion=_diffusion,
294 294
        )
295 -
        # assert info is empty. Otherwise, we need to change
296 -
        # things in info in which case we want to be warned.
297 -
        assert not info
298 295
299 296
        return _apply_precon(self.precon(dt), rv), info
300 297
@@ -460,10 +457,6 @@
Loading
460 457
            _diffusion=_diffusion,
461 458
        )
462 459
463 -
        # assert info is empty. Otherwise, we need to change
464 -
        # things in info in which case we want to be warned.
465 -
        assert not info
466 -
467 460
        # Undo preconditioning and return
468 461
        rv = _apply_precon(self.precon(dt), rv)
469 462
        self.driftmat = self.precon(dt) @ self.driftmat @ self.precon.inverse(dt)
@@ -603,10 +596,6 @@
Loading
603 596
            _diffusion=_diffusion,
604 597
        )
605 598
606 -
        # assert info is empty. Otherwise, we need to change
607 -
        # things in info in which case we want to be warned.
608 -
        assert not info
609 -
610 599
        # Undo preconditioning and return
611 600
        rv = _apply_precon(self.precon(dt), rv)
612 601
        self.driftmat = self.precon(dt) @ self.driftmat @ self.precon.inverse(dt)
Files Coverage
src/probnum 84.46%
Project Totals (107 files) 84.46%
1
coverage:
2
  precision: 2
3
  status:
4
    project:
5
      default:
6
        target: auto
7
        threshold: 1%
8
    patch:
9
      default:
10
        target: 90%
11
        threshold: 1%
12

13
comment:
14
  layout: "reach, diff, files"
15
  behavior: default
16
  require_changes: true
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading