Esempio n. 1
0
 def _strategy(self):
     return implicit.krons(*[S._strategy() for S in self.strategies])
Esempio n. 2
0
 def _inverse(self):
     return implicit.krons(*[S._inverse() for S in self.strategies])
Esempio n. 3
0
 def squared_error(self, noise):
     WtW = implicit.krons(*[w.WtW for w in self.workloads])
     return noise.dot(WtW.dot(noise))
Esempio n. 4
0
 def evaluate(self, x):
     W = implicit.krons(*[w.W for w in self.workloads])
     return W.dot(x)
Esempio n. 5
0
    for eps in [0.1, 1.0]:

        if geography:
            dims = [[0], [1], [2], [4], [5]]
            axes = 3
            p = [1, 1, 8, 10, 1]
        else:
            dims = [[0], [1], [2], [4]]
            axes = (3, 5)
            p = [1, 1, 8, 10]

        x = X.sum(axis=axes).flatten()
        N = x.sum()
        sf1 = CensusSF1(geography=True).project_and_merge(dims)
        W = implicit.stack(*[
            implicit.krons(*[S.W for S in K.workloads]) for K in sf1.workloads
        ])

        A_sf1 = optimize.restart_union_kron(sf1, 50, p)
        A1 = implicit.krons(*[np.linalg.pinv(A) for A in A_sf1])
        noise = A1.dot(
            np.random.laplace(loc=0, scale=1.0 / eps, size=A1.shape[1]))
        err = W.dot(noise)
        ans = W.dot(x)
        result[(geography, eps)] = (ans, err)
        rel = np.abs(err) / np.maximum(W.dot(x),
                                       100)  #np.maximum(W.dot(x), 0.001*N)
        print geography, '%.1f, %.4f, %.4f' % (eps, np.median(rel),
                                               np.percentile(rel, 95))
#        tmp = np.arange(ans.max())
#        plt.plot(ans, ans+err, '.')
Esempio n. 6
0
    try:
        time2d, time3d, time4d, timesum, timedc = pickle.load(
            open('scalability_running.pkl', 'rb'))
        print 'checkpt try'
    except:

        time2d = []
        time3d = []
        time4d = []
        timesum = []
        timedc = []

        for n in dom2d:
            A = sparse.csr_matrix(strategies[n])
            T = np.ones((1, n))
            B1 = implicit.krons(A, T)
            B2 = implicit.krons(T, A)
            B = implicit.stack(B1, B2)

            #            B1 = sparse.kron(A, T, format='csr')
            #            B2 = sparse.kron(T, A, format='csr')
            #            B = sparse.vstack([B1, B2], format='csr')

            timesum.append(run_mechanism(B, implicit.sparse_inverse(B)))
            print n, timesum[-1]

    #    embed()
    # 2d domains
        for n in dom2d:
            print n
            A = strategies[n]
Esempio n. 7
0
X = np.load('%s/census.npy' % base)

for geography in [True]:  #[False, True]:
    if geography:
        x = X.flatten()
    else:
        x = X.sum(axis=5).flatten()
    for compact in [False]:  # [False, True]:
        if compact:
            sf1 = CensusSF1(geography)
        else:
            sf1 = CensusSF1Big(geography, reallybig=False)

        t0 = time.time()
        W = implicit.stack(*[
            implicit.krons(*[S.W for S in K.workloads]) for K in sf1.workloads
        ])
        marg = approximation.marginals_approx(sf1)
        q = sf1.queries
        split = len(sf1.workloads) / 2
        sf1a = workload.Concat(sf1.workloads[:split])
        sf1b = workload.Concat(sf1.workloads[split:])

        strategy = optimize.restart_union_kron(sf1, 25, [1, 1, 8, 1, 10, 1])
        theta, phi = optimize.restart_marginals(marg, 25)
        A1 = optimize.restart_union_kron(sf1a, 25, [1, 1, 8, 1, 10, 1])
        A2 = optimize.restart_union_kron(sf1b, 25, [1, 1, 8, 1, 10, 1])

        for A in strategy:
            A[A < 1e-3] = 0.0