在golang中模拟钟形曲线上的数值

huangapple go评论75阅读模式
英文:

Values on a simulated bell curve in golang

问题

我的数学知识有点基础,所以提前对任何假设表示歉意。

我想获取存在于模拟钟形曲线上的数值。我不想真正创建一个钟形曲线或绘制一个钟形曲线,我只想使用一个函数,给定一个输入值,可以告诉我在假设的钟形曲线上相应的Y轴值。

以下是完整的问题陈述:

我正在生成介于0.0和1.0之间的浮点数。

0.50代表钟形曲线上的最大值2.0。小于0.50和大于0.50的值在钟形曲线上开始下降,所以例如0.40和0.60是相同的,可以是类似于1.8的值。1.8在这个例子中是任意选择的,我想知道如何调整这个“梯度”。

目前,我正在进行一个非常粗糙的实现,例如,对于任何大于0.40且小于0.60的值,该函数返回2.0,但我想“平滑”这个过程,并对下降/梯度获得更多“控制”。

有什么办法可以在Go语言中实现这个?

英文:

My math is a bit elementary so I apologize for any assumptions in advance.

I want to fetch values that exist on a simulated bell curve. I don't want to actually create a bell curve or plot one, I'd just like to use a function that given an input value can tell me the corresponding Y axis value on a hypothetical bell curve.

Here's the full problem statement:

I am generating floating point values between 0.0 and 1.0.

0.50 represents 2.0 on the bell curve, which is the maximum. The values < 0.50 and > 0.50 start dropping on this bell curve, so for example 0.40 and 0.60 are the same and could be something like 1.8. 1.8 is arbitrarily chosen for this example, and I'd like to know how I can tweak this 'gradient'.

Right now Im doing a very crude implementation, for example, for any value > 0.40 and < 0.60 the function returns 2.0, but I'd like to 'smooth' this and gain more 'control' over the descent/gradient

Any ideas how I can achieve this in Go

答案1

得分: 1

高斯函数是一种具有钟形曲线形状的函数。你可以在这里了解更多信息:https://en.wikipedia.org/wiki/Gaussian_function

以下是一个实现的示例代码:

package main
import (
    "math"
)

const (
    a = 2.0 // 曲线峰值的高度
    b = 0.5 // 峰值的位置
    c = 0.1 // 标准差,控制曲线的宽度(较小的c值表示“更长”的曲线)
)

func curveFunc(x float64) float64 {
    return a * math.Exp(-math.Pow(x-b, 2)/(2.0*math.Pow(c, 2)))
}

希望对你有帮助!

英文:

Gaussian function described here : https://en.wikipedia.org/wiki/Gaussian_function
has a bell-curve shape. Example of implementation :

package main
import (
	&quot;math&quot;
)

const (
	a = 2.0 // height of curve&#39;s peak
	b = 0.5 // position of the peak
	c = 0.1 // standart deviation controlling width of the curve 
            //( lower abstract value of c -&gt; &quot;longer&quot; curve)
)

func curveFunc(x float64) float64 {
	return a *math.Exp(-math.Pow(x-b, 2)/(2.0*math.Pow(c, 2)))
}

huangapple
  • 本文由 发表于 2017年1月12日 15:43:00
  • 转载请务必保留本文链接:https://go.coder-hub.com/41607610.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定