<commit_before>import numpy as np
import matplotlib.pyplot as plt

from latent_crf import LatentGridCRF
from latent_structured_svm import StupidLatentSVM

import toy_datasets as toy

from IPython.core.debugger import Tracer
tracer = Tracer()


def main():
    X, Y = toy.generate_crosses_latent(n_samples=50, noise=10)
    n_labels = 2
    crf = LatentGridCRF(n_labels=n_labels, n_states_per_label=2,
                        inference_method='dai')
    clf = StupidLatentSVM(problem=crf, max_iter=100, C=10 ** 8, verbose=2,
            check_constraints=True, n_jobs=12)
    clf.fit(X, Y)
    Y_pred = clf.predict(X)

    i = 0
    loss = 0
    tracer()
    for x, y, y_pred in zip(X, Y, Y_pred):
        y_pred = y_pred.reshape(x.shape[:2])
        loss += np.sum(y / 2 != y_pred / 2)
        if i > 20:
            continue
        plt.subplot(131)<commit_msg>works! (c=10000 is enough and allows for stable optimization)<commit_after>import numpy as np
import matplotlib.pyplot as plt

from latent_crf import LatentGridCRF
from latent_structured_svm import StupidLatentSVM

import toy_datasets as toy

from IPython.core.debugger import Tracer
tracer = Tracer()


def main():
    X, Y = toy.generate_crosses_latent(n_samples=25, noise=10)
    n_labels = 2
    crf = LatentGridCRF(n_labels=n_labels, n_states_per_label=2,
                        inference_method='dai')
    clf = StupidLatentSVM(problem=crf, max_iter=50, C=10000, verbose=2,
            check_constraints=True, n_jobs=12)
    #clf = StupidLatentSVM(problem=crf, max_iter=50, C=1, verbose=2,
            #check_constraints=True, n_jobs=12)
    clf.fit(X, Y)
    Y_pred = clf.predict(X)

    i = 0
    loss = 0
    for x, y, y_pred in zip(X, Y, Y_pred):
        y_pred = y_pred.reshape(x.shape[:2])
        loss += np.sum(y / 2 != y_pred / 2)
        if i > 20:
            continue
        plt.subplot(131)
{'fraction_non_alphanumeric': 0.10250934329951948, 'fraction_numerical': 0.03310197544046983, 'mean_word_length': 2.904166666666667, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '199375', 'n_tokens_mistral': 755, 'n_tokens_neox': 696, 'n_words': 162}