就我的问题所涉及的数学而言,我有点超出我的深度,所以我为任何不正确的命名道歉.
我正在考虑使用scipy函数leastsq,但我不确定它是否是正确的函数.我有以下等式:
eq = lambda PLP,p0,l0,kd : 0.5*(-1-((p0+l0)/kd) + np.sqrt(4*(l0/kd)+(((l0-p0)/kd)-1)**2))
Run Code Online (Sandbox Code Playgroud)
除了kd(PLP,p0,l0)之外,我有所有项的数据(8套).我需要通过上述方程的非线性回归找到kd的值.从我读过的例子来看,lesssq似乎不允许输入数据,以获得我需要的输出.
谢谢您的帮助
考虑在父环境中fn()
存储最新输入x
及其返回值的函数ret <- x^2
。
makeFn <- function(){
xx <- ret <- NA
fn <- function(x){
if(!is.na(xx) && x==xx){
cat("x=", xx, ", ret=", ret, " (memory)", fill=TRUE, sep="")
return(ret)
}
xx <<- x; ret <<- sum(x^2)
cat("x=", xx, ", ret=", ret, " (calculate)", fill=TRUE, sep="")
ret
}
fn
}
fn <- makeFn()
Run Code Online (Sandbox Code Playgroud)
fn()
仅在提供其他输入值时才进行计算。否则,它将ret
从父环境中读取。
fn(2)
# x=2, ret=4 (calculate)
# [1] 4
fn(3)
# x=3, ret=9 (calculate)
# [1] 9
fn(3)
# x=3, ret=9 …
Run Code Online (Sandbox Code Playgroud) optimization r mathematical-optimization nonlinear-optimization
我正在寻找一个非线性曲线拟合程序(可能最有可能在R或Python中找到,但我对其他语言开放),这将采用x,y数据并拟合曲线.
我应该能够将我想要的表达式类型指定为字符串.
例子:
"A+B*x+C*x*x"
"(A+B*x+C*x*x)/(D*x+E*x*x)"
"sin(A+B*x)*exp(C+D*x)+E+F*x"
Run Code Online (Sandbox Code Playgroud)
我得到的是至少常数(A,B,C等)的值,并希望有关比赛适合度的统计数据.
有商业程序可以做到这一点,但我希望能找到适合现在语言库中所需表达式的常用内容.我怀疑SciPy的优化能力可能会做到这一点,但我看不出它让我定义了一个等式.同样,我似乎无法在R中找到我想要的东西.
我正在寻找那里,还是我需要自己动手?我讨厌这样做,如果它在那里,我只是找不到它.
编辑:我想这样做是为了更多地控制过程,而不是从LAB Fit获得.LAB Fit UI非常糟糕.我也希望能够将范围分成多个部分,并且不同的曲线代表范围的不同部分.最后,结果必须能够(速度)用线性插值击败LUT,或者我不感兴趣.
在我当前的一组问题中,我有trig函数或exp(),我需要实时执行它们每秒352,800次(并且只使用一小部分CPU).因此,我绘制曲线并使用数据来驱动曲线拟合器以获得更便宜的近似值.在过去,LUT几乎总是解决方案,但现在跳过内存查找并进行近似有时会更快.
我有约束的非线性优化问题.它可以使用Solver加载项在Microsoft Excel中解决,但我无法在C#中复制它.
我的问题显示在以下电子表格中.我正在解决经典的A x = b问题,但需要注意的是x的所有分量都必须是非负的.因此,不使用标准线性代数,而是使用具有非负约束的Solver,最小化平方差的总和,并获得合理的解.我试图使用Microsoft Solver Foundation或Solver SDK在C#中复制它.然而,我似乎无法与他们在任何地方,因为有了MSF,我无法弄清楚如何定义目标和使用Solver SDK我总是回到状态"最佳"和所有0的解决方案,这绝对不是一个本地最小.
这是我的Solver SDK代码:
static double[][] A = new double[][] { new double[] { 1, 0, 0, 0, 0 }, new double[] { 0.760652602, 1, 0, 0, 0 }, new double[] { 0.373419404, 0.760537565, 1, 0, 0 }, new double[] { 0.136996731, 0.373331934, 0.760422587, 1, 0 }, new double[] { 0.040625222, 0.136953801, 0.373244464, 0.76030755, 1 } };
static double[][] b = new …
Run Code Online (Sandbox Code Playgroud) 我正在开发一种有限元软件,可最大程度地减少机械结构的能量。使用倍频程及其优化包,我遇到了一个奇怪的问题:当我使用300个以上的自由度(DoF)时,lm_feasible算法根本无法计算。另一种算法(sqp)执行计算,但是当我复杂化结构并且超出测试用例时,效果不佳。
使用lm_feasible算法的DoF数量是否有限制?
如果是这样,最大可能有多少个自由度?
概述和大致了解代码的工作原理:
[x,y] = geometryGenerator()
U = zeros(lenght(x)*2,1);
U(1:2:end-1) = x;
U(2:2:end) = y;
%Non geometric argument are not optimised, and fixed during calculation
fct =@(U)complexFunctionOfEnergyIWrap(U(1:2:end-1),U(2:2:end), variousMaterialPropertiesAndOtherArgs)
para = optimset("f_equc_idx",contEq,"lb",lb,"ub",ub,"objf_grad",dEne,"objf_hessian",d2Ene,"MaxIter",1000);
[U,eneFinale,cvg,outp] = nonlin_min(fct,U,para)
Run Code Online (Sandbox Code Playgroud)
完整示例:
clear
pkg load optim
function [x,y] = geometryGenerator(r,elts = 100)
teta = linspace(0,pi,elts = 100);
x = r * cos(teta);
y = r * sin(teta);
endfunction
function ene = complexFunctionOfEnergyIWrap (x,y,E,P, X,Y)
ene = 0;
for i = 1:length(x)-1
ene += E*(x(i)/X(i))^4+ E*(y(i)/Y(i))^4- P …
Run Code Online (Sandbox Code Playgroud) 我正在阅读 Ceres Solver教程。
鲍威尔的函数映射自R^4 -> R^4
,因此定义一个接受 4 元素数组x
并填充 4 元素数组 的残差块似乎很直观residual
。
相反,教程中的示例定义了映射 的 4 个不同的残差块R^2 -> R^1
。
当然,如果我们试图最小化1/2 || F(x) ||^2
,那么最小化 的每个元素F
将隐式产生与直接最小化相同的解决方案1/2 || F(x) ||^2
(即我的建议是返回单个残差向量F
而不是F1
...F4
单独)。(我已经通过使用下面的成本函子验证了这一点)。
struct F {
template<typename T>
bool operator() (const T* const x, T* residual) const {
residual[0] = x[0] + 10.0 * x[1];
residual[1] = sqrt(5.0) * (x[2] - x[3]);
residual[2] …
Run Code Online (Sandbox Code Playgroud) mathematical-optimization nonlinear-optimization ceres-solver
是否有任何库用于顺序非线性优化,具有上限和下限,以及不等式约束,这些库是用Haskell编写的或可以从Haskell轻松调用的?
我正在尝试通过运行包附带的测试代码来测试Eigen的非线性优化功能.
这些错误让我陷入困境(更像是困惑):
Error 5 error C2039: 'please_protect_your_min_with_parentheses' : is not a member of 'std::numeric_limits<double>' c:\program files (x86)\microsoft sdks\windows\v7.0a\include\eigen-eigen-5097c01bcdc4\unsupported\eigen\src\nonlinearoptimization\lmpar.h 184
Error 7 error C2039: 'please_protect_your_min_with_parentheses' : is not a member of 'std::numeric_limits<double>' c:\program files (x86)\microsoft sdks\windows\v7.0a\include\eigen-eigen-5097c01bcdc4\unsupported\eigen\src\nonlinearoptimization\lmpar.h 28
Error 6 error C2065: 'please_protect_your_min_with_parentheses' : undeclared identifier c:\program files (x86)\microsoft sdks\windows\v7.0a\include\eigen-eigen-5097c01bcdc4\unsupported\eigen\src\nonlinearoptimization\lmpar.h 184
Error 8 error C2065: 'please_protect_your_min_with_parentheses' : undeclared identifier c:\program files (x86)\microsoft sdks\windows\v7.0a\include\eigen-eigen-5097c01bcdc4\unsupported\eigen\src\nonlinearoptimization\lmpar.h 28
Run Code Online (Sandbox Code Playgroud)
顺便说一句(我认为)导致这样的行:
#define min(A,B) please_protect_your_min_with_parentheses
Run Code Online (Sandbox Code Playgroud)
并且错误是指这一行(在上面提到的2个不同的地方,作为第28和184行):
const Scalar dwarf = std::numeric_limits<Scalar>::min();
Run Code Online (Sandbox Code Playgroud)
任何建议应该并且将非常感激
我正在用张量流求解这个方程组:
f1 = y - x*x = 0
f2 = x - (y - 2)*(y - 2) + 1.1 = 0
Run Code Online (Sandbox Code Playgroud)
如果我选择错误的起点 (x,y)=(-1.3,2),那么我会使用以下代码进入局部最小值优化 f1^2+f2^2:
f1 = y - x*x
f2 = x - (y - 2)*(y - 2) + 1.1
sq=f1*f1+f2*f2
o = tf.train.AdamOptimizer(1e-1).minimize(sq)
with tf.Session() as sess:
init = tf.global_variables_initializer()
sess.run([init])
for i in range(50):
sess.run([o])
r=sess.run([x,y,f1,f2])
print("x",r)
Run Code Online (Sandbox Code Playgroud)
如何使用内置张量流工具摆脱这个局部最小值?可能还有其他 TF 方法可以用来从这个坏点开始求解这个方程吗?
python nonlinear-optimization equation-solving gradient-descent tensorflow
我想知道是否有人能够建议一些软件包来解决非线性优化问题,该问题可以为最佳解决方案提供整数变量?问题是最小化具有等式约束的函数,该函数受一些下边界和上边界约束。
我在 R 中使用了 'nloptr' 包来解决非线性优化问题,该问题效果很好,但现在想扩展该方法以将某些变量作为整数。从我到目前为止对 nloptr 的使用和理解来看,它只能返回连续变量,而不是整数变量以获得最佳解决方案。
我相信这类问题需要使用混合整数非线性规划来解决。
nloptr 形式的问题的一个示例:
min f(x) (x-y)^2/y + (p-q)^2/q
so that (x-y)^2/y + (p-q)^2/q = 10.2
where
x and p are positive integers not equal to 0
and
y and q may or may not be positive integers not equal to 0
Run Code Online (Sandbox Code Playgroud)
R 中的 nloptr 代码如下所示
library('nloptr')
x1 <- c(50,25,20,15)
fn <- function(x) {
(((x[1] - x[2])^2)/x[2]) + (((x[3] - x[4])^2)/x[4])
}
heq <- function(x) {
fn(x)-10.2
}
lower_limit <- c(0,0,0,0)
upper_limit <- …
Run Code Online (Sandbox Code Playgroud) r ×3
octave ×2
python ×2
.net ×1
c# ×1
c++ ×1
ceres-solver ×1
eigen ×1
excel ×1
haskell ×1
optimization ×1
scipy ×1
solver ×1
tensorflow ×1