[ADOL-C] piecewise defined functions

Kshitij Kulshreshtha kshitij at math.upb.de
Tue Sep 23 10:02:38 EDT 2014


Dear Philipp,

Use the following code as a template for fun(x,y)

fun(x,y) {
    adouble curindex, minindex, dist;
    advector distvals(num_segments);
    for(int i = 0; i< num_segments; i++)
       distvals[i] = segment[i].distance(x,y);
    minindex = 0;
    for(curindex = 0; curindex < num_segments; curindex++)
       condassign(minindex,
            distvals[minindex] > distvals[curindex], curindex);
    dist = distvals[minindex];
    return dist;
}

This will work as long as num_segments is a constant, i.e. the
iteration count in fun() remains the same for all values of x and y.

Warm regards
Kshitij

On 2014-09-23 15:37, Philipp Bender wrote:
> Dear list,
> 
> as always when learning a new tool ... as soon as one issue seems 
> solved, the next one shows up, so this is my second question today
> ...
> 
> I have a function which can be considered as piecewise. It's a 
> polygonal line strip, and the function returns the shortest
> distance to one of the strips, but with some interpolation tricks
> to circumvent discontinuities and so on. So contrary to "usual"
> piecewise definitions, I cannot simply look at the parameters to
> see which definition I have to use at this particular point.
> 
> Basically, I do this (Pseudocode):
> 
> fun(x, y): dist = big number iterate over all segments of the line
> strip: dist'  = segment.distance(x, y) dist = min(dist, dist')
> 
> return dist
> 
> and somewhere else:
> 
> trace_on(0) fun(...) trace_off()
> 
> Now, I think I cannot simply declare this to be a template and
> stop thinking. I assume that now *every* segment's operation stack
> gets recorded in the tape, and I end up with something wrong.
> 
> My idea was to first have a dry run with doubles (not adoubles),
> just to obtain the correct index. Then, with adoubles x and y,
> call segment[index].distance(x, y). So with N segments, I need N+1
> calls (instead of N). Not that this would be a problem, I mention
> it only to explain what I mean.
> 
> Is there an error in my thinking, do I miss something here?
> 
> Best regards, Philipp
> 
> _______________________________________________ ADOL-C mailing
> list ADOL-C at list.coin-or.org 
> http://list.coin-or.org/mailman/listinfo/adol-c
> 

-- 
Dr. Kshitij Kulshreshtha

Institut für Mathematik,
Universität Paderborn,
Warburger Straße 100,
33098 Paderborn.

Büro: A3.235

Privatanschrift:
Arnikaweg 62
33100 Paderborn.


More information about the ADOL-C mailing list