From: Faheem Yar Khan Khuhawar on
i want to design a neural network to solve the problems of classification;

if
P = [x y z] % where x,y,z is random in the range from 5 to 11, y is 10-15, z is 20-30
then
T = [1 1 1];
elseif
P = [a b c]; % where a,b,c is random in the range from 12 to 18, y is 20-25, z is 30-35
then
T = [2 2 2];

AND SO ON ... Please advise how may i accomplish this task using neural network ...
From: Greg Heath on
On Mar 7, 8:59 am, "Faheem Yar Khan Khuhawar" <ykkfah...(a)msn.com>
wrote:
> i want to design a neural network to solve the problems of classification;
>
> if
> P = [x y z]    % where x,y,z is random in the range from 5 to 11, y is 10-15, z is 20-30
> then
> T = [1 1 1];
> elseif
> P = [a b c]; % where a,b,c is random in the range from 12 to 18, y is 20-25, z is 30-35
> then
> T = [2 2 2];
>
> AND SO ON ... Please advise how may i accomplish this task using neural network ...

size(P) = [Nvarin Nobs]
size(T) = [Nvarout Nobs]

For c classes, Nvarout = c and the target output for an
input of class i is the ith column of a c-dimensional
unit matrix.

Hope this helps.

Greg
From: Faheem Yar Khan Khuhawar on
Greg Heath <heath(a)alumni.brown.edu> wrote in message <6ac3b109-e1e7-4f4b-b277-552d50203968(a)q21g2000yqm.googlegroups.com>...
> On Mar 7, 8:59 am, "Faheem Yar Khan Khuhawar" <ykkfah...(a)msn.com>
> wrote:
> > i want to design a neural network to solve the problems of classification;
> >
> > if
> > P = [x y z]    % where x,y,z is random in the range from 5 to 11, y is 10-15, z is 20-30
> > then
> > T = [1 1 1];
> > elseif
> > P = [a b c]; % where a,b,c is random in the range from 12 to 18, y is 20-25, z is 30-35
> > then
> > T = [2 2 2];
> >
> > AND SO ON ... Please advise how may i accomplish this task using neural network ...
>
> size(P) = [Nvarin Nobs]
> size(T) = [Nvarout Nobs]
>
> For c classes, Nvarout = c and the target output for an
> input of class i is the ith column of a c-dimensional
> unit matrix.
>
> Hope this helps.
>
> Greg




Sorry Greg, i couldn't catch your advise. i can implement for one class, how can i implement for multiple classes. Please help, here is the code, please pin out the place for modification in the code. Thanks

%% Creating Vectors

P1 = [ 6 10 15 32;
6 10 16 31;
6 10 16 32];
T1 = [6144 6144 6144 6144];

P2 = [ 15 13 27 42;
15 13 27 43;
15 14 26 41];
T2 = [4096];

P3 = [ 6 9 23 14;
6 9 24 14;
6 10 23 14];
T3 = [1024];

%% Creating and training of the Neural Network

[S2,Q] = size(P1);
S1 = 10;
net = newelm(P1,T1,[S1 S2],{'logsig' 'logsig'},'traingdx');
net.LW{2,1} = net.LW{2,1}*0.01;
net.b{2} = net.b{2}*0.01;
net.performFcn = 'sse';
net.trainParam.goal = 0.1;
net.trainParam.show = 20;
net.trainParam.epochs = 5;
net.trainParam.mc = 0.95;

Pseq = con2seq(P1);
Tseq = con2seq(T1);
[net,tr] = train(net,Pseq,Tseq);
save('my_class_pattern.mat', 'net');

%% Testing the Neural Network

y = sim(net,Pseq);
z = seq2con(y);
f = z{1,1};
disp(f);
From: Greg Heath on
% On Mar 7, 3:35 pm, "Faheem Yar Khan Khuhawar" <ykkfah...(a)msn.com>
wrote:
% > Greg Heath <he...(a)alumni.brown.edu> wrote in message <6ac3b109-
e1e7-4f4b-b277-552d50203...(a)q21g2000yqm.googlegroups.com>...
% > > On Mar 7, 8:59 am, "Faheem Yar Khan Khuhawar"
<ykkfah...(a)msn.com>
% > > wrote:
% > > > i want to design a neural network to solve the problems of
classification;
% >
% > > > if
% > > > P = [x y z] % where x,y,z is random in the range from 5 to
11, y is 10-15, z is 20-30
% > > > then
% > > > T = [1 1 1];
% > > > elseif
% > > > P = [a b c]; % where a,b,c is random in the range from 12 to
18, y is 20-25, z is 30-35
% > > > then
% > > > T = [2 2 2];
% >
% > > > AND SO ON ... Please advise how may i accomplish this task
using neural network ...
% >
% > > size(P) = [Nvarin Nobs]
% > > size(T) = [Nvarout Nobs]
% >
% > > For c classes, Nvarout = c and the target output for an
% > > input of class i is the ith column of a c-dimensional
% > > unit matrix.
% >
% > > Hope this helps.
% >
% > > Greg
% >
% > Sorry Greg, i couldn't catch your advise. i can implement for one
class, how can i implement for multiple classes. Please help, here is
the code, please pin out the place for modification in the code.
Thanks

close all, clear all, clc, k = 0

%% Creating Vectors

P1 = [ 6 10 15 32;
6 10 16 31;
6 10 16 32];
T1 = [6144 6144 6144 6144];

P2 = [ 15 13 27 42;
15 13 27 43;
15 14 26 41];
T2 = [4096];

P3 = [ 6 9 23 14;
6 9 24 14;
6 10 23 14];
T3 = [1024];

P = [P1 P2 P3 ]
T = [ones(1,4) zeros(1,8);
zeros(1,4) ones(1,4) zeros(1,4);
zeros(1,8) ones(1,4) ]
[I N] = size(P)
[O N] = size(T)

% Constant Model

y00 = repmat(mean(T,2),1,N)
e00 = T-y00
MSE00 = mse(e00)

% Linear Model

W = T/[ones(1,N); P]
y0 = W*[ones(1,N); P]
e0 = T-y0
MSE0 = mse(e0)
NMSE0 = MSE0/MSE00
R20 = 1-NMSE0 % 0.13618

'The Linear Model only accounts for ~ 13.6% of the output'
'variance!'
' ==> try a Neural Net'

%% Creating and training of the Neural Network

rand('state',0)
Hmax = 10
ntrial = 0
for H = 1:Hmax
for weighttrial = 1:10
ntrial = ntrial + 1
net = newff(minmax(P),[H 3]); % help newff
net.trainParam.goal = MSE00/100;
net.trainParam.show = inf;
[net,tr] = train(net,P,T); % help trainlm
y = sim(net,P);

e = T-y;
MSE(ntrial) = mse(e);
NMSE(ntrial) = MSE(ntrial)/MSE00;
R2(ntrial) = 1-NMSE(ntrial);
end
end

[ R2max ntrialopt] = max(R2)

rawsummary = [(1:ntrial)' R2'];
sortedsummary = [ (1:ntrial)' -sortrows(-rawsummary,2)]

'53% of the nets are better than the Linear Model'
'15% of the nets have R2 >~ 85% '

k=k+1,figure(k), hold on
plot((1:ntrial),R2,'.')
plot(100*R20*ones(1,ntrial),'r')
xlabel('Trial')
ylabel('Per Cent of Output Variance Modeled by the NNET')
ylim([0 1])
title('Neural Network Performance')
return

%Hope this helps,

%Greg
From: Faheem Yar Khan Khuhawar on
I Got it Worked out ... Thanks to the "Shahzad, Greg and Steve" :)

%% Neural Network Classification

clc, clear all, close all;
x = importdata('best_1mb.txt', '\t', 1); % load data from file
y = importdata('best_4mb.txt', '\t', 1); % load data from file
z = importdata('best_6mb.txt', '\t', 1); % load data from file
P1 = x.data(:,3:6); % snr_margin_up/dn and attenuation_up/dn (1024)
P2 = y.data(:,3:6); % snr_margin_up/dn and attenuation_up/dn (4096)
P3 = z.data(:,3:6); % snr_margin_up/dn and attenuation_up/dn (6144)
[r1 c1] = size(P1);
[r2 c2] = size(P2);
[r3 c3] = size(P3);

%% Taking Input

P = [P1;P2;P3];
T = [ones(r1,1);zeros(r2,1);ones(r3,1)*-1];

P = transpose(P);
[rP cP] = size(P); % 4x1058
T = transpose(T);
[rT cT] = size(T); % 1x1058

%% Creating and training of the Neural Network

net = newff(P,T,[20 3],{'tansig' 'purelin'},'traingdx');

net.trainParam.show = inf;
net.trainParam.goal = 1e-5;
net.trainParam.lr = 0.01;
net.trainparam.lr_inc = 1.05;
net.trainparam.lr_dec = 0.7;
net.trainparam.max_perfect_inc = 1.04;
net.trainparam.mc = 0.9;
net.trainparam.min_grad = 1e-10;
net.trainParam.epochs = 1000;

[net,tr] = train(net,P,T);
y = sim(net,P);

%% Save the Network

save('classinetwork.mat', 'net');

%% Taking Input

Po(1) = input('Enter the value of SNR Up: ');
Po(2) = input('Enter the value of SNR Down: ');
Po(3) = input('Enter the value of Attenuation Up: ');
Po(4) = input('Enter the value of Attenuation Down: ');
fprintf('\n');

%% Testing the Network

Po = transpose(Po);
data = load('classinetwork.mat');
newnet = data.net;
yo = sim(newnet,Po);
disp(yo);
yo = round(yo);

if (yo == 1)
disp('Expexted Current down according to Neural Network = 1024 Kbps');
elseif (yo == 0)
disp('Expexted Current down according to Neural Network = 4096 Kbps');
elseif (yo == -1)
disp('Expexted Current down according to Neural Network = 6144 Kbps');
end

%% Data Set Comparison

n1=length(P1);
numMatches1 = 0;
for i=1:n1
if (isequal(Po', P1(i,:)))
numMatches1 = numMatches1+1;
end
end

n2=length(P2);
numMatches2 = 0;
for i=1:n2
if (isequal(Po', P2(i,:)))
numMatches2 = numMatches2+1;
end
end

n3=length(P3);
numMatches3 = 0;
for i=1:n3
if (isequal(Po', P3(i,:)))
numMatches3 = numMatches3+1;
end
end

if (numMatches1 >= 1)
disp([num2str(numMatches1) ' Match Found in 1024 Kbps Data Set']);
elseif (numMatches2 >= 1)
disp([num2str(numMatches2) ' Match Found in 4096 Kbps Data Set']);
elseif (numMatches3 >= 1)
disp([num2str(numMatches3) ' Match Found in 6144 Kbps Data Set']);
else
disp('No Match Found in given Data Set');
end