Ejemplo n.º 1
0
def round_function(message_L, message_R, internal_key, iteration):
    new_L = message_R

    # process the right part of message
    if iteration % 2 == 0:
        transposed = helper.shuffle(message_R, False)
    else:
        transposed = helper.shuffle(message_R)

    dotted = np.remainder(np.dot(transposed, internal_key), 2).astype(int)
    substituted = dotted[:, :]
    for i in range(len(dotted)):
        substituted[i] = helper.substitute(dotted[i])

    new_R = substituted ^ message_L
    return new_L, new_R
Ejemplo n.º 2
0
def assign_team_ids(pids, intgen):
    '''
    pids: [t]
    intgen: int -> int -> int
    return: [Player]

    '''
    roles = get_default_roles(len(pids))
    shuffled_roles = shuffle(roles, intgen)
    return map(lambda pid, role: r.Player(pid, role), pids, shuffled_roles)
Ejemplo n.º 3
0
 def reshuffle_data(self):
     """
     Reshuffle train data between epochs
     """
     graphs, labels = helper.group_same_size(self.train_graphs,
                                             self.train_labels)
     graphs, labels = helper.shuffle_same_size(graphs, labels)
     graphs, labels = helper.split_to_batches(graphs, labels,
                                              self.batch_size)
     self.num_iterations_train = len(graphs)
     graphs, labels = helper.shuffle(graphs, labels)
     self.iter = zip(graphs, labels)
Ejemplo n.º 4
0
def make_poly_ratio_limit(var="x", s=[0, 1, 2]):
    """
    Generates a ratio of two polynomials, and evaluates them at infinity.

    x : charector for the variable to be solved for. defaults to "x".
                            OR
        a list of possible charectors. A random selection will be made from them.

    s : selects the kind of solution
        0 : limit at infinity is zero
        1 : limit as infinity is a nonzero finite number
        2 : limit at infinity is either +infinity or -infinity

        default: one of the above is randomly selected
    """
    if isinstance(var, str):
        var = sympy.Symbol(var)
    elif isinstance(var, list):
        var = sympy.Symbol(random.choice(var))
    if isinstance(s, list):
        s = random.choice(s)
    if s == 2:  # infinity
        p1 = random.randint(2, 4)
        p2 = p1 - 1
    elif s == 1:  # ratio of leading coefficients
        p1 = random.randint(2, 4)
        p2 = p1
    elif s == 0:  # zero
        p1 = random.randint(2, 4)
        p2 = random.randint(p1, p1 + 2)
    select = [shuffle(digits_nozero)[0]] + shuffle(range(10)[:p1 - 1])
    num = sum([(k + 1) * var**i for i, k in enumerate(select)])
    select = [shuffle(digits_nozero)[0]] + shuffle(range(10)[:p2 - 1])
    denom = sum([(k + 1) * var**i for i, k in enumerate(select)])
    e = num / denom
    s = sympy.limit(e, var, sympy.oo)

    e = "\lim_{x \\to \infty}" + sympy.latex(e)
    return render(e), render(s)
Ejemplo n.º 5
0
def make_rational_poly_simplify(var="x"):
    """
    Generates a rational expression of 4 polynomials, to be simplified.
    Example:
        ( (x**2 + 16*x + 60) / (x**2 - 36)) / 
        ( (x**2 - 2*x - 63) / (x**2 - 5*x - 36)

    x : charector for the variable to be solved for. defaults to random selection
        from the global list `alpha`.
                            OR
        a list of possible charectors. A random selection will be made from them.
    """
    if not var:
        var = random.choice(alpha)
    elif isinstance(var, list):
        var = random.choice(var)

    exclude = [var.upper(), var.lower()]
    x = sympy.Symbol(var)
    select = shuffle(range(-10,-1) + range(1,10))[:6]
    e1 = sympy.prod([x - i for i in shuffle(select)[:2]]).expand()
    e2 = sympy.prod([x - i for i in shuffle(select)[:2]]).expand()
    e3 = sympy.prod([x - i for i in shuffle(select)[:2]]).expand()
    e4 = sympy.prod([x - i for i in shuffle(select)[:2]]).expand()
    L = len(set([e1, e2, e3, e4]))
    e = ((e1/e2) / (e3 / e4))
    s1 = ''.join(["\\frac{", sympy.latex(e1), "}", "{", sympy.latex(e2), "}"])
    s2 = ''.join(["\\frac{", sympy.latex(e3), "}", "{", sympy.latex(e4), "}"])
    s3 = ''.join(["$$\\frac{", s1, "}", "{", s2, "}$$"])
    pieces = str(e.factor()).split("/")
    try:
        num, denom= [parse_expr(i).expand() for i in pieces]
    except:
        return make_rational_poly_simplify(var)
    if len(pieces) !=2 or L < 4 or degree(num) > 2 or  degree(denom) > 2:
        return make_rational_poly_simplify(var)
    return s3, render(num / denom)
Ejemplo n.º 6
0
def make_rational_poly_simplify(var="x"):
    """
    Generates a rational expression of 4 polynomials, to be simplified.
    Example:
        ( (x**2 + 16*x + 60) / (x**2 - 36)) / 
        ( (x**2 - 2*x - 63) / (x**2 - 5*x - 36)

    x : charector for the variable to be solved for. defaults to random selection
        from the global list `alpha`.
                            OR
        a list of possible charectors. A random selection will be made from them.
    """
    if not var:
        var = random.choice(alpha)
    elif isinstance(var, list):
        var = random.choice(var)

    exclude = [var.upper(), var.lower()]
    x = sympy.Symbol(var)
    select = shuffle(range(-10, -1) + range(1, 10))[:6]
    e1 = sympy.prod([x - i for i in shuffle(select)[:2]]).expand()
    e2 = sympy.prod([x - i for i in shuffle(select)[:2]]).expand()
    e3 = sympy.prod([x - i for i in shuffle(select)[:2]]).expand()
    e4 = sympy.prod([x - i for i in shuffle(select)[:2]]).expand()
    L = len(set([e1, e2, e3, e4]))
    e = ((e1 / e2) / (e3 / e4))
    s1 = ''.join(["\\frac{", sympy.latex(e1), "}", "{", sympy.latex(e2), "}"])
    s2 = ''.join(["\\frac{", sympy.latex(e3), "}", "{", sympy.latex(e4), "}"])
    s3 = ''.join(["$$\\frac{", s1, "}", "{", s2, "}$$"])
    pieces = str(e.factor()).split("/")
    try:
        num, denom = [parse_expr(i).expand() for i in pieces]
    except:
        return make_rational_poly_simplify(var)
    if len(pieces) != 2 or L < 4 or degree(num) > 2 or degree(denom) > 2:
        return make_rational_poly_simplify(var)
    return s3, render(num / denom)
Ejemplo n.º 7
0
import numpy as np
import time
import matplotlib.pyplot as plt
from loadFile import read_file, read_csv
from helper import split_set, shuffle
import neuralNetwork as nn
from plotCurve import learning_curve, learning_rate_curve
import roc
X, Y, titles = read_csv("data.csv")
X_norm = nn.normalization(X)
layers_dims = [X.shape[0], 25, 15, 5, 1]
hyperparameters = nn.hyperparameter_initialization(layers_dims,
                                                   learning_rate=0.001,
                                                   num_iter=20000,
                                                   print_cost=True,
                                                   reg_factor=1)
#learning_rate_curve(X, Y, hyperparameters)
X_shuffled, Y_shuffled = shuffle(X_norm, Y)
X_train, Y_train, X_test, Y_test = split_set(X_shuffled, Y_shuffled, 0.6)

parameters = nn.model(X_train, Y_train, hyperparameters)
pred = nn.predict(X_test, parameters)

roc.plot(pred, Y_test)
Ejemplo n.º 8
0
def words(num=False):
    if not num:
        num = 3
    return helper.shuffle(definitions.lorem())[:num]
Ejemplo n.º 9
0
def init_tagged(percentage, rng):
    corp = helper.read_tiger(TIGER_FILE)
    tagged_sents = corp.tagged_sents()
    return helper.shuffle(tagged_sents,
                          rng), int(len(tagged_sents) * percentage)
Ejemplo n.º 10
0
import os
reload(sys)
sys.setdefaultencoding("utf-8")
import helper
import tensorflow as tf
import numpy as np

image_size = 64
depth_1st_layer = 32
depth_2rd_layer = 64
batch_size = 128
fc1 = 1024
if (True):
    (XoB, YoB) = helper.storeAllPicInMe(flagOfO=False, flagOfB=True, size=64)
    (Xo0, Yo0) = helper.storeAllPicInMe(flagOfB=False, flagOfO=True, size=64)
    Xo0, Yo0 = helper.shuffle(Xo0, Yo0)
    X = Xo0 + XoB
    Y = Yo0 + YoB
    dictory, Y = helper.convertDiscretToContinueT(Y)
    Y = helper.convertIndexTovector(len(dictory), Y)

    print "loading finished"
if (False):
    (X, Y) = helper.storeAllPicInMe(flagOfO=True, flagOfB=True)
    dictory, Y = helper.convertDiscretToContinueT(Y)
    Y = helper.convertIndexTovector(len(dictory), Y)
    X, Y = helper.shuffle(X, Y)

train_data_x = X[994:]
train_data_y = Y[994:]
test_data_x = X[0:994]
Ejemplo n.º 11
0
def words(num=False):
  if not num:
    num = 3
  return helper.shuffle(definitions.lorem())[:num]