Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8835089
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:10:48+00:00 2026-06-14T09:10:48+00:00

Here’s my code: a function to be optimized with DEoptim algorithm; the function is

  • 0

Here’s my code: a function to be optimized with DEoptim algorithm; the function is quite simple, indeed.

Reproducible code:

library(DEoptim)
library(sm)

tau.0 <- c(58.54620, 61.60164, 64.65708, 71.19507, 82.39836, 101.28953, 119.68789)
rate <- c(0.04594674, 0.01679026, 0.02706263, 0.04182605, 0.03753949, 0.04740187, 0.05235710)
Du <- c(4.27157210, -0.07481174, -0.10551229, 0.51753843, 1.51075420, 6.51483315, 7.35631500)
Co <- c(0.2364985, -6.2947479, -7.5422644, -1.2745887, -42.6203118, 55.7663196, 70.9541141)

h <- h.select(x = tau.0, y = rate, method = 'cv')
sm <- sm.regression(x = tau.0, y = rate, h = h)
ya <- sm$estimate
xa <- sm$eval.points
y <- approx(x = xa, y = ya, xout = tau.0, rule = 2)$y

besty <- function(x) {

    dtau.0 <- x
    xout <- seq(1, max(tau.0), dtau.0)
    ratem <- approx(x = tau.0, y = rate / 1, xout = xout)$y
    ym <- approx(x = tau.0, y = y / 1, xout = xout)$y
    Dum <- approx(x = tau.0, y = Du, xout = xout)$y
    Com <- approx(x = tau.0, y = Co, xout = xout)$y
    dy <- NULL

    for(i in 1:length(ym)) {

        dy[i] <- ratem[i] - ym[i-1]

    }

    dy[is.na(dy)] <- na.omit(dy)[1]
    Dum[is.na(Dum)] <- na.omit(Dum)[1]
    Com[is.na(Com)] <- na.omit(Com)[1]
    dP <- Dum * dy - .5 * Com * dy ^ 2
    xout.m <- xout / 12
    dcurve <- cbind(dP * 100, xout.m)
    PVBP <- dcurve[which(dP == max(dP)),1]
    Maty <- dcurve[which(dP == max(dP)),2]

    return(- PVBP / x)

}

DEoptim(fn = besty, lower = 1, upper = 120)

To me the last command returns

ERROR: unsupported objective function return value

What’s wrong with my code for which good DEoptim does not succeed in optimizing?

If I replace the last function’s command line

return(- PVBP / x)

with

return(as.numeric(- PVBP / x))

it seems DEoptim works fine till few iterations, then…

> DEoptim(fn = besty, lower = 1, upper = 12)
Iteration: 1 bestvalit: -0.898391 bestmemit:    1.186242
Iteration: 2 bestvalit: -0.903304 bestmemit:    1.185117
Iteration: 3 bestvalit: -0.999273 bestmemit:    1.043355
Iteration: 4 bestvalit: -0.999273 bestmemit:    1.043355
Error in DEoptim(fn = besty, lower = 1, upper = 12) : 
  unsupported objective function return value

Maybe something in function syntax?

Thanks, guys 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T09:10:49+00:00Added an answer on June 14, 2026 at 9:10 am

    Solved due to Aaron, Joshua Ulrich and csgillespie tips.

    Two modifications are required in order the code worked properly:

    ...
    PVBP <- dcurve[which(dP == max(dP)),1]
    Maty <- dcurve[which(dP == max(dP)),2]
    ...
    

    must be replaced with

    ...
    PVBP <- dcurve[which(dP == max(dP)),1][1]
    Maty <- dcurve[which(dP == max(dP)),2][1]
    ...
    

    while

    ...
    return(- PVBP / x)
    ...
    

    must be replaced with

    ...
    return(as.numeric(- PVBP / x))
    ...
    

    and in order to avoid NAs in objective function it is required that boundaries are set to

    DEoptim(fn = besty, lower = 1, upper = max(tau.0) / 12)
    

    Thanks guys who helped me!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is the code in a function I'm trying to revise. This example works
Here's the code I'm running. Basically I scrape data, and place them into simple
Here a simple question : What do you think of code which use try
Here's what I'm trying to do... It's quite simple and obviously there must be
Here's my code in the <head></head> : <link rel=stylesheet href=http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.css /> <script type=text/javascript src=http://code.jquery.com/jquery-1.7.1.min.js></script>
Here is the code: create table `team`.`User`( `UserID` bigint NOT NULL AUTO_INCREMENT , `Username`
Here is the Javascript I currently have <script type=text/javascript> $(function() { $('.slideshow').hover( function() {
Here is an example: I write html code inside of textarea, then I swap
Here is my code, which takes two version identifiers in the form 1, 5,
here is my php code $titikPetaInti = array(); while($row = mysql_fetch_assoc($hasil2)) { $titikPetaInti[] =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.