1. Trang chủ
  2. » Ngoại Ngữ

Investigation of bayesian networks for classification problems involving binary data

91 289 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 91
Dung lượng 406,62 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

Trang 1

1 function nb_data_run()

2

3 % Used to do inference testing for NB Data Strcuture

4 % This is the corrected code !!!!!!

5

6 fid=fopen('NB Data Structure Full Summary.txt','w');

7 fprintf(fid,'This is the Full details for NB Data Structure with varying Data Size.');

8 fprintf(fid,'\n -\n') ;

23 fid=fopen('NB Data Structure Full Summary.txt','a');

24 fid1=fopen('NB Data Structure Dataset.txt','a');

25 fid2=fopen('NB Data Structure Summarised Results.csv','a');

Trang 2

82 fprintf(fid,'\nNumber of Nodes %3.0f\n',num_of_nodes);

83 fprintf(fid,'\nRun Number %3.0f\n',run);

84 fprintf(fid,'\n%3.0f training examples\n',train_counter);

85

86 fprintf(fid1,'\nNumber of Nodes %3.0f\n',num_of_nodes);

87 fprintf(fid1,'\nRun Number %3.0f\n',run);

88 fprintf(fid1,'\n%3.0f training examples\n',train_counter);

Trang 3

145 % Calculating Accuracy of Actual Prediction or Bayes Error

146 % *************************************************************************** **************************************************

Trang 4

201 fprintf(fid,'\n%3.0f correct for Actual Structure.\n',correct);

202 fprintf(fid,'\n%3.3f is the Actual Negative Log Likelihood Score.\n',BN_llhoo d);

203 fprintf(fid,'\n%3.0f unknown for Actual Structure.\n',unknown);

210 % Calculating Accuracy of Naive Bayes Prediction

211 % *************************************************************************** **************************************************

Trang 5

262 for row= 1:1:size(xt,1)

263 for col= 1:1:(num_var)

305 fprintf(fid,'\n%3.0f correct for Actual Structure.\n',correct);

306 fprintf(fid,'\n%3.3f is the Actual Negative Log Likelihood Score.\n',BN_llhoo d);

307 fprintf(fid,'\n%3.0f unknown for Actual Structure.\n',unknown);

308 fprintf(fid,'\n%3.0f time for inference and learning for Actual Structure.\n' ,Actual_Time);

Trang 6

309

310 % fprintf(fid1,'\n%3.0f correct for Actual Structure.\n',correct);

311 % fprintf(fid1,'\n%3.3f is the Actual Negative Log Likelihood Score.\n',BN_ll hood);

312 % fprintf(fid1,'\n%3.0f unknown for Actual Structure.\n',unknown);

313 % fprintf(fid1,'\n%3.0f time for inference and learning for Actual Structure \n',Actual_Time);

314

315 fprintf(fid2,'%3.0f,%3.3f,%3.0f,%3.2f,',correct,BN_llhood,unknown,Actual_Time );

320 % *************************************************************************** *******************************************************

321 % *************************************************************************** *******************************************************

334 % Build a Maximumlly Weighted Tree

335 for var1 = 1:1:num_var

336 for var2 = 1:1:num_var

Trang 7

375 % the data has to be fed in with examples in columns

376 % the data to be fed in must be (1,2) and not (1,0)

421 for row= 1:1:size(xt,1)

422 for col= 1:1:(num_var)

Trang 8

466 fprintf(fid,'\n%3.0f correct for TANB Structure.\n',correct);

467 fprintf(fid,'\n%3.3f is the TANB Negative Log Likelihood Score.\n',BN_llhood) ;

468 fprintf(fid,'\n%3.0f unknown for TANB Structure.\n',unknown);

469 fprintf(fid,'\n%3.2f time for learning for TANB Structure.\n',TANB_learn_time );

470 fprintf(fid,'\n%3.2f time for inference for TANB Structure.\n',TANB_infer_tim e);

471 fprintf(fid,'\n%3.2f time for inference and learning for TANB Structure.\n',T ANB_time);

472

473 fprintf(fid2,'%3.0f,%3.3f,%3.0f,%3.2f,%3.2f,%3.2f,',correct,BN_llhood,unknown ,TANB_learn_time,TANB_infer_time,TANB_time);

478 % *************************************************************************** *******************************************************

479 % *************************************************************************** *******************************************************

Trang 9

519 % the data has to be fed in with examples in columns

520 % the data to be fed in must be (1,2) and not (1,0)

Trang 10

567 for row= 1:1:size(xt,1)

568 for col= 1:1:(num_var)

Trang 11

614 fprintf(fid,'\n%3.0f correct for Full BN.\n',correct);

615 fprintf(fid,'\n%3.3f is the BN Negative Log Likelihood Score.\n',BN_llhood);

616 fprintf(fid,'\n%3.0f unknown for FULL BN Structure.\n',unknown);

617 fprintf(fid,'\n%3.2f needed to learn for K2 algo.\n',BN_learn_time);

618 fprintf(fid,'\n%3.2f needed to infer for K2 algo.\n',BN_infer_time);

619 fprintf(fid,'\n%3.2f needed to infer and learn for K2 algo.\n',BN_time);

620 fprintf(fid,'\n************************************************************** *******************\n');

621

622 % fprintf(fid1,'\n%3.0f correct for Full BN.\n',correct);

623 % fprintf(fid1,'\n%3.3f is the BN Negative Log Likelihood Score.\n',BN_llhood );

624 % fprintf(fid1,'\n%3.0f unknown for FULL BN Structure.\n',unknown);

625 % fprintf(fid1,'\n%3.2f needed to learn for K2 algo.\n',BN_learn_time);

626 % fprintf(fid1,'\n%3.2f needed to infer for K2 algo.\n',BN_infer_time);

627 % fprintf(fid1,'\n%3.2f needed to infer and learn for K2 algo.\n',BN_time);

628 % fprintf(fid1,'\n*********************************************************** **********************\n');

629

630 fprintf(fid2,'%3.0f,%3.3f,%3.0f,%3.2f,%3.2f,%3.2f,',correct,BN_llhood,unknown ,BN_learn_time,BN_infer_time,BN_time);

Trang 12

1 function tanb_data_run()

2

3 % Used to do inference testing for TANB Data Strcuture

4 % This is used to test out when ordering is opposite to that stated for BN

5 % This is the corrected code !!!!!!

6

7 fid=fopen('TANB Data Structure Full Summary.txt','w');

8 fprintf(fid,'This is the Full details for TANB Data Structure with varying Data Size.');

9 fprintf(fid,'\n -\n') ;

24 fid=fopen('TANB Data Structure Full Summary.txt','a');

25 fid1=fopen('TANB Data Structure Dataset.txt','a');

26 fid2=fopen('TANB Data Structure Summarised Results.txt','a');

34 dag(2:N-1,1:N-2)=(eye(N-2)); % rot90 rotates the matrix by 90 degrees

35 dag(N,1:(N-1))=1; % Root Node to all nodes

Trang 13

78 fprintf(fid,'\nNumber of Nodes %3.0f\n',num_of_nodes);

79 fprintf(fid,'\nRun Number %3.0f\n',run);

80 fprintf(fid,'\n%3.0f training examples\n',train_counter);

81

82 fprintf(fid1,'\nNumber of Nodes %3.0f\n',num_of_nodes);

83 fprintf(fid1,'\nRun Number %3.0f\n',run);

84 fprintf(fid1,'\n%3.0f training examples\n',train_counter);

Trang 14

145 % Calculating Accuracy of Naive Bayes

146 % *************************************************************************************** **************************************

163 % Creating the Structure of NB

164 % *************************************************************************************** **************************************

Trang 15

188 fprintf(fid,'\nDisplaying Learned Parameters using Actual Network Structure.\n');

210 for row= 1:1:size(xt,1)

211 for col= 1:1:(num_var)

Trang 16

252 fprintf(fid,'\n%3.3f is the Actual Negative Log Likelihood Score.\n',BN_llhood);

253 fprintf(fid,'\n%3.0f unknown for Actual Structure.\n',unknown);

254 fprintf(fid,'\n%3.0f time for inference and learning for Actual Structure.\n',NB_Time);

255

256 % fprintf(fid1,'\n%3.0f correct for Actual Structure.\n',correct);

257 % fprintf(fid1,'\n%3.3f is the Actual Negative Log Likelihood Score.\n',BN_llhood);

258 % fprintf(fid1,'\n%3.0f unknown for Actual Structure.\n',unknown);

259 % fprintf(fid1,'\n%3.0f time for inference and learning for Actual Structure.\n',NB_Time) ;

266 % *************************************************************************************** *******************************************

267 % *************************************************************************************** *******************************************

280 % Build a Maximumlly Weighted Tree

281 for var1 = 1:1:num_var

282 for var2 = 1:1:num_var

Trang 17

321 % the data has to be fed in with examples in columns

322 % the data to be fed in must be (1,2) and not (1,0)

367 for row= 1:1:size(xt,1)

368 for col= 1:1:(num_var)

Trang 18

410 fprintf(fid,'\n%3.0f correct for TANB Structure.\n',correct);

411 fprintf(fid,'\n%3.3f is the TANB Negative Log Likelihood Score.\n',BN_llhood);

412 fprintf(fid,'\n%3.0f unknown for TANB Structure.\n',unknown);

413 fprintf(fid,'\n%3.2f time for learning for TANB Structure.\n',TANB_learn_time);

414 fprintf(fid,'\n%3.2f time for inference for TANB Structure.\n',TANB_infer_time);

415 fprintf(fid,'\n%3.2f time for inference and learning for TANB Structure.\n',TANB_time);

416

417 % fprintf(fid1,'\n%3.0f correct for TANB Structure.\n',correct);

418 % fprintf(fid1,'\n%3.3f is the TANB Negative Log Likelihood Score.\n',BN_llhood);

419 % fprintf(fid1,'\n%3.0f unknown for TANB Structure.\n',unknown);

420 % fprintf(fid1,'\n%3.2f time for learning for TANB Structure.\n',TANB_learn_time);

421 % fprintf(fid1,'\n%3.2f time for inference for TANB Structure.\n',TANB_infer_time);

422 % fprintf(fid1,'\n%3.2f time for inference and learning for TANB Structure.\n',TANB_time) ;

423

424 fprintf(fid2,'%3.0f\t%3.3f\t%3.0f\t%3.2f\t%3.2f\t%3.2f\t',correct,BN_llhood,unknown,TANB_ learn_time,TANB_infer_time,TANB_time);

429 % *************************************************************************************** *******************************************

430 % *************************************************************************************** *******************************************

Trang 19

470 % the data has to be fed in with examples in columns

471 % the data to be fed in must be (1,2) and not (1,0)

Trang 20

518 for row= 1:1:size(xt,1)

519 for col= 1:1:(num_var)

563 fprintf(fid,'\n%3.0f correct for Full BN.\n',correct);

564 fprintf(fid,'\n%3.3f is the BN Negative Log Likelihood Score.\n',BN_llhood);

Trang 21

565 fprintf(fid,'\n%3.0f unknown for FULL BN Structure.\n',unknown);

566 fprintf(fid,'\n%3.2f needed to learn for K2 algo.\n',BN_learn_time);

567 fprintf(fid,'\n%3.2f needed to infer for K2 algo.\n',BN_infer_time);

568 fprintf(fid,'\n%3.2f needed to infer and learn for K2 algo.\n',BN_time);

569 fprintf(fid,'\n************************************************************************** *******\n');

570

571 % fprintf(fid1,'\n%3.0f correct for Full BN.\n',correct);

572 % fprintf(fid1,'\n%3.3f is the BN Negative Log Likelihood Score.\n',BN_llhood);

573 % fprintf(fid1,'\n%3.0f unknown for FULL BN Structure.\n',unknown);

574 % fprintf(fid1,'\n%3.2f needed to learn for K2 algo.\n',BN_learn_time);

575 % fprintf(fid1,'\n%3.2f needed to infer for K2 algo.\n',BN_infer_time);

576 % fprintf(fid1,'\n%3.2f needed to infer and learn for K2 algo.\n',BN_time);

577 % fprintf(fid1,'\n*********************************************************************** **********\n');

578

579 fprintf(fid2,'%3.0f\t%3.3f\t%3.0f\t%3.2f\t%3.2f\t%3.2f\t',correct,BN_llhood,unknown,BN_le arn_time,BN_infer_time,BN_time);

Trang 22

1 function bn_data_run_20()

2

3 % Used to do inference testing for BN Data Strcuture for 100 Nodes

4 % This code involves noise in both training and testing sets

5 % This is the corrected code !!!!!!

6

7 fid=fopen('BN Data Structure Full Summary.txt','w');

8 fprintf(fid,'This is the Full details for NB Data Structure with varying Data Size.');

9 fprintf(fid,'\n -\n') ;

25 fid=fopen('BN Data Structure Full Summary.txt','a');

26 fid1=fopen('BN Data Structure Dataset.txt','a');

27 fid2=fopen('BN Data Structure Summarised Results.csv','a');

Trang 23

90 fprintf(fid,'\nNumber of Nodes %3.0f\n',num_of_nodes);

91 fprintf(fid,'\nRun Number %3.0f\n',run);

92 fprintf(fid,'\n%3.0f training examples\n',train_counter);

93

94 fprintf(fid1,'\nNumber of Nodes %3.0f\n',num_of_nodes);

95 fprintf(fid1,'\nRun Number %3.0f\n',run);

96 fprintf(fid1,'\n%3.0f training examples\n',train_counter);

Trang 24

126 train_filename = strcat(nodes_string,'_nodes_',num_of_links_string,'_max_ links_',run_string,'_run_',train_string,'_train_num_TRAIN.csv');

148 dlmwrite(test_filename,initial_gen_tdata');

149

150 % % ********************************************************************* ********************************************************

151 % % Calculating Accuracy of Actual Prediction or Bayes Error

152 % % ********************************************************************* ********************************************************

Trang 25

207 % fprintf(fid,'\n%3.0f correct for Actual Structure.\n',correct);

208 % fprintf(fid,'\n%3.3f is the Actual Negative Log Likelihood Score.\n',BN _llhood);

209 % fprintf(fid,'\n%3.0f unknown for Actual Structure.\n',unknown);

216 % Calculating Accuracy of Naive Bayes Prediction

217 % *********************************************************************** ******************************************************

Trang 26

270 for row= 1:1:size(xt,1)

271 for col= 1:1:(num_var)

Trang 27

313 fprintf(fid,'\n%3.0f correct for Actual Structure.\n',correct);

314 fprintf(fid,'\n%3.3f is the Actual Negative Log Likelihood Score.\n',BN_l lhood);

315 fprintf(fid,'\n%3.0f unknown for Actual Structure.\n',unknown);

316 fprintf(fid,'\n%3.0f time for inference and learning for Actual Structure .\n',Actual_Time);

317

318 % fprintf(fid1,'\n%3.0f correct for Actual Structure.\n',correct);

319 % fprintf(fid1,'\n%3.3f is the Actual Negative Log Likelihood Score.\n',B N_llhood);

320 % fprintf(fid1,'\n%3.0f unknown for Actual Structure.\n',unknown);

321 % fprintf(fid1,'\n%3.0f time for inference and learning for Actual Struct ure.\n',Actual_Time);

322

323 fprintf(fid2,'%3.0f,%3.3f,%3.0f,%3.2f,',correct,BN_llhood,unknown,Actual_ Time);

328 % *********************************************************************** ***********************************************************

329 % *********************************************************************** ***********************************************************

342 % Build a Maximumlly Weighted Tree

343 for var1 = 1:1:num_var

344 for var2 = 1:1:num_var

Trang 28

383 % the data has to be fed in with examples in columns

384 % the data to be fed in must be (1,2) and not (1,0)

Trang 29

429 for row= 1:1:size(xt,1)

430 for col= 1:1:(num_var)

474 fprintf(fid,'\n%3.0f correct for TANB Structure.\n',correct);

475 fprintf(fid,'\n%3.3f is the TANB Negative Log Likelihood Score.\n',BN_llh ood);

476 fprintf(fid,'\n%3.0f unknown for TANB Structure.\n',unknown);

477 fprintf(fid,'\n%3.2f time for learning for TANB Structure.\n',TANB_learn_ time);

478 fprintf(fid,'\n%3.2f time for inference for TANB Structure.\n',TANB_infer _time);

479 fprintf(fid,'\n%3.2f time for inference and learning for TANB Structure.\ n',TANB_time);

480

481 fprintf(fid2,'%3.0f,%3.3f,%3.0f,%3.2f,%3.2f,%3.2f,',correct,BN_llhood,unk nown,TANB_learn_time,TANB_infer_time,TANB_time);

482

Trang 30

483 clear x y xt yt engine evidence bnet1 correct unknown BN_llhood TANB_lear n_time TANB_infer_time TANB_time;

484

485 % *********************************************************************** ***********************************************************

486 % *********************************************************************** ***********************************************************

487 % *********************************************************************** ***********************************************************

527 % the data has to be fed in with examples in columns

528 % the data to be fed in must be (1,2) and not (1,0)

Trang 31

575 for row= 1:1:size(xt,1)

576 for col= 1:1:(num_var)

Trang 32

622 fprintf(fid,'\n%3.0f correct for Full BN.\n',correct);

623 fprintf(fid,'\n%3.3f is the BN Negative Log Likelihood Score.\n',BN_llhoo d);

624 fprintf(fid,'\n%3.0f unknown for FULL BN Structure.\n',unknown);

625 fprintf(fid,'\n%3.2f needed to learn for K2 algo.\n',BN_learn_time);

626 fprintf(fid,'\n%3.2f needed to infer for K2 algo.\n',BN_infer_time);

627 fprintf(fid,'\n%3.2f needed to infer and learn for K2 algo.\n',BN_time);

628 fprintf(fid,'\n********************************************************** ***********************\n');

629

630 % fprintf(fid1,'\n%3.0f correct for Full BN.\n',correct);

631 % fprintf(fid1,'\n%3.3f is the BN Negative Log Likelihood Score.\n',BN_ll hood);

632 % fprintf(fid1,'\n%3.0f unknown for FULL BN Structure.\n',unknown);

633 % fprintf(fid1,'\n%3.2f needed to learn for K2 algo.\n',BN_learn_time);

634 % fprintf(fid1,'\n%3.2f needed to infer for K2 algo.\n',BN_infer_time);

635 % fprintf(fid1,'\n%3.2f needed to infer and learn for K2 algo.\n',BN_time );

636 % fprintf(fid1,'\n******************************************************* **************************\n');

637

638 fprintf(fid2,'%3.0f,%3.3f,%3.0f,%3.2f,%3.2f,%3.2f,',correct,BN_llhood,unk nown,BN_learn_time,BN_infer_time,BN_time);

Trang 34

1 function nb_data_run_noise()

2

3 % Used to do inference testing for NB Data Strcuture

4 % This code involves noise in both training and testing sets

5 % This is the corrected code !!!!!!

6

7 fid=fopen('NB Data Structure Full Summary.txt','w');

8 fprintf(fid,'This is the Full details for NB Data Structure with varying Data Size.');

9 fprintf(fid,'\n -\n') ;

24 fid=fopen('NB Data Structure Full Summary.txt','a');

25 fid1=fopen('NB Data Structure Dataset.txt','a');

26 fid2=fopen('NB Data Structure Summarised Results.csv','a');

Trang 35

63 % To Display the Actual Parameters

83 fprintf(fid,'\nNumber of Nodes %3.0f\n',num_of_nodes);

84 fprintf(fid,'\nRun Number %3.0f\n',run);

85 fprintf(fid,'\n%3.0f training examples\n',train_counter);

86

87 fprintf(fid1,'\nNumber of Nodes %3.0f\n',num_of_nodes);

88 fprintf(fid1,'\nRun Number %3.0f\n',run);

89 fprintf(fid1,'\n%3.0f training examples\n',train_counter);

Trang 36

149 dlmwrite(test_filename,initial_gen_tdata');

150

151 % *************************************************************************** **************************************************

152 % Calculating Accuracy of Actual Prediction or Bayes Error

153 % *************************************************************************** **************************************************

Trang 37

208 fprintf(fid,'\n%3.0f correct for Actual Structure.\n',correct);

209 fprintf(fid,'\n%3.3f is the Actual Negative Log Likelihood Score.\n',BN_llhoo d);

210 fprintf(fid,'\n%3.0f unknown for Actual Structure.\n',unknown);

217 % Calculating Accuracy of Naive Bayes Prediction

218 % *************************************************************************** **************************************************

Trang 38

269 for row= 1:1:size(xt,1)

270 for col= 1:1:(num_var)

Trang 39

311

312 fprintf(fid,'\n%3.0f correct for Actual Structure.\n',correct);

313 fprintf(fid,'\n%3.3f is the Actual Negative Log Likelihood Score.\n',BN_llhoo d);

314 fprintf(fid,'\n%3.0f unknown for Actual Structure.\n',unknown);

315 fprintf(fid,'\n%3.0f time for inference and learning for Actual Structure.\n' ,Actual_Time);

316

317 % fprintf(fid1,'\n%3.0f correct for Actual Structure.\n',correct);

318 % fprintf(fid1,'\n%3.3f is the Actual Negative Log Likelihood Score.\n',BN_ll hood);

319 % fprintf(fid1,'\n%3.0f unknown for Actual Structure.\n',unknown);

320 % fprintf(fid1,'\n%3.0f time for inference and learning for Actual Structure \n',Actual_Time);

321

322 fprintf(fid2,'%3.0f,%3.3f,%3.0f,%3.2f,',correct,BN_llhood,unknown,Actual_Time );

327 % *************************************************************************** *******************************************************

328 % *************************************************************************** *******************************************************

341 % Build a Maximumlly Weighted Tree

342 for var1 = 1:1:num_var

343 for var2 = 1:1:num_var

Trang 40

382 % the data has to be fed in with examples in columns

383 % the data to be fed in must be (1,2) and not (1,0)

428 for row= 1:1:size(xt,1)

429 for col= 1:1:(num_var)

Ngày đăng: 08/11/2015, 17:00

TỪ KHÓA LIÊN QUAN

TÀI LIỆU CÙNG NGƯỜI DÙNG

TÀI LIỆU LIÊN QUAN