コード例 #1
0
# print 'knn acuracy is ',accuracy_score(label_test.ravel(),predict_result) # 0.86
# # #--------------------------------

# ---------------BF'ed data ML -----------
length = 10000
b = 10
num_hash = 5
dis = float(50)

g = (2 * b + 2) * com_to_len
false_positive = math.pow(1 - math.exp(-(num_hash * g) / length), num_hash)

print 'lenth:', length, 'b:', b, 'num_hash:', num_hash, 'dis:', dis, 'false_positive: ', false_positive

# # generate the npy with the bf and data
bf_ts = BF_TS(length, num_hash, b, dis / (2 * b), dis)

# print 'BF filter'
# print 'start'
# start_time=time.time()
bf_train = bf_ts.convert_set_to_bf(
    compressed_data)  # the result it a list and hard to convert to np array
# print len(bf_train)
bf_test = bf_ts.convert_set_to_bf(compressed_test_data)
# convert_time=time.time()-start_time
# print 'using time: ',convert_time
# print len(bf_train)
# print 'BF filter done'
# # print bf_train[0]
# # print bf_train[0].to01()
#
コード例 #2
0

# compress_matrix = np.load('../data/HAR_compress.npy')
# print 'Compress'
# compressed_data = np.matmul(compress_matrix,data_train.T).T
# print compressed_data.shape  #(7352,50)
# print 'Compress done'


compressed_data = data_train


length = 10000
b=5
num_hash = 1
dis = float(0.05)
com_to_len = 561

# g=(2*b+1)*com_to_len
false_positive= math.pow( 1-math.exp(-float(num_hash*2*b*com_to_len)/length) , num_hash )
print ('lenth:',length,'num_hash:',num_hash,'total distance:',dis,\
       'step dis:',dis/(2*b),'neighbours:',b, 'false_positive: ', false_positive)
bf_ts=BF_TS(length,num_hash,b,dis/(2*b),-100)


bf_train = bf_ts.only_store_neibour(compressed_data)  # the result it a list and hard to convert to np array
print(len(bf_train[0]))

filename = '/Users/wanli/Dropbox/ppml_code_with_dataset/distribution_plot_about_paras/har_dis005.npy'
np.save(filename, bf_train)
# print('using time, ', time.time() - timenow)
コード例 #3
0
#
for i in range(1, 11):
    #
    # ------- BF data--------
    length = 500  #(300)
    print(length)
    b = 5  #(5)
    num_hash = 2  #2
    dis = float(i * 0.01)  #0.03
    g = (2 * b + 2)
    false_positive = math.pow(1 - math.exp(-(float)(num_hash * g) / length),
                              num_hash)
    print('lenth:', length, 'b:', b, 'num_hash:', num_hash, 'dis:', dis,
          'false_positive: ', false_positive, 'stepdis', dis)

    bf_ts = BF_TS(length, num_hash, b, dis, -1000)

    print 'BF start'
    # start_time=time.time()
    bf_train = bf_ts.convert_set_to_bf(
        data)  # the result it a list and hard to convert to np array
    print 'BF filter done'

    bfdata_train = bf_ts.convert_bitarray_to_train_data(
        bf_train, len(bf_train), length)
    print(bfdata_train)

    savepath = '/Users/wanli/Desktop/weitao/after/data_bfed_' + str(i) + '.csv'
    print(savepath)

    np.savetxt(savepath, (bfdata_train), delimiter=',')
コード例 #4
0



length = 10000
b=5
num_hash = 1
dis = float(0.05)
com_to_len = 1024

# g=(2*b+1)*com_to_len
false_positive= math.pow( 1-math.exp(-float(num_hash*2*b*com_to_len)/length) , num_hash )
print ('lenth:',length,'num_hash:',num_hash,'total distance:',dis,\
       'step dis:',dis/(2*b),'neighbours:',b, 'false_positive: ', false_positive)

bf_ts=BF_TS(length,num_hash,b,dis/(2*b),-100)

batch = 1
print('batch ', batch)

filename = '/Users/wanli/Desktop/tmp/aruna/raw_cifar_preprocess/preprocess_batch_'+str(batch)+'.npy'
cifar_data = np.load(filename)
print(cifar_data.shape)


testdata = cifar_data[0:2,:,0]
print(testdata.shape)

bf_train = bf_ts.convert_set_to_bf(testdata)  # the result it a list and hard to convert to np array
output1 = bf_ts.convert_bitarray_to_train_data(bf_train, len(bf_train), length)
コード例 #5
0
# -------ML on compressed and BF data--------
length = 10000
b = 5
num_hash = 1
dis = float(5)

g = (2 * b + 1) * 80
false_positive = math.pow(1 - math.exp(-(float)(num_hash * g) / length),
                          num_hash)
print 'lenth:', length, 'b:', b, 'num_hash:', num_hash, 'dis:', dis, 'false_positive: ', false_positive, 'stepdis: ', dis / (
    2 * b)

# -----BF-----
# generate the npy with the bf and data
bf_ts = BF_TS(length, num_hash, b, dis / (2 * b), dis)

print 'BF start'
# start_time=time.time()
bf_train = bf_ts.convert_set_to_bf(
    compressed_data)  # the result it a list and hard to convert to np array
# print len(bf_train)
# bf_test = bf_ts.convert_set_to_bf(compressed_test_data)
# convert_time=time.time()-start_time
# print 'using time: ',convert_time
# print len(bf_train)
print 'BF filter done'
# # print bf_train[0]
# # print bf_train[0].to01()
#