[R] DEoptim example illustrating use of fnMap parameter for enforcement of cardinality constraints

David-Michael Lincke dlincke at lincke.com
Sat Jun 16 21:41:08 CEST 2012


Hi Joshua,

Thank you very much for the comprehensive response. 

In the meantime, I had taken a look at the source code of function DEoptim() and your example below confirms the conclusions that I have arrived at from that review as to the expected nature of the function passed as fnMap. What I continue to find confusing and a bit disconcerting, however, is that DEoptim() actively tries to avoid duplicates in the parameter vector which of course is the intended result when enforcing a cardinality constraint on a vector of allocation weights by forcing some of them to 0. As DEoptim() will make five attempts at randomly perturbing the parameter vector and resubmitting it to the mapping function before giving up I am concerned that this may at least slow down if not potentially even derail or otherwise interfere with convergence. I have yet to run a practical test but I wonder whether there is a deeper reason for this or if this can be safely ignored.

Btw, I have checked out the SVN repository and had a quick look at the example in slimLargeN_map.R, but I do not see the fnMap functionality being used in the large-scale optimization vignette. The vignette performs rescaling of the allocation weights vector to meet the budget constraint inside the objective function but does not seem to enforce any cardinality constraints.

Best regards,
David

-----Original Message-----
From: Joshua Ulrich [mailto:josh.m.ulrich at gmail.com] 
Sent: Saturday, June 16, 2012 3:29 AM
To: David-Michael Lincke
Cc: r-help at r-project.org
Subject: Re: [R] DEoptim example illustrating use of fnMap parameter for enforcement of cardinality constraints

Hi David,

I apologize for the lack of documentation.  I added it quickly and didn't have adequate time to document it.

The function below works with the objective function in the "Large-scale portfolio optimization with DEoptim" vignette.
Also, I just committed the full example
(pkg/DEoptim/sandbox/slimLargeN_map.R) to the DEoptim repository on
R-forge: https://r-forge.r-project.org/projects/deoptim/

mappingFun <- function(x) {
  x[which(order(x) < 6)] <- 0
  x <- round(x,2) # produce some dups
  x/sum(x)
}
set.seed(1234)
out <- DEoptim(fn=obj, lower=lower,
  upper=upper, control=controlDE, fnMap=mappingFun)

Best,
--
Joshua Ulrich  |  FOSS Trading: www.fosstrading.com


On Fri, Jun 15, 2012 at 3:24 AM, David-Michael Lincke <dlincke at lincke.com> wrote:
> Function DEoptim in package DEoptim for differential evolution defines an optional parameter fnMap:
>
> fnMap
>
> "an optional function that will be run after each population is created, but before the population is passed to the objective function. This allows the user to impose integer/cardinality constriants."
>
> Unfortunately, there is no further documentation decribing the kind of parameters being passed to this function on invocation or the structure of the return value expected. I would very much appreciate it if somebody familiar with this package could provide an example illustrating how this interface is meant to be used to enforce cardinality constraints.
>
> Thanks,
> David
>
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list