douchuopiao9002 2017-01-12 07:43
浏览 57
已采纳

Golang中模拟钟形曲线上的值

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条回答 默认 最新

  • duanji7881 2017-01-12 08:07
    关注

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

    package main
    import (
        "math"
    )
    
    const (
        a = 2.0 // height of curve's peak
        b = 0.5 // position of the peak
        c = 0.1 // standart deviation controlling width of the curve 
                //( lower abstract value of c -> "longer" curve)
    )
    
    func curveFunc(x float64) float64 {
        return a *math.Exp(-math.Pow(x-b, 2)/2.0*math.Pow(c, 2))
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 2024-五一综合模拟赛
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭