-
Notifications
You must be signed in to change notification settings - Fork 149
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from mrognlie/refactor
Consolidate refactor
- Loading branch information
Showing
78 changed files
with
4,648 additions
and
6,026 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 11 additions & 14 deletions
25
src/sequence_jacobian/blocks/auxiliary_blocks/jacobiandict_block.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,23 @@ | ||
"""A simple wrapper for JacobianDicts to be embedded in DAGs""" | ||
|
||
from numbers import Real | ||
from typing import Dict, Union, List | ||
|
||
from ...primitives import Block, Array | ||
from ...jacobian.classes import JacobianDict | ||
|
||
from ..block import Block | ||
from ...classes import ImpulseDict, JacobianDict | ||
|
||
class JacobianDictBlock(JacobianDict, Block): | ||
"""A wrapper for nested dicts/JacobianDicts passed directly into DAGs to ensure method compatibility""" | ||
def __init__(self, nesteddict, outputs=None, inputs=None, name=None): | ||
super().__init__(nesteddict, outputs=outputs, inputs=inputs, name=name) | ||
Block.__init__(self) | ||
|
||
def __repr__(self): | ||
return f"<JacobianDictBlock outputs={self.outputs}, inputs={self.inputs}>" | ||
|
||
def impulse_linear(self, ss: Dict[str, Union[Real, Array]], | ||
exogenous: Dict[str, Array], **kwargs) -> Dict[str, Array]: | ||
return self.jacobian(list(exogenous.keys())).apply(exogenous) | ||
def _impulse_linear(self, ss, inputs, outputs, Js): | ||
return ImpulseDict(self.jacobian(ss, list(inputs.keys()), outputs, inputs.T, Js).apply(inputs)) | ||
|
||
def jacobian(self, exogenous: List[str] = None, **kwargs) -> JacobianDict: | ||
if exogenous is None: | ||
return JacobianDict(self.nesteddict) | ||
else: | ||
return self[:, exogenous] | ||
def _jacobian(self, ss, inputs, outputs, T): | ||
if not inputs <= self.inputs: | ||
raise KeyError(f'Asking JacobianDictBlock for {inputs - self.inputs}, which are among its inputs {self.inputs}') | ||
if not outputs <= self.outputs: | ||
raise KeyError(f'Asking JacobianDictBlock for {outputs - self.outputs}, which are among its outputs {self.outputs}') | ||
return self[outputs, inputs] |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.