diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/toolboxes/RBM/Main.m	Tue Feb 10 15:05:51 2015 +0000
@@ -0,0 +1,66 @@
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
+% Main script of KRBM-Knowledge-based Restricted Boltzmann Machine   %
+% -*-sontran2012-*-                                                  %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%% loading background knowledge 
+% bk_file  = 'XOR.bk';
+% w = 5;
+W  = rand(0,0);
+mW = rand(0,0);
+% [W mW nNames] = encode_bk(bk_file,w)
+%%% visualize_system(W,nNames,w,100,100);
+%% Loading data
+PRO_DIR = 'C://Pros/';
+% dat_file = 'XOR.dat';
+% dat_file = 'DNA.dat';
+% train_file  = strcat(PRO_DIR,'/Data/ICDAR/digit_train_data.mat';
+% train_label = strcat(PRO_DIR,'/Data/ICDAR/digit_train_label.mat';
+% test_file   = strcat(PRO_DIR,'/Data/ICDAR/digit_test_data.mat';
+% test_label  = strcat(PRO_DIR,'/Data/ICDAR/digit_test_label.mat';
+%-----------------------------------------------------
+% train_file  = strcat(PRO_DIR,'/Data/MNIST/mnist_train_data.mat';
+% train_label = strcat(PRO_DIR,'/Data/MNIST/mnist_train_label.mat';
+% test_file   = strcat(PRO_DIR,'/Data/MNIST/mnist_test_data.mat';
+% test_label  = strcat(PRO_DIR,'/Data/MNIST/mnist_test_label.mat';
+%-----------------------------------------------------
+% train_file  = strcat(PRO_DIR,'/RBMLIB/train_dat.mat');
+% train_label = strcat(PRO_DIR,'/RBMLIB/train_lab.mat');
+% test_file   = strcat(PRO_DIR,'/RBMLIB/test_dat.mat');
+% test_label  = strcat(PRO_DIR,'/RBMLIB/test_lab.mat');
+%-----------------------------------------------------
+% train_file  = strcat(PRO_DIR,'/RBMLIB/train_dat.mat');
+data_file = strcat(PRO_DIR,'/DATA/XOR/xorall.mat');
+mod_file = strcat(PRO_DIR,'/DATA/XOR/model.mat');
+%% Move weights encoded from rule to right position of input if needed
+
+%% Setting parameters
+conf.hidNum = 4;
+conf.eNum   = 50;                                                           % number of epoch
+conf.bNum   = 1;                                                           % number of batches devides the data set
+conf.sNum   = 4;                                                          % number of samples per batch
+conf.gNum   = 1;                                                            % number of iteration for gibb sampling
+conf.params = [0.5 0.5 0.1 0.00002];                                        % [lr1 lr2 momentum cost] 
+                                                                            % lr1: learning rate in first 10 epoches
+                                                                            % lr2: learning rate in the other epoches
+%% Training system
+% training_kbrm(conf,W,mW,dat_file);                                        % unsupevised learning
+% [W visB hidB] = gen_training_kbrbm(conf,W,mW,train_file,train_label);     % unsupervised learning for generative classification
+% dis_training_kbrm(conf,W,mW,dat_file,dat_label);                          % unsupervised learning for discriminative classification
+[W visB hidB] = training_rbm(conf,W,mW,data_file);
+save(mod_file,'W','mW','visB','hidB');
+nNames = {'X' 'Y' 'Z'};
+visualize_system(W,nNames,100,100);
+%% Classify (if wanted)
+% gen_classify(W, visB, hidB,mW,test_file,test_label);
+%% Generate features (if wanted)
+% in_f_file = '../Data/ICDAR/images.bin';
+% out_f_file = '../Data/ICDAR/feature.mat';
+% input_features = mnist2mat(in_f_file);
+% output_features = input_features*W;
+% save(out_f_file,'output_features');
+%% Extract knowledge (if wanted)
+% name_file = 'names.txt';                                                    % File contains name of input
+% rule_file = 'rules.txt';
+% extract_knowledge(rule_file,W);
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% END%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+clear;
\ No newline at end of file