コード例 #1
0
ファイル: model.py プロジェクト: Filhagosa/dolo
    def get_exogenous(self):

        if "exogenous" not in self.data:
            return {}

        exo = self.data['exogenous']
        calibration = self.get_calibration()
        from dolo.compiler.language import eval_data
        exogenous = eval_data(exo, calibration)

        from ruamel.yaml.comments import CommentedMap, CommentedSeq
        from dolo.numeric.processes import ProductProcess, Process
        if isinstance(exogenous, Process):
            # old style
            return exogenous
        elif isinstance(exo, list):
            # old style (2)
            return ProductProcess(*exogenous)
        else:
            # new style
            syms = self.symbols['exogenous']
            # first we check that shocks are defined in the right order
            ssyms = []
            for k in exo.keys():
                vars = [v.strip() for v in k.split(',')]
                ssyms.append(vars)
            ssyms = tuple(sum(ssyms, []))
            if tuple(syms) != ssyms:
                from dolo.compiler.language import ModelError
                lc = exo.lc
                raise ModelError(
                    f"{lc.line}:{lc.col}: 'exogenous' section. Shocks specification must match declaration order. Found {ssyms}. Expected{tuple(syms)}"
                )

            return ProductProcess(*exogenous.values())
コード例 #2
0
ファイル: model.py プロジェクト: zhuang13atJHU/dolark
    def distribution(self):

        # old style only
        calib = self.calibration.flat
        if 'distribution' in self.data:
            return eval_data(self.data['distribution'], calibration=calib)
        else:
            return None
コード例 #3
0
ファイル: model.py プロジェクト: Filhagosa/dolo
    def get_endo_grid(self):

        # determine bounds:
        domain = self.get_domain()
        min = domain.min
        max = domain.max

        options = self.data.get("options", {})

        # determine grid_type
        grid_type = get_type(options.get("grid"))
        if grid_type is None:
            grid_type = get_address(self.data,
                                    ["options:grid:type", "options:grid_type"])
        if grid_type is None:
            raise Exception('Missing grid geometry ("options:grid:type")')

        args = {'min': min, 'max': max}
        if grid_type.lower() in ('cartesian', 'cartesiangrid'):
            from dolo.numeric.grids import UniformCartesianGrid
            orders = get_address(self.data,
                                 ["options:grid:n", "options:grid:orders"])
            if orders is None:
                orders = [20] * len(min)
            grid = UniformCartesianGrid(min=min, max=max, n=orders)
        elif grid_type.lower() in ('nonuniformcartesian',
                                   'nonuniformcartesiangrid'):
            from dolo.compiler.language import eval_data
            from dolo.numeric.grids import NonUniformCartesianGrid
            calibration = self.get_calibration()
            nodes = [
                eval_data(e, calibration) for e in self.data['options']['grid']
            ]
            print(nodes)
            # each element of nodes should be a vector
            return NonUniformCartesianGrid(nodes)
        elif grid_type.lower() in ('smolyak', 'smolyakgrid'):
            from dolo.numeric.grids import SmolyakGrid
            mu = get_address(self.data, ["options:grid:mu"])
            if mu is None:
                mu = 2
            grid = SmolyakGrid(min=min, max=max, mu=mu)
        else:
            raise Exception("Unknown grid type.")

        return grid
コード例 #4
0
ファイル: model.py プロジェクト: Filhagosa/dolo
    def get_domain(self):

        calibration = self.get_calibration()
        states = self.symbols['states']

        sdomain = self.data.get("domain", {})
        for k in sdomain.keys():
            if k not in states:
                sdomain.pop(k)

        # backward compatibility
        if len(sdomain) == 0 and len(states) > 0:
            try:
                import warnings
                min = get_address(self.data,
                                  ["options:grid:a", "options:grid:min"])
                max = get_address(self.data,
                                  ["options:grid:b", "options:grid:max"])
                for i, s in enumerate(states):
                    sdomain[s] = [min[i], max[i]]
                # shall we raise a warning for deprecated syntax ?
            except Exception as e:
                print(e)
                pass

        if len(sdomain) < len(states):
            missing = [s for s in states if s not in sdomain]
            raise Exception("Missing domain for states: {}.".format(
                str.join(', ', missing)))

        from dolo.compiler.objects import Domain
        from dolo.compiler.language import eval_data
        sdomain = eval_data(sdomain, calibration)
        domain = Domain(**sdomain)
        domain.states = states

        return domain
コード例 #5
0
ファイル: model.py プロジェクト: zhuang13atJHU/dolark
    def exogenous(self):

        # old style only
        calib = self.calibration.flat
        return eval_data(self.data['exogenous'], calibration=calib)