<commit_before>import itertools
import random
import math


def simulated_annealing_simple(h, J, steps=5000):

    nodes = list(h.keys())

    energies = {}

    def ising_energy(s):
        key = tuple(s[n] for n in nodes)

        if key in energies:
            return energies[key]

        en = 0

        for v in h:
            en += s[v] * h[v]

        for v0, v1 in J:
            en += s[v0] * s[v1] * J[(v0, v1)]

        energies[key] = en

        return en

    s = {v: bias > 0 and -1 or 1 for v, bias in h.items()}
    energy = ising_energy(s)

    for k in range(1, steps):
        T = float(k) / steps

        sp = neighbor(s)
        energy_p = ising_energy(sp)

        if accept(energy, energy_p, T):
            s = sp
            energy = energy_p

    return s


def accept(en, enp, T):
    if enp < en:<commit_msg>nothing works, everything is broken<commit_after>import itertools
import random
import math


def simulated_annealing_simple(h, J, steps=5000):

    nodes = list(h.keys())

    energies = {}

    def energy_difference(s0, s1):
        diff = 0

        for v in h:
            if s0[v] > s1[v]:
                diff -= h[v]
            elif s0[v] < s1[v]:
                diff += h[v]

        for v0, v1 in J:
            if s0[v0] != s1[v0] or s0[v1] != v1[v1]:
                diff += J[(v0, v1)] * (s0[v0] * s0[v1] - s1[v0] * s1[v1])

        return diff

    s = {v: bias > 0 and -1 or 1 for v, bias in h.items()}
    energy = ising_energy(s)

    for k in range(1, steps):
        T = float(k) / steps

        sp = neighbor(s)
        energy_p = ising_energy(sp)

        if accept(diff, 0, T):
            s = sp
            energy = energy_p

    return s


def accept(en, enp, T):
    if enp < en:
{'fraction_non_alphanumeric': 0.12528604118993136, 'fraction_numerical': 0.02917620137299771, 'mean_word_length': 1.6261261261261262, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1442824', 'n_tokens_mistral': 671, 'n_tokens_neox': 631, 'n_words': 193}