diff options
| author | ziejd2 | 2018-03-14 23:23:33 -0500 |
|---|---|---|
| committer | GitHub | 2018-03-14 23:23:33 -0500 |
| commit | 1ff6baa44e22b91eefb48aea6f3befa078c0489b (patch) | |
| tree | e0fd79d2e32fd2aedda2eadaed0f19af3514c520 /sourcecodes/bnt-master/BNT/CPDs/@generic_CPD | |
| parent | 6882395afdadf4e982b25b5215071a0932730950 (diff) | |
| parent | c80226899f5cdd9f11c163817d59445213f5bef0 (diff) | |
| download | BNW-1ff6baa44e22b91eefb48aea6f3befa078c0489b.tar.gz | |
Merge pull request #1 from ziejd2/octave_php_separate
Octave php separate
Diffstat (limited to 'sourcecodes/bnt-master/BNT/CPDs/@generic_CPD')
16 files changed, 116 insertions, 0 deletions
diff --git a/sourcecodes/bnt-master/BNT/CPDs/@generic_CPD/CVS/Entries b/sourcecodes/bnt-master/BNT/CPDs/@generic_CPD/CVS/Entries new file mode 100644 index 00000000..47f0e262 --- /dev/null +++ b/sourcecodes/bnt-master/BNT/CPDs/@generic_CPD/CVS/Entries @@ -0,0 +1,8 @@ +/README/1.1.1.1/Wed May 29 15:59:52 2002// +/adjustable_CPD.m/1.1.1.1/Wed May 29 15:59:52 2002// +/display.m/1.1.1.1/Wed May 29 15:59:52 2002// +/generic_CPD.m/1.1.1.1/Wed May 29 15:59:52 2002// +/learn_params.m/1.1.1.1/Thu Jun 10 01:53:20 2004// +/log_prior.m/1.1.1.1/Wed May 29 15:59:52 2002// +/set_clamped.m/1.1.1.1/Wed May 29 15:59:52 2002// +D diff --git a/sourcecodes/bnt-master/BNT/CPDs/@generic_CPD/CVS/Entries.Log b/sourcecodes/bnt-master/BNT/CPDs/@generic_CPD/CVS/Entries.Log new file mode 100644 index 00000000..24f16336 --- /dev/null +++ b/sourcecodes/bnt-master/BNT/CPDs/@generic_CPD/CVS/Entries.Log @@ -0,0 +1 @@ +A D/Old//// diff --git a/sourcecodes/bnt-master/BNT/CPDs/@generic_CPD/CVS/Repository b/sourcecodes/bnt-master/BNT/CPDs/@generic_CPD/CVS/Repository new file mode 100644 index 00000000..19ab61e0 --- /dev/null +++ b/sourcecodes/bnt-master/BNT/CPDs/@generic_CPD/CVS/Repository @@ -0,0 +1 @@ +FullBNT/BNT/CPDs/@generic_CPD diff --git a/sourcecodes/bnt-master/BNT/CPDs/@generic_CPD/CVS/Root b/sourcecodes/bnt-master/BNT/CPDs/@generic_CPD/CVS/Root new file mode 100644 index 00000000..f3bd14a6 --- /dev/null +++ b/sourcecodes/bnt-master/BNT/CPDs/@generic_CPD/CVS/Root @@ -0,0 +1 @@ +:ext:nsaunier@bnt.cvs.sourceforge.net:/cvsroot/bnt diff --git a/sourcecodes/bnt-master/BNT/CPDs/@generic_CPD/Old/BIC_score_CPD.m b/sourcecodes/bnt-master/BNT/CPDs/@generic_CPD/Old/BIC_score_CPD.m new file mode 100644 index 00000000..a73d073b --- /dev/null +++ b/sourcecodes/bnt-master/BNT/CPDs/@generic_CPD/Old/BIC_score_CPD.m @@ -0,0 +1,26 @@ +function score = BIC_score_CPD(CPD, fam, data, ns, cnodes) +% BIC_score_CPD Compute the BIC score of a generic CPD +% score = BIC_score_CPD(CPD, fam, data, ns, cnodes) +% +% We assume this node has a maximize_params method + +ncases = size(data, 2); +CPD = reset_ess(CPD); +% make a fully observed joint distribution over the family +fmarginal.domain = fam; +fmarginal.T = 1; +fmarginal.mu = []; +fmarginal.Sigma = []; +if ~iscell(data) + cases = num2cell(data); +else + cases = data; +end +for m=1:ncases + CPD = update_ess(CPD, fmarginal, cases(:,m), ns, cnodes); +end +CPD = maximize_params(CPD); +self = fam(end); +ps = fam(1:end-1); +L = log_prob_node(CPD, cases(self,:), cases(ps,:)); +score = L - 0.5*CPD.nparams*log(ncases); diff --git a/sourcecodes/bnt-master/BNT/CPDs/@generic_CPD/Old/CPD_to_dpots.m b/sourcecodes/bnt-master/BNT/CPDs/@generic_CPD/Old/CPD_to_dpots.m new file mode 100644 index 00000000..47daac88 --- /dev/null +++ b/sourcecodes/bnt-master/BNT/CPDs/@generic_CPD/Old/CPD_to_dpots.m @@ -0,0 +1,16 @@ +function pots = CPD_to_dpots(CPD, domain, ns, cnodes, evidence) +% CPD_TO_DPOTS Convert the CPD to several discrete potentials, for different instantiations (generic) +% pots = CPD_to_dpots(CPD, domain, ns, cnodes, evidence) +% +% domain(:,i) is the domain of the i'th instantiation of CPD. +% node_sizes(i) is the size of node i. +% cnodes = all the cts nodes +% evidence{i} is the evidence on the i'th node. +% +% This just calls CPD_to_dpot for each domain. + +nCPDs = size(domain,2); +pots = cell(1,nCPDs); +for i=1:nCPDs + pots{i} = CPD_to_dpot(CPD, domain(:,i), ns, cnodes, evidence); +end diff --git a/sourcecodes/bnt-master/BNT/CPDs/@generic_CPD/Old/CVS/Entries b/sourcecodes/bnt-master/BNT/CPDs/@generic_CPD/Old/CVS/Entries new file mode 100644 index 00000000..505b09aa --- /dev/null +++ b/sourcecodes/bnt-master/BNT/CPDs/@generic_CPD/Old/CVS/Entries @@ -0,0 +1,3 @@ +/BIC_score_CPD.m/1.1.1.1/Wed May 29 15:59:52 2002// +/CPD_to_dpots.m/1.1.1.1/Wed May 29 15:59:52 2002// +D diff --git a/sourcecodes/bnt-master/BNT/CPDs/@generic_CPD/Old/CVS/Repository b/sourcecodes/bnt-master/BNT/CPDs/@generic_CPD/Old/CVS/Repository new file mode 100644 index 00000000..96b94fc8 --- /dev/null +++ b/sourcecodes/bnt-master/BNT/CPDs/@generic_CPD/Old/CVS/Repository @@ -0,0 +1 @@ +FullBNT/BNT/CPDs/@generic_CPD/Old diff --git a/sourcecodes/bnt-master/BNT/CPDs/@generic_CPD/Old/CVS/Root b/sourcecodes/bnt-master/BNT/CPDs/@generic_CPD/Old/CVS/Root new file mode 100644 index 00000000..f3bd14a6 --- /dev/null +++ b/sourcecodes/bnt-master/BNT/CPDs/@generic_CPD/Old/CVS/Root @@ -0,0 +1 @@ +:ext:nsaunier@bnt.cvs.sourceforge.net:/cvsroot/bnt diff --git a/sourcecodes/bnt-master/BNT/CPDs/@generic_CPD/README b/sourcecodes/bnt-master/BNT/CPDs/@generic_CPD/README new file mode 100644 index 00000000..7a9b164b --- /dev/null +++ b/sourcecodes/bnt-master/BNT/CPDs/@generic_CPD/README @@ -0,0 +1,2 @@ +A generic CPD implements general purpose functions like 'display', +that subtypes can inherit. diff --git a/sourcecodes/bnt-master/BNT/CPDs/@generic_CPD/adjustable_CPD.m b/sourcecodes/bnt-master/BNT/CPDs/@generic_CPD/adjustable_CPD.m new file mode 100644 index 00000000..78feea55 --- /dev/null +++ b/sourcecodes/bnt-master/BNT/CPDs/@generic_CPD/adjustable_CPD.m @@ -0,0 +1,5 @@ +function p = adjustable_CPD(CPD) +% ADJUSTABLE_CPD Does this CPD have any adjustable params? (generic) +% p = adjustable_CPD(CPD) + +p = ~CPD.clamped; diff --git a/sourcecodes/bnt-master/BNT/CPDs/@generic_CPD/display.m b/sourcecodes/bnt-master/BNT/CPDs/@generic_CPD/display.m new file mode 100644 index 00000000..001ab2c9 --- /dev/null +++ b/sourcecodes/bnt-master/BNT/CPDs/@generic_CPD/display.m @@ -0,0 +1,3 @@ +function display(CPD) + +disp(struct(CPD)); diff --git a/sourcecodes/bnt-master/BNT/CPDs/@generic_CPD/generic_CPD.m b/sourcecodes/bnt-master/BNT/CPDs/@generic_CPD/generic_CPD.m new file mode 100644 index 00000000..66a85e6a --- /dev/null +++ b/sourcecodes/bnt-master/BNT/CPDs/@generic_CPD/generic_CPD.m @@ -0,0 +1,8 @@ +function CPD = generic_CPD(clamped) +% GENERIC_CPD Virtual constructor for generic CPD +% CPD = discrete_CPD(clamped) + +if nargin < 1, clamped = 0; end + +CPD.clamped = clamped; +CPD = class(CPD, 'generic_CPD'); diff --git a/sourcecodes/bnt-master/BNT/CPDs/@generic_CPD/learn_params.m b/sourcecodes/bnt-master/BNT/CPDs/@generic_CPD/learn_params.m new file mode 100644 index 00000000..c36eb004 --- /dev/null +++ b/sourcecodes/bnt-master/BNT/CPDs/@generic_CPD/learn_params.m @@ -0,0 +1,32 @@ +function CPD = learn_params(CPD, fam, data, ns, cnodes) +% LEARN_PARAMS Compute the maximum likelihood estimate of the params of a generic CPD given complete data +% CPD = learn_params(CPD, fam, data, ns, cnodes) +% +% data(i,m) is the value of node i in case m (can be cell array). +% We assume this node has a maximize_params method. + +%error('no longer supported') % KPM 1 Feb 03 + +if 1 +ncases = size(data, 2); +CPD = reset_ess(CPD); +% make a fully observed joint distribution over the family +fmarginal.domain = fam; +fmarginal.T = 1; +fmarginal.mu = []; +fmarginal.Sigma = []; +if ~iscell(data) + cases = num2cell(data); +else + cases = data; +end +hidden_bitv = zeros(1, max(fam)); +for m=1:ncases + % specify (as a bit vector) which elements in the family domain are hidden + hidden_bitv = zeros(1, max(fmarginal.domain)); + ev = cases(:,m); + hidden_bitv(find(isempty(evidence)))=1; + CPD = update_ess(CPD, fmarginal, ev, ns, cnodes, hidden_bitv); +end +CPD = maximize_params(CPD); +end diff --git a/sourcecodes/bnt-master/BNT/CPDs/@generic_CPD/log_prior.m b/sourcecodes/bnt-master/BNT/CPDs/@generic_CPD/log_prior.m new file mode 100644 index 00000000..a73dcde0 --- /dev/null +++ b/sourcecodes/bnt-master/BNT/CPDs/@generic_CPD/log_prior.m @@ -0,0 +1,5 @@ +function L = log_prior(CPD) +% LOG_PRIOR Return log P(theta) for a generic CPD - we return 0 +% L = log_prior(CPD) + +L = 0; diff --git a/sourcecodes/bnt-master/BNT/CPDs/@generic_CPD/set_clamped.m b/sourcecodes/bnt-master/BNT/CPDs/@generic_CPD/set_clamped.m new file mode 100644 index 00000000..5ad68037 --- /dev/null +++ b/sourcecodes/bnt-master/BNT/CPDs/@generic_CPD/set_clamped.m @@ -0,0 +1,3 @@ +function CPD = set_clamped(CPD, bit) + +CPD.clamped = bit; |
