示例#1
0
    def test_HB(self):
        op_HB_1D = selection.HB(self.domain_shape_1D)
        queries = op_HB_1D.select()

        self.assertEqual(len(queries.shape), 2)
        self.assertEqual(queries.shape[1], 16)

        op_HB_2D = selection.HB(self.domain_shape_2D)
        queries = op_HB_2D.select()

        self.assertEqual(len(queries.shape), 2)
        self.assertEqual(queries.shape[1], 256)
示例#2
0
    def Run(self, W, x, eps, seed):
        x = x.flatten()
        prng = np.random.RandomState(seed)

        striped_mapping = mapper.Striped(self.domain,
                                         self.stripe_dim).mapping()
        x_sub_list = meta.SplitByPartition(striped_mapping).transform(x)

        Ms = []
        ys = []
        scale_factors = []
        group_idx = sorted(set(striped_mapping))
        for i in group_idx:

            x_i = x_sub_list[group_idx.index(i)]
            P_i = support.projection_matrix(striped_mapping, i)

            M_bar = selection.HB(x_i.shape).select()
            y_i = measurement.Laplace(M_bar, eps).measure(x_i, prng)

            noise_scale_factor = laplace_scale_factor(M_bar, eps)

            M_i = M_bar * P_i

            Ms.append(M_i)
            ys.append(y_i)
            scale_factors.append(noise_scale_factor)

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

        return x_hat
示例#3
0
    def test_HB(self):
        op_HB_1D = selection.HB(self.domain_shape_1D)
        queries = op_HB_1D.select()
        if sparse.issparse(queries):
            queries = queries.todense()

        self.assertEqual(len(queries.shape), 2)
        self.assertEqual(queries.shape[1], 16)

        op_HB_2D = selection.HB(self.domain_shape_2D)
        queries = op_HB_2D.select()
        if sparse.issparse(queries):
            queries = queries.todense()

        self.assertEqual(len(queries.shape), 2)
        self.assertEqual(queries.shape[1], 256)
示例#4
0
    def Run(self, W, x, eps, seed):
        x = x.flatten()
        prng = np.random.RandomState(seed)
        M = selection.HB(self.domain_shape).select()
        y = measurement.Laplace(M, eps).measure(x, prng)
        x_hat = inference.LeastSquares().infer(M, y)

        return x_hat
示例#5
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)
            self.domain_shape = x.shape

        M = selection.HB(self.domain_shape).select()
        y = measurement.Laplace(M, eps).measure(x, prng)
        x_hat = inference.LeastSquares().infer(M, y)

        return x_hat