diff options
| author | ziejd2 | 2017-09-28 15:04:40 -0500 |
|---|---|---|
| committer | ziejd2 | 2017-09-28 15:04:40 -0500 |
| commit | 8070dc963753142bb86c4ed698d91fd623ed28e7 (patch) | |
| tree | d0f6dd8fc46a49b819aa55c1a90faa14d8448883 /sourcecodes/bnt-master/SLP/misc/cpdag_to_dag.m | |
| parent | 7cc31810d53176e805532b2789955f4eedbce6bb (diff) | |
| download | BNW-8070dc963753142bb86c4ed698d91fd623ed28e7.tar.gz | |
BNW using Octave instead of Matlab.
This version of BNW should perform the same as the original version. The only difference is that it uses Octave instead of Matlab when running BayesNet Toolbox during parameter learning. I am calling this BNW_1.02. It can be accessed at: compbio.uthsc.edu/BNW_1.02
Diffstat (limited to 'sourcecodes/bnt-master/SLP/misc/cpdag_to_dag.m')
| -rw-r--r-- | sourcecodes/bnt-master/SLP/misc/cpdag_to_dag.m | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/sourcecodes/bnt-master/SLP/misc/cpdag_to_dag.m b/sourcecodes/bnt-master/SLP/misc/cpdag_to_dag.m new file mode 100644 index 00000000..8e106610 --- /dev/null +++ b/sourcecodes/bnt-master/SLP/misc/cpdag_to_dag.m @@ -0,0 +1,52 @@ +function dag = cpdag_to_dag(cpdags) +% dags = cpdag_to_dag(cpdags) +% +% CPDAG_TO_DAG produce a N*N matrix of a dag which instantiate cpdag. +% (also works with a cell array of cpdags, returning a cell array of dags) +% make sur that your entry is a completed PDAG +% this function can't be use instead of PDAG_TO_DAG +% +% see Chickering (2002) : Learning equivalence classes of bayesian networks, JMLR2, pp475-479 +% +% francois.olivier.c.h@gmail.com, philippe.leray@univ-nantes.fr +% 31 march 2006 + +if ~iscell(cpdags) + cpdag=cell(1,1); + cpdag{1}=cpdags; +else + cpdag=cpdags; +end + +for da=1:length(cpdag) + + N=length(cpdag{da}); + dag=cpdag{da}; + + unprocessed = find_nodes_in_undirected_component(dag); + while ~isempty(unprocessed) + nbr_parents = []; + for i=1:length(unprocessed) + nbr_parents(end+1)=length(parents(dag-dag.*dag',unprocessed(i))); %nbr_parents(end+1)=length(parents(dag,unprocessed(i))); + end + [tmp, idx] = max(nbr_parents); + node = unprocessed(idx); + dag(parents(dag.*dag',node),node)=0; %dag(parents(dag,node),node)=0; + %dag(myintersect(parents(dag,node),unprocessed), node)=0; % Wei Lu + unprocessed = find_nodes_in_undirected_component(dag); + end + + dags{da}=dag; +end + +if ~iscell(cpdags) + dag=dags{1}; +else + dag=dags; +end + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +function unprocessed = find_nodes_in_undirected_component(dag) +undirected_edges = dag.*dag'; +[unprocessed, tmp] = find(undirected_edges); +unprocessed = unique(unprocessed); |
