Ejemplo n.º 1
0
def main():
    # we destroy the stack like men https://stackoverflow.com/a/16248113
    #  resource.setrlimit(resource.RLIMIT_STACK, (2**29,-1))
    #  sys.setrecursionlimit(10**6)

    args = parse_arguments()
    print(args)

    # setup width and heigth
    rows, columns = popen('stty size', 'r').read().split()
    #  mywidth, myheigth = 27,9
    if args['columns'] == -1: columns = int(columns)
    else: columns = args['columns']
    if args['rows'] == -1: rows = int(rows)
    else: rows = args['rows']

    # setup seed value
    if args['seed'] == -1:
        myseed = 1
        myseed = int(timer() * 1e9 % 2**32)
    else:
        myseed = args['seed']
    seed(myseed)
    npseed(myseed)

    print(f'python3 sim_waves_main.py -s {myseed} -r {rows} -c {columns}')

    #  run_test_lcs_base(rows=rows, columns=columns)
    #  run_test_lcs_base(rows=4000, columns=4000)
    run_test_lcs_base(rows=20, columns=100)
Ejemplo n.º 2
0
def main():
    args = parse_arguments()
    print(args)

    # setup width and heigth
    rows, columns = popen('stty size', 'r').read().split()
    #  mywidth, myheigth = 27,9
    if args.columns == -1: columns = int(columns)
    else: columns = args.columns
    if args.rows == -1: rows = int(rows)
    else: rows = args.rows
    if args.num_iter == -1: num_iter = 3
    else: num_iter = args.num_iter

    # setup seed value
    if args.seed == -1:
        myseed = 1
        myseed = int(timer() * 1e9 % 2**32)
    else:
        myseed = args.seed
    seed(myseed)
    npseed(myseed)

    print(
        f'python3 sim_waves_main.py -s {myseed} -r {rows} -c {columns} -i {num_iter}'
    )

    #  test_waves_base(rows=rows, columns=columns, num_iter=num_iter)
    #  test_waves_big(rows=rows, columns=columns, num_iter=num_iter)
    #  test_waves_mini(num_iter)
    test_waves_mini_moving(num_iter)
Ejemplo n.º 3
0
def set_seed(myseed):
    """Globally set seed."""
    from random import seed
    from numpy.random import seed as npseed
    from tensorflow import set_random_seed as tfseed

    seed(myseed)
    npseed(int(myseed))
    tfseed(int(myseed))
    os.environ['PYTHONHASHSEED'] = str(myseed)
def simulation_parameters(total, s):
    seed(s)
    npseed(s)
    r_p = {i: poisson(15) for i in range(total)}  # El tiempo de recuperacion
    c_p = {i: min(r_p[i], negative_binomial(6, 0.5))
           for i in range(total)}  # Tiempo en que se da cuenta
    contagios = {i: random()
                 for i in range(total)
                 }  # Esto es basicamente para la bernoulli
    return r_p, c_p, contagios
Ejemplo n.º 5
0
    def __init__(self, parameters: dict = {}):
        """
        TBA
        """
        self._parameters = copy.deepcopy(self.DEFAULT_PARAMETERS)
        self._parameters.update(parameters)
        self._random = Random(x=self._parameters['seed'])
        if isinstance(self._parameters['seed'], numbers.Number):
            npseed(self._parameters['seed'])
        map = Map(self._parameters['map'], self._parameters['P_task_appears'])
        # use "set" to get rid of weird wrappers
        # if set(self._parameters['P_action_succeed'].keys()) != set(FactoryFloor.ACTIONS.values()):
        #    raise ValueError("P_action_succeed must contain values for all actions")

        robots = []
        tasks = []
        self._state = FactoryFloorState(robots, tasks, map)

        # TODO: remove code duplication
        for item in self._parameters['robots']:
            pos = item['pos']
            robotId = item['id']
            if isinstance(pos, list):
                if len(pos) != 2:
                    raise ValueError(
                        "position vector must be length 2 but got " + str(pos))
                robot = FactoryFloorRobot(robotId, array(pos))
            elif pos == 'random':
                robot = FactoryFloorRobot(robotId, self._getFreeMapPosition())
            else:
                raise ValueError(
                    "Unknown robot position, expected list but got " +
                    str(type(pos)))
            self._state.addRobot(robot)
        for pos in self._parameters['tasks']:
            if isinstance(pos, list):
                if len(pos) != 2:
                    raise ValueError(
                        "position vector must be length 2 but got " + str(pos))
                task = FactoryFloorTask(array(pos))
            elif pos == 'random':
                task = FactoryFloorTask(self._getFreeMapPosition())
            else:
                raise ValueError(
                    "Unknown task position, expected list but got " +
                    str(type(pos)))
            self._state.addTask(task)

        if not USE_PossibleActionsSpace:
            self._actSpace = spaces.Dict({
                robot.getId(): spaces.Discrete(len(self.ACTIONS))
                for robot in self._state.robots
            })
            seed = self._random.randint(0, 10 * len(self._state.robots))
            self._actSpace.seed(seed)
Ejemplo n.º 6
0
def simulation_parameters(total, delta_t, s):
    seed(s)
    npseed(s)
    r_p = {i: poisson(15) for i in range(total)}  # El tiempo de recuperacion
    c_p = {i: min(r_p[i], negative_binomial(6, 0.5))
           for i in range(total)}  # Tiempo en que se da cuenta
    contagios = {
        t: {i: random()
            for i in range(total)}
        for t in range(delta_t + 1)
    }

    return r_p, c_p, contagios
Ejemplo n.º 7
0
 def __init__(self, password):
     password += "yozh"
     if len(password.encode('utf-8')) - 4 < 8:
         for i in range(1, 8 - len(password) + 4 + 1):
             password += str(i)
     passbits = bitarray(endian='big')
     passbits.frombytes(password.encode('utf-8'))
     shuffled_bits = [int(i) for i in str(passbits)[10:-2]]
     npseed(int.from_bytes(passbits[::2][:32].tobytes(), byteorder='big'))
     npshuffle(shuffled_bits)
     self.mainseed = bitarray(shuffled_bits)
     self.seedsz = 32
     self.newseed(0, 4, 4)
     self.minval = -2**63
     self.maxval = 2**63
Ejemplo n.º 8
0
def test_optimisation(suppliers_allcards, all_ensembles_dict, fitness_list):
    #setup cost
    cost_calculator = t.CostCalculator(suppliers_allcards, all_ensembles_dict)
    bounds = np.array(cost_calculator.ensemble_sizes) - 1
    cost_func = lambda p: sum(cost_calculator.get_cost(p))
    #setup random seeds
    npseed(1)
    rdseed(1)

    model = ga(cost_func, bounds, N=1000)

    fitness_list2 = []
    num_iterations = 10
    for i in range(num_iterations):
        #Update
        f = next(model)
        #get fitness values
        fitness_list2.append(f[0])
        #Output
        print('\r(%d/%d) ' % (i + 1, num_iterations), end='')
        print('top ensemble fitness: %1.1f   ' % f[0], end='')

    assert (fitness_list2 == fitness_list)
Ejemplo n.º 9
0
def main():
    args = parse_arguments()
    #  print(args)

    # setup seed value
    if args.seed == -1:
        myseed = 1
        myseed = int(timer() * 1e9 % 2**32)
    else:
        myseed = args.seed
    seed(myseed)
    npseed(myseed)

    path_input = args.input_image
    path_output = args.output_image

    print(
        f"python3 line_drawer_main.py -s {myseed} -i {path_input} -o {path_output}"
    )

    #  test_shading(path_input, path_output)
    #  test_pins_line(path_input, path_output)
    #  test_loss_experiment(path_input, path_output)
    test_benchmark_looping_line(path_input, path_output)
 def seed(self, seed):
     self._parameters['seed'] = seed
     if isinstance(self._parameters['seed'], numbers.Number):
         npseed(self._parameters['seed'])
     random.seed(seed)
Ejemplo n.º 11
0
 def set_seed(self, value=None):
     npseed(value)
Ejemplo n.º 12
0
        res_rejection = estimate_patterns_by_rejection(patterns, mallows)
        print('MIS-AMP1:', res, '\nrejection:', res_rejection)
        break


def test_4_labels(pid=2):
    from inference.sampling.utils import get_test_case_of_patterns_from_synthetic_4_labels

    patterns, mallows, p_exact = get_test_case_of_patterns_from_synthetic_4_labels(pid)
    print(f'p_exact = {p_exact}')

    verbose = True
    res = estimate_patterns_by_misamp1(mallows=mallows, patterns=patterns, k=1000, verbose=verbose)
    print(res)
    res = estimate_patterns_by_misamp1(mallows=mallows, patterns=patterns, k=100, verbose=verbose)
    print(res)
    res = estimate_patterns_by_misamp1(mallows=mallows, patterns=patterns, k=10, verbose=verbose)
    print(res)
    res = estimate_patterns_by_misamp1(mallows=mallows, patterns=patterns, k=3, verbose=verbose)
    print(res)
    print(f'p_exact = {p_exact}')


if __name__ == '__main__':
    from random import seed
    from numpy.random import seed as npseed

    seed(0)
    npseed(0)
    test_4_labels(10)
Ejemplo n.º 13
0
from sys import argv

busy = argv[4] if len(argv) > 4 else "5"
path = "fuzzme/fuzzme_busy%s_read" % busy
num_gens = int(argv[2] if len(argv) > 2 else 30)

ind = int(argv[1])
seed = int(argv[3] if len(argv) > 3 else 1)
fuzzerlist = [ForkFuzzer, NaiveFuzzer, NaiveFuzzerForkever, FuzzerForkserver]
to_test = fuzzerlist[ind]

log_file = open(
    "fuzzme/results_%s/results%s-seed%d-DOSYS%d--%s" %
    (busy, str(to_test)[6:], seed, DO_SYSCALL, random.randint(0, 9999)), "a")
out_file = open("/dev/null", "w")

for num_gens in [num_gens + 1]:  #range(30,90,5):
    random.seed(seed)
    npseed(seed)

    with redirect_stdout(out_file):
        try:
            result = time_fuzzer(to_test, path, num_gens)
        except OSError as e:
            log_file.close()
            raise e

    #print(str(to_test),"num_gens = %d" % num_gens, result[0][0], result[1], "seed = %d" % seed, "DO_SYSCALL = %d" % DO_SYSCALL, file=log_file)
    os.closerange(out_file.fileno() + 1, soft_filelimit)