The Simple Demo Code and Reference Figures

This commit is contained in:
Malcolm Slaney 2014-11-21 19:18:09 -08:00
Родитель 0dfaf94f14
Коммит c9ed3ec65e
8 изменённых файлов: 10813 добавлений и 0 удалений

110
Demos/Simple/MakeData.m Executable file
Просмотреть файл

@ -0,0 +1,110 @@
%%
% Create training and test sets for the simple CNTK demo. Plot the results
% Create some 2-dimensional data for the testing the CNTK Toolkit
N = 10000;
x = 2*(rand(N,1) - 0.5); % Uniform from -1 to 1
y = 2*(rand(N,1) - 0.5); % Uniform from -1 to 1
label = 0.25*sin(2*pi*0.5*x) > y; % Sinusoidal decision boundary
%%
% Plot the training data
figure(1);
plot(x(label), y(label), 'rx', ...
x(~label), y(~label), 'bo');
xlabel('X axis');
ylabel('Y axis');
title('Simple Data Training Plot');
print -dpng SimpleDemoData
%%
% Dump the data to a file. Label needs to be an integer so we can't just
% dump the entire array at once.
fp = fopen('SimpleDataTrain.txt','w');
for i=1:N
fprintf(fp, '%g %g %d\n', x(i), y(i), label(i));
end
fclose(fp);
%%
% Create a uniform grid of test data. This is easier to plot than the
% training data.
testDelta = 0.01;
testMax = 1;
testPoints = [-testMax:testDelta:testMax];
testN = length(testPoints);
[testX, testY] = meshgrid(testPoints, testPoints);
fp = fopen('SimpleDataTest.txt','w');
for i=1:length(testX(:))
fprintf(fp, '%g %g %d\n', testX(i), testY(i), 0);
end
fclose(fp);
%%
%
% Run CNTK here.
% The rest of the command in this file plot the results.
%%
load SimpleDataTrain.txt
load SimpleDataTest.txt
load SimpleOutput.ScaledLogLikelihood
%%
figure(2);
if 0
% Plot each test point.
pos = SimpleOutput(:,1)>SimpleOutput(:,2);
plot(SimpleDataTest(pos,1), SimpleDataTest(pos,2), 'rx', ...
SimpleDataTest(~pos,1), SimpleDataTest(~pos,2), 'bo')
else
data=reshape(SimpleOutput(:,1), testN, testN);
imagesc(testPoints, testPoints, data);
axis xy
colorbar
title('Output 2 from DNN');
[m,i] = min(data.^2);
hold on; plot(testPoints, testPoints(i), '--'); hold off
end
print -dpng SimpleDemoOutput
%%
% Capture the training error rate information from the log file.
fp = fopen('Demo_Simple_Demo_Simple_Demo_Output.log', 'r');
if fp
clear trainingError
while true
theLine = fgets(fp);
if isempty(theLine) || theLine(1) == -1
break;
end
% Look for the message at the end of each epoch.
if strncmp(theLine, 'Finished ', length('Finished '))
try
% Pick out the epoch number and training error
strToks = regexprep(theLine, ...
'.*Epoch\[(\d*)].*EvalErr Per Sample = (.*) +Ave Learn.*', ...
'$1 $2');
numericToks = str2num(strToks);
trainingError(numericToks(1)) = numericToks(2);
catch e
% Ignore lines we can't read
end
end
end
fclose(fp);
else
fprintf('Can not find the demo training log\n');
end
%%
figure(3);
loglog(trainingError)
title('Performance of Simple Demo');
xlabel('Epoch Number');
ylabel('Average Error Rate (training data)');
print -dpng SimpleDemoErrorRate

98
Demos/Simple/Simple.config Executable file
Просмотреть файл

@ -0,0 +1,98 @@
# command=Simple_Demo_Output
command=Simple_Demo:Simple_Demo_Output
# deviceId=-1 for CPU, >=0 for GPU devices
DeviceNumber=0
stderr=Demo
precision=float
modelPath=models/simple.dnn
deviceId=$DeviceNumber$
outputNodeNames=ScaledLogLikelihood
traceLevel=1
#######################################
# TRAINING CONFIG (Simple, Fixed LR) #
#######################################
Simple_Demo=[
action=train
# Notation xxx:yyy*n:zzz is equivalent to xxx, then yyy repeated n times,
# then zzz
# example: 10:20*3:5 is equivalent to 10:20:20:20:5
SimpleNetworkBuilder=[
layerSizes=2:50*2:2
trainingCriterion=CrossEntropyWithSoftmax
evalCriterion=ErrorPrediction
layerTypes=Sigmoid
initValueScale=1.0
applyMeanVarNorm=true
uniformInit=true
needPrior=true
]
SGD=[
# epochSize=0 means epochSize is the size of the training set
epochSize=0
# Must be evenly divisible into number of data frames
minibatchSize=25
learningRatesPerMB=0.5:0.2*20:0.1
momentumPerMB=0.9
dropoutRate=0.0
maxEpochs=500
]
# Parameter values for the reader
reader=[
# reader to use
readerType=UCIFastReader
file=SimpleDataTrain.txt
miniBatchMode=Partial
randomize=Auto
verbosity=1
features=[
dim=2
start=0
]
labels=[
start=2
dim=1
labelDim=2
labelMappingFile=SimpleMapping.txt
]
]
]
#######################################
# OUTPUT RESUTLS (Simple) #
#######################################
Simple_Demo_Output=[
action=write
# Parameter values for the reader
reader=[
# reader to use
readerType=UCIFastReader
file=SimpleDataTest.txt
features=[
dim=2
start=0
]
labels=[
start=2
dim=1
labelDim=2
labelMappingFile=SimpleMapping.txt
]
]
outputPath=SimpleOutput # Dump output as text
]

603
Demos/Simple/SimpleDataTest.txt Executable file
Просмотреть файл

@ -0,0 +1,603 @@
-1 -1 0
-1 -0.99 0
-1 -0.98 0
-1 -0.97 0
-1 -0.96 0
-1 -0.95 0
-1 -0.94 0
-1 -0.93 0
-1 -0.92 0
-1 -0.91 0
-1 -0.9 0
-1 -0.89 0
-1 -0.88 0
-1 -0.87 0
-1 -0.86 0
-1 -0.85 0
-1 -0.84 0
-1 -0.83 0
-1 -0.82 0
-1 -0.81 0
-1 -0.8 0
-1 -0.79 0
-1 -0.78 0
-1 -0.77 0
-1 -0.76 0
-1 -0.75 0
-1 -0.74 0
-1 -0.73 0
-1 -0.72 0
-1 -0.71 0
-1 -0.7 0
-1 -0.69 0
-1 -0.68 0
-1 -0.67 0
-1 -0.66 0
-1 -0.65 0
-1 -0.64 0
-1 -0.63 0
-1 -0.62 0
-1 -0.61 0
-1 -0.6 0
-1 -0.59 0
-1 -0.58 0
-1 -0.57 0
-1 -0.56 0
-1 -0.55 0
-1 -0.54 0
-1 -0.53 0
-1 -0.52 0
-1 -0.51 0
-1 -0.5 0
-1 -0.49 0
-1 -0.48 0
-1 -0.47 0
-1 -0.46 0
-1 -0.45 0
-1 -0.44 0
-1 -0.43 0
-1 -0.42 0
-1 -0.41 0
-1 -0.4 0
-1 -0.39 0
-1 -0.38 0
-1 -0.37 0
-1 -0.36 0
-1 -0.35 0
-1 -0.34 0
-1 -0.33 0
-1 -0.32 0
-1 -0.31 0
-1 -0.3 0
-1 -0.29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82 0
-1 0.83 0
-1 0.84 0
-1 0.85 0
-1 0.86 0
-1 0.87 0
-1 0.88 0
-1 0.89 0
-1 0.9 0
-1 0.91 0
-1 0.92 0
-1 0.93 0
-1 0.94 0
-1 0.95 0
-1 0.96 0
-1 0.97 0
-1 0.98 0
-1 0.99 0
-1 1 0
0 -1 0
0 -0.99 0
0 -0.98 0
0 -0.97 0
0 -0.96 0
0 -0.95 0
0 -0.94 0
0 -0.93 0
0 -0.92 0
0 -0.91 0
0 -0.9 0
0 -0.89 0
0 -0.88 0
0 -0.87 0
0 -0.86 0
0 -0.85 0
0 -0.84 0
0 -0.83 0
0 -0.82 0
0 -0.81 0
0 -0.8 0
0 -0.79 0
0 -0.78 0
0 -0.77 0
0 -0.76 0
0 -0.75 0
0 -0.74 0
0 -0.73 0
0 -0.72 0
0 -0.71 0
0 -0.7 0
0 -0.69 0
0 -0.68 0
0 -0.67 0
0 -0.66 0
0 -0.65 0
0 -0.64 0
0 -0.63 0
0 -0.62 0
0 -0.61 0
0 -0.6 0
0 -0.59 0
0 -0.58 0
0 -0.57 0
0 -0.56 0
0 -0.55 0
0 -0.54 0
0 -0.53 0
0 -0.52 0
0 -0.51 0
0 -0.5 0
0 -0.49 0
0 -0.48 0
0 -0.47 0
0 -0.46 0
0 -0.45 0
0 -0.44 0
0 -0.43 0
0 -0.42 0
0 -0.41 0
0 -0.4 0
0 -0.39 0
0 -0.38 0
0 -0.37 0
0 -0.36 0
0 -0.35 0
0 -0.34 0
0 -0.33 0
0 -0.32 0
0 -0.31 0
0 -0.3 0
0 -0.29 0
0 -0.28 0
0 -0.27 0
0 -0.26 0
0 -0.25 0
0 -0.24 0
0 -0.23 0
0 -0.22 0
0 -0.21 0
0 -0.2 0
0 -0.19 0
0 -0.18 0
0 -0.17 0
0 -0.16 0
0 -0.15 0
0 -0.14 0
0 -0.13 0
0 -0.12 0
0 -0.11 0
0 -0.1 0
0 -0.09 0
0 -0.08 0
0 -0.07 0
0 -0.06 0
0 -0.05 0
0 -0.04 0
0 -0.03 0
0 -0.02 0
0 -0.01 0
0 0 0
0 0.01 0
0 0.02 0
0 0.03 0
0 0.04 0
0 0.05 0
0 0.06 0
0 0.07 0
0 0.08 0
0 0.09 0
0 0.1 0
0 0.11 0
0 0.12 0
0 0.13 0
0 0.14 0
0 0.15 0
0 0.16 0
0 0.17 0
0 0.18 0
0 0.19 0
0 0.2 0
0 0.21 0
0 0.22 0
0 0.23 0
0 0.24 0
0 0.25 0
0 0.26 0
0 0.27 0
0 0.28 0
0 0.29 0
0 0.3 0
0 0.31 0
0 0.32 0
0 0.33 0
0 0.34 0
0 0.35 0
0 0.36 0
0 0.37 0
0 0.38 0
0 0.39 0
0 0.4 0
0 0.41 0
0 0.42 0
0 0.43 0
0 0.44 0
0 0.45 0
0 0.46 0
0 0.47 0
0 0.48 0
0 0.49 0
0 0.5 0
0 0.51 0
0 0.52 0
0 0.53 0
0 0.54 0
0 0.55 0
0 0.56 0
0 0.57 0
0 0.58 0
0 0.59 0
0 0.6 0
0 0.61 0
0 0.62 0
0 0.63 0
0 0.64 0
0 0.65 0
0 0.66 0
0 0.67 0
0 0.68 0
0 0.69 0
0 0.7 0
0 0.71 0
0 0.72 0
0 0.73 0
0 0.74 0
0 0.75 0
0 0.76 0
0 0.77 0
0 0.78 0
0 0.79 0
0 0.8 0
0 0.81 0
0 0.82 0
0 0.83 0
0 0.84 0
0 0.85 0
0 0.86 0
0 0.87 0
0 0.88 0
0 0.89 0
0 0.9 0
0 0.91 0
0 0.92 0
0 0.93 0
0 0.94 0
0 0.95 0
0 0.96 0
0 0.97 0
0 0.98 0
0 0.99 0
0 1 0
1 -1 0
1 -0.99 0
1 -0.98 0
1 -0.97 0
1 -0.96 0
1 -0.95 0
1 -0.94 0
1 -0.93 0
1 -0.92 0
1 -0.91 0
1 -0.9 0
1 -0.89 0
1 -0.88 0
1 -0.87 0
1 -0.86 0
1 -0.85 0
1 -0.84 0
1 -0.83 0
1 -0.82 0
1 -0.81 0
1 -0.8 0
1 -0.79 0
1 -0.78 0
1 -0.77 0
1 -0.76 0
1 -0.75 0
1 -0.74 0
1 -0.73 0
1 -0.72 0
1 -0.71 0
1 -0.7 0
1 -0.69 0
1 -0.68 0
1 -0.67 0
1 -0.66 0
1 -0.65 0
1 -0.64 0
1 -0.63 0
1 -0.62 0
1 -0.61 0
1 -0.6 0
1 -0.59 0
1 -0.58 0
1 -0.57 0
1 -0.56 0
1 -0.55 0
1 -0.54 0
1 -0.53 0
1 -0.52 0
1 -0.51 0
1 -0.5 0
1 -0.49 0
1 -0.48 0
1 -0.47 0
1 -0.46 0
1 -0.45 0
1 -0.44 0
1 -0.43 0
1 -0.42 0
1 -0.41 0
1 -0.4 0
1 -0.39 0
1 -0.38 0
1 -0.37 0
1 -0.36 0
1 -0.35 0
1 -0.34 0
1 -0.33 0
1 -0.32 0
1 -0.31 0
1 -0.3 0
1 -0.29 0
1 -0.28 0
1 -0.27 0
1 -0.26 0
1 -0.25 0
1 -0.24 0
1 -0.23 0
1 -0.22 0
1 -0.21 0
1 -0.2 0
1 -0.19 0
1 -0.18 0
1 -0.17 0
1 -0.16 0
1 -0.15 0
1 -0.14 0
1 -0.13 0
1 -0.12 0
1 -0.11 0
1 -0.1 0
1 -0.09 0
1 -0.08 0
1 -0.07 0
1 -0.06 0
1 -0.05 0
1 -0.04 0
1 -0.03 0
1 -0.02 0
1 -0.01 0
1 0 0
1 0.01 0
1 0.02 0
1 0.03 0
1 0.04 0
1 0.05 0
1 0.06 0
1 0.07 0
1 0.08 0
1 0.09 0
1 0.1 0
1 0.11 0
1 0.12 0
1 0.13 0
1 0.14 0
1 0.15 0
1 0.16 0
1 0.17 0
1 0.18 0
1 0.19 0
1 0.2 0
1 0.21 0
1 0.22 0
1 0.23 0
1 0.24 0
1 0.25 0
1 0.26 0
1 0.27 0
1 0.28 0
1 0.29 0
1 0.3 0
1 0.31 0
1 0.32 0
1 0.33 0
1 0.34 0
1 0.35 0
1 0.36 0
1 0.37 0
1 0.38 0
1 0.39 0
1 0.4 0
1 0.41 0
1 0.42 0
1 0.43 0
1 0.44 0
1 0.45 0
1 0.46 0
1 0.47 0
1 0.48 0
1 0.49 0
1 0.5 0
1 0.51 0
1 0.52 0
1 0.53 0
1 0.54 0
1 0.55 0
1 0.56 0
1 0.57 0
1 0.58 0
1 0.59 0
1 0.6 0
1 0.61 0
1 0.62 0
1 0.63 0
1 0.64 0
1 0.65 0
1 0.66 0
1 0.67 0
1 0.68 0
1 0.69 0
1 0.7 0
1 0.71 0
1 0.72 0
1 0.73 0
1 0.74 0
1 0.75 0
1 0.76 0
1 0.77 0
1 0.78 0
1 0.79 0
1 0.8 0
1 0.81 0
1 0.82 0
1 0.83 0
1 0.84 0
1 0.85 0
1 0.86 0
1 0.87 0
1 0.88 0
1 0.89 0
1 0.9 0
1 0.91 0
1 0.92 0
1 0.93 0
1 0.94 0
1 0.95 0
1 0.96 0
1 0.97 0
1 0.98 0
1 0.99 0
1 1 0

10000
Demos/Simple/SimpleDataTrain.txt Executable file

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Двоичные данные
Demos/Simple/SimpleDemoDataReference.png Executable file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 177 KiB

Двоичные данные
Demos/Simple/SimpleDemoErrorRateReference.png Executable file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 11 KiB

Двоичные данные
Demos/Simple/SimpleDemoOutputReference.png Executable file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 22 KiB

2
Demos/Simple/SimpleMapping.txt Executable file
Просмотреть файл

@ -0,0 +1,2 @@
0
1