function [k1,k2] = dist_double_power_wts_transform_plot(b,f1,f2);

% This version of DIST_DOUBLE_POWER_WTS uses two alternative parameters.
% Here one asks two questions:
% 
% (1) At what point (as a fraction of b) should influence fall to .95 ?  
%     Answer = f1
% 
% (2) At what further point (fraction of b) should influence fall to .05 ?  
%     Answer = f2 ( > f1 )
% 
% NOTE 1: The implicit assumption here is that the kernel function is bell
% shaped. This implies certain restrictions on f1 and f2, namely that
%
%    1 - .95 < f1  <  f2  < 1 - .05 
%
% NOTE 2: Even with these constraints, not all values can be calculated.
% For example, if f1 = .3 and f2 = .5 then k1 = 77.75, and the quantity
% log(1 - f2^k1) is so close to zero that a "division by zero" error is 
% given when trying to calculate:
%
%   k2 = log(s2)/log(1 - f2^k1)
%
% More generally, whenever f2^k1 < 10^(-16) the result will be k2 = Inf.
% In such cases, the program terminates with the following error message:
%
% %***************************************************
%  
% VALUE OUT OF RANGE: k2 is too large to calculate
%  
% ***************************************************


% Written by: T.E.SMITH  3/11/08

% DIST_POWER_WTS computes power weights of the form
% 
% a(dij) = [1 - (dij/b)^k1]^k2 , dij <= b
%        = 0  ,  dij > b
% 
% for any integer k > 1, where b > Dmin = bandwidth. These weights are then
% row normalized as
%     
% wij = s(dij)/sum[a(dih): h = 1,..n]%

%INPUTS:  b = bandwidth
%        f1 = fraction of b at which influence falls to .95
%        f2 = fraction of b at which influence falls to .05


% First solve for k1 and k2

s1 = .95; s2 = .05;

diff = min([(1 - s2) - f2, f2 - f1, f1 - (1 - s1)]);

if diff <= 0
    
    error('Fractions must satisfy (1-.95) < f1 < f2 < (1-.05)');
    
end

[k1,k2] = dist_double_power_calib(s1,f1,s2,f2);

% Now plot the function

del = b/100; %increment

d = [0:del:b];

N = length(d);

a = zeros(N,1);

for i = 1:N
    
    a(i) = [1 - (d(i)./b).^k1].^k2;   
     
end     
 
r = [0:del:b]; %plot range

M = length(r);

A = zeros(1,M);

A(1:N) = a;

plot(r,A,'k','LineWidth',3);

xlabel('Distance','Fontsize',12, 'FontWeight', 'bold');

ylabel('Influence Weight','Fontsize',12, 'FontWeight', 'bold');

title(['D-POWER KERNEL (k1 = ',num2str(k1),', k2 = ',num2str(k2),', b = ',num2str(b),')'],'Fontsize',12, 'FontWeight', 'bold');





