Example #1
0
def new_data():
    """Create a data set for figure 7, with one threshold, and exactly one
    observation for each trial-RP-AP combination.
    """
    threshold = 60
    max_rp = 35
    max_t = 8

    points = _new_points(threshold, max_rp).reshape(-1, order='f')

    all_combs = np.array(list(prd(np.arange(8), points)))
    points = all_combs[:, 1]
    offers = all_combs[:, 0]
    trials = np.tile(np.arange(max_t), max_rp * 8)

    data_flat = {'NumberGames': 1,
                 'NumberTrials': max_t,
                 'TargetLevels': np.array([threshold * 10]),
                 'obs': points * 10,
                 'reihe': offers + 1,
                 'threshold': np.tile(threshold * 10, len(trials)),
                 'trial': trials,
                 'choice': np.tile(0, len(trials))}

    return data_flat
Example #2
0
def init_grid():
    even_line = range(0,10,2)
    odd_line = range(1,10,2)
    indices=[]
    grid_actual = [[0 for a in range(10)]for a in range(10)]

    # remember that we need product both ways
    for a in prd(even_line,odd_line): indices.append(a) #;print (a)
    for a in prd(odd_line,even_line): indices.append(a) # print (a)
    # print(len(indices))
    # indices
    for a in indices:
        # print(a)
        if a[0]<4: grid_actual[a[0]][a[1]] = 1
        if a[0]>5: grid_actual[a[0]][a[1]] = 2
    print_grid(grid_actual)
    return grid_actual, indices
Example #3
0
def checkio(matrix):

    N = len(matrix[0])
    num = [0, 0]
    cnt = {'V': 0, 'H': 0, 'D1': 0, 'D2': 0}

    # vertical and horizontal
    for i in range(N):
        for j in range(N):
            if num[0] == matrix[j][i]:
                cnt['V'] += 1
            else:
                cnt['V'] = 0
                num[0] = matrix[j][i]
            if num[1] == matrix[i][j]:
                cnt['H'] += 1
            else:
                cnt['H'] = 0
                num[1] = matrix[i][j]
            if cnt['V'] == 3 or cnt['H'] == 3:
                return True
        cnt['V'] = 0
        cnt['H'] = 0
        num = [0, 0]

    # diagonal
    for i in prd(range(N), range(N)):
        for j in range(N):
            if i[0] + j < N and i[1] + j < N:
                if num[0] == matrix[i[0] + j][i[1] + j]:
                    cnt['D1'] += 1
                else:
                    cnt['D1'] = 0
                    num[0] = matrix[i[0] + j][i[1] + j]
                if cnt['D1'] == 3:
                    return True

            if i[0] + j < N and i[1] - j >= 0:
                if num[1] == matrix[i[0] + j][i[1] - j]:
                    cnt['D2'] += 1
                else:
                    cnt['D2'] = 0
                    num[1] = matrix[i[0] + j][i[1] - j]
                if cnt['D2'] == 3:
                    return True
        cnt['D1'] = 0
        cnt['D2'] = 0
        num = [0, 0]

    return False
Example #4
0
def similarity_matrix(sim, rep):

    score_matrix = []

    for product in product_category_list:
        #この時点でproductはリスト
        product_row = []
        for site in site_category_list:
            # product site ともにリスト、中身は一つ〜
            best = 0
            allsyns1 = set(ss for word in product for ss in (
                wn.synsets(word) if wn.synsets(word) else flatten_list(
                    [wn.synsets(w) for w in word.split("_")])))
            allsyns2 = set(ss for word in site for ss in (
                wn.synsets(word) if wn.synsets(word) else flatten_list(
                    [wn.synsets(w) for w in word.split("_")])))
            #allsynsには入っているのは各単語のsynsetのset
            comparison_result = [(compute_similarities(s1, s2, sim)
                                  or 0, s1, s2)
                                 for s1, s2 in prd(allsyns1, allsyns2)
                                 if s1.pos() == s2.pos() and s1.pos() != "s"]
            # if "games" in product and "Games" in site:
            #     print("{}, {}".format(product, site))
            #     print("{}".format(comparison_result[:10]))
            if comparison_result:
                if rep == "max":
                    best = max([x[0] for x in comparison_result])
                elif rep == "mean":
                    best = np.mean([x[0] for x in comparison_result])
                elif rep == "median":
                    best = np.median([x[0] for x in comparison_result])
                elif rep == "min":
                    best = min([x[0] for x in comparison_result])
            product_row.append(best)

        score_matrix.append(product_row)

    file_name = "big" + sim + "_" + rep + ".tsv"
    result = pd.DataFrame(score_matrix,
                          index=tf.product_ctgr_name,
                          columns=df.name)
    result.to_csv(file_name, sep="\t", encoding="utf-8")
Example #5
0
            words = item.split('/')
            product_category_list.append(words)
        else:
            product_category_list.append([item])

    pprint(site_category_list)
    print(len(site_category_list))
    pprint(product_category_list)
    print(len(product_category_list))

    similarity_measures = ["lch"]
    reppresentation_measures = ["max"]
    # similarity_measures = ["path","lch","wup","res","jcn","lin"]
    # reppresentation_measures = ["max","mean","median","min"]

    for sim, rep in prd(similarity_measures, reppresentation_measures):
        similarity_matrix(sim, rep)

    # simple_similarity_matrix(product_category_list,site_category_list)

    # score_matrix = []

    # for product in product_category_list:
    #     product_row = []
    #     #print(product)
    #     #print("Above is the product #############################################")
    #     for site in site_category_list:
    #         #print(site)
    #         temp_sim = []
    #         for prod in product:
    #             for sit in site:
Example #6
0
            return [
            (pos[0]+dirs_down[0][0],pos[1]+dirs_down[0][1]),
            (pos[0]+dirs_down[1][0],pos[1]+dirs_down[1][1])
            ]

test_data = [(1,2), (6,5), (0,7), (7,0)]
for a in test_data:
    print(a, movements(a), movements(a, False))
##################### initiating the grid ########################
from itertools import product as prd
even_line = range(0,10,2)
odd_line = range(1,10,2)
indices=[]

# remember that we need product both ways
for a in prd(even_line,odd_line):
    indices.append(a)
    print (a)
for a in prd(odd_line,even_line):
    indices.append(a)
    # print (a)
# print(len(indices))
# indices
for a in indices:
    # print(a)
    if a[0]<4: grid[a[0]][a[1]] = 1
    if a[0]>5: grid[a[0]][a[1]] = 2
#################################################################

def print_grid2():
    print('################################')
Example #7
0
#log# Automatic Logger file. *** THIS MUST BE THE FIRST LINE ***
#log# DO NOT CHANGE THIS LINE OR THE TWO BELOW
#log# opts = Struct({'__allownew': True, 'logfile': 'hrm.py'})
#log# args = []
#log# It is safe to make manual edits below here.
#log#-----------------------------------------------------------------------
axisiter = lambda l,maxn: enumerate(chain(*(imap(str.join, prd(*((l,)*n))) for n in range(maxn+1))))
matrixiter = lambda l,maxn: enumerate(prd(axisiter(l,maxn), axisiter(l,maxn)))
for x in matrixiter(['X','Y'],2): print x
from itertools import product as prd
for x in matrixiter(['X','Y'],2): print x
from itertools import product as prd, chain
for x in matrixiter(['X','Y'],2): print x
from itertools import product as prd, chain, imap
for x in matrixiter(['X','Y'],2): print x
axisiter = lambda l,maxn: enumerate(chain(*(imap(lambda x: str.join((*x,)), prd(*((l,)*n))) for n in range(maxn+1))))
axisiter = lambda l,maxn: enumerate(chain(*(imap(lambda x: str.join(*x,), prd(*((l,)*n))) for n in range(maxn+1))))
axisiter = lambda l,maxn: enumerate(chain(*(imap(lambda x: str.join(*x), prd(*((l,)*n))) for n in range(maxn+1))))
for x in matrixiter(['X','Y'],2): print x
axisiter = lambda l,maxn: enumerate(chain(*(imap(lambda x: str.join(str(s) for s in x), prd(*((l,)*n))) for n in range(maxn+1))))
for x in matrixiter(['X','Y'],2): print x
axisiter = lambda l,maxn: enumerate(chain(*(imap(lambda x: str.join(*(str(s) for s in x)), prd(*((l,)*n))) for n in range(maxn+1))))
for x in matrixiter(['X','Y'],2): print x
axisiter = lambda l,maxn: enumerate(chain(*(prd(*((l,)*n))) for n in range(maxn+1)))
axisiter = lambda l,maxn: enumerate(chain(*(prd(*((l,)*n))) for n in range(maxn+1))))
axisiter = lambda l,maxn: enumerate(chain(*(prd(*((l,)*n))) for n in range(maxn+1)))))
axisiter = lambda l,maxn: enumerate(chain(*(prd(*((l,)*n))) for n in range(maxn+1)
axisiter = lambda l,maxn: enumerate(chain(*(prd(*((l,)*n))) for n in range(maxn+1)))
axisiter = lambda l,maxn: izip(count(), chain(*(prd(*((l,)*n))) for n in range(maxn+1))))
axisiter = lambda l,maxn: izip(count(), chain(*(prd(*((l,)*n)) for n in range(maxn+1))))
for x in matrixiter(['X','Y'],2): print x
Example #8
0
 def merge_mfq_arr(mfq_main, mfq_minor):
     mfq_merge = [main + minor for main, minor in prd(mfq_main, mfq_minor)]
     mfq_merge = np.array(mfq_merge, dtype="uint32").transpose()
     mfq_merge = np.unique(mfq_merge, axis=1)
     return mfq_merge
Example #9
0
        if cur:
            if isX: xs.append(cur)
            else: ys.append(cur)
        isX = not isX
        cur = 0
    elif S[i] == 'F':
        cur += 1

if cur:
    if isX: xs.append(cur)
    else: ys.append(cur)
sumxs = sum(xs)
sumys = sum(ys)

if abs(X) > sumxs or abs(Y) > sumys:
    print('No')
    exit()

memo1 = [[0] * (sumxs * 2 + 1) for i in range(len(xs) + 1)]
memo2 = [[0] * (sumys * 2 + 1) for i in range(len(ys) + 1)]

memo1[0][0] = 1
memo2[0][0] = 1
for i, j in prd(range(1, len(xs) + 1), range(-sumxs, sumxs + 1)):
    memo1[i][j] = memo1[i - 1][j + xs[i - 1]] or memo1[i - 1][j - xs[i - 1]]

for i, j in prd(range(1, len(ys) + 1), range(-sumys, sumys + 1)):
    memo2[i][j] = memo2[i - 1][j + ys[i - 1]] or memo2[i - 1][j - ys[i - 1]]

print('Yes' if memo1[len(xs)][X] and memo2[len(ys)][Y] else 'No')
from itertools import product as prd
k,m = map(int,input().split())
fx = [map(int,input().split()[1:]) for _ in range(k)]
print(max([sum([int(t)**2 for t in d])%m for d in prd(*fx) ]))