Skip to content

Commit

Permalink
Fix MATLAB compatibility.
Browse files Browse the repository at this point in the history
  • Loading branch information
klho committed Apr 23, 2018
1 parent f1d3d8a commit 1a5a1e9
Show file tree
Hide file tree
Showing 63 changed files with 753 additions and 727 deletions.
2 changes: 1 addition & 1 deletion hifde/test/fd_cube1_diag.m
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,4 @@ function fd_cube1_diag(n,occ,rank_or_tol,skip,symm,spdiag)
fprintf([repmat('-',1,80) '\n'])
fprintf('diag: %10.4e / %10.4e\n',e1,e2)
end
end
end
8 changes: 4 additions & 4 deletions hifde/test/fd_cube2.m
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,9 @@ function fd_cube2(n,occ,rank_or_tol,skip,symm)
ld = hifde_logdet(F);
t = toc;
fprintf('logdet: %22.16e / %10.4e (s)\n',ld,t)
end

% Gaussian PDF
function y = normpdf(x,mu,sigma)
y = exp(-0.5*((x - mu)./sigma).^2)./(sqrt(2*pi).*sigma);
end
% Gaussian PDF
function y = normpdf(x,mu,sigma)
y = exp(-0.5*((x - mu)./sigma).^2)./(sqrt(2*pi).*sigma);
end
8 changes: 4 additions & 4 deletions hifde/test/fd_cube2x.m
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,9 @@ function fd_cube2x(n,occ,rank_or_tol,skip,symm)
ld = hifde_logdet(F);
t = toc;
fprintf('logdet: %22.16e / %10.4e (s)\n',ld,t)
end

% Gaussian PDF
function y = normpdf(x,mu,sigma)
y = exp(-0.5*((x - mu)./sigma).^2)./(sqrt(2*pi).*sigma);
end
% Gaussian PDF
function y = normpdf(x,mu,sigma)
y = exp(-0.5*((x - mu)./sigma).^2)./(sqrt(2*pi).*sigma);
end
8 changes: 4 additions & 4 deletions hifde/test/fd_square2.m
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,9 @@ function fd_square2(n,occ,rank_or_tol,skip,symm)
ld = hifde_logdet(F);
t = toc;
fprintf('logdet: %22.16e / %10.4e (s)\n',ld,t)
end

% Gaussian PDF
function y = normpdf(x,mu,sigma)
y = exp(-0.5*((x - mu)./sigma).^2)./(sqrt(2*pi).*sigma);
end
% Gaussian PDF
function y = normpdf(x,mu,sigma)
y = exp(-0.5*((x - mu)./sigma).^2)./(sqrt(2*pi).*sigma);
end
8 changes: 4 additions & 4 deletions hifde/test/fd_square2x.m
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,9 @@ function fd_square2x(n,occ,rank_or_tol,skip,symm)
ld = hifde_logdet(F);
t = toc;
fprintf('logdet: %22.16e / %10.4e (s)\n',ld,t)
end

% Gaussian PDF
function y = normpdf(x,mu,sigma)
y = exp(-0.5*((x - mu)./sigma).^2)./(sqrt(2*pi).*sigma);
end
% Gaussian PDF
function y = normpdf(x,mu,sigma)
y = exp(-0.5*((x - mu)./sigma).^2)./(sqrt(2*pi).*sigma);
end
28 changes: 14 additions & 14 deletions hifie/test/cov_cube1.m
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ function cov_cube1(n,occ,p,rank_or_tol,skip,symm,noise,scale,spdiag)
clear x1 x2 x3

% factor matrix
Afun = @(i,j)Afun2(i,j,x,noise);
pxyfun = @(x,slf,nbr,l,ctr)pxyfun2(x,slf,nbr,l,ctr,proxy);
Afun = @(i,j)Afun2(i,j,x,noise,scale);
pxyfun = @(x,slf,nbr,l,ctr)pxyfun2(x,slf,nbr,l,ctr,proxy,scale);
opts = struct('skip',skip,'symm',symm,'verb',1);
F = hifie3(Afun,x,occ,rank_or_tol,pxyfun,opts);
w = whos('F');
Expand Down Expand Up @@ -164,29 +164,29 @@ function cov_cube1(n,occ,p,rank_or_tol,skip,symm,noise,scale,spdiag)
fprintf([repmat('-',1,80) '\n'])
fprintf('diag: %10.4e / %10.4e\n',e1,e2)
end
end

% kernel function
function K = Kfun(x,y)
dx = bsxfun(@minus,x(1,:)',y(1,:));
dy = bsxfun(@minus,x(2,:)',y(2,:));
dz = bsxfun(@minus,x(3,:)',y(3,:));
dr = scale*sqrt(dx.^2 + dy.^2 + dz.^2);
K = exp(-0.5*dr.^2);
end
% kernel function
function K = Kfun(x,y,scale)
dx = bsxfun(@minus,x(1,:)',y(1,:));
dy = bsxfun(@minus,x(2,:)',y(2,:));
dz = bsxfun(@minus,x(3,:)',y(3,:));
dr = scale*sqrt(dx.^2 + dy.^2 + dz.^2);
K = exp(-0.5*dr.^2);
end

% matrix entries
function A = Afun2(i,j,x,noise)
A = Kfun(x(:,i),x(:,j));
function A = Afun2(i,j,x,noise,scale)
A = Kfun(x(:,i),x(:,j),scale);
[I,J] = ndgrid(i,j);
idx = I == J;
A(idx) = A(idx) + noise^2;
end

% proxy function
function [Kpxy,nbr] = pxyfun2(x,slf,nbr,l,ctr,proxy)
function [Kpxy,nbr] = pxyfun2(x,slf,nbr,l,ctr,proxy,scale)
pxy = bsxfun(@plus,proxy*l,ctr');
Kpxy = Kfun(pxy,x(:,slf));
Kpxy = Kfun(pxy,x(:,slf),scale);
dx = x(1,nbr) - ctr(1);
dy = x(2,nbr) - ctr(2);
dz = x(3,nbr) - ctr(3);
Expand Down
28 changes: 14 additions & 14 deletions hifie/test/cov_cube2.m
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ function cov_cube2(n,occ,p,rank_or_tol,skip,symm,noise,scale,spdiag)
clear x1 x2 x3

% factor matrix
Afun = @(i,j)Afun2(i,j,x,noise);
pxyfun = @(x,slf,nbr,l,ctr)pxyfun2(x,slf,nbr,l,ctr,proxy);
Afun = @(i,j)Afun2(i,j,x,noise,scale);
pxyfun = @(x,slf,nbr,l,ctr)pxyfun2(x,slf,nbr,l,ctr,proxy,scale);
opts = struct('skip',skip,'symm',symm,'verb',1);
F = hifie3(Afun,x,occ,rank_or_tol,pxyfun,opts);
w = whos('F');
Expand Down Expand Up @@ -164,29 +164,29 @@ function cov_cube2(n,occ,p,rank_or_tol,skip,symm,noise,scale,spdiag)
fprintf([repmat('-',1,80) '\n'])
fprintf('diag: %10.4e / %10.4e\n',e1,e2)
end
end

% kernel function
function K = Kfun(x,y)
dx = bsxfun(@minus,x(1,:)',y(1,:));
dy = bsxfun(@minus,x(2,:)',y(2,:));
dz = bsxfun(@minus,x(3,:)',y(3,:));
dr = scale*sqrt(dx.^2 + dy.^2 + dz.^2);
K = (1 + sqrt(3)*dr).*exp(-sqrt(3)*dr);
end
% kernel function
function K = Kfun(x,y,scale)
dx = bsxfun(@minus,x(1,:)',y(1,:));
dy = bsxfun(@minus,x(2,:)',y(2,:));
dz = bsxfun(@minus,x(3,:)',y(3,:));
dr = scale*sqrt(dx.^2 + dy.^2 + dz.^2);
K = (1 + sqrt(3)*dr).*exp(-sqrt(3)*dr);
end

% matrix entries
function A = Afun2(i,j,x,noise)
A = Kfun(x(:,i),x(:,j));
function A = Afun2(i,j,x,noise,scale)
A = Kfun(x(:,i),x(:,j),scale);
[I,J] = ndgrid(i,j);
idx = I == J;
A(idx) = A(idx) + noise^2;
end

% proxy function
function [Kpxy,nbr] = pxyfun2(x,slf,nbr,l,ctr,proxy)
function [Kpxy,nbr] = pxyfun2(x,slf,nbr,l,ctr,proxy,scale)
pxy = bsxfun(@plus,proxy*l,ctr');
Kpxy = Kfun(pxy,x(:,slf));
Kpxy = Kfun(pxy,x(:,slf),scale);
dx = x(1,nbr) - ctr(1);
dy = x(2,nbr) - ctr(2);
dz = x(3,nbr) - ctr(3);
Expand Down
26 changes: 13 additions & 13 deletions hifie/test/cov_square1.m
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ function cov_square1(n,occ,p,rank_or_tol,skip,symm,noise,scale,spdiag)
clear x1 x2

% factor matrix
Afun = @(i,j)Afun2(i,j,x,noise);
pxyfun = @(x,slf,nbr,l,ctr)pxyfun2(x,slf,nbr,l,ctr,proxy);
Afun = @(i,j)Afun2(i,j,x,noise,scale);
pxyfun = @(x,slf,nbr,l,ctr)pxyfun2(x,slf,nbr,l,ctr,proxy,scale);
opts = struct('skip',skip,'symm',symm,'verb',1);
F = hifie2(Afun,x,occ,rank_or_tol,pxyfun,opts);
w = whos('F');
Expand Down Expand Up @@ -159,28 +159,28 @@ function cov_square1(n,occ,p,rank_or_tol,skip,symm,noise,scale,spdiag)
fprintf([repmat('-',1,80) '\n'])
fprintf('diag: %10.4e / %10.4e\n',e1,e2)
end
end

% kernel function
function K = Kfun(x,y)
dx = bsxfun(@minus,x(1,:)',y(1,:));
dy = bsxfun(@minus,x(2,:)',y(2,:));
dr = scale*sqrt(dx.^2 + dy.^2);
K = exp(-0.5*dr.^2);
end
% kernel function
function K = Kfun(x,y,scale)
dx = bsxfun(@minus,x(1,:)',y(1,:));
dy = bsxfun(@minus,x(2,:)',y(2,:));
dr = scale*sqrt(dx.^2 + dy.^2);
K = exp(-0.5*dr.^2);
end

% matrix entries
function A = Afun2(i,j,x,noise)
A = Kfun(x(:,i),x(:,j));
function A = Afun2(i,j,x,noise,scale)
A = Kfun(x(:,i),x(:,j),scale);
[I,J] = ndgrid(i,j);
idx = I == J;
A(idx) = A(idx) + noise^2;
end

% proxy function
function [Kpxy,nbr] = pxyfun2(x,slf,nbr,l,ctr,proxy)
function [Kpxy,nbr] = pxyfun2(x,slf,nbr,l,ctr,proxy,scale)
pxy = bsxfun(@plus,proxy*l,ctr');
Kpxy = Kfun(pxy,x(:,slf));
Kpxy = Kfun(pxy,x(:,slf),scale);
dx = x(1,nbr) - ctr(1);
dy = x(2,nbr) - ctr(2);
dist = sqrt(dx.^2 + dy.^2);
Expand Down
24 changes: 12 additions & 12 deletions hifie/test/cov_square2.m
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ function cov_square2(n,occ,p,rank_or_tol,skip,symm,noise,scale,spdiag)
clear x1 x2

% factor matrix
Afun = @(i,j)Afun2(i,j,x,noise);
pxyfun = @(x,slf,nbr,l,ctr)pxyfun2(x,slf,nbr,l,ctr,proxy);
Afun = @(i,j)Afun2(i,j,x,noise,scale);
pxyfun = @(x,slf,nbr,l,ctr)pxyfun2(x,slf,nbr,l,ctr,proxy,scale);
opts = struct('skip',skip,'symm',symm,'verb',1);
F = hifie2(Afun,x,occ,rank_or_tol,pxyfun,opts);
w = whos('F');
Expand Down Expand Up @@ -159,26 +159,26 @@ function cov_square2(n,occ,p,rank_or_tol,skip,symm,noise,scale,spdiag)
fprintf([repmat('-',1,80) '\n'])
fprintf('diag: %10.4e / %10.4e\n',e1,e2)
end
end

% kernel function
function K = Kfun(x,y)
dx = bsxfun(@minus,x(1,:)',y(1,:));
dy = bsxfun(@minus,x(2,:)',y(2,:));
dr = scale*sqrt(dx.^2 + dy.^2);
K = (1 + sqrt(3)*dr).*exp(-sqrt(3)*dr);
end
% kernel function
function K = Kfun(x,y,scale)
dx = bsxfun(@minus,x(1,:)',y(1,:));
dy = bsxfun(@minus,x(2,:)',y(2,:));
dr = scale*sqrt(dx.^2 + dy.^2);
K = (1 + sqrt(3)*dr).*exp(-sqrt(3)*dr);
end

% matrix entries
function A = Afun2(i,j,x,noise)
A = Kfun(x(:,i),x(:,j));
function A = Afun2(i,j,x,noise,scale)
A = Kfun(x(:,i),x(:,j),scale);
[I,J] = ndgrid(i,j);
idx = I == J;
A(idx) = A(idx) + noise^2;
end

% proxy function
function [Kpxy,nbr] = pxyfun2(x,slf,nbr,l,ctr,proxy)
function [Kpxy,nbr] = pxyfun2(x,slf,nbr,l,ctr,proxy,scale)
pxy = bsxfun(@plus,proxy*l,ctr');
Kpxy = Kfun(pxy,x(:,slf));
dx = x(1,nbr) - ctr(1);
Expand Down
14 changes: 7 additions & 7 deletions hifie/test/ie_cube1.m
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,14 @@ function ie_cube1(n,occ,p,rank_or_tol,skip,symm)
e2 = norm(X - mv(Z))/norm(X);
fprintf('gmres: %10.4e / %10.4e / %4d (%4d) / %10.4e (s)\n',e1,e2, ...
piter(2),iter(2),t)
end

% kernel function
function K = Kfun(x,y)
dx = bsxfun(@minus,x(1,:)',y(1,:));
dy = bsxfun(@minus,x(2,:)',y(2,:));
dz = bsxfun(@minus,x(3,:)',y(3,:));
K = 1/(4*pi)./sqrt(dx.^2 + dy.^2 + dz.^2);
end
% kernel function
function K = Kfun(x,y)
dx = bsxfun(@minus,x(1,:)',y(1,:));
dy = bsxfun(@minus,x(2,:)',y(2,:));
dz = bsxfun(@minus,x(3,:)',y(3,:));
K = 1/(4*pi)./sqrt(dx.^2 + dy.^2 + dz.^2);
end

% matrix entries
Expand Down
14 changes: 7 additions & 7 deletions hifie/test/ie_cube2.m
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,14 @@ function ie_cube2(n,occ,p,rank_or_tol,skip,symm)
t = toc;
[e,niter] = snorm(N,@(x)(x - mv(hifie_sv(F,x))),[],[],1);
fprintf('sv: %10.4e / %4d / %10.4e (s)\n',e,niter,t)
end

% kernel function
function K = Kfun(x,y)
dx = bsxfun(@minus,x(1,:)',y(1,:));
dy = bsxfun(@minus,x(2,:)',y(2,:));
dz = bsxfun(@minus,x(3,:)',y(3,:));
K = 1/(4*pi)./sqrt(dx.^2 + dy.^2 + dz.^2);
end
% kernel function
function K = Kfun(x,y)
dx = bsxfun(@minus,x(1,:)',y(1,:));
dy = bsxfun(@minus,x(2,:)',y(2,:));
dz = bsxfun(@minus,x(3,:)',y(3,:));
K = 1/(4*pi)./sqrt(dx.^2 + dy.^2 + dz.^2);
end

% matrix entries
Expand Down
14 changes: 7 additions & 7 deletions hifie/test/ie_cube2x.m
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,14 @@ function ie_cube2x(n,occ,p,rank_or_tol,skip,symm)
t = toc;
[e,niter] = snorm(N,@(x)(x - mv(hifie_sv(F,x))),[],[],1);
fprintf('sv: %10.4e / %4d / %10.4e (s)\n',e,niter,t)
end

% kernel function
function K = Kfun(x,y)
dx = bsxfun(@minus,x(1,:)',y(1,:));
dy = bsxfun(@minus,x(2,:)',y(2,:));
dz = bsxfun(@minus,x(3,:)',y(3,:));
K = 1/(4*pi)./sqrt(dx.^2 + dy.^2 + dz.^2);
end
% kernel function
function K = Kfun(x,y)
dx = bsxfun(@minus,x(1,:)',y(1,:));
dy = bsxfun(@minus,x(2,:)',y(2,:));
dz = bsxfun(@minus,x(3,:)',y(3,:));
K = 1/(4*pi)./sqrt(dx.^2 + dy.^2 + dz.^2);
end

% matrix entries
Expand Down
Loading

0 comments on commit 1a5a1e9

Please sign in to comment.