有没有办法根据先前的值来预测未知函数值
我有未知函数返回的值,例如
# this is an easy case - parabolic function
# but in my case function is realy unknown as it is connected to process execution time
[0, 1, 4, 9]
有没有办法预测下一个值?
I have values returned by unknown function like for example
# this is an easy case - parabolic function
# but in my case function is realy unknown as it is connected to process execution time
[0, 1, 4, 9]
is there a way to predict next value?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
您可以尝试使用神经网络方法。 通过Google查询“神经网络函数近似”可以找到很多文章。 还有许多书籍可供参考,例如这本书。
You can try using neural networks approach. There are pretty many articles you can find by Google query "neural network function approximation". Many books are also available, e.g. this one.
如果您只需要数据点,则
可以估计已知点外部的数据,但您需要接受潜在差异远大于数据插值已知点之间。 严格来说,两者都可能是任意不准确的,因为该函数可以在已知点之间做任何疯狂的事情,即使它是一个表现良好的连续函数。 如果它表现不佳,那么所有的赌注都已经失败了;-p
有许多数学方法可以解决这个问题(直接应用于计算机科学) - 从简单的线性代数到像三次样条这样的东西; 以及介于两者之间的一切。
如果你想要功能
变得深奥; 另一个有趣的模型是遗传编程; 通过在已知数据点上演化表达式,可以找到适当接近的近似值。 有时它会起作用;有时它会起作用。 有时则不然。 不是您正在寻找的语言,但 Jason Bock 展示了一些在 .NET 3.5 中执行此操作的 C# 代码,此处:不断发展的 LINQ 表达式。
我碰巧“手边”有他的代码(我在一些演示中使用过它); 类似于
a =>; a * a
它几乎会立即找到它,但它(理论上)应该能够找到几乎任何方法 - 但没有任何定义的最大运行长度;-p 也有可能进入死胡同(从进化的角度来说)你永远无法恢复......If you just want data points
Extrapolation of data outside of known points can be estimated, but you need to accept the potential differences are much larger than with interpolation of data between known points. Strictly, both can be arbitrarily inaccurate, as the function could do anything crazy between the known points, even if it is a well-behaved continuous function. And if it isn't well-behaved, all bets are already off ;-p
There are a number of mathematical approaches to this (that have direct application to computer science) - anything from simple linear algebra to things like cubic splines; and everything in between.
If you want the function
Getting esoteric; another interesting model here is genetic programming; by evolving an expression over the known data points it is possible to find a suitably-close approximation. Sometimes it works; sometimes it doesn't. Not the language you were looking for, but Jason Bock shows some C# code that does this in .NET 3.5, here: Evolving LINQ Expressions.
I happen to have his code "to hand" (I've used it in some presentations); with something like
a => a * a
it will find it almost instantly, but it should (in theory) be able to find virtually any method - but without any defined maximum run length ;-p It is also possible to get into a dead end (evolutionary speaking) where you simply never recover...使用 Wolfram Alpha API :)
Use the Wolfram Alpha API :)
是的。 或许。
如果您有一些输入和输出值,即在您的情况下 [0,1,2,3] 和 [0,1,4,9],您可以使用响应面(我相信基本上是函数拟合)来“猜测”实际函数(在您的情况下 f(x)=x^2)。 如果你让你的猜测函数为 f(x)=c1*x+c2*x^2+c3 ,那么有一些算法可以根据你的输入和输出并给出结果来确定 c1=0、c2=1 和 c3=0函数可以预测下一个值。
请注意,这个问题的大多数其他答案也是有效的。 我只是假设您想要将某些函数拟合到数据。 换句话说,我发现你的问题很模糊,请尝试尽可能完整地提出你的问题!
Yes. Maybe.
If you have some input and output values, i.e. in your case [0,1,2,3] and [0,1,4,9], you could use response surfaces (basicly function fitting i believe) to 'guess' the actual function (in your case f(x)=x^2). If you let your guessing function be f(x)=c1*x+c2*x^2+c3 there are algorithms that will determine that c1=0, c2=1 and c3=0 given your input and output and given the resulting function you can predict the next value.
Note that most other answers to this question are valid as well. I am just assuming that you want to fit some function to data. In other words, I find your question quite vague, please try to pose your questions as complete as possible!
一般来说,不会...除非您知道它是特定形式的函数(例如,N 次多项式)并且有足够的信息来约束该函数。
例如,对于一个更“普通”的反例(参见查克的答案),为什么你不一定可以假设 n^2 不知道它是一个二次方程,你可以有 f(n) = n4 - 6n3 + 12n2 - 6n,其中 n=0,1,2,3,4,5 f(n) = 0,1,4, 9,40,145。
如果您确实知道它是一种特定形式,则有一些选项...如果该形式是基函数的线性加法(例如 f(x) = a + bcos(x) + csqrt (x)) 然后使用最小二乘可以使用这些基函数获得最佳拟合的未知系数。
In general, no... unless you know it's a function of a particular form (e.g. polynomial of some degree N) and there is enough information to constrain the function.
e.g. for a more "ordinary" counterexample (see Chuck's answer) for why you can't necessarily assume n^2 w/o knowing it's a quadratic equation, you could have f(n) = n4 - 6n3 + 12n2 - 6n, which has for n=0,1,2,3,4,5 f(n) = 0,1,4,9,40,145.
If you do know it's a particular form, there are some options... if the form is a linear addition of basis functions (e.g. f(x) = a + bcos(x) + csqrt(x)) then using least-squares can get you the unknown coefficients for the best fit using those basis functions.
另请参阅 这个问题。
See also this question.
您可以应用统计方法来尝试猜测下一个答案,但如果函数像这样(c),那么这可能不会很好地工作:
该函数将返回漂亮的简单递增数字,然后... BAM。
You can apply statistical methods to try and guess the next answer, but that might not work very well if the function is like this one (c):
This function will return nice simple increasing numbers then ... BAM.
这是一个难题。
您应该查看递归关系方程,以了解可能执行此类任务的特殊情况。
That's a hard problem.
You should check out the recurrence relation equation for special cases where it could be possible such a task.
不必要。 你的“抛物线函数”可能是这样实现的:
你可以猜测,但准确预测是不可能的。
Not necessarily. Your "parabolic function" might be implemented like this:
You can take a guess, but to predict with certainty is impossible.