Esempio n. 1
0
    def grad_loop(self, miu):
        """Gradient function for optimization

        Calculate gradient of objective function using finite differences.
        Is called by get_ipopt_miu(). Calls loop(). Stores and returns result.

        Args:
            miu (nd.array): Array of values for miu, n = Dice().params.tmax

        Returns:
            nd.array: gradient of objective

        """
        df = DiceDataMatrix(np.tile(self.vars, (61, 1, 1)).transpose(1, 2, 0))
        for i in xrange(self.params.tmax):
            df.miu[i, :] = miu[i]
            df.miu[i, i] += self.eps
            self.step(i, df, df.miu[i], deriv=True, opt=True)
        self.set_opt_values(df)
        return self.opt_grad_f
Esempio n. 2
0
    def obj_loop(self, miu):
        """Objective function for optimization

        Calculate objective function. Is called by get_ipopt_miu().
        Calls loop(). Stores and returns result.

        Args:
            miu (nd.array): Array of values for miu, n = Dice().params.tmax

        Returns:
            float: value of objective (utility)

        """
        df = DiceDataMatrix(np.tile(self.vars, (61, 1, 1)).transpose(1, 2, 0))
        for i in xrange(self.params.tmax):
            df.miu[i, :] = miu[i]
            df.miu[i, i] += self.eps
            self.step(i, df, df.miu[i], deriv=True, opt=True)
        self.set_opt_values(df)
        return self.opt_obj