about summary refs log tree commit diff
path: root/sourcecodes/bnt-master/SLP/misc/cpdag_to_dag2.m
blob: 1057a9ebe455cd2e9b72e638e53dd7ebc18b11c5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
function dag = cpdag_to_dag2(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
%
% francois.olivier.c.h@gmail.com
% 7 may 2003 - OLD version

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}; dag2=dag;
    unprocessed = [];

    for i=1:(N-1)
        for j=(i+1):N
            if dag2(i,j)==1 & dag2(j,i)==1
                if ~myismember(i,unprocessed)
                    unprocessed = [unprocessed;i];
                end
                if ~myismember(j,unprocessed)
                    unprocessed = [unprocessed;j];
                end
            end
        end
    end

    for i=1:length(unprocessed)
        for j=1:N
            if dag(unprocessed(i),j)==1 & dag(j,unprocessed(i))==1
                dag(j,unprocessed(i))=0;
            end
        end
    end
    dags{da}=dag;
end

if ~iscell(cpdags)
    dag=dags{1};
else
    dag=dags;
end