コード例 #1
0
ファイル: transformer_zoo.py プロジェクト: jeremy43/autodp-1
    def compose(self, mechanism_list, coeff_list):
        """
        In the composition, we keep track of two lists of characteristic functions (Phi(t) and Phi'(t))with
        respect to the privacy loss R.V. log(p/q) and log(q/p).
        For most basic mechanisms (e.g., Gaussian mechanism, Lapalce mechanism), their phi(t) and Phi'(t) are the same.
        For some advanced mechanisms (e.g., SubsampleGaussian mechanism), their characteristic functions are not symmetric.
        """

        newmech = Mechanism()

        # update the functions: log_phi_p and log_phi_q
        def new_log_phi_p(x):
            return sum([c * mech.log_phi_p(x) for (mech, c) in zip(mechanism_list, coeff_list)])

        def new_log_phi_q(x):
            return sum([c * mech.log_phi_q(x) for (mech, c) in zip(mechanism_list, coeff_list)])

        newmech.exactPhi = False

        # For mechanism with an exact phi-function, it admits both upper and lower bound phi-functions.
        # The phi-functions of mechanisms that are being composed shall be all (upper_bound / exact_phi)  or (lower_bound / exact_phi.

        newmech.log_phi_p = lambda x: new_log_phi_p(x)
        newmech.log_phi_q = lambda x: new_log_phi_q(x)

        newmech.propagate_updates((new_log_phi_p, new_log_phi_q), 'log_phi')
        # Other book keeping
        newmech.name = self.update_name(mechanism_list, coeff_list)
        # keep track of all parameters of the composed mechanisms
        newmech.params = self.update_params(mechanism_list)

        return newmech
コード例 #2
0
ファイル: transformer_zoo.py プロジェクト: jeremy43/autodp-1
    def compose(self, mechanism_list, comp_list):
        """
        In the composition, we keep track of two lists of characteristic functions (Phi(t) and Phi'(t))with
        respect to the privacy loss R.V. log(p/q) and log(q/p).
        For most basic mechanisms (e.g., Gaussian mechanism, Laplace mechanism), their phi(t) and Phi'(t) are the same.
        For some advanced mechanisms (e.g., SubsampleGaussian mechanism), their characteristic functions are not symmetric.
        """

        newmech = Mechanism()
        def new_log_phi_p(x):
            return sum([c * mech.log_phi_p(x) for (mech, c) in zip(mechanism_list, comp_list)])

        def new_log_phi_q(x):
            return sum([c * mech.log_phi_q(x) for (mech, c) in zip(mechanism_list, comp_list)])


        # Define a composed mechanism
        newmech.log_phi_p = lambda x: new_log_phi_p(x)
        newmech.log_phi_q = lambda x: new_log_phi_q(x)


        newmech.propagate_updates((newmech.log_phi_p, newmech.log_phi_q), 'log_phi', n_quad=self.n_quad)
        # Other book keeping
        newmech.name = self.update_name(mechanism_list, comp_list)
        # keep track of all parameters of the composed mechanisms
        newmech.params = self.update_params(mechanism_list)

        return newmech