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

        if self.workload_based:
            W = get_matrix(W)
            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


        if len(self.domain_shape) == 2:
            # apply hilbert transform to convert 2d domain into 1d
            hilbert_mapping = mapper.HilbertTransform(self.domain_shape).mapping()
            domain_reducer = transformation.ReduceByPartition(hilbert_mapping)

            x = domain_reducer.transform(x)

            W = get_matrix(W)
            W = W * support.expansion_matrix(hilbert_mapping)

            dawa = pmapper.Dawa(eps, self.ratio, self.approx)
            mapping = dawa.mapping(x, prng)

        elif len(self.domain_shape) == 1:

            W = get_matrix(W)
            dawa = pmapper.Dawa(eps, self.ratio, self.approx)
            mapping = dawa.mapping(x, prng)


        reducer = transformation.ReduceByPartition(mapping)
        x_bar = reducer.transform(x)
        W_bar = W * 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 = measurement.Laplace(M_bar, eps*(1-self.ratio)).measure(x_bar, prng)
        x_bar_hat = inference.LeastSquares().infer(M_bar, y)

        x_bar_hat_exp = support.expansion_matrix(mapping) * x_bar_hat


        if len(self.domain_shape) == 1:
            return x_bar_hat_exp
        elif len(self.domain_shape) == 2:
            return support.expansion_matrix(hilbert_mapping) * x_bar_hat_exp
コード例 #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
コード例 #4
0
    def Run(self, W, x, eps, seed):
        x = x.flatten()
        prng = np.random.RandomState(seed)
        if self.workload_based:
            W = get_matrix(W)
            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()

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

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

        return x_hat