コード例 #1
0
 def __init__(self, f, **kwargs):
     self.f = f
     self.input_list = utils.input_list(
         f) if "input_list" not in kwargs else kwargs["input_list"]
     self.output_list = utils.output_list(
         f) if "output_list" not in kwargs else kwargs["output_list"]
     self.inputs = set(self.input_list)
     self.outputs = set(self.output_list)
コード例 #2
0
    def attach_hetinput(self, hetinput):
        """Make new HetBlock that first processes inputs through function hetinput.
        Assumes 'self' currently does not have hetinput."""
        if self.hetinput is not None:
            raise ValueError('Trying to attach hetinput when it is already there!')

        newself = copy.deepcopy(self)
        newself.hetinput = hetinput
        newself.hetinput_inputs = set(utils.input_list(hetinput))
        newself.hetinput_outputs_order = utils.output_list(hetinput)

        # modify inputs to include hetinput's additional inputs, remove outputs
        newself.inputs |= newself.hetinput_inputs
        newself.inputs -= set(newself.hetinput_outputs_order)
        return newself
コード例 #3
0
ファイル: base.py プロジェクト: Chauhandeep/rbac
    def render(self):
        """
        Function to render the input form
        and capture the input data
        :return: Dict
        """
        clear()
        self.show_banner()

        admin_check = getattr(self, 'only_admin', None)

        if admin_check:
            UserLogin.admin_check()

        fields = self.get_fields()

        data = {}

        for field in fields:
            if field['type'] == 'list':
                print(
                    f'Enter {self.BOLD_COLOR}{stringcase.pascalcase(field["name"])}{self.COLOR_END}'
                )
                if field.get('supporting_text'):
                    print(f'({field["supporting_text"]})')
                data[field['name']] = input_list()
            else:
                print(
                    f'Enter {self.BOLD_COLOR}{stringcase.pascalcase(field["name"])}{self.COLOR_END}'
                )
                if field.get('supporting_text'):
                    print(f'({field["supporting_text"]})')
                data[field['name']] = input()

        print('\nDetails Entered: ')

        print(json.dumps(data, indent=2))

        print('\n')

        prompt_enter()

        self.pre_save()
        self.save(data)
        self.post_save()
コード例 #4
0
    def __init__(self, back_step_fun, exogenous, policy, backward):
        """Construct HetBlock from backward iteration function.

        Parameters
        ----------
        back_step_fun : function
            backward iteration function
        exogenous : str
            names of Markov transition matrix for exogenous variable
            (now only single allowed for simplicity; use Kronecker product for more)
        policy : str or sequence of str
            names of policy variables of endogenous, continuous state variables
            e.g. assets 'a', must be returned by function
        backward : str or sequence of str
            variables that together comprise the 'v' that we use for iterating backward
            must appear both as outputs and as arguments

        It is assumed that every output of the function (except possibly backward), including policy,
        will be on a grid of dimension 1 + len(policy), where the first dimension is the exogenous
        variable and then the remaining dimensions are each of the continuous policy variables, in the
        same order they are listed in 'policy'.

        The Markov transition matrix between the current and future period and backward iteration
        variables should appear in the backward iteration function with '_p' subscripts ("prime") to
        indicate that they come from the next period.

        Currently, we only support up to two policy variables.
        """

        self.back_step_fun = back_step_fun

        self.all_outputs_order = utils.output_list(back_step_fun)
        all_outputs = set(self.all_outputs_order)
        self.all_inputs = set(utils.input_list(back_step_fun))

        self.exogenous = exogenous
        self.policy, self.backward = (utils.make_tuple(x) for x in (policy, backward))

        if len(self.policy) > 2:
            raise ValueError(f"More than two endogenous policies in {back_step_fun.__name__}, not yet supported")

        self.inputs_p = {self.exogenous} | set(self.backward)

        # input checking
        if self.exogenous + '_p' not in self.all_inputs:
            raise ValueError(f"Markov matrix '{self.exogenous}_p' not included as argument in {back_step_fun.__name__}")
        
        for pol in self.policy:
            if pol not in all_outputs:
                raise ValueError(f"Policy '{pol}' not included as output in {back_step_fun.__name__}")

        for back in self.backward:
            if back + '_p' not in self.all_inputs:
                raise ValueError(f"Backward variable '{back}_p' not included as argument in {back_step_fun.__name__}")

            if back not in all_outputs:
                raise ValueError(f"Backward variable '{back}' not included as output in {back_step_fun.__name__}")

        self.non_back_outputs = all_outputs - set(self.backward)
        for out in self.non_back_outputs:
            if out.isupper():
                raise ValueError("Output '{out}' is uppercase in {back_step_fun.__name__}, not allowed")

        # aggregate outputs and inputs for utils.block_sort
        self.inputs = self.all_inputs - {k + '_p' for k in self.backward}
        self.inputs.remove(exogenous + '_p')
        self.inputs.add(exogenous)
        
        self.outputs = {k.upper() for k in self.non_back_outputs}

        # start without a hetinput
        self.hetinput = None
        self.hetinput_inputs = set()
        self.hetinput_outputs_order = tuple()

        # 'saved' arguments start empty
        self.saved = {}
        self.prelim_saved = {}
        self.saved_shock_list = []
        self.saved_output_list = []
コード例 #5
0
 def __init__(self, f):
     self.f = f
     self.input_list = utils.input_list(f)
     self.output_list = utils.output_list(f)
     self.inputs = set(self.input_list)
     self.outputs = set(self.output_list)