bot_gen.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:pysimgrid 作者: alexmnazarenko 项目源码 文件源码
def generate_values(spec, num, inputs=None):
    try:
        # fixed value
        fixed = float(spec)
        values = [fixed] * num

    except ValueError:
        parts = spec.split(':')
        type = parts[0]
        params = parts[1:]

        # uniform distribution: u:min:max
        if type == "u":
            min = float(params[0])
            max = float(params[1])
            values = [random.uniform(min, max) for _ in xrange(0, num)]

        # normal distribution: n:mean:std_dev
        elif type == "n":
            mean = float(params[0])
            std_dev = float(params[1])
            values = [random.normalvariate(mean, std_dev) for _ in xrange(0, num)]

        # scaled values: x:factor
        elif type == "x":
            factor = float(params[0])
            if inputs is not None:
                values = [inputs[i] * factor for i in xrange(0, num)]
            else:
                print("Inputs are not specified")
                sys.exit(-1)

        else:
            print("Unknown distribution")
            sys.exit(-1)

    return values
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号