필터 지우기
필터 지우기

Changing the format of output of data from a neural network

조회 수: 1 (최근 30일)
John
John 2012년 1월 24일
Hi there,
I'm using the code below to loop through files in a folder and classifying data with a neural network.
files = dir(fullfile(pwd,'*.txt'));
for k = 1 : numel(files)
%%%%reading the txt file
fid01 = fopen(fullfile(pwd,files(k).name));
idx = 0; tmparray = [];
tline = fgetl(fid01);
while ischar(tline)
idx = idx + 1;
tmparray(idx,:) = str2num(tline);
tline = fgetl(fid01);
end
fclose(fid01);
%%%%simulate net
output = sim(net, tmparray);
%%%%save the output
filename = strcat(regexprep(files(k).name,'.txt',''),'-output.txt');
fid02 = fopen(filename,'w');
fprintf(fid02,'%.2f\n',output');
fclose(fid02);
end
However the output is in the form of a 1x1 array, for example 1x1 array. For example
output =
[
0
0
0
0
1
1
1
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
]
Would it be possible to convert it into a sparse matrix like this
output = full(output)
0 0 0 0
1 1 1 0
0 0 0 1
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
and then convert it to vectors , for example
Output = vec2ind(output)
2 2 2 3
I'm trying to get the output in integer format.
I would really appreciate any help
Thank you
John

답변 (1개)

Greg Heath
Greg Heath 2012년 1월 25일
For a net with I-H-O node topology, an input matrix of N I-dimensional input column vectors has size(input) = [ I N ] . The command output = sim(net,input) will yield an output matrix of N O-dimensional output column vectors with size(output) = [ O N ]. If output is binary, with at least one "1" in each column, vec2ind(output) will yield a row vector containing the row numbers of each unit element. and full(ind2vec(result)) will recover the original matrix.
rand('state',4151941)
output = round(rand(3,4))
result = vec2ind(output)
output = [ 1 0 0 0; 1 1 1 0; 0 0 1 1]
result = [ 1 2 2 2 3 3 ]
full(ind2vec(result)) = [ 1 0 0 0; 1 1 1 0; 0 0 1 1]
Hope this helps.
Greg

카테고리

Help CenterFile Exchange에서 Classification에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by