Re: [R] Optimisation does not optimise!
Thanks for this guidance. In light of your advice I have reduced the titanic to a dingy by reducing the size of my sample to just 100 instances, making this an optimisation of 100 parameters. I am, however, seeing similar output when I output the function value at each evaluation. This is the tail of the information in the optout results structure [1] 70104.64 [1] 70104.67 [1] 70104.64 [1] 70104.67 [1] 70104.64 [1] 70104.67 [1] 70104.64 [1] 70104.66 [1] 70104.64 [1] 70104.66 > optout $par [1] 1.003 1.003 1.003 1.003 1.003 1.003 1.003 1.003 1.003 1.003 1.003 1.003 [13] ... [97] 1.003 1.003 1.003 1.003 $value [1] 70104.4 $counts function gradient 501 NA $convergence [1] 1 $message NULL Can you or anyone suggest another optimisation routine I can use? I initially coded this into EXCEL and used the solver addin to do an optimisation of 200 parameters. R was my attempt to increase this number of parameters. I do not, unfortunately, have any derivative information. -- Stephen Clark, Second year PhD, School of Geography Tel : 0113 343 6707 Email : g...@leeds.ac.uk Web : http://www.geog.leeds.ac.uk/people/s.clark -Original Message- From: Prof J C Nash (U30A) [mailto:nas...@uottawa.ca] Sent: 13 July 2013 13:07 To: r-help@r-project.org; Stephen Clark Subject: [R] Optimisation does not optimise! Considering that I devised the code initially on a computer with only 8K bytes for program and data, and it appears that your problem has 1 parameters, I'm surprised you got any output. I suspect the printout is the BUILD phase where each weight is being adjusted in turn by the same shift. Don't try to move the Titanic on a pram. If you work out a gradient function, you can likely use Rcgmin (even though I wrote original CG in optim(), not recommended). spg from BB may also work OK. This problem is near linear, so there are other approaches. JN __ R-help@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.
[R] Optimisation does not optimise!
Considering that I devised the code initially on a computer with only 8K bytes for program and data, and it appears that your problem has 1 parameters, I'm surprised you got any output. I suspect the printout is the BUILD phase where each weight is being adjusted in turn by the same shift. Don't try to move the Titanic on a pram. If you work out a gradient function, you can likely use Rcgmin (even though I wrote original CG in optim(), not recommended). spg from BB may also work OK. This problem is near linear, so there are other approaches. JN On 13-07-13 06:00 AM, r-help-requ...@r-project.org wrote: Date: Fri, 12 Jul 2013 21:22:00 +0100 From: Stephen Clark To:"r-help@R-project.org" Subject: [R] Optimisation does not optimise! Message-ID: <928c4f7877280844b906d12d63a3f15b01145e5b5...@hermes8.ds.leeds.ac.uk> Content-Type: text/plain; charset="us-ascii" Hello, I have the following code and data. I am basically trying to select individuals in a sample (by setting some weights) to match known counts for a zone. This is been done by matching gender and age bands. I have tested the function to be optimised and it does behave as I would expect when the weights are changed. However when I run the optimisation I get the following output >optout<-optim(weights0, func_opt, control=list(REPORT=1)) [1] 27164 [1] 27163.8 [1] 27163.8 [1] 27163.8 [1] 27163.8 [1] 27163.8 [1] 27163.8 [1] 27163.8 [1] 27163.8 etc which suggest an initial change but thereafter the optimisation does not appear to adapt the weights at all. Can anyone see what this is happening and how to make the problem optimise? __ R-help@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.
[R] Optimisation does not optimise!
Hello, I have the following code and data. I am basically trying to select individuals in a sample (by setting some weights) to match known counts for a zone. This is been done by matching gender and age bands. I have tested the function to be optimised and it does behave as I would expect when the weights are changed. However when I run the optimisation I get the following output > optout<-optim(weights0, func_opt, control=list(REPORT=1)) [1] 27164 [1] 27163.8 [1] 27163.8 [1] 27163.8 [1] 27163.8 [1] 27163.8 [1] 27163.8 [1] 27163.8 [1] 27163.8 etc which suggest an initial change but thereafter the optimisation does not appear to adapt the weights at all. Can anyone see what this is happening and how to make the problem optimise? sample<-read.csv(file="C:\\sample.csv") cons1<-read.csv(file="C:\\Gender.csv") cons2<-read.csv(file="C:\\Age9.csv") weights0 <- array(dim = c(nrow(sample))) for (zone in 1:2){ weights0 <- rep(1, nrow(sample)) optout<-optim(weights0, func_opt, control=list(REPORT=1)) optout.value } func_opt<-function(weights){ TAE <- 0.0 sumMale <- sum(weights[sample[1:nrow(sample),2]=="Male"]) sumFemale <- sum(weights[sample[1:nrow(sample),2]=="Female"]) sumAged50to54 <-sum(weights[sample[1:nrow(sample),3]=="Aged 50 to 54"]) sumAged55to59 <-sum(weights[sample[1:nrow(sample),3]=="Aged 55 to 59"]) sumAged60to64 <-sum(weights[sample[1:nrow(sample),3]=="Aged 60 to 64"]) sumAged65to69 <-sum(weights[sample[1:nrow(sample),3]=="Aged 65 to 69"]) sumAged70to74 <-sum(weights[sample[1:nrow(sample),3]=="Aged 70 to 74"]) sumAged75to79 <-sum(weights[sample[1:nrow(sample),3]=="Aged 75 to 79"]) sumAged80to84 <-sum(weights[sample[1:nrow(sample),3]=="Aged 80 to 84"]) sumAged85to89 <-sum(weights[sample[1:nrow(sample),3]=="Aged 85 to 89"]) sumAged90andolder <-sum(weights[sample[1:nrow(sample),3]=="Aged90 and older"]) TAE <- abs(cons1[zone, 2] - sumMale) TAE <- TAE + abs(cons1[zone, 3] - sumFemale) TAE <- TAE + abs(cons2[zone, 2] - sumAged50to54) TAE <- TAE + abs(cons2[zone, 3] - sumAged55to59) TAE <- TAE + abs(cons2[zone, 4] - sumAged60to64) TAE <- TAE + abs(cons2[zone, 5] - sumAged65to69) TAE <- TAE + abs(cons2[zone, 6] - sumAged70to74) TAE <- TAE + abs(cons2[zone, 7] - sumAged75to79) TAE <- TAE + abs(cons2[zone, 8] - sumAged80to84) TAE <- TAE + abs(cons2[zone, 9] - sumAged85to89) TAE <- TAE + abs(cons2[zone, 10] - sumAged90andolder) print(TAE) return(TAE) } sample.csv id sex Age10 103712 Female Aged 50 to 54 103713 MaleAged 65 to 69 103715 Female Aged 60 to 64 103716 MaleAged 65 to 69 103717 MaleAged 70 to 74 103718 Female Aged 80 to 84 103721 Female Aged 65 to 69 103722 MaleAged 70 to 74 103723 MaleAged 65 to 69 103724 Female Aged 60 to 64 103728 MaleAged 65 to 69 103729 Female Aged 50 to 54 103730 MaleAged 75 to 79 103731 Female Aged 50 to 54 103733 Female Aged 55 to 59 (this goes on for 1 individuals) Gender.csv ZoneMaleFemale Z1 10547 13234 Z2 16393 18759 Z3 57136462 Z4 19651 21834 Z5 26918 33992 Z6 17596 19665 Age9.csv LA Aged50to54 Aged55to59 Aged60to64 Aged65to69 Aged70to74 Aged75to79 Aged80to84 Aged85to89 Aged90andolder Z1 42743852330730963123272818961056449 Z2 74166015540248524304340522701047441 Z3 242520931864175715201218766 376 156 Z4 92367713601352574696407227021293503 Z5 965588418199825283757559551131981320 Z6 7797721057544851421636642376994 399 __ R-help@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.