Пример #1
0
metricList = [Metric.Energy, Metric.Consensus]

state = '$r_{stable}$'
c_len = 'length'
data = {c_len: [], state: [], 'fct': []}
for metric in metricList:
    data[metric.name] = []
conf = create_config(c_type, n=args.n)

states = states_per_magnet(size, 0.0)
conf.set_states(states)
for i, p in enumerate(r_factor):
    rules = rules_per_ratio(size, p)
    conf.set_rules(rules)
    evol, metrics = evolve(config=conf,
                           perm=pi,
                           steps=args.steps,
                           metricList=metricList,
                           cycleBreak=True)
    data[c_len].append(cycle_length(evol)[0])
    rstab = p / (size - p) if size != p else np.inf
    data[state].append(rstab)
    data['fct'].append(p)
    for e in metrics:
        data[e.name].append(metrics[e][-1])

datum = pd.DataFrame(data)

csv = datum.to_csv(encoding='utf-8', index=False)
print(csv)
Пример #2
0
for i, mag in enumerate(magnetList):
    init_states = [State.ON] * round((size * (0.5 + mag / 2)) - 10**
                                     (-9)) + [State.OFF] * round(
                                         (size * (0.5 - mag / 2) + 10**(-9)))
    rng.shuffle(init_states)
    init_rule = np.array([Rule.STABLE] * size)
    curr_rule = init_rule
    conf.set_rules(init_rule)
    conf.set_states(init_states)
    curr_magnet = mag
    stables = [0]
    while curr_magnet < 1 and stables != []:
        array, out = evolve(conf,
                            perm=pi,
                            steps=args.steps,
                            metricList=metricList,
                            cycleBreak=True)
        curr_energy = out[Metric.Energy][-1]
        curr_magnet = out[Metric.Consensus][-1]
        length, start = cycle_length(array)

        stables = [k for k in range(size) if curr_rule[k] == Rule.STABLE]
        agree['init_magnet'].append(mag)
        agree['length'].append(length)
        agree['Magnetization_mean'].append(curr_magnet)
        agree['Magnetization_std'].append(
            np.std(consensus(array[start:start + length])))
        agree['Magnetization_min'].append(
            np.min(consensus(array[start:start + length])))
        agree['Magnetization_max'].append(