Homwork3 4

Page 1

‫ميحرلا نمحرلا هللا‬

‫بسم‬

Islamic University – Gaza Faculty of Engineering Department of Computer Engineering

Neural Networks Assignment # 3 +4

Prepared By: Natheer A. Abu Jarir

120120820

Submitted to: Associate Professor: Mohammed Alhanjouri

2014


Third Assignment : Use all your data (F0, F1, F2, F3, and F4) for speaker classification (M, W, or C) by using Multi-layer Forward Neural Network with backpropagation training.

Matlab Code Neural Network : close all, clear all, clc, format compact % loading data M = [138 143

135

133

427

378

476 623

2322 2034 1122

997

1200

2343

2691

3557

224

219

218

519

459

1225

1105

2827

2735

4052

4115

2365

236

568

494

1490

1345

452 3081 3702 3988 4572 4276

588

768

652

497

1799

1952

1333

997

910

2605

2601

2522

2538

2459

3677

3624

3687

3486

3384

214

215

215

210

217

230

731

669

936

781

555

2530

2058

2349

1551

1136

1035

2979

2972

2815

2824

2828

4294

4290

4299

3923

3927

1588

3053

3047 1929

4334

4319

4092

3914 ];

241

249

580

523

2933

4352

237

230

228

229

225

236

243

237 511 749 2552 1546 3403 3145

564

749

717

2267

2501

3310 4671

1002

803

597

1688

1210

1137

3289

2950

2982

2987

4409

4307

3919

4167

586 2656 1719 3323 2143

4575

4422

4320

3788];

% define inputs (combine samples from all four classes) P=[M W C];

133

3334 ];

536

1426

3372

C = [ 246

483 753

2761

4328

129

217

437

3072

121

1710 3649

3357

W = [ 227 235

123

1379

2550

3657 3616 3400

123

474 2089

3000 2684 2434

127

130

342 269

129


% define output coding for classes a = [+1 +1]'; b = [+1 -1]'; c = [-1 +1]'; % define targets T = [repmat(a,1,length(man)) repmat(b,1,length(woman)) ... repmat(c,1,length(child))]; %# create ANN of one hidden layer with 7 nodes net = feedforwardnet(10);

%# set params net.layers{1}.transferFcn = 'logsig'; net.trainFcn = 'trainscg';

%# training function

net.trainParam.epochs = 5000;

%# max number of iterations

net.trainParam.lr =.1; net.performFcn = 'mse';

%# learning rate %# mean-squared error function

net.divideFcn = 'dividerand'; %# how to divide data net.divideParam.trainRatio = 70/100; %# training set net.divideParam.valRatio = 15/100;

%# validation set

net.divideParam.testRatio = 30/100;

%# testing set

% % %# training net = init(net); [net,tr] = train(net, P,T); %# testing y_hat = net(ptest); perf = perform(net, T, y_hat); err = gsubtract(T, y_hat);

Results:




Fourth Assignment: Use all data to classify 5 classes of vowels as following: 1st class: 1st, 2nd, and 3rd columns. 2nd class: 4th and 5th columns. 3rd class: 6th and 7th columns. 4th class: 8th, 9th, and 10th columns. 5th class: 11th and 12th columns. by using Multi-layer Forward Neural Network with backpropagation training.

Matlab Code Neural Network : close all, clear all, clc, format compact class1 = [ 138

135

129

227

224

219

246

241

237

342

427

476

437

483

536

452

511

564

2322

2034

2089

2761

2365

2530

3081

2552

2656

3000

2684

2691

3372

3053

3047

3702

3403

3323

3657

3616

3649

4352

4334

4319

4572

4575

4422 ];

class2 = [ 127

123

214

215

230

228

580

588

731

669

749

717

1799 1952 2058 2349 2267 2501 2605 2601 2979 2972 3310 3289 3677 3624 4294 4290 4671 4409 ];


class3 = [ 123 215

121 210

229

225

768

652

936

781

1002

803

1333

997

1551

1136

1688

1210

2522

2538

2815

2824

2950

2982

3687

3486

4299

3923

4307

3919];

class4 = [ 129

133

143

217

230

235

236

243

249

497

269

378

555

519

459

597

568

494

910

1122

997

1035

1225

1105

1137

1490

1345

2459

2434

2343

2828

2827

2735

2987

3072

3988

3384

3400

3357

3927

4052

4115

4167

4328

4276];

class5 = [ 133

130

218

217

236

237

623

474

753

523

749

586

1200

1379

1426

1588

1546

1719

2550

1710

2933

1929

3145

2143

3557

3334

4092

3914

4320

3788];


% define inputs (combine samples from all four classes) P=[class1 class2 class3 class4 class5]; % define output coding for classes a = [+1 +1 +1]'; b = [+1 -1 +1]'; c = [-1 +1 +1]'; d = [+1 -1 -1]'; e = [-1 +1 -1]'; % define targets T = [repmat(a,1,length(class1)) repmat(b,1,length(class2)) ... repmat(c,1,length(class3)) repmat(d,1,length(class4)) ... repmat(e,1,length(class5))];

%# create ANN of one hidden layer with 7 nodes net = feedforwardnet(10); %# set params net.layers{1}.transferFcn = 'logsig'; net.layers{2}.transferFcn = 'purelin'; net.trainFcn = 'trainscg';

%# training function

net.trainParam.epochs = 5000;

%# max number of iterations

net.trainParam.lr =.1; net.performFcn = 'mse';

%# learning rate %# mean-squared error function

net.divideFcn = 'dividerand'; %# how to divide data net.divideParam.trainRatio = 70/100; %# training set net.divideParam.valRatio = 15/100;

%# validation set

net.divideParam.testRatio = 30/100;

%# testing set

%# training net = init(net); [net,tr] = train(net, P,T); %# testing y_hat = net(ptest); perf = perform(net, T, y_hat); err = gsubtract(T, y_hat);

Results:





References: [1] Neural Networks: MATLAB examples. [2] http://www.mathworks.com/help/nnet/index.html.


Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.