-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgaus_in_a_box.m
65 lines (59 loc) · 2.17 KB
/
gaus_in_a_box.m
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
64
65
function gf = gaus_in_a_box(sigma)
% memo = sparse([],[],[],1000,1000, ceil( (SS*3*sigma)^2 ) ) ;
gf = @gib ;
function out = gib(dx,dy)
% out = zeros(size(in)); % preallocate output
% [tf,loc] = ismember(in,x); % find which in's already computed in x
% ft = ~tf; % ones to be computed
% out(ft) = F(in(ft)); % get output values for ones not already in
% % place new values in storage
% x = [x in(ft(:).')];
% y = [y reshape(out(ft),1,[])];
% out(tf) = y(loc(tf)); % fill in the rest of the output values
dx = dx(:) ;
dy = dy(:) ;
l = ones(size(dx)) ;
O = zeros(size(dx)) ;
out = mvncdf([dx dy] + [l l],[],sigma.*[1 1]) ...
- mvncdf([dx dy] + [O l],[],sigma.*[1 1]) ...
- mvncdf([dx dy] + [l O],[],sigma.*[1 1]) ...
+ mvncdf([dx dy] ,[],sigma.*[1 1]) ;
out = out / sqrt(0.1083) ;
end
end
% function gf = gaus_in_a_box(sigma,SS)
%
% % memo = sparse([],[],[],1000,1000, ceil( (SS*3*sigma)^2 ) ) ;
% memo = cell(30,30,100,100) ;
% gf = @gib ;
%
% function out = gib(dx,dy)
%
% % out = zeros(size(in)); % preallocate output
% % [tf,loc] = ismember(in,x); % find which in's already computed in x
% % ft = ~tf; % ones to be computed
% % out(ft) = F(in(ft)); % get output values for ones not already in
% % % place new values in storage
% % x = [x in(ft(:).')];
% % y = [y reshape(out(ft),1,[])];
% % out(tf) = y(loc(tf)); % fill in the rest of the output values
%
% m = memo{100+dx*SS*2,100+dy*SS*2} ;
% if isempty(m)
% dx = dx(:) ;
% dy = dy(:) ;
% l = ones(size(dx)) ;
% O = zeros(size(dx)) ;
%
% out = mvncdf([dx dy] + [l l],[],sigma.*[1 1]) ...
% - mvncdf([dx dy] + [O l],[],sigma.*[1 1]) ...
% - mvncdf([dx dy] + [l O],[],sigma.*[1 1]) ...
% + mvncdf([dx dy] ,[],sigma.*[1 1]) ;
% out = out / sqrt(0.1083) ;
% memo{100+dx*SS*2,100+dy*SS*2} = out ;
% else
% out = m ;
% end
% end
%
% end