ndnSIM 如何获取实验过程中的转发日志 运行日志中的转发信息缺失 NS_LOG=nfd.Forwarder 失效

在ndnSIM运行过程中遇到日志中缺失Forwarder转发信息的问题,使用NS_LOG=nfd.Forwarder无效。原因是不同ndnSIM版本对应的日志模块不同。在ndnSIM 2.7版本中,正确模块为ndn-cxx.nfd.Forwarder。通过查看所有有效参数列表来确认正确的日志模块设置。

问题

ndnSIM无法在运行日志中输出转发信息,使用 NS_LOG=nfd.Forwarder 无效。ndnSIM中如何 打印 运行日志 的方法可以参考:ndnSIM 如何打印 运行日志 获取日志 调试 获取实验数据_ndnsim运行日志-优快云博客

可以看到只有 Consumer 和 Producer 的日志信息,没有 Forwarder 的。

问题原因

ndnSIM中转发模块(/ndnSIM2.7/ns-3/src/ndnSIM/NFD/daemon/fw/forwarder.cpp)在不同ndnSIM版本中对应了不同的日志模块。

在老版本中使用:nfd.Forwarder

NS_LOG=nfd.Forwarder ./waf --run ndn-simple

但在最新版本需要使用:ndn-cxx.nfd.Forwarder

NS_LOG=ndn-cxx.nfd.Forwarder ./waf --run ndn-simple

因此需要根据ndnSIM版本进行确定。(实测 ndnSIM 2.7 中 使用后者

解决方法

在终端里输入一个错误的参数以查看所有有效参数列表,如:

如果有 nfd.Forwarder 则可以使用:

NS_LOG=nfd.Forwarder ./waf --run ndn-simple

如果没有,则需要使用:

NS_LOG=ndn-cxx.nfd.Forwarder ./waf --run ndn-simple

NDN科研工作者,长期研究,欢迎讨论交流与合作!  

from io import open import glob def findFiles(path): return glob.glob(path) #print(findFiles('nlpdata/data/names/*.txt')) import unicodedata import string # 所有的英文字母 all_letters = string.ascii_letters + " .,;'" n_letters = len(all_letters) # Turn a Unicode string to plain ASCII, thanks to http://stackoverflow.com/a/518232/2809427 def unicodeToAscii(s): return ''.join( c for c in unicodedata.normalize('NFD', s) if unicodedata.category(c) != 'Mn' and c in all_letters ) #print(unicodeToAscii('Ślusàrski')) # Build the category_lines dictionary, a list of names per language category_lines = {} all_categories = [] # Read a file and split into lines def readLines(filename): lines = open(filename, encoding='utf-8').read().strip().split('\n') return [unicodeToAscii(line) for line in lines] for filename in findFiles('F:/实验9-16/实验8 基于RNN判别姓名的国别/data/names/*.txt'): category = filename.split('/')[-1].split('.')[0] category = category.split('\\')[1] all_categories.append(category) lines = readLines(filename) category_lines[category] = lines n_categories = len(all_categories) import torch # Find letter index from all_letters, e.g. "a" = 0 # 字母所在位置 def letterToIndex(letter): return all_letters.find(letter) # Just for demonstration, turn a letter into a <1 x n_letters> Tensor def letterToTensor(letter): tensor = torch.zeros(1, n_letters) # One-hot encoding tensor[0][letterToIndex(letter)] = 1 return tensor # Turn a line into a <line_length x 1 x n_letters>, # or an array of one-hot letter vectors def lineToTensor(line): tensor = torch.zeros(len(line), 1, n_letters) #print(tensor) for li, letter in enumerate(line): tensor[li][0][letterToIndex(letter)] = 1 return tensor import torch.nn as nn from torch.autograd import Variable # Creating the network class RNN(nn.Module): def __init__(self, input_size, hidden_size, output_size): super(RNN, self).__init__() self.hidden_size = hidden_size self.i2h = nn.Linear(input_size + hidden_size, hidden_size) self.i2o = nn.Linear(input_size + hidden_size, output_size) self.softmax = nn.LogSoftmax(dim=1) def forward(self, input, hidden): combined = torch.cat((input, hidden), 1) hidden = self.i2h(combined) output = self.i2o(combined) output = self.softmax(output) return output, hidden # 初始化第一个隐藏层输入 def initHidden(self): return Variable(torch.zeros(1, self.hidden_size)) # our model n_hidden = 128 rnn = RNN(n_letters, n_hidden, n_categories) # 类别 def categoryFromOutput(output): top_n, top_i = output.data.topk(1) # Tensor out of Variable with .data category_i = top_i[0][0] return all_categories[category_i], category_i # loss function criterion = nn.NLLLoss() # Train loop learning_rate = 0.005 # If you set this too high, it might explode. If too low, it might not learn def train(category_tensor, line_tensor): hidden = rnn.initHidden() rnn.zero_grad() for i in range(line_tensor.size()[0]): output, hidden = rnn(line_tensor[i], hidden) loss = criterion(output, category_tensor) loss.backward() # Add parameters' gradients to their values, multiplied by learning rate for p in rnn.parameters(): p.data.add_(-learning_rate, p.grad.data) return output, loss.data # 随机采样训练样本对 import random def randomChoice(l): return l[random.randint(0, len(l) - 1)] def randomTrainingExample(): category = randomChoice(all_categories) line = randomChoice(category_lines[category]) category_tensor = Variable(torch.LongTensor([all_categories.index(category)])) line_tensor = Variable(lineToTensor(line)) return category, line, category_tensor, line_tensor import time import math n_iters = 200000 print_every = 10000 plot_every = 1000 # Keep track of losses for plotting current_loss = 0 all_losses = [] def timeSince(since): now = time.time() s = now - since m = math.floor(s / 60) s -= m * 60 return '%dm %ds' % (m, s) start = time.time() for iter in range(1, n_iters + 1): category, line, category_tensor, line_tensor = randomTrainingExample() output, loss = train(category_tensor, line_tensor) current_loss += loss # Print iter number, loss, name and guess if iter % print_every == 0: guess, guess_i = categoryFromOutput(output) correct = '✓' if guess == category else '✗ (%s)' % category print('%d %d%% (%s) %.4f %s / %s %s' % (iter, iter / n_iters * 100, timeSince(start), loss, line, guess, correct)) # Add current loss avg to list of losses if iter % plot_every == 0: all_losses.append(current_loss / plot_every) current_loss = 0 import matplotlib.pyplot as plt import matplotlib.ticker as ticker plt.figure() plt.plot(all_losses) plt.show() # 矩阵 confusion = torch.zeros(n_categories, n_categories) n_confusion = 10000 # Just return an output given a line def evaluate(line_tensor): hidden = rnn.initHidden() for i in range(line_tensor.size()[0]): output, hidden = rnn(line_tensor[i], hidden) return output # Go through a bunch of examples and record which are correctly guessed for i in range(n_confusion): category, line, category_tensor, line_tensor = randomTrainingExample() output = evaluate(line_tensor) guess, guess_i = categoryFromOutput(output) category_i = all_categories.index(category) confusion[category_i][guess_i] += 1 # Normalize by dividing every row by its sum for i in range(n_categories): confusion[i] = confusion[i] / confusion[i].sum() # Set up plot fig = plt.figure() ax = fig.add_subplot(111) cax = ax.matshow(confusion.numpy()) fig.colorbar(cax) # Set up axes ax.set_xticklabels([''] + all_categories, rotation=90) ax.set_yticklabels([''] + all_categories) # Force label at every tick ax.xaxis.set_major_locator(ticker.MultipleLocator(1)) ax.yaxis.set_major_locator(ticker.MultipleLocator(1)) # sphinx_gallery_thumbnail_number = 2 plt.show()给出修正后的完整程序Ok?
05-18
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值