How can optimization be used as a solver?

On the issue of Cross Validated ( How to simulate censored data ), I saw that optim

was used as a kind of solver, rather than the optimizer. Here's an example:

optim(1, fn=function(scl){(pweibull(.88, shape=.5, scale=scl, lower.tail=F)-.15)^2})
# $par
# [1] 0.2445312
# ...
pweibull(.88, shape=.5, scale=0.2445312, lower.tail=F)
# [1] 0.1500135

      

I found a tutorial on optim

here , but I still can't figure out how to use optim

to work as a solver. I have several questions:

  • What is the first parameter (i.e. the value is passed 1

    )?

  • What is the function that is being passed?

  • I can understand that it takes a Weibull probability distribution and subtracts 0.15, but why are we squaring the result?

+3


source to share


1 answer


I believe you mean my answer. Skip a few points:



  • The OP of (of this question) wanted to generate (pseudo) random data from a Weibull distribution with given shape and scale parameters and where censorship would be applied for all data that passed a given censorship time and ultimately censored. The problem is that as soon as you have specified any three of them, the fourth is necessarily captured. You cannot specify all four at the same time unless you are very lucky and the values โ€‹โ€‹you specify work well with each other. How it happened, the OP was not so lucky with the four preferred values: it was impossible to have all four as they were inconsistent. At this point, you can choose to list any three and decide for the last. The code I presented was an example of how to do this.

  • As stated in the documentation for ? optim , the first argument is par

    "[i] nitial values โ€‹โ€‹for parameters to be optimized".

    The very weakness of how the optimization procedure works is that it calculates the output value given the function and the input value. It then "looks back" to see if moving to a different input will result in a better output. If so, then it moves in that direction and starts the process again. (It stops when it doesn't appear that moving in either direction will give the best output.)

    The point is that you have to start somewhere, and the user must specify this value. In each case, I started with the OP's preferred value (although indeed I could start most anywhere).

  • The function I was passing with is ? pweibull . This is the Cumulative Distribution Function (CDF) of the Weibull distribution . It takes a quantile value ( X ) as its input and returns the proportion of the distribution that was passed up to that point. Since the OP wanted to censor the most extreme 15% of this distribution, I indicated that it pweibull

    returns a proportion that has not yet been transmitted (this is a fraction lower.tail=F

    ). Then I subtracted .15

    from the result.

  • So the ideal output (from my point of view) would be 0 . However, it is possible to get values โ€‹โ€‹below zero by looking for a scale parameter that outputs pweibull

    <+0.15. Since optim

    (or indeed most any optimizer) finds the input value that minimizes the output value, this is what it would do. To prevent this from happening, I divided the difference. This means that when the optimizer is "too far away" and finds a scale parameter that yields .05

    out pweibull

    , but the difference was -.10

    (ie <0 ), squaring produces the final output +.01

    (ie 0 , or worse). This will nudge the optimizer towards the scale parameter, which will pweibull

    infer ( .15

    -. 15) ^ 2 = 0
    ...

  • In general, the distinction you make between "optimizer" and "solver" is not transparent to me. They look like two different species of the same elephant .

  • Another possible confusion here relates to optimization versus regression. Optimization is simply a search for the input value [s] that minimizes (maximizes) the function's output. In regression, we conceptualize data as images from the data generation process, which is stochastic... Given the set of realized values โ€‹โ€‹and the functional form, we use optimization methods to estimate the function parameters, thereby extracting the data generation process from noisy instances. Some regression analyzes are involved in optimization, but other aspects of regression are less related to optimization, and the optimization itself is much more than regression. For example, the functions optimized in my answer to another question are deterministic and do not parse "data".

+4


source







All Articles