示例#1
0
    def parse(self, entry):
        fieldkeys = [
            'ENTRY', 'NAME', 'FORMULA', 'EXACT_MASS', 'MOL_WEIGHT', 'SEQUENCE',
            'REMARK', 'COMMENT', 'REACTION', 'PATHWAY', 'BRITE', 'ENZYME',
            'PATHWAY', 'OTHER DBS', 'LINKDB', 'MODULE', 'STRUCTURE', 'ATOM',
            'BOND', 'DBLINKS'
        ]
        pattern = '|'.join(fieldkeys)

        data = [x.strip() for x in re.split(pattern, entry)[1:]]
        keys = re.findall(pattern, entry)
        for key, val in zip(keys, data):
            if key == 'ENTRY':
                self.id = re.search('C\\d{5}', val).group(0)
            elif key == 'NAME':
                self.names = [x.strip('; ') for x in val.split('\n')]
            elif key == 'FORMULA':
                self.formula = val.strip()
            elif key == 'COMMENT':
                self.comment = val.strip()
            elif key == 'REACTION':
                self.reactions = re.findall('R\d{5}', val)
            elif key == 'MOL_WEIGHT':
                self.molweight = helper.f(val.strip())
            elif key == 'PATHWAY':
                self.pathways = re.findall('map(\d{5})', val)
            elif key == 'ATOM':
                self.__parse_atomtypes(val.strip())
            elif key == 'BRITE':
                self.brite = re.findall('(br\d{5}|ko\d{5})', val)
            elif key == 'REMARK':
                self.remark = re.findall('[DG]\\d{5}', val)
示例#2
0
    def __parse_equation(self, equation):
        tokens = ['-->', '<==>', '<=>']
        pattern = '|'.join(tokens)
        left, right = [x.strip() for x in re.split(pattern, equation)[0:]]

        self.reactants = dict()
        self.__reactants = list()
        self.__substrates = list()
        self.__products = list()
        for m in re.finditer(
                r'((?:[0-9]*|\([^)]*\)|[n,m]))\s*((?:C|G)[0-9]{5})', left):
            self.reactants[m.group(
                2)] = -1.0 if m.group(1) is '' else -helper.f(m.group(1))
            self.__reactants.append(m.group(2))
            self.__substrates.append(m.group(2))
        for m in re.finditer(
                r'((?:[0-9]*|\([^)]*\)|[n,m]))\s*((?:C|G)[0-9]{5})', right):
            stoich = 1.0 if m.group(1) is '' else helper.f(m.group(1))
            self.reactants[m.group(2)] = self.reactants[m.group(
                2)] + stoich if m.group(2) in self.reactants else stoich
            self.__reactants.append(m.group(2))
            self.__products.append(m.group(2))
示例#3
0
def encrypt(message, key):
    simulator.simulate_inputs(message, key)
    simulator.simulate_init_binary(helper.getBinary(message),
                                   helper.getBinary(key))

    M = helper.applyTable(helper.getBinary(message), 'ip')
    L0, R0 = helper.makeHalf(M)

    simulator.simulate_init_iptable_effects(M, L0, R0)

    K = helper.applyTable(helper.getBinary(key), "pc1")
    C0, D0 = helper.makeHalf(K)

    simulator.simulate_init_pc1table_effects(K, C0, D0)

    Ln = L0
    Rn = R0
    Cn = C0
    Dn = D0
    Kn = K
    for n in range(16):
        simulator.simulate_round_number(n + 1)
        Cn = helper.leftShift(Cn, n + 1)
        Dn = helper.leftShift(Dn, n + 1)
        Kn = helper.applyTable(Cn + Dn, 'pc2')
        tempL = Ln[:]
        Ln = Rn
        ern, xor, sbox, sbox_result = helper.f(Rn, Kn)

        simulator.simulate_f_calculations(ern, xor, sbox, sbox_result)

        Rn = bin(int(tempL, 2) ^ int(sbox_result, 2))[2:].zfill(32)

        simulator.simulate_round_results(n + 1, Cn, Dn, Kn, Ln, Rn)

    ip1_effect = helper.applyTable(Rn + Ln, 'ip-1')
    final_result = helper.getHexa(ip1_effect)

    simulator.simulate_final_result(ip1_effect, final_result)

    return final_result
示例#4
0
import numpy as np

from helper import f
from helper import f_prime_x0
from helper import f_prime_x1
from helper import plot_rosenbrock

if __name__ == "__main__":
    x0 = np.random.uniform(-2, 2)
    x1 = np.random.uniform(-2, 2)
    x_start = (x0, x1)
    y_start = f(x0, x1)

    print(f"Global minimum: {(1, 1)}")
    print(f"X_start = {x_start}")
    print(f"Y_start = {y_start}")
    plot_rosenbrock(x_start)

    learning_rate = 0.005  # [0.001, 0.00001]
    num_iterations = 1000

    gradient_steps = []

    for it in range(num_iterations):
        x0 = x0 - learning_rate * f_prime_x0(x0, x1)
        x1 = x1 - learning_rate * f_prime_x1(x0, x1)
        y = f(x0, x1)
        if it % 100 == 0:
            print(f"x0 = {x0} x1 = {x1} y = {y}")
            gradient_steps.append((x0, x1))
示例#5
0
Created on Tue Feb 12 11:41:30 2019

@author: qinzhen
"""
import helper as hlp
import numpy as np
import matplotlib.pyplot as plt

#设置随机种子,保证每次结果一致
seed = 42
rnd = np.random.RandomState(seed)

#(a)(b)(c)
N = 20
d = 2
a, b, c, X, y, s, w = hlp.f(N, d, rnd)
hlp.plot_helper(a, b, c, X, y, s, w)

#(d)
N = 100
a, b, c, X, y, s, w = hlp.f(N, d, rnd)
hlp.plot_helper(a, b, c, X, y, s, w)

#(e)
N = 1000
a, b, c, X, y, s, w = hlp.f(N, d, rnd)
hlp.plot_helper(a, b, c, X, y, s, w)

#(f)
#修改数据维度
N = 1000