将线性范围转换为值的正态分布

时间:2019-04-05 23:33:10

标签: python

我正在尝试将值的线性范围(0-300)转换为钟形曲线分布,以python表示以英寸为单位的高度(22-107,平均值为72),但是我没有数学培训,以了解我在Google上发现的任何内容。有一些numpy或scipy函数可以很简单地做到这一点吗?

要提供更多细节,它是用于游戏中,标称范围为0-300的属性表示高度。因此,我需要将其转换为一个钟形曲线,该钟形曲线的范围从最小到最大可能的高度(22-107英寸),平均值为72英寸。

我可以使用scipy.stats.norm.pdf查找我认为是任何给定属性在钟形曲线上该点的概率。但是,如果这就是这样做的话,那么我需要使用pdf作为索引从高度钟形曲线中获取高度的值。而且,我似乎找不到任何能够做到这一点的东西,只是编写了一个不断迭代直到匹配的函数,这似乎效率很低。

进一步研究这一点,我相信我要做的与这些工具的用途相反。我不是在为工具提供数据集和外推统计数据,而是尝试获取一个随机数并将其强制为另一个数字范围的理想钟形曲线分布。

1 个答案:

答案 0 :(得分:0)

好吧,我最终做了我本能的本能:我捏造了它。基本上,我创建了一个函数,可以吐出类似于钟形曲线的结果:

def height_curve(height_score, race_avg = 72):
    if height_score < 30:
        height = (race_avg*.3) + (height_score/150)*race_avg #22 - 36
    elif height_score < 50:
        height = (race_avg*.5) + ((height_score-29)/132)*race_avg #36 - 47
    elif height_score < 100:
        height = (race_avg*.66) + ((height_score-49)/258)*race_avg #48 - 62
    elif height_score < 160:
        height = (race_avg*.86) + ((height_score-99)/240)*race_avg #62 - 80
    elif height_score < 210:
        height = (race_avg*1.11) + ((height_score-159)/602)*race_avg #80 - 86
    elif height_score < 230:
        height = (race_avg*1.19) + ((height_score-209)/364)*race_avg #86 - 90
    else:
        height = (race_avg*1.25) + ((height_score-229)/297)*race_avg #90+ (300 = 107")

    return height

在我的角色生成算法中迭代了100,000次,它吐出了这些结果,这些结果虽然不完美,但目前已经足够了。我待会再调:

How many characters to generate?100000
MIN SET

INTELLECT:      115
STRENGTH:       112
AGILITY:        94
CONSTITUTION:   101
SENSES:         111
APPEARANCE:     96
Height:         5' 9"
Weight:         200 lbs
Reach:          34"
Stamina:        417
Stamina Regen:  19/rd
Vitae:          6667 ml
Vitae Regen:    3 ml/min
Move (walk):    19 sq/rd
Move (jog):     27 sq/rd
Move (run):     36 sq/rd
Eff. Power:     300 PSI
Brawling:       103%


MAX SET

INTELLECT:      140
STRENGTH:       326
AGILITY:        166
CONSTITUTION:   181
SENSES:         166
APPEARANCE:     78
Height:         6' 10"
Weight:         478 lbs
Reach:          41"
Stamina:        657
Stamina Regen:  47/rd
Vitae:          15933 ml
Vitae Regen:    12 ml/min
Move (walk):    53 sq/rd
Move (jog):     80 sq/rd
Move (run):     106 sq/rd
Eff. Power:     2058 PSI
Brawling:       225%


AVG SET

INTELLECT:      137
STRENGTH:       137
AGILITY:        137
CONSTITUTION:   137
SENSES:         137
APPEARANCE:     94
Height:         6' 1"
Weight:         254 lbs
Reach:          36"
Stamina:        548
Stamina Regen:  33/rd
Vitae:          8467 ml
Vitae Regen:    5 ml/min
Move (walk):    36 sq/rd
Move (jog):     55 sq/rd
Move (run):     72 sq/rd
Eff. Power:     557 PSI
Brawling:       137%


MIN ATTRIBUTES

INTELLECT:      76
STRENGTH:       78
AGILITY:        77
CONSTITUTION:   77
SENSES:         78
APPEARANCE:     65
Height:         4' 8"
Weight:         112 lbs
Reach:          28"
Stamina:        315
Stamina Regen:  11/rd
Vitae:          3733 ml
Vitae Regen:    1 ml/min
Move (walk):    8 sq/rd
Move (jog):     13 sq/rd
Move (run):     17 sq/rd
Eff. Power:     161 PSI
Brawling:       77%


MAX ATTRIBUTES

INTELLECT:      382
STRENGTH:       407
AGILITY:        399
CONSTITUTION:   398
SENSES:         415
APPEARANCE:     228
Height:         11' 8"
Weight:         1586 lbs
Reach:          70"
Stamina:        1546
Stamina Regen:  260/rd
Vitae:          52867 ml
Vitae Regen:    99 ml/min
Move (walk):    468 sq/rd
Move (jog):     702 sq/rd
Move (run):     936 sq/rd
Eff. Power:     7540 PSI
Brawling:       400%