Beispiel #1
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
Beispiel #2
0
    def Run(self, W, x, eps, seed):
        x = x.flatten()            
        prng = np.random.RandomState(seed)

        striped_vectors = mapper.Striped(self.domain, self.stripe_dim).partitions()
        hd_vector = support.combine_all(striped_vectors)
        striped_mapping = hd_vector.flatten()

        x_sub_list = meta.SplitByPartition(striped_mapping).transform(x)

        Ms = []
        ys = []
        scale_factors = []
        group_idx = sorted(set(striped_mapping))

        # Given a group id on the full vector, recover the group id for each partition
        # put back in loop to save memory
        self.subgroups = {}
        for i in group_idx:
            selected_idx = np.where(hd_vector == i)
            ans = [p[i[0]] for p, i in zip(striped_vectors, selected_idx)]
            self.subgroups[i] = ans

        for i in group_idx: 
            x_i = x_sub_list[group_idx.index(i)]
            
            # overwriting standard projection for efficiency
            W_i = self.project_workload(W, striped_vectors, hd_vector, i)

            dawa = pmapper.Dawa(eps, 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()
            if not isinstance(M_bar, np.ndarray):
                M_bar = M_bar.toarray()

            y_i = measurement.Laplace(
                M_bar, eps * (1 - self.ratio)).measure(x_bar, prng)

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

            # convert the measurement back to the original domain for inference
            P_i = support.projection_matrix(striped_mapping, i)
            M_i = (M_bar * support.reduction_matrix(mapping)) * 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
Beispiel #3
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))

        W = get_matrix(W)

        for i in group_idx: 
            x_i = x_sub_list[group_idx.index(i)]
            P_i = support.projection_matrix(striped_mapping, i)
            W_i = W * P_i.T

            dawa = pmapper.Dawa(eps, 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()

            if not isinstance(M_bar, np.ndarray):
                M_bar = M_bar.toarray()

            y_i = measurement.Laplace(
                M_bar, eps * (1 - self.ratio)).measure(x_bar, prng)

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

            M_i = (M_bar * support.reduction_matrix(mapping)) * 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