LSPM Examples

Hi Josh I am trying to replicate the results on p…

Chris - Nov 2, 2011

Hi Josh

I am trying to replicate the results on page 87 (as mentioned in your post above) of the LSPM book. I do the following:
> data(port)
> DEctrl <- list(NP=30, itermax=100)
> res <- optimalf(port, control=DEctrl)

The result is :

Iteration: 100 bestvalit: -1.293917 bestmemit: 1.000000 0.000000 0.857813

Page 87 reads:
MktSysA 0.307
MktSysB 0
MktSysC 0.693

Hi Chris,

I mention that in the post; in the last paragraph of text before the code. In short, the optimization algorithms are different and the algorithm in my post is able to find a set of f values that produce a higher GHPR.


I am looking to accomplish two things with your R implementation of LSPM:

1. The ability to pickup the f values from a previous search and then continue the search with those values.

2. The ability to stop a search that is in process yet retain the current f values for use.

I have managed to accomplish the former with some rather inefficient code (coding is not my strong point) yet am at a loss as to how one could accomplish the latter:

I accomplish the former by writing the f values to file at the end of a run:

write.csv(results$f, file="OUTPUT [f].csv”)

and then pick them up again prior to the next run by repopulating the initialpop with the following (here N=47):

f <- read.csv(“OUTPUT [f].csv”, header=TRUE,, sep=”,", dec=”.")

However would you know how I could accomplish stoping a process that is running yet retain the f values so that they could be used or the process can be restarted again at a latter time if required?


I created a more elegant solution to (1):

f <- read.csv(“OUTPUT [f].csv”, header=TRUE,, sep=”,", dec=”.")
for(i in 1:N){initialpop[(i-1)*NP+1] <- f$x[i]}

I am still however wondering how to achieve (2):

2. The ability to stop a search that is in process yet retain the current f values for use.

Hi Grant,

I don’t currently know to accomplish your second request. Stopping the optimization requires you interrupt the code. There’s probably a way to catch the interrupt and return the current iteration’s f values to the caller, but I’m not sure how to do it.

That said, you can set DEoptim.control$trace=TRUE, manually copy/paste the last iteration’s f values prior to interrupt, then manually restart the job like you do to solve your first request.