about summary refs log tree commit diff
path: root/sourcecodes/bnt-master/SLP/scoring/score_find_in_cache.m
blob: 61f282e9609ce82b5bd92704599d83e48518afce (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
53
54
55
56
57
58
59
60
61
62
63
function [bool, score] = score_find_in_cache(cache,j,ps,scoring_fn)
% [bool, score] = score_find_in_cache(cache,j,ps,scoring_fn)
% 
% francois.olivier.c.h@gmail.com

%tic
L=size(cache,1);
N=size(cache,2)-3;

if N<1
  bool=0;
  score=0;
  return
end

parents=zeros(1,N+1);
parents(ps)=1;parents(N+1)=j;

switch scoring_fn
  case 'bic',
    fn=1;
  case 'bayesian',
    fn=2;
  otherwise,
    fn=3;
    %error(['unrecognized scoring fn ' scoring_fn]);     
end

%parent = str2num(num2str(parents,'%1d'));
%[tmp y]=find(cache(:,N+3)==fn);
%if ~isempty(tmp)
%  [tmp2 y]=find(str2num(num2str(cache(tmp,1:N+1),'%1d'))==parent);
%  candidats=tmp(tmp2);
%else
%  candidats=[];
%end

[tmp y]=find(cache(2:L,N+3)==fn);
tmp=tmp+1;
[tmp2 y]=find(cache(tmp,N+1)==j);
candidats=tmp(tmp2);
if ~isempty(candidats)
  for i=1:N      % N=size(cache,2)-3;
    if ~isempty(candidats)
      [tmp2 y]=find(cache(tmp,i)==parents(i));
      candidats=intersect(candidats,tmp(tmp2));
    end
  end
end

%Tpre=toc

if ~isempty(candidats)
  bool=1;
else
  bool=0;
end

if bool
  score=cache(candidats(1),N+2);
else
  score=0;
end