Ejemplo n.º 1
0
    def propose_second(self):
        """
        This method proposes values for stochastics based on the empirical
        covariance of the values sampled so far.

        The proposal jumps are drawn from a multivariate normal distribution.
        """

        arrayjump = self.drscale*np.dot( self.proposal_sd,\
                            np.random.normal(size=self.proposal_sd.shape[0]))

        if self.verbose > 2: print('Second jump:', arrayjump)

        # Update each stochastic individually.
        for stochastic in self.stochastics:
            jump = arrayjump[self._slices[stochastic]].squeeze()
            if np.iterable(stochastic.value):
                jump = np.reshape( arrayjump[ self._slices[stochastic]],\
                                                 np.shape(stochastic.value))
            if self.isdiscrete[stochastic]:
                jump = round_array(jump)
            stochastic.value = stochastic.value + jump

        arrayjump1 = self.arrayjump1
        arrayjump2 = arrayjump

        self.q = np.exp(-0.5 * (np.linalg.norm(
            np.dot(arrayjump2 - arrayjump1,
                   self.proposal_sd_inv), ord=2)**2 - np.linalg.norm(
                       np.dot(-arrayjump1, self.proposal_sd_inv), ord=2)**2))
Ejemplo n.º 2
0
    def propose(self):
        """
        This method proposes values for stochastics based on the empirical
        covariance of the values sampled so far.

        The proposal jumps are drawn from a multivariate normal distribution.
        """

        # fill_stdnormal(self._proposal_deviate)
        # arrayjump = np.inner(self._proposal_deviate, self._sig)

        arrayjump = np.dot(self._sig, np.random.normal(size=self._sig.shape[0]))

        # 4. Update each stochastic individually.
        for stochastic in self.stochastics:
            jump = np.reshape(arrayjump[self._slices[stochastic]], np.shape(stochastic.value))
            if self.isdiscrete[stochastic]:
                stochastic.value = stochastic.value + round_array(jump)
            else:
                stochastic.value = stochastic.value + jump
Ejemplo n.º 3
0
    def propose(self):
        """
        This method proposes values for stochastics based on the empirical
        covariance of the values sampled so far.

        The proposal jumps are drawn from a multivariate normal distribution.
        """

        #fill_stdnormal(self._proposal_deviate)
        #arrayjump = np.inner(self._proposal_deviate, self._sig)

        arrayjump = np.dot(self._sig, np.random.normal(size=self._sig.shape[0]))

        # 4. Update each stochastic individually.
        for stochastic in self.stochastics:
            jump = np.reshape(arrayjump[self._slices[stochastic]],np.shape(stochastic.value))
            if self.isdiscrete[stochastic]:
                stochastic.value = stochastic.value + round_array(jump)
            else:
                stochastic.value = stochastic.value + jump
Ejemplo n.º 4
0
    def propose(self):
        """
        This method proposes values for stochastics based on the empirical
        covariance of the values sampled so far.

        The proposal jumps are drawn from a multivariate normal distribution.
        """

        arrayjump = np.dot(self.proposal_sd,
                           np.random.normal(size=self.proposal_sd.shape[0]))
        if self.verbose > 2:
            print('Jump :', arrayjump)

        # Update each stochastic individually.
        for stochastic in self.stochastics:
            jump = arrayjump[self._slices[stochastic]].squeeze()
            if np.iterable(stochastic.value):
                jump = np.reshape(arrayjump[self._slices[stochastic]],
                                  np.shape(stochastic.value))
            if self.isdiscrete[stochastic]:
                jump = round_array(jump)
            stochastic.value = stochastic.value + jump