You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
1.1 KiB
Matlab
45 lines
1.1 KiB
Matlab
function [W,alpha,mImage,nLetters]=words_weights(incFeedback)
|
|
|
|
%define weights for the first layer of nodes representing letters and numbers
|
|
%weights define mapping between the 14 image features (LCD segments) and letters
|
|
W{1}=zeros(26,14);
|
|
for i=1:26 %encode letters
|
|
W{1}(i,encode_letter(i))=1;
|
|
end
|
|
for i=0:9 %encode numbers
|
|
W{1}(27+i,encode_letter(i-48))=1;
|
|
end
|
|
[nLetters]=size(W{1},1);
|
|
|
|
%expand by 4, so that input can be a four-letter word
|
|
for i=1:2
|
|
[numLetters,mImage]=size(W{1});
|
|
W{1}(numLetters+1:2*numLetters,mImage+1:2*mImage)=W{1};
|
|
end
|
|
[numLetters,mImage]=size(W{1});
|
|
|
|
%normalise weights
|
|
W{1}=bsxfun(@rdivide,W{1},max(1e-6,sum(W{1},2)));
|
|
|
|
if incFeedback
|
|
%add extra weights for recurrent feedback from second stage - driving connections
|
|
W{1}=[W{1},0.5.*eye(numLetters)];
|
|
end
|
|
|
|
%define weights for the second layer of nodes representing words
|
|
%weights define image to letter encodings
|
|
alpha=importdata('wordlist.txt');
|
|
numWords=length(alpha);
|
|
W{2}=zeros(numWords,numLetters);
|
|
for i=1:numWords
|
|
tmp=double(alpha{i})-96;
|
|
for l=1:4
|
|
W{2}(i,tmp(l)+(l-1)*nLetters)=1;
|
|
end
|
|
end
|
|
|
|
%normalise weights
|
|
W{2}=bsxfun(@rdivide,W{2},max(1e-6,sum(W{2},2)));
|
|
|
|
|