bdm.py 文件源码

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

项目:elfi 作者: elfi-dev 项目源码 文件源码
def prepare_inputs(*inputs, **kwinputs):
    """Prepare the inputs for the simulator.

    The signature follows that given in `elfi.tools.external_operation`. This function
    appends kwinputs with unique and descriptive filenames and writes an input file for
    the bdm executable.
    """
    alpha, delta, tau, N = inputs
    meta = kwinputs['meta']

    # Organize the parameters to an array. The broadcasting works nicely with constant
    # arguments.
    param_array = np.row_stack(np.broadcast(alpha, delta, tau, N))

    # Prepare a unique filename for parallel settings
    filename = '{model_name}_{batch_index}_{submission_index}.txt'.format(**meta)
    np.savetxt(filename, param_array, fmt='%.4f %.4f %.4f %d')

    # Add the filenames to kwinputs
    kwinputs['filename'] = filename
    kwinputs['output_filename'] = filename[:-4] + '_out.txt'

    # Return new inputs that the command will receive
    return inputs, kwinputs
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号