2018-12-01 警告AVX2 zipf分布样本

1.警告: Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2

解决办法: 加入代码

import os 
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2' 

2. zipf分布生成样本

法一:利用现有函数

y = np.random.zipf(alf,shape=none)

注意:alf>1

法二:从统计学方面

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Nov 27 10:00:00 2018

@author: yi&gua"""

import numpy as np
import pandas as pd

N = 50   # zipf分布是1-50
a = np.array([2,1,0.5,0.7,1.2,0.6])   #zipf分布的参数
c = a[0]
pi = []#
req_cont = []
req = []
Rsize = 100    #每个时间段共有请求1000个
s = 0
n_sum = 0

#最初从1-50个数中生成request 1000个
req_init = np.random.randint(1, N+1,size=Rsize)  #生成内容
b = pd.value_counts(req_init)  #排序

req_size=[]
for k,v in b.items():
    req_size.append(k)
    req_size.append(v)
req_size_reshpe = np.reshape(req_size,[-1,2])   #[内容 ,出现次数]
req_cont = [x[0] for x in req_size_reshpe]   #按照概率排序的结果
print(req_cont)
N_L = len(req_cont)

for i in range(N_L):
    s += (i + 1)**(-c)      #求概率分母
for i in range(N_L):
    p = (i + 1) ** (-c) / s    #第i个内容 的概率
    pi.append(p)   #每个内容的概率
for i in range(N_L):
    n = round(pi[i] * Rsize)     #四舍五入取整
    n_sum += n     #确定概率的总数
    for j in range(int(n)):
        req_cont[i] = np.array(req_cont[i])
        req.append(req_cont[i])
if n_sum < Rsize:    #不够1000,加入1-50之间的数
    for i in range(int(Rsize - n_sum)):
        req.append(np.random.randint(1,N+1))
elif n_sum > Rsize:
    for i in range(int(n_sum - Rsize)):
        req.pop(np.random.randint(1,N+1))     #pop移除该列表最后一个元素
np.random.shuffle(req)     #将请求顺序打乱
np.savetxt('Lstm_4_DeepCaching_data1',req)
duqu=np.loadtxt('Lstm_4_DeepCaching_data1')
print(duqu)

法三:逆变换法 生成zipf样本

逆变换法 https://en.wikipedia.org/wiki/Inverse_transform_sampling?tdsourcetag=s_pctim_aiomsg

zipf(alp,N)

# -*- coding: UTF-8 -*-
"""
Created on Sat Dec 1 21:20:00 2018

@author: Agua"""


import numpy as np
#import tensorflow as tf
import matplotlib.pyplot as plt

alfall = [0.8,1.2,1]
alf = alfall[1]
yy = []
xx = []
valuearray = []
sumsort = []
yysort = []
N = 1000
Nsort = 50
sumy = 0
for i in range(Nsort):
    sumy += ((i + 1) ** (-1 * alf))
print(sumy)

for ii in range(N):
    y = np.random.rand()
    yy.append(y)
    j = 1
    sumx = 0
    while (sumx < y * sumy):
        sumx += (j ** (-1 * alf))
        j += 1
    xx.append(j)

i = 0
j = 1

while(j

你可能感兴趣的:(2018-12-01 警告AVX2 zipf分布样本)