xjtu_wong
发表于 2019-3-13 23:39:40
已经被魔法方法搞晕的小王
xjtu_wong
发表于 2019-3-14 23:27:11
关于写代码,还是背一些方法比较好用。。。晚安
xjtu_wong
发表于 2019-3-18 09:40:18
学院运动会小拿了个季军🥉哈哈哈,春天来了要多运动
xjtu_wong
发表于 2019-3-19 23:08:37
xjtu_wong
发表于 2019-3-21 21:25:46
xjtu_wong
发表于 2019-3-24 23:29:48
今天的仿真成果
xjtu_wong
发表于 2019-3-26 21:44:19
%{
作者:JamesWONG
%}
clc
clear all;
%图像的横坐标为平均接收信噪比(???=10log10?),纵坐标为归一化容量(C/B)
for each_SNR_dB = linspace(5,30,11)
index = ((each_SNR_dB-5)/2.5+1);
AWGN_lognormal(index)=log2(1+10^(0.1*(each_SNR_dB+8^2*log(10)/20)));
RX_CSI_lognormal_integrand=(@(x)log2(1+x).*10./((2*pi)^0.5.*x*8*log(10)).*exp(-(10*log10(x)-each_SNR_dB).^2/(2*(8)^2)));
RX_CSI_lognormal(index)=quadgk(RX_CSI_lognormal_integrand,0,inf);
TXnRX_CSI_lognormal_threshold_integrand=@(y) (quadgk((@(x)(1./y-1./x).*10./((2*pi)^0.5.*x*8*log(10)).*exp(-(10*log10(x)-each_SNR_dB).^2/(2*(8)^2))),y,inf)-1);
TXnRX_CSI_lognormal_threshold(index)=fzero(TXnRX_CSI_lognormal_threshold_integrand,1);%求收发两端都已知CSI时的中断门限
TXnRX_CSI_lognormal_integrand = (@(x) log2(x/TXnRX_CSI_lognormal_threshold(index)).*10./((2*pi)^0.5.*x*8*log(10)).*exp(-(10*log10(x)-each_SNR_dB).^2/(2*(8)^2)));
TXnRX_CSI_lognormal(index) = quadgk(TXnRX_CSI_lognormal_integrand,TXnRX_CSI_lognormal_threshold(index),inf);
Zero_outage_integrand=@(y) (quadgk((@(x)(y./x).*10./((2*pi)^0.5.*x*8*log(10)).*exp(-(10*log10(x)-each_SNR_dB).^2/(2*(8)^2))),0,inf)-1);
SNR_Zero_outage(index)=fzero(Zero_outage_integrand,1);%求零中断容量恒定信噪比
Zero_outage_logmormal(index)=log2(1+SNR_Zero_outage(index));
for k=(each_SNR_dB-10):(each_SNR_dB+10)%最大中断容量时对中断门限进行遍历
Max_outage_integrand=@(y) (quadgk((@(x)(y./x).*10./((2*pi)^0.5.*x*8*log(10)).*exp(-(10*log10(x)-each_SNR_dB).^2/(2*(8)^2))),10^(0.1*k),inf)-1);
SNR_Max_outage(51-each_SNR_dB+k)=fzero(Max_outage_integrand,1);%最大中断容量时求恒定信噪比
outrage_capacity(51-each_SNR_dB+k)=log2(1+SNR_Max_outage(51-each_SNR_dB+k))*(quadgk((@(x) 10./((2*pi)^0.5.*x*8*log(10)).*exp(-(10*log10(x)-each_SNR_dB).^2/(2*(8)^2))),10^(0.1*k),inf));
end
Maximum_outage_lognormal(index)=max(outrage_capacity); %取最大的中断容量
= Nakagami_fade(1,each_SNR_dB);
AWGN_Rayleigh(index) = ar_r;
RX_CSI_Rayleigh(index) = rcr_r;
TXnRX_CSI_Rayleigh(index) = trcr_r;
Zero_outage_Rayleigh(index) = zon_r;
Maximum_outage_Rayleigh(index) = mon_r;
= Nakagami_fade(2,each_SNR_dB);
AWGN_Nakagami(index) = ar;
RX_CSI_Nakagami(index) = rcr;
TXnRX_CSI_Nakagami(index) = trcr;
Zero_outage_Nakagami(index) = zon;
Maximum_outage_Nakagami(index) = mon;
end
figure(1)
E_SNR_dB=linspace(5,30,11);
plot(E_SNR_dB,AWGN_lognormal,'-*b',E_SNR_dB,RX_CSI_lognormal,'-+r',E_SNR_dB,TXnRX_CSI_lognormal,'-og',E_SNR_dB,Zero_outage_logmormal,'-.*y',E_SNR_dB,Maximum_outage_lognormal,'-ks');
hold on
legend('AWGN信道容量','RX CSI的香农容量','TX/RX CSI的香农容量','零中断容量','最大中断容量');
xlabel('平均接收信噪比(dB)');
ylabel('C/B (bit/s/Hz)');
title('对数正态衰落下的信道容量');
figure(2)
E_SNR_dB=linspace(5,30,11);
plot(E_SNR_dB,AWGN_Rayleigh,'-*b',E_SNR_dB,RX_CSI_Rayleigh,'-+r',E_SNR_dB,TXnRX_CSI_Rayleigh,'-og',E_SNR_dB,Zero_outage_Rayleigh,'-.*y',E_SNR_dB,Maximum_outage_Rayleigh,'-ks');hold on
legend('AWGN信道容量','RX CSI的香农容量','TX/RX CSI的香农容量','零中断容量','最大中断容量');
xlabel('平均接收信噪比(dB)');
ylabel('C/B (bit/s/Hz)');
title('瑞利衰落下的信道容量');
figure(3)
E_SNR_dB=linspace(5,30,11);
plot(E_SNR_dB,AWGN_Nakagami,'-*b',E_SNR_dB,RX_CSI_Nakagami,'-+r',E_SNR_dB,TXnRX_CSI_Nakagami,'-og',E_SNR_dB,Zero_outage_Nakagami,'-.*y',E_SNR_dB,Maximum_outage_Nakagami,'-ks');hold on
legend('AWGN信道容量','RX CSI的香农容量','TX/RX CSI的香农容量','零中断容量','最大中断容量');
xlabel('平均接收信噪比(dB)');
ylabel('C/B (bit/s/Hz)');
title('Nakagami衰落下的信道容量');
MATLAB程序,仿真无线信道容量对比(Goldsmith的教材)
%{
Nakagami_fade函数功能:给定Nakagami衰落的参数m以及平均接受信噪比,
返回五种信道下的归一化容量C/B
示例:
>>
= Nakagami_fade(1,5)
得到:
ar_r =2.0574
rcr_r =1.7160
trcr_r =1.8451
zon_r = 0.0531
mon_r =1.6577
%}
function = Nakagami_fade(m,E_SNR_dB)
AWGN_Rayleigh=log2(1+10^(0.1*E_SNR_dB));
RX_CSI_Rayleigh_integrand=(@(x)log2(1+x).*(m ./10^(0.1*E_SNR_dB)).^m .*x.^(m-1) /gamma(m) .*exp(-(x.*m ./10^(0.1*E_SNR_dB))));
RX_CSI_Rayleigh=quadgk(RX_CSI_Rayleigh_integrand,0,inf);
TXnRX_CSI_Rayleigh_threshold_integrand=@(y) (quadgk((@(x)(1./y-1./x).*(m ./10^(0.1*E_SNR_dB)).^m .*x.^(m-1) /gamma(m) .*exp(-(x.*m ./10^(0.1*E_SNR_dB)))),y,inf)-1);
TXnRX_CSI_Rayleigh_threshold=fzero(TXnRX_CSI_Rayleigh_threshold_integrand,0.55);%求收发两端都已知CSI时的中断门限,通过迭代初值所得
TXnRX_CSI_Rayleigh_integrand=(@(x) log2(x/TXnRX_CSI_Rayleigh_threshold).*(m ./10^(0.1*E_SNR_dB)).^m .*x.^(m-1) /gamma(m) .*exp(-(x.*m ./10^(0.1*E_SNR_dB))));
TXnRX_CSI_Rayleigh=quadgk(TXnRX_CSI_Rayleigh_integrand,TXnRX_CSI_Rayleigh_threshold,inf);
Zero_outage_integrand=@(y) (quadgk((@(x)(y./x).*(m ./10^(0.1*E_SNR_dB)).^m .*x.^(m-1) /gamma(m) .*exp(-(x.*m ./10^(0.1*E_SNR_dB)))),0,inf)-1);
SNR_Zero_outage=fzero(Zero_outage_integrand,1); %求零中断容量恒定信噪比
Zero_outage_Nakagami=log2(1+SNR_Zero_outage);
for k=(E_SNR_dB-10):(E_SNR_dB+10)%最大中断容量时对中断门限进行遍历
Max_outage_integrand=@(y) (quadgk((@(x)(y./x).*(m ./10^(0.1*E_SNR_dB)).^m .*x.^(m-1) /gamma(m) .*exp(-(x.*m ./10^(0.1*E_SNR_dB)))),10^(0.1*k),inf)-1);
SNR_Max_outage(31-E_SNR_dB+k)=fzero(Max_outage_integrand,1);%最大中断容量时求恒定信噪比
max_outage_capacity(31-E_SNR_dB+k)=log2(1+SNR_Max_outage(31-E_SNR_dB+k))*(quadgk((@(x) (m ./10^(0.1*E_SNR_dB)).^m .*x.^(m-1)/gamma(m).*exp(-(x.*m ./10^(0.1*E_SNR_dB)))),10^(0.1*k),inf));
end
Maximum_outage_Nakagami=max(max_outage_capacity); %取最大的中断容量
end
xjtu_wong
发表于 2019-3-27 23:06:40
xjtu_wong
发表于 2019-4-25 21:32:40
1、复习随机过程第二章第二节
2、英语打卡
最近某东买书打折。
xjtu_wong
发表于 2019-6-4 11:10:06
Eric Matthes课后习题9.7:
#-*-coding:utf-8-*-
#author:JamesW
class User():
def __init__(self,first_name,last_name,**profile):
self.first_name = first_name
self.last_name = last_name
self.profile = profile
profile = {}
profile['first_name'] = self.first_name
profile['Last_name'] = self.last_name
for key,value in profile.items():
profile = value
def describe_user(self):
for each in self.profile:
print(each+':'+self.profile)
def greet_user(self):
formatted_name = self.first_name + ' ' +self.last_name
print('Hello,%s!'%formatted_name)
class Admin(User):
def __init__(self,first_name,last_name,*can_do,**profile):
super().__init__(first_name,last_name,**profile)
self.privileges = can_do
def show_privileges(self):
print('User %s %s is a Administrater, :'%(self.first_name,self.last_name))
for each in self.privileges:
print('He '+each)
if __name__ == '__main__':
ad1 = Admin('James','Wong','can add post','can delete post',age='22',hometown='cz')
ad1.show_privileges()
ad1.describe_user()
ad1.greet_user()
xjtu_wong
发表于 2019-6-4 11:35:20
Eric Matthes 习题9.8,将实例用作属性#-*-coding:utf-8-*-
#author:JamesW
class User():
def __init__(self,first_name,last_name,**profile):
self.first_name = first_name
self.last_name = last_name
self.profile = profile
profile = {}
profile['first_name'] = self.first_name
profile['Last_name'] = self.last_name
for key,value in profile.items():
profile = value
def describe_user(self):
for each in self.profile:
print(each+':'+self.profile)
def greet_user(self):
formatted_name = self.first_name + ' ' +self.last_name
print('Hello,%s!'%formatted_name)
class Privileges():
def __init__(self,*can_do):
self.privileges = can_do
def show_privileges(self):
print('This is a Administrater, :')
for each in self.privileges:
print('He '+each)
class Admin(User):
def __init__(self,first_name,last_name,**profile):
super().__init__(first_name,last_name,**profile)
self.ad1 = Privileges('can add post','can delete post')
if __name__ == '__main__':
ad = Admin('James','Wong',age='22',hometown='cz')
ad.ad1.show_privileges()
ad.describe_user()
ad.greet_user()
xjtu_wong
发表于 2019-6-4 20:11:07
Json 和 Pickle:
python的pickle模块实现了python的所有数据序列和反序列化。基本上功能使用和JSON模块没有太大区别,方法也同样是dumps/dump和loads/load。cPickle是pickle模块的C语言编译版本相对速度更快。
与JSON不同的是pickle不是用于多种语言间的数据传输,它仅作为python对象的持久化或者python程序间进行互相传输对象的方法,因此它支持了python所有的数据类型。
---------------------
作者:shuyededenghou
来源:CSDN
原文:https://blog.csdn.net/shuyededenghou/article/details/75923353
版权声明:本文为博主原创文章,转载请附上博文链接!JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式。它基于ECMAScript的一个子集。 JSON采用完全独立于语言的文本格式,但是也使用了类似于C语言家族的习惯(包括C、C++、Java、JavaScript、Perl、Python等)。这些特性使JSON成为理想的数据交换语言。易于人阅读和编写,同时也易于机器解析和生成(一般用于提升网络传输速率)。
JSON在python中分别由list和dict组成。
---------------------
作者:shuyededenghou
来源:CSDN
原文:https://blog.csdn.net/shuyededenghou/article/details/75923353
版权声明:本文为博主原创文章,转载请附上博文链接!
json与pickle模块是将Python中的数据进行序列化,便于存取与传输。
处理文件时,考虑多行数据的存取,如换行符的使用
json序列化时,是以字符串的形式存取,所以对于字典的存取时,关键字或值经过序列化与反序列化后,类型都是字符串,有些表面看起来是数值,其实还是字符串,在使用时一定要注意类型的转换
---------------------
作者:shuyededenghou
来源:CSDN
原文:https://blog.csdn.net/shuyededenghou/article/details/75923353
版权声明:本文为博主原创文章,转载请附上博文链接!
Eric Matthes习题10_11
#-*-coding:utf-8-*-
#author:JamesW
import json
num = input("plz input ur favorite number:")
filename = 'num.json'
with open(filename,'w') as f:
json.dump(num,f)
print("file saved!")
with open(filename) as rf:
fav_num = json.load(rf)
print("ur favorite number is:"+fav_num)
xjtu_wong
发表于 2019-6-5 09:27:13
Eric Marrhes 习题10_13
#-*-coding:utf-8-*-
#author:JamesW
import json
def get_stored_uesrname():
filename = 'username.json'
try:
with open(filename) as f_obj:
username = json.load(f_obj)
except FileNotFoundError:
return None
else:
return username
def get_new_username():
username = input("What's ur name?")
filename = 'username.json'
with open(filename,'w') as f_obj:
json.dump(username,f_obj)
return username
def greet_user():
"""问候用户,指出其姓名"""
username = get_stored_uesrname()
if username:
flag = input('R u %s ?(Y/N)'%username)
if flag == 'Y':
print('Welcome back,'+username+'!')
elif flag == 'N':
username = get_new_username()
else:
username = get_new_username()
print("We'll remeber you when you come back,"+username+'!')
if __name__ == '__main__':
greet_user()
xjtu_wong
发表于 2019-8-8 11:25:13
分享多元线性回归梯度下降法更新权值推导
xjtu_wong
发表于 2019-8-28 10:23:55
根据奥莱利《深度学习入门》中学习到的神经网络,其中激活函数和MNIST数据集以经预先保存为包,网络的权值与偏置预先设定。分类结果准确率为0.9352.
# coding: utf-8
import sys, os
sys.path.append(os.pardir)# 为了导入父目录的文件而进行的设定
import numpy as np
import pickle
from dataset.mnist import load_mnist
from common.functions import sigmoid, softmax
def get_data():
(x_train, t_train), (x_test, t_test) = load_mnist(normalize=True, flatten=True, one_hot_label=False)
return x_test, t_test #x为数据,t为标签
def init_network():
with open("sample_weight.pkl", 'rb') as f:
network = pickle.load(f)
return network
def predict(network, x):
W1, W2, W3 = network['W1'], network['W2'], network['W3']
b1, b2, b3 = network['b1'], network['b2'], network['b3']
a1 = np.dot(x, W1) + b1 # (1*784)*(784*50)+50
z1 = sigmoid(a1)
a2 = np.dot(z1, W2) + b2 # (1*50)*(50*100)+100
z2 = sigmoid(a2)
a3 = np.dot(z2, W3) + b3 # (1*100)*(100*10)+10
y = softmax(a3) # 1*10 (one-hot)
return y
x, t = get_data() #x保存数据,t保存标签
network = init_network() #导入预存的权值矩阵!难怪有这么高的精度。
print(network.keys()) #['b2', 'W1', 'b1', 'W2', 'W3', 'b3']
accuracy_cnt = 0
for i in range(len(x)):
y = predict(network, x)
p= np.argmax(y) # 获取概率最高的元素的索引
if p == t:
accuracy_cnt += 1
print("Accuracy:" + str(float(accuracy_cnt) / len(x)))
偏置:
xjtu_wong
发表于 2019-8-28 10:48:30
引入批处理后,实现将原来的单个训练改进为多组数据同时训练,精度不变的情况下缩短运算时间。
局部晚期统计,可以缩短三分之二的时间。
# -*- coding: utf-8 -*-
"""
Created on Wed Aug 28 10:33:32 2019
@author: u
"""
# coding: utf-8
import time
import sys, os
sys.path.append(os.pardir)# 为了导入父目录的文件而进行的设定
import numpy as np
import pickle
from dataset.mnist import load_mnist
from common.functions import sigmoid, softmax
batch_size = 100
def get_data():
(x_train, t_train), (x_test, t_test) = load_mnist(normalize=True, flatten=True, one_hot_label=False)
return x_test, t_test #x为数据,t为标签
def init_network():
with open("sample_weight.pkl", 'rb') as f:
network = pickle.load(f)
return network
def predict(network, x):
W1, W2, W3 = network['W1'], network['W2'], network['W3']
b1, b2, b3 = network['b1'], network['b2'], network['b3']
a1 = np.dot(x, W1) + b1 # (1*784)*(784*50)+50
z1 = sigmoid(a1)
a2 = np.dot(z1, W2) + b2 # (1*50)*(50*100)+100
z2 = sigmoid(a2)
a3 = np.dot(z2, W3) + b3 # (1*100)*(100*10)+10
y = softmax(a3) # 1*10 (one-hot)
return y
time_start=time.time()
x, t = get_data() #x保存数据,t保存标签
network = init_network() #导入预存的权值矩阵!难怪有这么高的精度。
print(network.keys()) #['b2', 'W1', 'b1', 'W2', 'W3', 'b3']
accuracy_cnt = 0
for i in range(0, len(x), batch_size):
x_batch = x
#print(x_batch.shape) #(100, 784)
y_batch = predict(network, x_batch)
#print(y_batch.shape) #(100,10)
p = np.argmax(y_batch, axis=1)
accuracy_cnt += np.sum(p == t)
time_end=time.time()
print('totally cost',time_end-time_start)
print("Accuracy:" + str(float(accuracy_cnt) / len(x)))
xjtu_wong
发表于 2019-8-30 10:07:41
加入SGD后具有学习参数的神经网络。此处计算梯度采用数值计算法,可以看到运行时间较慢:
total time cost 38.359713554382324
若采用梯度反向传播则可以提高代码效率。
# coding: utf-8
import sys, os
sys.path.append(os.pardir)# 为了导入父目录的文件而进行的设定
import numpy as np
import matplotlib.pyplot as plt
import time
from dataset.mnist import load_mnist
from two_layer_net import TwoLayerNet
# 读入数据
(x_train, t_train), (x_test, t_test) = load_mnist(normalize=True, one_hot_label=True)
network = TwoLayerNet(input_size=784, hidden_size=50, output_size=10)
iters_num = 10000# 适当设定循环的次数
train_size = x_train.shape
batch_size = 100
learning_rate = 0.1
train_loss_list = []
train_acc_list = []
test_acc_list = []
iter_per_epoch = max(train_size / batch_size, 1)
time_start=time.time()
time_before = time_start
for i in range(iters_num):
batch_mask = np.random.choice(train_size, batch_size)
x_batch = x_train
t_batch = t_train
# 计算梯度
#grad = network.numerical_gradient(x_batch, t_batch)
grad = network.gradient(x_batch, t_batch)
# 更新参数
for key in ('W1', 'b1', 'W2', 'b2'):
network.params -= learning_rate * grad
loss = network.loss(x_batch, t_batch)
train_loss_list.append(loss)
if i % iter_per_epoch == 0:
train_acc = network.accuracy(x_train, t_train)
test_acc = network.accuracy(x_test, t_test)
train_acc_list.append(train_acc)
test_acc_list.append(test_acc)
print("train acc, test acc | " + str(train_acc) + ", " + str(test_acc))
time_end_this = time.time()
print('this epoch time cost',time_end_this-time_before)
time_before = time_end_this
time_end = time.time()
print('total time cost',time_end-time_start)
# 绘制图形
markers = {'train': 'o', 'test': 's'}
x = np.arange(len(train_acc_list))
plt.plot(x, train_acc_list, label='train acc')
plt.plot(x, test_acc_list, label='test acc', linestyle='--')
plt.xlabel("epochs")
plt.ylabel("accuracy")
plt.ylim(0, 1.0)
plt.legend(loc='lower right')
plt.show()
xjtu_wong
发表于 2019-8-30 10:10:11
数值法计算梯度的类:# coding: utf-8
import numpy as np
def _numerical_gradient_1d(f, x):
h = 1e-4 # 0.0001
grad = np.zeros_like(x)
for idx in range(x.size):
tmp_val = x
x = float(tmp_val) + h
fxh1 = f(x) # f(x+h)
x = tmp_val - h
fxh2 = f(x) # f(x-h)
grad = (fxh1 - fxh2) / (2*h)
x = tmp_val # 还原值
return grad
def numerical_gradient_2d(f, X):
if X.ndim == 1:
return _numerical_gradient_1d(f, X)
else:
grad = np.zeros_like(X)
for idx, x in enumerate(X):
grad = _numerical_gradient_1d(f, x)
return grad
def numerical_gradient(f, x):
h = 1e-4 # 0.0001
grad = np.zeros_like(x)
it = np.nditer(x, flags=['multi_index'], op_flags=['readwrite'])
while not it.finished:
idx = it.multi_index
tmp_val = x
x = float(tmp_val) + h
fxh1 = f(x) # f(x+h)
x = tmp_val - h
fxh2 = f(x) # f(x-h)
grad = (fxh1 - fxh2) / (2*h)
x = tmp_val # 还原值
it.iternext()
return grad
xjtu_wong
发表于 2019-9-6 17:04:07
1.读完R. Wen, J. Tang, T. Q. S. Quek, G. Feng, G. Wang, and W. Tan, “Robust Network Slicing in Software-Defined 5G Networks,” 2017 IEEE Glob. Commun. Conf. GLOBECOM 2017 - Proc., vol. 2018-January, pp. 1–6, 2018.并总结;
2.重构网络SDN架构实现前两章;
3.行书入门一页
xjtu_wong
发表于 2019-9-8 14:55:45
1.重构网络SDN架构实现读完第二章;
2.读完R. Wen et al., “On Robustness of Network Slicing for Next-Generation Mobile Networks,” IEEE Trans. Commun., vol. 67, no. 1, pp. 430–444, 2019.;
3.行书入门一页;
4.组会PPT提纲。