コード例 #1
0
ファイル: predictors.py プロジェクト: gic888/mienblocks
def projectionAnalyzer(ds, dpathUE="/UE", dpathECE='/evtcond', dpathFilters='/pca', bins=60, smooth=0, newpath='/hists'):
	'''construct the de-biased distribution of conditioned projections onto a filter or set of filters. The filters must have the same length as the conditioned events in dpathConditional. The distributions are calculated as histograms in bins of width "step"'''
	raw=ds.getSubData(dpathUE).getData()
	cond = ds.getSubData(dpathECE).getData()
	comps=ds.getSubData(dpathFilters).getData()
	hists=zeros((bins, comps.shape[1]), float32)
	ranges=[]
	for v in range(comps.shape[1]):
		filt=comps[:,v]
		cp=dot(filt, cond)
		rp=dot(filt, raw)
		st=min([rp.min(), cp.min()])
		top=max([cp.max(), rp.max()])
		bw=(top-st)/float(bins)
		ranges.append((st, bw))
		rp=hist2(rp, bw, st, bins).astype(float32)/raw.shape[1]
		cp=hist2(cp, bw, st, bins).astype(float32)/cond.shape[1]
		z = arange(rp.shape[0])
		if smooth:
			rp = dimr._lstsqO4(rp, z)[1]
			cp = dimr._lstsqO4(cp, z)[1]
		mask=nonzero1d(rp==0)
		put(rp, mask, 1)
		put(cp, mask, 0.0)
		hists[:,v]=cp/rp
	h=ds.header()
	h['Labels']=ds.getSubData(dpathFilters).getLabels()
	h['BinWidths']=[q[1] for q in ranges]
	h['StartBins']=[q[0] for q in ranges]
	ds.createSubData(newpath, data=hists, head=h, delete=True)
	return ds
コード例 #2
0
ファイル: clusters.py プロジェクト: gic888/mienblocks
def fitTSO4(ds, newpath=""):
    chans = []
    h = ds.header()
    fs = h["SamplesPerSecond"]
    start = h.get("StartTime", 0)
    for i in range(ds.data.shape[1]):
        dat = ds.data[:, i]
        v = DR._lstsqO4(dat, fs, start)
        chans.append(v[1])
    if newpath:
        ds.createSubData(newpath, column_stack(chans), h, True)
    else:
        echans = []
        for i in range(ds.data.shape[1]):
            echans.extend([ds.data[:, i], chans[i]])
        ds.datinit(column_stack(echans), {"SampleType": "ensemble", "Reps": 2, "SamplesPerSecond": fs}, True)
コード例 #3
0
ファイル: clusters.py プロジェクト: gic888/mienblocks
def fitFunctionsO4(ds):
    dats = ds.getElements("Data", {"SampleType": "function"})
    mfv = max([d.data[:, 0].max() for d in dats])
    vals = array([e.attrib("length") for e in dats])
    order = vals.argsort()
    off = 0
    for i in order:
        f = dats[i]
        print i, f.attrib("length"), f.name()
        h = f.header()
        x = f.data[:, 0]
        y = f.data[:, 1]
        pars, vals = DR._lstsqO4(y, x)
        f.data[:, 0] += off
        off += mfv
        x = f.data[:, 0]
        h.update(dict(zip(["m", "gamp", "mean", "std", "e"], pars)))
        d = column_stack([x, vals])
        h["style"] = "line"
        path = f.dpath() + "_fit"
        ds.createSubData(path, d, h, True)