Ich möchte eine Funktion optimieren, die wie folgt aussieht:R lpSolveAPI mit nicht triviale Koeffizienten in set.objfn
y= P1*y+sum(x1-P1) + P2*y+sum(x2-P2) + P3*y+sum(x3-P3)
mit P1, P2 und P3 die drei Parameter optimiert und y die Funktion minimiert werden. x1, x2x3 sind Vektoren von Daten.
Unter den Einschränkungen:
P2-P1 >= 0
P3-P2 >=0
Da es Einschränkungen gibt, kann ich nicht die Funktion Optim() in R verwenden, so hatte ich einen Blick auf lpSolveAPI.
lpSolveAPI Verwendung Ich würde:
lps.model <- make.lp(0, 3)
add.constraint(lps.model, c(-1,1,0), ">=", 1)
add.constraint(lps.model, c(0,-1,1), ">=", 1)
Aber dann wird es ein Problem, wenn ich will "set.objfn" definieren, die auf diese Weise definiert werden müssen:
set.objfn(lprec, obj, indices) with
lprec: an lpSolve linear program model object.
obj: a numeric vector of length n (where n is the number of decision variables in lprec) containing the coefficients of the objective function. Alternatively, if indices is also provided, a numeric vector of the same length as indices containing only the nonzero coefficients.
indices: optional for sparse obj. A numeric vector the same length as obj of unique values from the set {1, ..., n} where n is the number of decision variables in lprec; obj[i] is entered into column indices[i] in objective function. The coefficients for the columns not in indices are set to zero. This argument should be omitted when length(obj) == n.
Ich kann die Funktion y immer noch wie folgt schreiben:
y = P1 (y + [ (x1/P1) - 1 ]) + P2 (y + [ (x2/P2) - 1 ]) + P3 (y + [ (x3/P3) - 1 ])
Wie soll ich diese Koeffizienten vor meinen Parametern im "obj" -Teil der Funktion "set.objfn" schreiben, da meine Parameter P1 - P3 tatsächlich Teil der Koeffizienten sind?
obj = c((y + [ (x1/ P1) - 1 ] , ...)
Es ist möglich, dass lpSolveAPI nicht das Paket soll ich diese Art von Funktion zu optimieren, aber ich habe nicht wirklich irgendwelche anderen Pakete gefunden zu verwenden.