Пример #1
0
def run_sim(rootv, mname, params, n, minsz=0.0):
    simvs = []
    simvs.append({"size": rootv, "mult_factor": 0.0, "depth": 0.0})

    rgen = rng.Rangen(mname, params)
    rvs = rgen.rvs(n)

    r = rng.get_random()

    for i in xrange(n):
        l = len(simvs)
        fchosen = r.randint(0, l - 1)
        s = simvs[fchosen]
        mf = rvs[i]

        ns = max(s["size"] * mf, minsz)
        nmf = s["mult_factor"] * mf
        ndepth = s["depth"] + 1

        nsv = {"size": ns, "mult_factor": nmf, "depth": ndepth}
        simvs.append(nsv)

    fsz = []
    mfs = []
    dp = []

    for simv in simvs:
        fsz.append(simv["size"])
        mfs.append(simv["mult_factor"])
        dp.append(simv["depth"])

    return (np.array(fsz), np.array(mfs), np.array(dp))
Пример #2
0
def run_sim(rootv, mname, params, n, minsz = 0.0):
	simvs = []
	simvs.append({"size": rootv, "mult_factor": 0.0, "depth": 0.0})

	rgen = rng.Rangen(mname, params)	
	rvs = rgen.rvs(n)

	r = rng.get_random()

	for i in xrange(n):
		l = len(simvs)
		fchosen = r.randint(0, l-1)
		s = simvs[fchosen]
		mf = rvs[i]

		ns = max(s["size"]*mf, minsz)
		nmf = s["mult_factor"]*mf
		ndepth = s["depth"] + 1

		nsv = {"size": ns, "mult_factor": nmf, "depth": ndepth}
		simvs.append(nsv)
	
	fsz=[]
	mfs=[]
	dp=[]

	for simv in simvs:
		fsz.append(simv["size"])
		mfs.append(simv["mult_factor"])
		dp.append(simv["depth"])

	return (np.array(fsz), np.array(mfs), np.array(dp))
Пример #3
0
def get_root_from_data(data_file):
    """
	Get a random root value from the points specified by the data file
	"""
    fp_df = os.path.join(os.environ["TRACE_DB_LOC"], data_file)
    vals = util.read_data(fp_df)
    n = len(vals)
    r = rng.get_random()
    i_rootv = r.randint(0, n - 1)
    rootv = vals[i_rootv]
    return rootv
Пример #4
0
def get_root_from_data(data_file):
	"""
	Get a random root value from the points specified by the data file
	"""
	fp_df = os.path.join(os.environ["TRACE_DB_LOC"], data_file)
	vals = util.read_data(fp_df)
	n = len(vals)
	r = rng.get_random()
	i_rootv = r.randint(0, n-1)
	rootv = vals[i_rootv]
	return rootv
def recursive_model(**kwargs):
	"""
	Recursive forest file model simulator
	Params:
	file = data file to pick initial roots
	nroots = number of roots
	d1 = model for roots
	d1params = (param1, param2,...) parameters for d1
	d2 = model for children nodes
	d2params = (param1, param2, ...) parameters for d2
	g = probability of a new file
	nu = probability of a deletion
	n = number of iterations
	minsize = minimum file size
	"""

	sroots = None
	d1f = None
	d2f = None
	g = None
	nu = None
	minsize = 0.0
	
	nroots = kwargs["nroots"]
	if "minsize" in kwargs:
		minsize = kwargs["minsize"]

	if "file" in kwargs:
		fname = kwargs["file"]
		fl = util.read_data(fname)
		d1f = DFile(flist=fl, minsize=0.0)
	else:
		d1model = kwargs["d1"]
		d1params = kwargs["d1params"]
		d1f = DFile(d=d1model, plist=d1params, minsize=0.0)
	
	d2model = kwargs["d2"]
	d2params = kwargs["d2params"]
	d2f = DFile(d=d2model, plist=d2params)

	gf = rng.get_random() # random.Random()
	nf = rng.get_random() # random.Random()
	fpick = rng.get_random() # random.Random()
	g = kwargs["g"]
	nu = kwargs["nu"]
	n = kwargs["n"]

	sroots = d1f.random(nroots)
	simvs = []
	for sroot in sroots:
		s = {"size": sroot, "deleted": False, "mult_factor": 0.0, "depth": 0}
		simvs.append(s)
		
	for i in xrange(nroots, n+1):
		gvar = gf.random()
		if gvar <= g:
			a = d1f.random(1)
			sa = {"size": a, "deleted": False, "mult_factor": 0.0, "depth": 0}
			simvs.append(sa)
		else:
			idx = fpick.randint(0, len(simvs)-1) 
			nvar = nf.random()
			if nvar <= nu:
				simvs.pop(idx)
			else:
				mf = d2f.random(1)
				idx = fpick.randint(0, len(simvs)-1)
				pick = simvs[idx]

				ns = max(pick["size"]*mf[0], minsize)
				ndel = False
				nmf = pick["mult_factor"] * mf[0]
				ndepth = pick["depth"] + 1

				simvs.append({"size": ns, "deleted": ndel, "mult_factor": nmf, "depth": ndepth})

	sizev=[]	
	mfv=[]
	depthv=[]

	for simv	in simvs:
		sizev.append(simv["size"])
		mfv.append(simv["mult_factor"])
		depthv.append(simv["depth"])
	
	return (np.array(sizev), np.array(mfv), np.array(depthv))