Java 高斯分布-钟形曲线
我计算了一组值的平均值和标准差。现在我需要使用这些值绘制一条钟形曲线来显示 JAVA Swing 中的正态分布。我该如何处理这种情况。
列表:204 297 348 528 681 684 785 957 1044 1140 1378 1545 1818
总数:13
平均值(平均值):877.615384615385
标准差(SD):477.272626245539
如果我能得到 x 和y 坐标 我可以做到,但是怎么办我得到那些价值观?
I have calculated mean and SD of a set of values. Now I need to draw a bell curve using those value to show the normal distribution in JAVA Swing. How do i proceed with this situation.
List : 204 297 348 528 681 684 785 957 1044 1140 1378 1545 1818
Total count : 13
Average value (Mean): 877.615384615385
Standard deviation (SD) : 477.272626245539
If i can get the x and y cordinates I can do it, but how do i get those values?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首先,您需要计算该集合的方差。方差计算为每个数字与其平均值的平均平方偏差。
一旦你知道了,你可以根据你的图形分辨率与你的值集分布进行比较来选择x,并将其代入以下方程以获得y。
要显示结果集:假设我们采用您布置的总体集,并决定要在 x 分辨率为 1000 像素的图表上显示 x=0 到 x=2000。然后插入一个循环 (int x = 0; x <= 2000; x = 2) 并将这些值输入到上面的方程中以获得该对的 y 值。由于您想要显示的 y 是 0-1,因此您可以将这些值映射到您希望 y 分辨率具有适当舍入行为的任何值,这样您的图形就不会变得太锯齿状。因此,如果您希望 y 分辨率为 500 像素,那么您将 0 设置为 0,将 1 设置为 500,将 0.5 设置为 250 等等。这是一个人为的示例,您可能需要更多的灵活性,但我认为它说明了这一点。大多数图形库都会为您处理这些小事情。
First you need to calculate the variance for the set. The variance is computed as the average squared deviation of each number from its mean.
Once you have that you can choose x depending on your graph resolution compared to your value set spread and plug it in to the following equation to get y.
To display the resulting set: say we take the population set you laid out and decide you want to show x=0 to x=2000 on a graph with an x resolution of 1000 pixels. Then you would plug in a loop (int x = 0; x <= 2000; x = 2) and feed those values into the equation above to get your y values for the pair. Since the y you want to show is 0-1 then you map these values to whatever you want your y resolution to be with appropriate rounding behavior so your graph doesn't end up too jaggy. So if you want your y resolution to be 500 pixels then you set 0 to 0 and 1 to 500 and .5 to 250 etc. etc. This is a contrived example and you might need a lot more flexibility but I think it illustrates the point. Most graphing libraries will handle these little things for you.
下面是使用 XChart 绘制一些高斯曲线的示例。代码可以在 此处。免责声明:我是 XChart Java 图表库的创建者。
结果图如下所示:
Here's an example of plotting some Gaussian curves using XChart. The code can be found here. Disclaimer: I'm the creator of the XChart Java charting library.
The resulting plot looks like this: