Hello,

Thanks a lot for the replies.

I tried to use the "optim" function in R, and chose the "L-BFGS-B" method
of optimization. Now the result is very sensitive to the starting values. I
use the same function, but I give the line of  code I use for "optim".

optim(0.25, f, method= "L-BFGS-B", lower = 0, upper=5). Here 0.25 is the
starting value.

Result: $ par = 0, $Value = 1 (this is correct). $par indicates that the
maximum value of the function is at 0, and $ Value says that the maximum
value is 1.

However, I produced a quick table for the results with different starting
values:
Starting Value         $par                 $Value
 Result
0.25                             0                          1
          Correct
0.5                              0.4999                  4.1223e-09
Wrong
1                                    1                           0
               Wrong
3                                     3                           0
              Wrong

I wanted to optimise the logistic function, as the logistic function
approximates an indicator function. The indicator function is defined as
follows:  I(u), where I(u) = 1, where u = 0, and I(u) = 0, for all other
 u. u is strictly positive.

My objective function contains a indicator function.As the indicator
function is non-continuous, the optimization would become non-convex. To
bypass this limitation, I used the logistic function to approximate the
indicator function.

A simple example: f(u) = I(u) + u/6;    Maximise f(u) where u is between (0
to 5).
Correct Answer: f(u) =1, where u=0.
Code:
f= function (k) {
T_s = 20
result = (2- 2/(1+ exp(-2*T_s*k))) + (k/6)
return(result)
}
optim(0.15, f, method= "L-BFGS-B", lower = 0, upper=5,control =
list(fnscale=-1) )
## Here 0.15 is the starting value. I produce a similar table as above:

Starting Value         $par                 $Value
 Result
0.15                             0                          1
          Correct
0.16                             5                       0.833
         Wrong
0.17                             5                       0.833
         Wrong
2                                   5                       0.833
           Wrong

Questions:
1. If my objective function contains an Indicator function, is there an
efficient way to implement it?
2. Does R have any quick non-convex optimiser functions?

Best Regards,
Shantanu Mullick
PhD Candidate
ESSEC Business School

On 28 October 2013 22:01, Rolf Turner <r.turner@auckland.ac.nz> wrote:

>
> This could be described as a bug, perhaps.  Or it could be described as
> an indication that numerical optimization is inevitably tricky. Notice that
> if you narrow down your search interval from [0,5] to [0,0.5] you get the
> right answer:
>
> > optimize(f, c(0, 0.5), maximum= TRUE,tol=1e-10)
> $maximum
> [1] 4.192436e-11
>
> $objective
> [1] 1
>
> I guess there's a problem with finding a gradient that is effectively
> (numerically) zero when "k" is equal to 5.
>
>
>     cheers,
>
>     Rolf Turner
>
>
>
> On 10/29/13 06:00, Shantanu MULLICK wrote:
>
>> Hello Everyone,
>>
>> I want to perform a 1-D optimization by using the optimize() function. I
>> want to find the maximum value of a "logistic" function. The optimize()
>> function gives the wrong result.
>>
>> My code:
>> f= function (k) {
>> T_s = 20
>> result = (2- 2/(1+ exp(-2*T_s*k)))
>> return(result)
>> }
>> optimize(f, c(0, 5), tol = 0.0000000000001, maximum= TRUE)
>>
>> The maximum value for the function happens at k=0, and the maximum value
>> is
>> 1. Yet  the optimise function, says that the maximum value happens at k=
>> 4.9995, and the maximum value is 0.
>>
>>

	[[alternative HTML version deleted]]

