Every time I give a seminar on optimization (most recently in Feb
at Univ Cote d'Azur -- thank you Yassine for the welcome!) I point out

   Algorithms CONVERGE
   Programs  TERMINATE

If you race a Maserati (fmincon?) on a dirt bike course, you'll likely
get stuck on the first mud mound, which could be higher than the start.
You might to better with a Nelder-Mead type minimizer, setting the
objective very large when constraints violated, but ensuring starting
polytope is all-feasible. Not guaranteed, but NM methods are surprisingly
robust. My experience is that they get "near" a local min quite quickly,
then take forever to decide they're done. And if you have quite large
flat areas, polytope may collapse. I'm suggesting this as I don't have
knowledge of a discrete optimizer in R.

JN




On 2025-03-28 09:59, Daniel Lobo wrote:
Hi Duncan,

Thanks for your comment, I agree with that.

But, how it can be justified that an Optimizer gives a result which is
inferior to the starting value? At most, resulting value can remain at the
same level, isnt it?

On Fri, 28 Mar 2025 at 14:34, Duncan Murdoch <murdoch.dun...@gmail.com>
wrote:

I haven't run your code, but since Kendall correlation is based on
ranks, your Fn is probably locally constant with jumps when the ranks
change.  That's a really hard kind of function to maximize, and the
algorithm used by fmincon is not appropriate to do it.

Sorry, but I don't know if there is an R function that can do
constrained discrete maximization.

Duncan Murdoch

On 2025-03-27 2:35 p.m., Daniel Lobo wrote:
Hi,

I have below minimization problem


MyDat = structure(list(c(50L, 0L, 0L, 50L, 75L, 100L, 50L, 0L, 50L, 0L,
25L, 50L, 50L, 75L, 75L, 75L, 0L, 75L, 75L, 75L, 0L, 25L, 75L,
75L, 0L, 75L, 100L, 0L, 25L, 100L), c(75L, 0L, 0L, 50L, 100L,
50L, 75L, 75L, 100L, 25L, 0L, 25L, 100L, 0L, 50L, 0L, 25L, 25L,
100L, 75L, 0L, 0L, 0L, 50L, 0L, 75L, 75L, 0L, 50L, 25L), c(50L,
0L, 0L, 0L, 100L, 25L, 0L, 0L, 25L, 50L, 0L, 25L, 75L, 50L, 100L,
50L, 0L, 75L, 25L, 50L, 0L, 0L, 25L, 0L, 50L, 100L, 100L, 0L,
75L, 50L), c(25L, 0L, 0L, 75L, 75L, 25L, 50L, 50L, 100L, 25L,
0L, 100L, 50L, 25L, 100L, 25L, 25L, 100L, 50L, 100L, 0L, 0L,
100L, 50L, 0L, 50L, 75L, 0L, 50L, 25L), c(50L, 0L, 0L, 75L, 75L,
75L, 25L, 25L, 0L, 100L, 0L, 25L, 25L, 75L, 100L, 0L, 25L, 0L,
75L, 25L, 25L, 25L, 75L, 25L, 0L, 75L, 100L, 0L, 100L, 100L),
      c(50L, 0L, 0L, 50L, 100L, 25L, 25L, 25L, 50L, 50L, 0L, 50L,
      75L, 0L, 100L, 50L, 25L, 100L, 50L, 75L, 0L, 0L, 50L, 25L,
      0L, 100L, 100L, 0L, 75L, 50L), c(50L, 0L, 0L, 50L, 75L, 25L,
      75L, 50L, 100L, 25L, 0L, 75L, 25L, 0L, 50L, 0L, 50L, 75L,
      100L, 75L, 0L, 0L, 100L, 0L, 0L, 50L, 75L, 0L, 100L, 100L
      ), c(25L, 75L, 50L, 25L, 75L, 50L, 100L, 75L, 100L, 25L,
      0L, 75L, 25L, 50L, 25L, 25L, 75L, 75L, 100L, 75L, 75L, 100L,
      75L, 25L, 0L, 75L, 75L, 0L, 75L, 100L), c(55L, 30L, 20L,
      30L, 45L, 30L, 30L, 30L, 70L, 30L, 10L, 45L, 45L, 45L, 45L,
      30L, 30L, 55L, 45L, 45L, 30L, 30L, 30L, NA, 30L, 55L, 45L,
      20L, 45L, 70L), c(85L, 40L, 40L, 40L, 55L, 40L, 20L, 30L,
      30L, 30L, 20L, 30L, 70L, 40L, 85L, 55L, 30L, 40L, 30L, 55L,
      20L, 30L, 55L, 0L, 40L, 55L, 70L, 40L, 85L, 70L), c(45L,
      45L, 0L, 45L, 45L, 45L, 0L, 0L, 100L, 45L, 0L, 100L, 45L,
      45L, 100L, 45L, 45L, 100L, 45L, 45L, 45L, 45L, 25L, 45L,
      0L, 100L, 45L, 0L, 45L, 45L), c(55L, 45L, 45L, 45L, 55L,
      45L, 45L, 45L, 45L, 45L, 45L, 45L, 45L, 45L, 55L, 55L, 45L,
      55L, 45L, 45L, 45L, 45L, 45L, 45L, 45L, 55L, 45L, 45L, 45L,
      45L), c(100L, 100L, 50L, 100L, 100L, 100L, 100L, 100L, 100L,
      100L, 50L, 100L, 100L, 100L, 100L, 100L, 100L, 100L, 100L,
      100L, 100L, 100L, 100L, 50L, 100L, 100L, 100L, 100L, 100L,
      100L), c(100L, 25L, 25L, 0L, 100L, 60L, 0L, 0L, 25L, 60L,
      0L, 60L, 100L, 60L, 100L, 100L, 25L, 100L, 60L, 100L, 100L,
      60L, 100L, 60L, 100L, 100L, 100L, 100L, 60L, 60L), c(0L,
      0L, 50L, 50L, 100L, 100L, 0L, 0L, 100L, 100L, 0L, 100L, 100L,
      0L, 100L, 100L, 0L, 100L, 100L, 100L, 100L, 100L, 100L, 0L,
      100L, 100L, 100L, 100L, 100L, 100L), c(40L, 100L, 40L, 100L,
      100L, 40L, 100L, 100L, 100L, 40L, 100L, 100L, 100L, 100L,
      100L, 100L, 100L, 100L, 100L, 100L, 100L, 100L, 100L, 100L,
      100L, 100L, 100L, 0L, 100L, 100L), c(100L, 100L, 100L, 100L,
      100L, 100L, 100L, 100L, 100L, 100L, 100L, 100L, 100L, 100L,
      100L, 100L, 100L, 100L, 100L, 100L, 100L, 100L, 100L, -10L,
      100L, 100L, 100L, -10L, 100L, 100L), c(70L, 0L, 25L, 0L,
      100L, 25L, 0L, 0L, 0L, 45L, 0L, 25L, 100L, 100L, 100L, 100L,
      0L, 70L, 0L, 100L, 45L, 45L, 0L, 0L, 100L, 100L, 100L, 0L,
      100L, 100L), c(55L, 55L, 55L, 55L, 55L, 55L, 55L, 55L, 55L,
      55L, 55L, 55L, 55L, 55L, 55L, 55L, 20L, 55L, 20L, 55L, 20L,
      20L, 100L, 55L, 55L, 55L, 55L, 0L, 55L, 55L), c(65L, 65L,
      100L, 65L, 100L, 100L, 100L, 100L, 100L, 100L, 100L, 100L,
      100L, 100L, 100L, 100L, 65L, 100L, 100L, 100L, 65L, 100L,
      0L, 65L, 100L, 100L, 100L, 100L, 100L, 100L), c(85L, 85L,
      85L, 85L, 85L, 85L, 85L, 85L, 85L, 85L, 85L, 85L, 56L, 85L,
      100L, 85L, 85L, 85L, 0L, 85L, 85L, 85L, 85L, 85L, 85L, 85L,
      85L, 28L, 56L, 56L)), row.names = c(NA, -30L), class = "data.frame")

Fn = function(Wts) return(-Kendall::Kendall(1:Nobs,
rank(-as.vector(as.matrix(MyDat) %*% matrix(Wts, nc = 1)[, 1, drop =
T])))$tau[1])
q1 = pracma::fmincon(c(0.12, 0.04, 0.07, 0.03, 0.06, 0.07, 0.07, 0.04,
0.09, 0.08, 0.02, 0.02, 0.03, 0.06, 0.02, 0, 0.07, 0.05, 0.02, 0.02,
0.02),
fn = Fn,
            A = matrix(c(rep(0, 20), -1), nrow = 1), b = -2.05/100, Aeq =
matrix(c(rep(1, 20), 1), nrow = 1), beq = 1,
            lb = rep(0.01, 21),
            tol = 1e-16, maxfeval = 10000000, maxiter = 5000000)


However with above code, I got sub-optimal value in terms of minimization
of the objective function:

q1$value
#0.1632184
Fn(c(0.12, 0.04, 0.07, 0.03, 0.06, 0.07, 0.07, 0.04, 0.09, 0.08, 0.02,
0.02, 0.03, 0.06, 0.02, 0, 0.07, 0.05, 0.02, 0.02, 0.02))
#0.1586207

Could you please help me to understand what went wrong with my code and
how
to correct that?

       [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide
https://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.



        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide https://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide https://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to