% 10.12.99 
% matlab ACE script, uses ace.m
% Example: call with ace_m

clear; 

% Example 1 ------------------------------------------------
% Demonstration of how ACE finds logarithmic transformations
% Results in blue; green is exp(phi)

if 1
ll=500; % number of data points
dim=2;  % number of terms on right hand side
wl=5;   % width of smoothing kernel
oi=100; % maximum number of outer loop iterations
ii=10;  % maximum number of inner loop iterations
ocrit=10*eps; % numerical zeroes for convergence test
icrit=1e-4; 
shol=1; % 1-> show outer loop convergence, 0-> do not
shil=0; % same for inner loop

x1=rand(ll,1); x2=rand(ll,1);
y=x1.*x2;
x=[y x1 x2]';
end;

% Example 2 ------------------------------------------------
% Another dimension

if 0
ll=500; % number of data points
dim=3;  % number of terms on right hand side
wl=5;   % width of smoothing kernel
oi=100; % maximum number of outer loop iterations
ii=10;  % maximum number of inner loop iterations
ocrit=10*eps; % numerical zeroes for convergence test
icrit=1e-4; 
shol=1; % 1-> show outer loop convergence, 0-> do not
shil=0; % same for inner loop

x1=rand(ll,1); x2=rand(ll,1); x3=rand(ll,1); 
y=x1.^2+exp(x2)+5*x3;
x=[y x1 x2 x3]';
end;

% call ace.m  ---------------------------------------------

[psi,phi]=ace(x,ll,dim,wl,oi,ii,ocrit,icrit,shol,shil);

psi

% results -------------------------------------------------

figure(1)
for d=1:dim+1; 
subplot(2,2,d); 
plot(x(d,:),phi(d,:),'.'); 
hold on;
plot(x(d,:),exp(phi(d,:)),'g.');
hold off; 
axis tight; 
end;

figure(2); 
if dim==1 sum0=phi(2,:); else sum0=sum(phi(2:dim+1,:)); end;
plot(phi(1,:),sum0,'.');
xlabel('\Phi_0'); ylabel('\Sigma \Phi_i'); title('Regression');

%save tmpphis.dat phi -ascii






