optim - setting a common contraint for multiple parameters
I a looking to set a common constraint to a subset of my parameters:
c2 <- 2
nFeatures = 6
W2 <- rep(1,nFeatures)
w2 <- W2/sum(W2)
fguess2 <- 0.3
startParms2 <- c(c2,fguess2,w2)
names(startParms2) <- c("c2", "fguess",
"w21","w22","w23","w24","w25","w26")
xout2 <- optim(par=startParms2, fn=rmsd,
data1=mydata2, method = "L-BFGS-B",
lower = rep(0,8),
upper = c(Inf,1,1,1,1,1,1,1))
print(xout2)
Currently, all 6 parameters belonging to the vector w2
are constrained to a individual maximum of 1.
What I would like to do is to constrain the sum of these 6 parameters to 1 (while the remaining 2 parameters keep their current constraints).
r optimization constraints
add a comment |
I a looking to set a common constraint to a subset of my parameters:
c2 <- 2
nFeatures = 6
W2 <- rep(1,nFeatures)
w2 <- W2/sum(W2)
fguess2 <- 0.3
startParms2 <- c(c2,fguess2,w2)
names(startParms2) <- c("c2", "fguess",
"w21","w22","w23","w24","w25","w26")
xout2 <- optim(par=startParms2, fn=rmsd,
data1=mydata2, method = "L-BFGS-B",
lower = rep(0,8),
upper = c(Inf,1,1,1,1,1,1,1))
print(xout2)
Currently, all 6 parameters belonging to the vector w2
are constrained to a individual maximum of 1.
What I would like to do is to constrain the sum of these 6 parameters to 1 (while the remaining 2 parameters keep their current constraints).
r optimization constraints
You can encode the constrain into the objective function. Then you will have to optimize only 5 parameters... - However, without a MCVE it is difficult to say more stackoverflow.com/help/mcve
– Florian
Nov 24 '18 at 18:15
in principle you can useconstrOptim()
, but I suspect you really are trying to fit a composition parameter (all parameters bound in 0<p<1 and sum(p)==1), in which case you will be better off working with a softmax/Aitchison transformation
– Ben Bolker
Nov 26 '18 at 22:44
add a comment |
I a looking to set a common constraint to a subset of my parameters:
c2 <- 2
nFeatures = 6
W2 <- rep(1,nFeatures)
w2 <- W2/sum(W2)
fguess2 <- 0.3
startParms2 <- c(c2,fguess2,w2)
names(startParms2) <- c("c2", "fguess",
"w21","w22","w23","w24","w25","w26")
xout2 <- optim(par=startParms2, fn=rmsd,
data1=mydata2, method = "L-BFGS-B",
lower = rep(0,8),
upper = c(Inf,1,1,1,1,1,1,1))
print(xout2)
Currently, all 6 parameters belonging to the vector w2
are constrained to a individual maximum of 1.
What I would like to do is to constrain the sum of these 6 parameters to 1 (while the remaining 2 parameters keep their current constraints).
r optimization constraints
I a looking to set a common constraint to a subset of my parameters:
c2 <- 2
nFeatures = 6
W2 <- rep(1,nFeatures)
w2 <- W2/sum(W2)
fguess2 <- 0.3
startParms2 <- c(c2,fguess2,w2)
names(startParms2) <- c("c2", "fguess",
"w21","w22","w23","w24","w25","w26")
xout2 <- optim(par=startParms2, fn=rmsd,
data1=mydata2, method = "L-BFGS-B",
lower = rep(0,8),
upper = c(Inf,1,1,1,1,1,1,1))
print(xout2)
Currently, all 6 parameters belonging to the vector w2
are constrained to a individual maximum of 1.
What I would like to do is to constrain the sum of these 6 parameters to 1 (while the remaining 2 parameters keep their current constraints).
r optimization constraints
r optimization constraints
edited Nov 24 '18 at 18:18
Ben Bolker
133k11223311
133k11223311
asked Nov 24 '18 at 16:54
Moritz TruningerMoritz Truninger
91
91
You can encode the constrain into the objective function. Then you will have to optimize only 5 parameters... - However, without a MCVE it is difficult to say more stackoverflow.com/help/mcve
– Florian
Nov 24 '18 at 18:15
in principle you can useconstrOptim()
, but I suspect you really are trying to fit a composition parameter (all parameters bound in 0<p<1 and sum(p)==1), in which case you will be better off working with a softmax/Aitchison transformation
– Ben Bolker
Nov 26 '18 at 22:44
add a comment |
You can encode the constrain into the objective function. Then you will have to optimize only 5 parameters... - However, without a MCVE it is difficult to say more stackoverflow.com/help/mcve
– Florian
Nov 24 '18 at 18:15
in principle you can useconstrOptim()
, but I suspect you really are trying to fit a composition parameter (all parameters bound in 0<p<1 and sum(p)==1), in which case you will be better off working with a softmax/Aitchison transformation
– Ben Bolker
Nov 26 '18 at 22:44
You can encode the constrain into the objective function. Then you will have to optimize only 5 parameters... - However, without a MCVE it is difficult to say more stackoverflow.com/help/mcve
– Florian
Nov 24 '18 at 18:15
You can encode the constrain into the objective function. Then you will have to optimize only 5 parameters... - However, without a MCVE it is difficult to say more stackoverflow.com/help/mcve
– Florian
Nov 24 '18 at 18:15
in principle you can use
constrOptim()
, but I suspect you really are trying to fit a composition parameter (all parameters bound in 0<p<1 and sum(p)==1), in which case you will be better off working with a softmax/Aitchison transformation– Ben Bolker
Nov 26 '18 at 22:44
in principle you can use
constrOptim()
, but I suspect you really are trying to fit a composition parameter (all parameters bound in 0<p<1 and sum(p)==1), in which case you will be better off working with a softmax/Aitchison transformation– Ben Bolker
Nov 26 '18 at 22:44
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53460384%2foptim-setting-a-common-contraint-for-multiple-parameters%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53460384%2foptim-setting-a-common-contraint-for-multiple-parameters%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
You can encode the constrain into the objective function. Then you will have to optimize only 5 parameters... - However, without a MCVE it is difficult to say more stackoverflow.com/help/mcve
– Florian
Nov 24 '18 at 18:15
in principle you can use
constrOptim()
, but I suspect you really are trying to fit a composition parameter (all parameters bound in 0<p<1 and sum(p)==1), in which case you will be better off working with a softmax/Aitchison transformation– Ben Bolker
Nov 26 '18 at 22:44