优化以查找复数作为输入 [英] Optimization to find complex number as input

查看:77
本文介绍了优化以查找复数作为输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有C/C ++库或Matlab代码技术使用最小化求解器确定实数和复数.这是一个代码片段,显示了我想做什么.例如,假设我知道Utilde,但不知道xU变量.我想使用优化(fminsearch)确定给定UtildexU.请注意,Utilde是复数.

I am wondering if there is a C/C++ library or Matlab code technique to determine real and complex numbers using a minimization solver. Here is a code snippet showing what I would like to do. For example, suppose that I know Utilde, but not x and U variables. I want to use optimization (fminsearch) to determine x and U, given Utilde. Note that Utilde is a complex number.

x = 1.5;
U = 50 + 1i*25;
x0 = [1 20];  % starting values
Utilde = U * (1 / exp(2 * x)) * exp( 1i * 2 * x);
xout = fminsearch(@(v)optim(v, Utilde), x0);

function diff = optim(v, Utilde)
x = v(1);
U = v(2);
diff =  abs( -(Utilde/U) + (1 / exp(2 * x)) * exp( 1i * 2 * x  ) );

上面的代码未收敛到正确的值,并且xout = 1.7318 88.8760.但是,如果U = 50不是复数,则xout = 1.5000 50.0000是适当的值.

The code above does not converge to the proper values, and xout = 1.7318 88.8760. However, if U = 50, which is not a complex number, then xout = 1.5000 50.0000, which are the proper values.

Utilde为复数的情况下,Matlab或C/C ++中是否有办法确保适当的收敛?也许我必须更改上面的代码?

Is there a way in Matlab or C/C++ to ensure proper convergence, given Utilde as a complex number? Maybe I have to change the code above?

  • 如果在Matlab中没有本机执行此操作的方法,那么也许 问题的要点是:是否存在多元变量(即 Nelder-Mead或类似算法)的优化库 可以处理真实和复杂的输入和输出?

  • If there isn't a way to do this natively in Matlab, then perhaps one gist of the question is this: Is there a multivariate (i.e. Nelder-Mead or similar algorithm) optimization library that is able to work with real and complex inputs and outputs?

另一个问题是该函数是否收敛.一世 不知道是算法还是函数.我可能需要更改Utilde = U * (1 / exp(2 * x)) * exp( 1i * 2 * x)表达式中的某些内容以使其收敛吗?

Yet another question is whether the function is convergent or not. I don't know if it is the algorithm or the function. Might I need to change something in the Utilde = U * (1 / exp(2 * x)) * exp( 1i * 2 * x) expression to make it convergent?

推荐答案

此处的主要问题是此优化或参数拟合问题没有唯一的解决方案.例如,查看上面的预期结果和实际结果,对于两个(xU)对,即

Utilde是等效的(忽略舍入舍入差异).

The main problem here is that there is no unique solution to this optimization or parameter fitting problem. For example, looking at the expected and actual results above, Utilde is equivalent (ignoring round-off differences) for the two (x, U) pairs, i.e.

Utilde(x = 1.5, U = 50 + 25i) = Utilde(x = 1.7318, U = 88.8760)

尽管我没有深入研究它,但我什至怀疑对于任何x值,您都可以找到一个计算为Utilde(x, U) = Utilde(x = 1.5, U = 50 + 25i)U.

Although I have not examined it in depth, I even suspect that for any value of x, you can find an U that computes to Utilde(x, U) = Utilde(x = 1.5, U = 50 + 25i).

因此,这里的解决方案是进一步约束参数拟合问题,以便求解器生成可以被认为是可接受的任何解决方案.或者,将Utilde重新设置为对任何(xU)对都具有唯一值.

The solution here would thus be to further constrain the parameter fitting problem so that the solver yields any solution that can be considered acceptable. Alternatively, reformulate Utilde to have a unique value for any (x, U) pair.

更新,8月1日

给出合理的起始值,实际上似乎将x限制为实值就足够了.使用上面公式化的diff函数执行不受约束的非线性优化,我得到以下结果:

Given reasonable starting values, it actually seems like it is sufficient to restrict x to be real-valued. Performing unconstrained non-linear optimization using the diff function formulated above, I get the following result:

x = 1.50462926953244
U = 50.6977768845879 + 24.7676554234729i
diff = 3.18731710515855E-06

但是,将起始猜测值更改为距离期望值更远的值确实会产生不同的解决方案,因此将x限制为实值并不能单独提供问题的唯一解决方案.

However, changing the starting guess to values more distant from the desired values does yield different solutions, so restricting x to be real-values does not alone provide a unique solution to the problem.

我已经使用 BOBYQA 优化器在C#中实现了此功能,但数字应与以上.如果您想在Matlab之外尝试,使用 std :: complex 类和您自己选择的(不受约束的)非线性C ++优化器.您可以在此处中找到一些不需要梯度计算的C ++兼容代码在数字食谱中也有多种实现方式.例如,您可以在此处在线访问NR的C版本.

I have implemented this in C#, using the BOBYQA optimizer, but the numerics should be the same as above. If you want to try outside of Matlab, it should also be relatively simple to turn the C# code below into C++ code using the std::complex class and an (unconstrained) nonlinear C++ optimizer of your own choice. You could find some C++ compatible codes that do not require gradient computation here, and there is also various implementations available in Numerical Recipes. For example, you could access the C version of NR online here.

作为参考,这是我的C#代码的相关部分:

For reference, here are the relevant parts of my C# code:

class Program
{
    private static readonly Complex Coeff = new Complex(-2.0, 2.0);
    private static readonly Complex UTilde0 = GetUTilde(1.5, new Complex(50.0, 25.0));

    static void Main(string[] args)
    {
        double[] vars = new[] {1.0, 25.0, 0.0}; // xstart = 1.0, Ustart = 25.0
        BobyqaExitStatus status = Bobyqa.FindMinimum(GetObjfnValue, vars.Length, vars);
    }

    public static Complex GetUTilde(double x, Complex U)
    {
        return U * Complex.Exp(Coeff * x);
    }

    public static double GetObjfnValue(int n, double[] vars)
    {
        double x = vars[0]; 
        Complex U = new Complex(vars[1], vars[2]);
        return Complex.Abs(-UTilde0 / U + Complex.Exp(Coeff * x));
    }
}

这篇关于优化以查找复数作为输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆