annotate toolboxes/RBM/Main.m @ 0:e9a9cd732c1e tip

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
rev   line source
wolffd@0 1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
wolffd@0 2 % Main script of KRBM-Knowledge-based Restricted Boltzmann Machine %
wolffd@0 3 % -*-sontran2012-*- %
wolffd@0 4 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
wolffd@0 5 %% loading background knowledge
wolffd@0 6 % bk_file = 'XOR.bk';
wolffd@0 7 % w = 5;
wolffd@0 8 W = rand(0,0);
wolffd@0 9 mW = rand(0,0);
wolffd@0 10 % [W mW nNames] = encode_bk(bk_file,w)
wolffd@0 11 %%% visualize_system(W,nNames,w,100,100);
wolffd@0 12 %% Loading data
wolffd@0 13 PRO_DIR = 'C://Pros/';
wolffd@0 14 % dat_file = 'XOR.dat';
wolffd@0 15 % dat_file = 'DNA.dat';
wolffd@0 16 % train_file = strcat(PRO_DIR,'/Data/ICDAR/digit_train_data.mat';
wolffd@0 17 % train_label = strcat(PRO_DIR,'/Data/ICDAR/digit_train_label.mat';
wolffd@0 18 % test_file = strcat(PRO_DIR,'/Data/ICDAR/digit_test_data.mat';
wolffd@0 19 % test_label = strcat(PRO_DIR,'/Data/ICDAR/digit_test_label.mat';
wolffd@0 20 %-----------------------------------------------------
wolffd@0 21 % train_file = strcat(PRO_DIR,'/Data/MNIST/mnist_train_data.mat';
wolffd@0 22 % train_label = strcat(PRO_DIR,'/Data/MNIST/mnist_train_label.mat';
wolffd@0 23 % test_file = strcat(PRO_DIR,'/Data/MNIST/mnist_test_data.mat';
wolffd@0 24 % test_label = strcat(PRO_DIR,'/Data/MNIST/mnist_test_label.mat';
wolffd@0 25 %-----------------------------------------------------
wolffd@0 26 % train_file = strcat(PRO_DIR,'/RBMLIB/train_dat.mat');
wolffd@0 27 % train_label = strcat(PRO_DIR,'/RBMLIB/train_lab.mat');
wolffd@0 28 % test_file = strcat(PRO_DIR,'/RBMLIB/test_dat.mat');
wolffd@0 29 % test_label = strcat(PRO_DIR,'/RBMLIB/test_lab.mat');
wolffd@0 30 %-----------------------------------------------------
wolffd@0 31 % train_file = strcat(PRO_DIR,'/RBMLIB/train_dat.mat');
wolffd@0 32 data_file = strcat(PRO_DIR,'/DATA/XOR/xorall.mat');
wolffd@0 33 mod_file = strcat(PRO_DIR,'/DATA/XOR/model.mat');
wolffd@0 34 %% Move weights encoded from rule to right position of input if needed
wolffd@0 35
wolffd@0 36 %% Setting parameters
wolffd@0 37 conf.hidNum = 4;
wolffd@0 38 conf.eNum = 50; % number of epoch
wolffd@0 39 conf.bNum = 1; % number of batches devides the data set
wolffd@0 40 conf.sNum = 4; % number of samples per batch
wolffd@0 41 conf.gNum = 1; % number of iteration for gibb sampling
wolffd@0 42 conf.params = [0.5 0.5 0.1 0.00002]; % [lr1 lr2 momentum cost]
wolffd@0 43 % lr1: learning rate in first 10 epoches
wolffd@0 44 % lr2: learning rate in the other epoches
wolffd@0 45 %% Training system
wolffd@0 46 % training_kbrm(conf,W,mW,dat_file); % unsupevised learning
wolffd@0 47 % [W visB hidB] = gen_training_kbrbm(conf,W,mW,train_file,train_label); % unsupervised learning for generative classification
wolffd@0 48 % dis_training_kbrm(conf,W,mW,dat_file,dat_label); % unsupervised learning for discriminative classification
wolffd@0 49 [W visB hidB] = training_rbm(conf,W,mW,data_file);
wolffd@0 50 save(mod_file,'W','mW','visB','hidB');
wolffd@0 51 nNames = {'X' 'Y' 'Z'};
wolffd@0 52 visualize_system(W,nNames,100,100);
wolffd@0 53 %% Classify (if wanted)
wolffd@0 54 % gen_classify(W, visB, hidB,mW,test_file,test_label);
wolffd@0 55 %% Generate features (if wanted)
wolffd@0 56 % in_f_file = '../Data/ICDAR/images.bin';
wolffd@0 57 % out_f_file = '../Data/ICDAR/feature.mat';
wolffd@0 58 % input_features = mnist2mat(in_f_file);
wolffd@0 59 % output_features = input_features*W;
wolffd@0 60 % save(out_f_file,'output_features');
wolffd@0 61 %% Extract knowledge (if wanted)
wolffd@0 62 % name_file = 'names.txt'; % File contains name of input
wolffd@0 63 % rule_file = 'rules.txt';
wolffd@0 64 % extract_knowledge(rule_file,W);
wolffd@0 65 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% END%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
wolffd@0 66 clear;