about summary refs log tree commit diff
path: root/sourcecodes/bnt-master/BNT/CPDs/@tabular_CPD
diff options
context:
space:
mode:
Diffstat (limited to 'sourcecodes/bnt-master/BNT/CPDs/@tabular_CPD')
-rw-r--r--sourcecodes/bnt-master/BNT/CPDs/@tabular_CPD/CPD_to_CPT_orig.m5
-rw-r--r--sourcecodes/bnt-master/BNT/CPDs/@tabular_CPD/CPD_to_CPT_orig.m~5
-rw-r--r--sourcecodes/bnt-master/BNT/CPDs/@tabular_CPD/get_field.m1
-rw-r--r--sourcecodes/bnt-master/BNT/CPDs/@tabular_CPD/learn_params_orig.m20
-rw-r--r--sourcecodes/bnt-master/BNT/CPDs/@tabular_CPD/learn_params_orig.m~20
-rw-r--r--sourcecodes/bnt-master/BNT/CPDs/@tabular_CPD/tabular_CPD.m3
6 files changed, 54 insertions, 0 deletions
diff --git a/sourcecodes/bnt-master/BNT/CPDs/@tabular_CPD/CPD_to_CPT_orig.m b/sourcecodes/bnt-master/BNT/CPDs/@tabular_CPD/CPD_to_CPT_orig.m
new file mode 100644
index 00000000..707de900
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/CPDs/@tabular_CPD/CPD_to_CPT_orig.m
@@ -0,0 +1,5 @@
+function CPT = CPD_to_CPT_orig(CPD)
+% CPD_TO_CPT Convert the discrete CPD to tabular form (tabular)
+% CPT = CPD_to_CPT_orig(CPD)
+
+CPT = CPD.CPT_orig;
diff --git a/sourcecodes/bnt-master/BNT/CPDs/@tabular_CPD/CPD_to_CPT_orig.m~ b/sourcecodes/bnt-master/BNT/CPDs/@tabular_CPD/CPD_to_CPT_orig.m~
new file mode 100644
index 00000000..351f103c
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/CPDs/@tabular_CPD/CPD_to_CPT_orig.m~
@@ -0,0 +1,5 @@
+function CPT = CPD_to_CPT(CPD)
+% CPD_TO_CPT Convert the discrete CPD to tabular form (tabular)
+% CPT = CPD_to_CPT(CPD)
+
+CPT = CPD.CPT;
diff --git a/sourcecodes/bnt-master/BNT/CPDs/@tabular_CPD/get_field.m b/sourcecodes/bnt-master/BNT/CPDs/@tabular_CPD/get_field.m
index ba233db9..5812330d 100644
--- a/sourcecodes/bnt-master/BNT/CPDs/@tabular_CPD/get_field.m
+++ b/sourcecodes/bnt-master/BNT/CPDs/@tabular_CPD/get_field.m
@@ -10,6 +10,7 @@ function val = get_field(CPD, name)
 
 switch name
  case 'cpt',      val = CPD.CPT;
+ case 'cpt_orig',      val = CPD.CPT_orig;
  case 'counts',      val = CPD.counts;
  otherwise,
   error(['invalid argument name ' name]);
diff --git a/sourcecodes/bnt-master/BNT/CPDs/@tabular_CPD/learn_params_orig.m b/sourcecodes/bnt-master/BNT/CPDs/@tabular_CPD/learn_params_orig.m
new file mode 100644
index 00000000..c0948566
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/CPDs/@tabular_CPD/learn_params_orig.m
@@ -0,0 +1,20 @@
+function CPD = learn_params_orig(CPD,j,data,ns,cnodes)
+% LEARN_PARAMS_ORIG
+% Calculate the original distributions of the data.
+%   The original distributions are just the percentages of states in the 
+%        data file.
+
+local_data = data(j, :); 
+nobs = size(local_data,2);
+if iscell(local_data)
+  local_data = cell2num(local_data);
+end
+counts = compute_counts(local_data,ns(j));
+counts = counts/nobs;
+switch CPD.prior_type
+ case 'none', CPD.CPT_orig = counts; 
+% case 'dirichlet', CPD.CPT = mk_stochastic(counts + CPD.dirichlet); 
+% I will use 'dirichlet' priors incorrectly here.
+ case 'dirichlet', CPD.CPT_orig = counts; 
+ otherwise, error(['unrecognized prior ' CPD.prior_type])
+end
diff --git a/sourcecodes/bnt-master/BNT/CPDs/@tabular_CPD/learn_params_orig.m~ b/sourcecodes/bnt-master/BNT/CPDs/@tabular_CPD/learn_params_orig.m~
new file mode 100644
index 00000000..7a19a42d
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/CPDs/@tabular_CPD/learn_params_orig.m~
@@ -0,0 +1,20 @@
+function CPD = learn_params_orig(CPD,j,data,data,ns,cnodes)
+% LEARN_PARAMS_ORIG
+% Calculate the original distributions of the data.
+%   The original distributions are just the percentages of states in the 
+%        data file.
+
+local_data = data(j, :); 
+nobs = size(local_data,2);
+if iscell(local_data)
+  local_data = cell2num(local_data);
+end
+counts = compute_counts(local_data,ns(j));
+counts = counts/nobs;
+switch CPD.prior_type
+ case 'none', CPD.CPT_orig = counts; 
+% case 'dirichlet', CPD.CPT = mk_stochastic(counts + CPD.dirichlet); 
+% I will use 'dirichlet' priors incorrectly here.
+ case 'dirichlet', CPD.CPT_orig = counts; 
+ otherwise, error(['unrecognized prior ' CPD.prior_type])
+end
diff --git a/sourcecodes/bnt-master/BNT/CPDs/@tabular_CPD/tabular_CPD.m b/sourcecodes/bnt-master/BNT/CPDs/@tabular_CPD/tabular_CPD.m
index 728302d4..a41a23d9 100644
--- a/sourcecodes/bnt-master/BNT/CPDs/@tabular_CPD/tabular_CPD.m
+++ b/sourcecodes/bnt-master/BNT/CPDs/@tabular_CPD/tabular_CPD.m
@@ -9,6 +9,7 @@ function CPD = tabular_CPD(bnet, self, varargin)
 %   - T means use table T; it will be reshaped to the size of node's family.
 %   - 'rnd' creates rnd params (drawn from uniform)
 %   - 'unif' creates a uniform distribution
+% CPT_orig - specifies the distribution based on original data
 % adjustable - 0 means don't adjust the parameters during learning [1]
 % prior_type - defines type of prior ['none']
 %  - 'none' means do ML estimation
@@ -60,6 +61,7 @@ CPD.sparse = 0;
 
 % set defaults
 CPD.CPT = mk_stochastic(myrand(fam_sz));
+CPD.CPT_orig = mk_stochastic(myrand(ns([self])));
 CPD.adjustable = 1;
 CPD.prior_type = 'none';
 dirichlet_type = 'BDeu';
@@ -158,6 +160,7 @@ function CPD = init_fields()
 % or create it from scratch. (Matlab requires this.)
 
 CPD.CPT = [];
+CPD.CPT_orig = [];
 CPD.sizes = [];
 CPD.prior_type = [];
 CPD.dirichlet = [];