Exemplo n.º 1
0
    def Run(self, W, x, eps, seed):
        x = x.flatten()
        prng = np.random.RandomState(seed)

        if self.workload_based:
            mapping = mapper.WorkloadBased(W).mapping()
            reducer = transformation.ReduceByPartition(mapping)
            x = reducer.transform(x)
            # Reduce workload
            # W = support.reduce_queries(mapping, W)
            W = W * support.expansion_matrix(mapping)

        # Orange AHPparition(PA) operator in paper can be expressed
        # as the following sequence of simpler opeartors
        M = selection.Identity(x.shape).select()
        y = measurement.Laplace(M, self.ratio * eps).measure(x, prng)
        xest = inference.AHPThresholding(self.eta, self.ratio).infer(M, y, eps)
        mapping = mapper.AHPCluster(xest, (1 - self.ratio) * eps).mapping()

        # TR
        reducer = transformation.ReduceByPartition(mapping)

        x_bar = reducer.transform(x)
        # SI LM LS
        M_bar = selection.Identity(x_bar.shape).select()
        y_bar = measurement.Laplace(M_bar, eps * (1 - self.ratio)).measure(
            x_bar, prng)
        x_bar_hat = inference.LeastSquares().infer(M_bar, y_bar)
        x_hat = support.expansion_matrix(mapping) * x_bar_hat

        return x_hat
Exemplo n.º 2
0
    def Run(self, W, x, eps, seed):
        domain_dimension = len(self.domain_shape)
        eps_share = util.old_div(float(eps), domain_dimension)

        x = x.flatten()
        prng = np.random.RandomState(seed)
        
        Ms = []
        ys = []
        scale_factors = []
        for i in range(domain_dimension):
            # Reducde domain to get marginals
            marginal_mapping = mapper.MarginalPartition(
                domain_shape=self.domain_shape, proj_dim=i).mapping()
            reducer = transformation.ReduceByPartition(marginal_mapping)
            x_i = reducer.transform(x)

            if self.domain_shape[i] < 50:
                # run identity subplan
                M_i = selection.Identity(x_i.shape).select()
                y_i = measurement.Laplace(M_i, eps_share).measure(x_i, prng)
                noise_scale_factor = laplace_scale_factor(
                    M_i, eps_share)
                
            else:
                # run dawa subplan
                W = get_matrix(W)

                W_i = W * support.expansion_matrix(marginal_mapping)

                dawa = pmapper.Dawa(eps_share, self.ratio, self.approx)
                mapping = dawa.mapping(x_i, prng)

                reducer = transformation.ReduceByPartition(mapping)
                x_bar = reducer.transform(x_i)
                W_bar = W_i * support.expansion_matrix(mapping)

                M_bar = selection.GreedyH(x_bar.shape, W_bar).select()
                y_i = measurement.Laplace(
                    M_bar, eps_share * (1 - self.ratio)).measure(x_bar, prng)

                noise_scale_factor = laplace_scale_factor(
                    M_bar, eps_share * (1 - self.ratio))

                # expand the dawa reduction
                M_i = M_bar * support.reduction_matrix(mapping)

            MM = M_i * support.reduction_matrix(marginal_mapping)
            Ms.append(MM)
            ys.append(y_i)
            scale_factors.append(noise_scale_factor)

        x_hat = inference.LeastSquares(method='lsmr').infer(Ms, ys, scale_factors)

        return x_hat  
Exemplo n.º 3
0
    def Run(self, W, x, eps, seed):
        x = x.flatten()
        prng = np.random.RandomState(seed)
        if self.workload_based:
            mapping = mapper.WorkloadBased(W).mapping()
            reducer = transformation.ReduceByPartition(mapping)
            x = reducer.transform(x)
            # Reduce workload
            # W = support.reduce_queries(mapping, W)
            W = W * support.expansion_matrix(mapping)

        M = selection.Identity(x.shape).select()
        y = measurement.Laplace(M, eps).measure(x, prng)
        x_hat = inference.LeastSquares().infer(M, y)

        return x_hat
Exemplo n.º 4
0
 def test_Identity(self):
     op_identity = selection.Identity(self.domain_shape_1D)
     queries = op_identity.select()
     np.testing.assert_array_equal(queries.dense_matrix(), np.eye(16))
Exemplo n.º 5
0
    def ahp_partition(self, n, ratio, eta, eps):
        M = selection.Identity((n, )).select()
        y = self.laplace(M, ratio * eps)
        xest = inference.AHPThresholding(eta, ratio).infer(M, y, eps)

        return mapper.AHPCluster(xest, (1 - ratio) * eps).mapping()
Exemplo n.º 6
0
 def test_Identity(self):
     op_identity = selection.Identity(self.domain_shape_1D)
     queries = op_identity.select()
     if sparse.issparse(queries):
         queries = queries.todense()
     np.testing.assert_array_equal(queries, np.eye(16))