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( np.max(consensus(array[start:start + length]))) agree['SpinGlass'].append(curr_energy) agree['unstables'].append(size - len(stables)) # Choose a random stable node to change rule
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)
both = np.concatenate((inactive, active)) array[t] = order_update(array[t - 1].copy(), config, both, rules) magn = metrics[Metric.Consensus](array[t], config, single=1) t += 1 last = -1 if t > args.steps else t - 1 for metric in metricList: out[metric.name].append(metrics[metric](array[last], config, single=1)) out[le].append(0) out['order'].append('off_first') out['init_magnet'].append(mag) out['init_stab'].append(stab) # Now random order evol, vals = evolve(config=config, steps=args.steps, perm=pi, metricList=metricList, cycleBreak=True) length, start = cycle_length(evol) out[le].append(length) for metric in metricList: out[metric.name].append(vals[metric][-1]) out['order'].append('random') out['init_magnet'].append(mag) out['init_stab'].append(stab) df = pd.DataFrame(out) csv = df.to_csv(encoding='utf-8', index=False) print(csv)