Professional Documents
Culture Documents
*********************************************************************//
// The Following subroutines implements the computation of lower and upper bounds of
approximate subdifferential of a proper convex univariate
// PLQ function composed of quadratic pieces of the form ax^{2} + bx + c where, a>=0 (real number),
b is any real and c may be a real or +infinity.
//********************************************************************************
********************************************************************//
function [outputvalue]=
plq_binary_search(plqf,ind_L,ind_R,implementationtype,plql,x_bar,partFlag,varargin)
// plqf : Matix, Piecewise linear quadratic Functions(N) in Nx4 matrix(as per data
structure of CCA Toolbox)
// Implementationtype = 1 : Int, Binary search in the primal space to find the particular domain
or the interval in which x_bar belongs
// Implementationtype = 2 : Int, Binary search in dual space for finding the particular PLQ
functions
// partFlag : char, Flag for algorithm to compute the left/right side bound
[ind_L,ind_R,BreakEvenPointFlag] =
binary_search_cmp(ind_L,ind_R,ind_M,plqf(ind_M,1),x_bar); // a Function to compute the next
iteration's left and right indices
end
end
end
end
end
[ind_L,ind_R,FoundBoundValue] = binary_search_cmp(ind_L,ind_R,ind_M,L_SM,Fc_SM); //
Obtain Left and Right indices of Binary Search for next iteration
end
if ~FoundBoundValue then
if length(outputvalue) == 0 then cerror("No Solution found on left Side --> No solution .........
Check Function..."); end;
end
[outputvalue] = find_solutions(plqf,ind_R,ind_L,plql,x_bar,indxbar,partFlag,varargin(1)); //
For Right part of the graph, find solution
end
end
end
endfunction
// The Function finds solution by using the true_bound_check function but accomodating any
interval jump by Binary search(BS)
// plqf : Matrix, Piece-wise linear quadratic function
// xbar : Float, The point(in primal domain) for calculation of approximate subdifferential
end
end
if indxL<1 & isinf(plqf(indxR,4)) & xbar~=plqf(1,1) then // if function is left bounded &
xbar is not the bounded x value
end
else
if argn(2)>7 then // if optional value(lower bound) is present
else
end
end
endfunction
// Checks whether the solution found is in the bounds provided by S_indxL and S_indxR
// trueBoundFlag : Boolean, Flag to confirm the solution exists in [S_indxL,S_indxR]. starts with
assumption that it is; returns False if it doesn't
else // else
end
if indx_L < 1 then // if current left index is less the 1 implies first
part of the conjugate function
boundValue = lsol;
end
return; // return
end
if argn(2)> 7 then
[boundValue] = plq_lf_sol(plqf,PLQL,xbar,indxbar,partFlag,varargin(1)); //
compute solution from last function
else
[boundValue] = plq_lf_sol(plqf,PLQL,xbar,indxbar,partFlag,%F);
end
boundValue = lsol;
end
end
[SindxL,SindxR] = plq_sval_calc(plqf,indx_L,indx_R,a,xbar,indxbar,partFlag);
Sroots = roots_plq_plql(plqf(indx_R,2),plqf(indx_R,3),plqf(indx_R,4),PLQL(3),PLQL(4),indx_R,plqf);
// Calculate solution(s); intersection point(s) between for plqf and plql function
if ~isreal(Sroots) then
if length(boundValue)==0 then
boundValue = plq_extd_sol(plqf,indx_R-1,PLQL,xbar,indxbar,partFlag,%F);
end
return; // return
end
boundValue = plq_extd_sol(plqf,indx_R,PLQL,xbar,indxbar,partFlag,%F); //
compute solution in current index and current index+1's linearly extended region
end
end
boundValue = solrs(2);
end
endfunction
// Generalized
// This function plots any number of plq functions and points on a single graph and returns
handles to each plot; preferred order of inputs is plqf,points while output is exactly in the reverse
order;
// If input order is mixed the output of the function still remains the same (All the points in reverse
order>All the Plq functions), Think of it as forming a stack with PLQ functions first and then point of
top of that.
// varargin : Variable Inputs, Variable number of plq functions and points as input (preferred
oder is plqfs, points)
end
clf(gphNum);
inputValue = varargin(i);
end
end
end
end
//Points Handle(Stack)
end
for j=i+1:length(varargin) // PLQ Function Handles are from i+1 to total
number of inputs in the returned data structure from the gca() function
end
endfunction
// Generalized
function point_plot_prop(pointHandle,markSize,markColor)
// This functions alters the size and color of points plotted on a graph for better visualization
pointHandle.mark_mode = "on";
pointHandle.mark_size = markSize;
pointHandle.mark_foreground = markColor;
endfunction
//Generalized
function plq_plot_prop(gphHandle,gphThickness,gphColor)
// This functions alters the thickness and color of plots on a graph for better visualization
gphHandle.thickness = gphThickness;
gphHandle.foreground = gphColor;
endfunction
//Generalized
else
end
b = plqfunc(indx,3); // b
c = plqfunc(indx,4); // and c
endfunction
// Generalized for solution between a function and line
function[root] = roots_plq_plql(a,b,c,d,e,indx,plqf)
// The function outputs the roots for the intersection of function(a*x^2 + b*x + c; Quadratic, linear
or point accordingly) with a line
// a : Float, plqf(xindex,2) , xindex is a demo variable pointing to the index corresponding to the
PLQ function containing x
// b : Float, plqf(xindex,3)
// c : Float, plqf(xindex,4)
// x : Float, plqf(xindex,1)
// d : Float, xbar
end
x = plqf(indx,1);
end
elseif isinf(plqf(1,4)) then // if it is left bounded
end
end
if isinf(c) then
root = [];
else
end
end
if indx > 1 & indx < size(plqf,1) then // if not at first part of conjugate function
implies solution can be at just left breakpoint
if ((xminus-d)~=0) then
end
end
end
endfunction
// Generalized
function[ind_L,ind_R,fv] = binary_search_cmp(indxL,indxR,indxM,cmpval1,cmpval2)
// cmpval1 and cmpval2 are two floating values to be compared upon which decision of the
indices depend
// cmpval1 : Float, comparison value1 whose value depends upon the previous iteration's centre
index
end
end
end
endfunction
function plot_Modgphs(xvec,gphNum,gphTitle,plqf,ind_L,ind_R,ind_M)
[rightPoint,midPoint,leftPoint,upperBounds]=plq_plot_gp(xvec(1),xvec($-
1),gphNum,gphTitle,plqf,[xvec(ind_L),plq_eval(plqf,xvec(ind_L))],[xvec(ind_M),plq_eval(plqf,xvec(ind
_M))],[xvec(ind_R),plq_eval(plqf,xvec(ind_R))]);
endfunction
// varargin : Optional inputs; expceted Boolean, False if called from true_bound_check, else true
end
end
end
end
end
end
if length(ssol)==0 then // if number of solutions are zero
end
endfunction
// varargin : optional input; expected Boolean, False if called from true_bound_check, else true
else // else
[fconjL,SindxL] = point_lft_calc(plqf,endx-1); // compute SindxL from last-1 index
end
else // else
end
if partFlag=='R' & endx==indxbar then // if it's right part and last index ==
index of xbar
else // else
end
end
if partFlag=='L' & endx==indxbar // if it's left part and indxbar == last index
else // else
end
else //else
end
end
else // else
end
//mprintf("\n\ncomplex roots\n\n");
end
if length(ssol)~=1 then //& partFlag=='L' then // if number ao roots are not 1(0 or
2)
end
end
end
end
endfunction
function[S_indxL,S_indxR] = plq_sval_calc(plqf,indx_L,indx_R,a,xbar,indxbar,partFlag)
// a : float, plqf(indx_R,1)
else // else
else
end
end
else // else
if partFlag=='L' & indxbar==indx_R then
[Flft_R,S_indxR]= point_lft_calc(plqf,indx_R,xbar);
else
end
end
else
else
end
[Flft_R,S_indxR]= point_lft_calc(plqf,indx_R,xbar);
else
end
end
endfunction
function[ssol] = plq_rf(SindxL,SindxR,Sroots)
ssol = [];
// if length(Sroots)>1 then
// end
if (SindxL<=Sroots(1)) & (Sroots(1)<SindxR) then // if first root lies between left and
right differential values
end
end
end
endfunction
// plql : vector, plql line for computing solutions(intersection points) between plql and plqf
// xbar : floating point value, point at which subdifferentials are needed to be computed
else // else
else //else
end
end
else // else
else // else
end
end
return; // return
end
if SindxL<= sol & sol <=SindxR then // if solution exists between the left and
right diferential values
end
endfunction
// Function to find solutions in the extended linear part(in conjugate domain) between two
adjacent Quadratic functions(in primal domain)
// plql : vector, plql line for computing solutions(intersection points) between plql and plqf
// xbar : floating point value, point at which subdifferentials are needed to be computed
lsol = []; // solution set vector initialized to empty vector
[FcindxR,SindxR] = point_lft_calc(plqf,indx,xbar);
else
end
[Fcindx,SindxL] = point_lft_calc(plqf,indx,xbar);
else
SindxL = -%inf;
end
[Fcindxval,SindxLval] = point_lft_calc(plqf,indx,plqf(indx-1,1));
return; // return
end
sol = (e-c)/(b-d);
end
endfunction