内容简介:Matlab处理log文件
一般文本类文件都用 java 或 python 处理方便很多,此处记录一下matlab 处理文本文件的一些语法。
例如,程序记录下的日志文件为:dl4ss_output.log_2017_03_10_210643,其部分内容为:
[Epoch: 1] - SDR:1.308344, SIR:2.063156, SAR:-1.509836, NSDR:2.908430 Epoch 1/1 50/50 [==============================] - 178s - loss: 1.9203 - val_loss: 1.7383 Epoch 1/1 50/50 [==============================] - 176s - loss: 1.6208 - val_loss: 1.5113 Epoch 1/1 50/50 [==============================] - 176s - loss: 1.4212 - val_loss: 1.3334 Epoch 1/1 50/50 [==============================] - 175s - loss: 1.2612 - val_loss: 1.1911 Epoch 1/1 50/50 [==============================] - 176s - loss: 1.1320 - val_loss: 1.0740 [Epoch: 6] - SDR:2.128937, SIR:3.154744, SAR:0.774681, NSDR:3.729023 Epoch 1/1 50/50 [==============================] - 175s - loss: 1.0312 - val_loss: 0.9913
现在想对该日志文件进行处理,并将Epoch迭代过程中评估的结果值绘制成图,方法如下:
clc
clear
colours = ’rbckgcmbkgcmbkgcmbgrcmykbgrcmykb’; % ’bgrcmykw’ modified by jacoxu@msn.com
symbols = ’.x^os*.dvph><x+^os*.dvph><+’; % ’.ox+*sdv^<>ph’ %参考 http://blog.sina.com.cn/s/blog_618af1950100kdi2.html
linetypes = {‘-’,'-’,'-’,'-’,'-’,'-’,'-’,'-’,'-’,'-’,'-’,'-’,'-’,'-’,'-’,'-’,'-’,'-’,'-’,'-’,'-’,'-’}; % {‘-’,':’,'-.’,'–’}
figureSize = [300,200,500,300];
lineWidth = 1.5;
para_list = {‘SDR’, ’SIR’, ’SAR’, ’NSDR’};
log_file = ’dl4ss_output.log_2017_03_10_210643′;
log_file_fd = fopen(log_file);
epoch_idx = 0;
epoch_num = [];
sdr_value = [];
sir_value = [];
sar_value = [];
nsdr_value = [];
% 开始循环读取log文件
while true
% 获取当前行内容
line = fgets(log_file_fd);
% 如果当前行没有内容了
if ischar(line) == false
break
end
% 判断当前行中是否有评估值
if isempty(strfind(line, ’NSDR:’))
continue
end
epoch_idx = epoch_idx + 1;
results = regexp(line, ’ - ’, ’split’);
% 先获取当前的Epoch_num
epoch_num(epoch_idx) = str2double(results{1}(8:(length(results{1})-1)));
% 开始解析SDR, SIR, SAR 和 NSDR 值
results = results{2};
results = regexp(results, ’, ’, ’split’);
for idx = 1:length(results)
tmp_results = regexp(results{idx}, ’:', ’split’);
if strcmp(tmp_results{1}, ’SDR’)
sdr_value(epoch_idx) = str2double(tmp_results{2});
elseif strcmp(tmp_results{1}, ’SIR’)
sir_value(epoch_idx) = str2double(tmp_results{2});
elseif strcmp(tmp_results{1}, ’SAR’)
sar_value(epoch_idx) = str2double(tmp_results{2});
elseif strcmp(tmp_results{1}, ’NSDR’)
nsdr_value(epoch_idx) = str2double(tmp_results{2});
else
print (‘Error eval item’)
end
end
end
% 绘图
figure(‘position’, figureSize)
plot(epoch_num, sdr_value, [colours(1), symbols(1), char(linetypes(1))], ’linewidth’, lineWidth);
hold on;
plot(epoch_num, sir_value, [colours(2), symbols(1), char(linetypes(2))], ’linewidth’, lineWidth);
hold on;
plot(epoch_num, sar_value, [colours(3), symbols(1), char(linetypes(3))], ’linewidth’, lineWidth);
hold on;
plot(epoch_num, nsdr_value, [colours(4), symbols(1), char(linetypes(4))], ’linewidth’, lineWidth);
title(‘BSS\_Eval results’)
grid on;
xlabel(‘Epoch Number’)
ylabel(‘Value’)
axis([0 epoch_num(end) -2 5]);
legend(para_list, ’Location’, ’SouthEast’)
绘制的结果如下:
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网
猜你喜欢:本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Twenty Lectures on Algorithmic Game Theory
Tim Roughgarden / Cambridge University Press / 2016-8-31 / USD 34.99
Computer science and economics have engaged in a lively interaction over the past fifteen years, resulting in the new field of algorithmic game theory. Many problems that are central to modern compute......一起来看看 《Twenty Lectures on Algorithmic Game Theory》 这本书的介绍吧!