基于数据点创建S曲线
我有一系列数据点形成一条曲线,但我没有方程式,并且我无法使用 libreoffice 或谷歌结果前两页中的在线曲线拟合工具令人满意地计算方程式。
我想要曲线的方程,理想情况下是一个Python实现,用于计算沿着该曲线的给定x值的y值,以防出现意外的情况需要跳过。如果做不到这一点,我想要任何比 elif 语句列表更优雅的 python 解决方案,如果 x 足够高以使其增加一个整数,则递增 y,这是最后手段的丑陋解决方案 - 我的直接计划不需要小数精度。
曲线在 10 处与零线相交,y 每增加一个整数,都需要 x 比前一次增加一个整数,因此 y1 在 x11 处达到,y2 在 x13 处达到,y3 在 x16 处达到,依此类推,曲线弯曲在负数的另一个方向上,例如 y-1 位于 x9,y-2 位于 x7 等。当我已经有了这个时,我怀疑我在寻找曲线方程时遗漏了一些明显的东西 知识。
除了尝试使用 libreoffice calc 和几个在线曲线拟合网站都无济于事之外,我还尝试过对 s 曲线进行切片(我已经放弃搜索术语 sigmoid 函数,因为我所有的结果要么与神经网络相关,要么期望我的 y 值永远不会超过 +-1) 成两条对数曲线,这几乎有效 - 5 *(np.log(x) - 11) 令人沮丧地接近上半部分曲线,但我最终无法使用 - 除了在 9 处穿过数轴之外,当我直接返回 round() 四舍五入 y 值时,它还会产生一些奇怪的行为,直接返回时显示负 40 秒的结果,但是当这些数字被输入到其他计算中时,似乎工作得很好。
如果有人能给我两个工作对数,将 x 值舍入到 0 到 50 之间的正确数字,这对于这个项目来说就足够了。
感谢您的时间和耐心。
-编辑- 这些显然是三角形数,x-10 等于每边都有 y 点的三角形中的点数,我需要的是三角形数公式的逆。感谢所有发表评论的人。
I have a series of data points which form a curve I do not have an equation for, and for which i have not been able to satisfyingly calculate an equation with either libreoffice or the online curve fitting tools in the first 2 pages of google results.
I would like the equation for the curve and ideally a python implementation of calculating y values for a given x value along that curve in case there are unexpected hoops to jump through. Failing that I would like any more elegant python solution than a list of elif statements incrementing y if x is high enough for it to increase by a whole number, which is the ugly solution of last resort - my immediate plans do not require decimal precision.
The curve crosses the zero line at 10, and every whole number incrementation of y requires x to be incremented by one more whole number than the previous, so y1 is reached at x11, y2 at x13, y3 at x16 etc, with the curve bending in the other direction in the negatives such that y-1 is at x9, y-2 is at x7 etc. I suspect i am missing something obvious as far as finding the curve equation when i already have this knowledge.
In addition to trying to use libreoffice calc and several online curve-fitting websites to no avail, i have tried slicing the s-curve (I have given up on searching the term sigmoid function as all my results are either related to neural nets or expect my y values to never exceed +-1) into two logarythmic curves, which almost works - 5 *(np.log(x) - 11) gets something frustratingly close to the top half of the curve, but which i ultimately haven't been able to use - in addition to crossing the number line at 9 it produced some odd behaviour when I returned round() rounded y values directly, displaying results in the negative 40s when returned directly, but seeming to work fine when those numbers are fed into other calculations.
If somebody can give me two working logarythms that round to the right numbers for x values between 0 and 50 that is good enough for this project.
Thank you for your time and patience.
-EDIT-
these are triangular numbers apparently, x-10 is equal to the number of dots in a triangle with y dots on each side, what I need is the inverse of the triangular number formula. Thank you to everyone who commented.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如我的编辑中所述,Yi试图找到的是X的三角根。该解决方案:
目前似乎正常。奇怪的是,当我计算(-1+(sqrt(1+(8*x))))/2)使用libreoffice或google,而不是获得相同的结果,我的python脚本给了我,我得到的结果比实际的三角形低0.5根。目前不重要,但是我很好奇会导致它的原因。
无论如何,感谢所有借给我时间的人。我向任何看这个问题的人致歉,谁在寻找一种通用解决方案来创建S曲面,而不仅仅是一个适合我的特定任务的问题,但最好将答案附加出一个答案人们的时间。
-edit-更改了Python脚本以处理负三角形数字,这是我兴奋的忽视。
As mentioned in my edit, the y i am trying to find is the triangular root of x. This solution:
seems to work fine for now. Curiously, when I calculate (-1+(sqrt(1+(8*x)))/2) using libreoffice or google, rather than getting the same results this python script gives me, i get results 0.5 lower than the actual triangle root. Unimportant at this time, but I am curious as to what would cause it.
At any rate, thank you to everyone who lent their time to me. I apologise to anyone looking at this question who was looking for a universal solution for creating S-curves rather than just one that works for my specific task, but feel it is best to attach an answer to this question so as not to prevail on more people's time.
-EDIT- changed python script to handle negative triangular numbers as well, something i had overlooked in excitement.
您正在寻找的是一类称为“Sigmoid 函数”的函数。它们具有典型的 S 形。转到 Wolfram 并尝试一些常见的 Sigmoid 函数,记住函数 f(xa) 中的“a”将整个曲线向左或向右移动,并将值“b”附加到函数 f(xa) + b 将上下移动曲线。使用系数“c”,f(c*x - a) + b 在此充当标量。这应该能让你在短时间内到达你想要的地方。
示例:
(1/(1 + C*exp(-(x + A)))) + B
What you're looking for are a class of functions called "Sigmoid functions". They have a characteristic S-shape. Go to Wolfram and play around with some common Sigmoid funcs, remembering that the "a" in a function, f(x-a), shifts the entire curve left or right, and appending a value "b" to the function, f(x-a) + b will shift the curve up and down. Using a coefficient of "c", f(c*x - a) + b here acts as a scalar. That should get you where you want to be in short time.
Example:
(1/(1 + C*exp(-(x + A)))) + B