示例#1
0
def load(name, chains=None, model=None):
    """Load text database.

    Parameters
    ----------
    name : str
        Path to root directory for text database
    chains : list
        Chains to load. If None, all chains are loaded.
    model : Model
        If None, the model is taken from the `with` context.

    Returns
    -------
    ndarray.Trace instance
    """
    chain_dirs = _get_chain_dirs(name)
    if chains is None:
        chains = list(chain_dirs.keys())

    traces = []
    for chain in chains:
        chain_dir = chain_dirs[chain]
        shape_file = os.path.join(chain_dir, 'shapes.json')
        with open(shape_file, 'r') as sfh:
            shapes = json.load(sfh)
        samples = {}
        for varname, shape in shapes.items():
            var_file = os.path.join(chain_dir, varname + '.txt')
            samples[varname] = np.loadtxt(var_file).reshape(shape)
        trace = NDArray(model=model)
        trace.samples = samples
        trace.chain = chain
        traces.append(trace)
    return base.MultiTrace(traces)
示例#2
0
文件: text.py 项目: Synapski/pymc
def load(name, chains=None, model=None):
    """Load text database.

    Parameters
    ----------
    name : str
        Path to root directory for text database
    chains : list
        Chains to load. If None, all chains are loaded.
    model : Model
        If None, the model is taken from the `with` context.

    Returns
    -------
    ndarray.Trace instance
    """
    chain_dirs = _get_chain_dirs(name)
    if chains is None:
        chains = list(chain_dirs.keys())

    traces = []
    for chain in chains:
        chain_dir = chain_dirs[chain]
        shape_file = os.path.join(chain_dir, 'shapes.json')
        with open(shape_file, 'r') as sfh:
            shapes = json.load(sfh)
        samples = {}
        for varname, shape in shapes.items():
            var_file = os.path.join(chain_dir, varname + '.txt')
            samples[varname] = np.loadtxt(var_file).reshape(shape)
        trace = NDArray(model=model)
        trace.samples = samples
        trace.chain = chain
        traces.append(trace)
    return base.MultiTrace(traces)
示例#3
0
文件: hdfs.py 项目: wmastersonV/pymc
def load(name,
         chains=None,
         model=None,
         host='localhost',
         port='50070',
         user_name=None):
    '''
	Load text database

	Parameters
	----------
	name : str
		Path to root directory in HDFS for text database without a leading '/'
	chains : list
		Chains to load. If None, all chains are loaded
	model : Model
		If None, the model is taken from the 'with' context
	host : str
		The IP address or hostname of the HDFS namenode. By default,
		it is 'localhost'
	port : str
		The port number for WebHDFS on the namenode. By default, it
		is '50070'
	user_name : str
		WebHDFS user_name used for authentication. By default, it is
		None

	Returns
	-------
	ndarray.Trace instance
	'''
    hdfs = PyWebHdfsClient(host=host, port=port, user_name=user_name)
    chain_dirs = _get_chain_dirs(name, hdfs)
    if chains is None:
        chains = list(chain_dirs.keys())
    traces = []
    for chain in chains:
        chain_dir = chain_dirs[chain]
        dir_path = os.path.join(name, chain_dir)
        shape_file = os.path.join(dir_path, 'shapes.json')
        shapes = json.load(StringIO.StringIO(hdfs.read_file(shape_file)))
        samples = {}
        for varname, shape in shapes.items():
            var_file = os.path.join(dir_path, varname + '.txt')
            samples[varname] = np.loadtxt(
                StringIO.StringIO(str(
                    hdfs.read_file(var_file)))).reshape(shape)
        trace = NDArray(model=model)
        trace.samples = samples
        trace.chain = chain
        traces.append(trace)
    return base.MultiTrace(traces)
示例#4
0
文件: hdfs.py 项目: bkanuka/pymc
def load(name, chains=None, model=None, host='localhost', port='50070', user_name=None):
	'''
	Load text database

	Parameters
	----------
	name : str
		Path to root directory in HDFS for text database without a leading '/'
	chains : list
		Chains to load. If None, all chains are loaded
	model : Model
		If None, the model is taken from the 'with' context
	host : str
		The IP address or hostname of the HDFS namenode. By default,
		it is 'localhost'
	port : str
		The port number for WebHDFS on the namenode. By default, it
		is '50070'
	user_name : str
		WebHDFS user_name used for authentication. By default, it is
		None

	Returns
	-------
	ndarray.Trace instance
	'''
	hdfs = PyWebHdfsClient(host=host, port=port, user_name=user_name)
	chain_dirs = _get_chain_dirs(name, hdfs)
	if chains is None:
		chains = list(chain_dirs.keys())
	traces = []
	for chain in chains:
		chain_dir = chain_dirs[chain]
		dir_path = os.path.join(name, chain_dir)
		shape_file = os.path.join(dir_path, 'shapes.json')
		shapes = json.load(StringIO.StringIO(hdfs.read_file(shape_file)))
		samples = {}
		for varname, shape in shapes.items():
			var_file = os.path.join(dir_path, varname + '.txt')
			samples[varname] = np.loadtxt(StringIO.StringIO(str(hdfs.read_file(var_file)))).reshape(shape)
		trace = NDArray(model=model)
		trace.samples = samples
		trace.chain = chain
		traces.append(trace)
	return base.MultiTrace(traces)