class d:
    tr_x = t(np.load(os.path.join(ds, "tr.x.npy")))
    tr_y = e(np.load(os.path.join(ds, "tr.y.npy")))
    tr2_x = t(np.load(os.path.join(ds, "tr2.x.npy")))
    tr2_y = e(np.load(os.path.join(ds, "tr2.y.npy")))
    tr_g = e(np.load(os.path.join(ds, "tr.g.npy")))

    te_x = t(np.load(os.path.join(ds, "te.x.npy")))
    te_y = e(np.load(os.path.join(ds, "te.y.npy")))
    te_g = e(np.load(os.path.join(ds, "te.g.npy")))
def less_t(ei, rate):
    r = pickle.load(open(os.path.join(ds, "t_{}".format(rate)), 'rb'))

    dt.t = load_t()
    e_ = dt.t.ge(ei).gt(r[ei]).v
    v = dt.t.v[np.isin(dt.t.ei, ei, invert=True)]
    dt.t = t(np.r_[v, e_])
    print("dt {}".format(len(dt.t.v)))
示例#3
0
    def run2(self, q):
        t_ = dt.t
        t_ = t(t_.v[t_.c[:, q.c] > 0.0])

        qc = t_cv.v[q.c]  # wv
        qu = t_uv.v[q.u]  # wv

        if len(t_.v) > self.rn:
            w = {}
            for i, (c2, u2, l, z) in enumerate(zip(t_.c2, t_.u2, t_.l, t_.z)):
                w[i] = c_sim(qc, c2) + \
                    u_sim(qu, u2) + \
                    l_sim(q.l, l) + \
                    z_sim(q.z, z)

            o = sorted(w, key=w.get, reverse=True)  # max
            return t(t_.v[o[:self.rn]])
        return t_
	def c_pick(self):
		t_ = self.p.t1()
		r = []
		for i, c2 in enumerate(t_.c2):
			sc = c_sim(c2, self.ec)
			if sc >= self.sc_low:
				r.append(i)
		t2_ = t(t_.v[r])

		v = t2_.c_m()
		w = {i: v[i] for i in v_gi(v)}
		o = sorted(w, key=w.get, reverse=True)  # max
		return o
    def init(self):
        self.sr = sr(self)
        self.q_ = [q(c=0, u=0, l=[0.0, 0.0], z=[0.0])]

        t_ = t()  # e
        ec = de.to_t(self.e.c[0])
        t_.c_(np.array([ec]))
        t_.c2_(np.array([to_wv(ec, t_cv.v)]))
        self.t_ = [t_]

        self.d = {}
        self.d_ = [0.0]
        self.l = 0
示例#6
0
import numpy as np
import os
from d.d import d, ds
from d.t import t
from d.g.wv import e_cv, to_wv
from d.ul import c_sim
from rw.be_.m import m
from z2.ul import ndcg

np.set_printoptions(precision=3)

x = t(np.load(os.path.join(ds, "t_test.npy")))
g = d.te_g

m_ = m()
x2 = []
for i in x.c:
    x2.append(to_wv(m_.pd(i), e_cv.v))

top = 500
r = []
for g_, a in zip(g.c2, g.ei):
    s = {i: c_sim(g_, x2[i]) for i in range(len(x2))}
    o = sorted(s, key=s.get, reverse=True)  # max
    s2 = (x.ei[o] == a) * 1

    r_ = []
    for k in range(1, top + 1):
        r_.append(ndcg(s2, k))

    #print("@{} {}".format(10, r_[10-1]))
def load_t():
    #t_ = t(np.load(os.path.join(dd, "t4.npy")))
    #t_ = t(np.load(os.path.join(ds, "t_train.npy")))
    t_ = t(np.load(os.path.join(ds, "t_test.npy")))
    print("dt {}".format(len(t_.v)))
    return t_
import numpy as np
import os
from d.t import t
from d.d import d, ds
dd = "/ex/d/d_/1"

t1 = t(np.load(os.path.join(ds, "t_train.npy")))
t2 = t(np.load(os.path.join(ds, "t_test.npy")))
t_ = t(np.r_[t1.v, t2.v])

len(t_.v)
sum(t_.ei != -1)
len(np.unique(t_.ei)) - 1

t2_ = t(t_.v[t_.ei != -1])
sum(t2_.rf == 1)
sum(t2_.rf == 2)

len(np.unique(d.tr_g.ei))
len(np.unique(d.te_g.ei))

from d.dt import dt
a = dt.raw
u = {}
for k, v in a.items():
    if int(k) in t_.ti:
        u[v["user"]["id_str"]] = 1
示例#9
0
import numpy as np
import os
from d.t import t
from d.dt import dt, dd
from d.ul import v_gi, c_sim, u_sim, l_sim, z_sim
from d.g.wv import t_cv, t_uv

t_ = t(np.load(os.path.join(dd, "t4.npy")))

q = 65
qc = t_cv.v[q]
qu = t_uv.v[q]
ql = np.zeros(2)
qz = np.zeros(1)


# c
w = {}
for i, (c2, u2, l, z) in enumerate(zip(t_.c2, t_.u2, t_.l, t_.z)):
	# w[i] = c_sim(qc, c2) + \
	# 	   u_sim(qu, u2) + \
	# 	   l_sim(ql, l) + \
	# 	   z_sim(qz, z)
	w[i] = c_sim(qc, c2)
	#w[i] = u_sim(qu, u2)
	# w[i] = l_sim(ql, l)
	# w[i] = z_sim(qz, z)

o = sorted(w, key=w.get, reverse=True)  # max
r = t(t_.v[o[:30]])