# Re: [R] How to stop the minimization when the condition does not hold

From: Aleš Žiberna <ales.ziberna_at_guest.arnes.si>
Date: Fri 25 Mar 2005 - 19:16:29 EST

First you have to be more specific, what are actually the parameters of the function that
you want to optiomize and what are actually constants.

So you would need to specify your objective function "function(theta)=lambda*(Constr)^2-f(x,theta)" (which is not realy writen the R-way)
as
fun<-function(Constr,theta){lambda*(Constr)^2-f(x,theta)} However, since, if I understand correclty, you don't want Constr to be smaller or equal to d, you should somehow build this into your objective function, like:

fun<-function(Constr,theta){lambda*(Constr)^2-f(x,theta)+ifelse(Constr<=d, Inf, 0)}

I hope this helps,
Ales Ziberna

• Original Message ----- From: "Vicky Landsman" <msvika@mscc.huji.ac.il> To: <r-help@stat.math.ethz.ch> Sent: Thursday, March 24, 2005 8:38 PM Subject: [R] How to stop the minimization when the condition does not hold

> Dear experts!
> I have a minimization problem with non-linear constraint and Objective
> function(theta)=lambda*(Constr)^2-f(x,theta). Theta is a vector of
> parameters.
> I'd like to stop the optimization after the value of the constraint is
> less
> or equal some constant value, say d, and save the last computed value of
> the
> function.
> For this purpose, I thought to define the Objective function like this:
>
> if (Constraint>d) fun<- ....
> else stop
>
> but this does not work with error message:
>
> I am using nlm for minimization.
> Thanks a lot for help and suggestions,
> Vicky Landsman.
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
{"ft_lang_label":"__label__en","ft_lang_prob":0.73939735,"math_prob":0.6230177,"size":1616,"snap":"2020-24-2020-29","text_gpt3_token_len":431,"char_repetition_ratio":0.14019851,"word_repetition_ratio":0.0,"special_character_ratio":0.29393566,"punctuation_ratio":0.1682243,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.95354676,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2020-07-05T05:19:16Z\",\"WARC-Record-ID\":\"<urn:uuid:908b1b1d-3a15-4de1-90be-17bfb8b75477>\",\"Content-Length\":\"9192\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:9bb125d0-c03d-4a0b-bd01-2be2197b453a>\",\"WARC-Concurrent-To\":\"<urn:uuid:2c7746c4-5e6c-4a12-aa29-672403fa1e83>\",\"WARC-IP-Address\":\"99.84.176.72\",\"WARC-Target-URI\":\"https://tolstoy.newcastle.edu.au/R/help/05/03/1389.html\",\"WARC-Payload-Digest\":\"sha1:PFMWB3AJRKJ3SCEBU5UWAFQG7LJT3VKO\",\"WARC-Block-Digest\":\"sha1:GONULKRHVPKPOU7C44VX4RFSNFRIMZBZ\",\"WARC-Identified-Payload-Type\":\"application/xhtml+xml\",\"warc_filename\":\"/cc_download/warc_2020/CC-MAIN-2020-29/CC-MAIN-2020-29_segments_1593655886865.30_warc_CC-MAIN-20200705023910-20200705053910-00350.warc.gz\"}"}