예제 #1
0
import numpy as np
import dp_stats as dps

### example of mean and variance
x = np.random.rand(10)
x_mu = dps.dp_mean( x, 1.0, 0.1 )
x_vr = dps.dp_var( x, 1.0, 0.1 )
print(x_mu)
print(x_vr)

### example of DP-PCA
d = 10    # data dimension
n = 100   # number of samples
k = 5     # true rank

### create covariance matrix
A = np.zeros((d,d))
for i in range(d):
    if i < k:
        A[i,i] = d - i
    else:
        A[i, i] = 1
mean = 0.0 * np.ones(d) # true mean of the samples

### generate n samples
samps = np.random.multivariate_normal(mean, A, n)    # [nxd]
sigma = np.dot(samps.T, samps) # sample covariance matrix

U,S,V = np.linalg.svd(sigma, full_matrices=True)
U_reduce = U[:,:k]
quality = np.trace(np.dot(np.dot(U_reduce.T,A),U_reduce))
예제 #2
0
#while i < len(data):
#	if data[i] >= 1 or data[i] <=0:
#		print(i, data[i])
#
#	i = i + 1

### example of mean and variance
# x = np.random.rand(10)
# sum = 0

# #print (sum / 10.0)

histogram = plt.figure()

# #print(x)
x_mu = dps.dp_mean(newData, 1.0, 0.1)
#print(x_mu)
#print(dataMean)

hist = dps.dp_hist(newData,
                   num_bins=NUM_BINS,
                   epsilon=1.0,
                   delta=0.1,
                   histtype='continuous')

fakeData = np.zeros(len(newData))
print fakeData

j = 0
offset = 0
for j in range(NUM_BINS):