<commit_before>#!/bin/python
# just for testing the large-margin classifier

from SCIRL.SCIRL import clf_large_margin
import numpy as np

# -- make features -- #
A = 3
S = 10
k = 7
# not very reasonable
features = np.random.normal(size=(A, S, k))         # |A| x |S| x k (duh)

# -- define clf -- #
clf = clf_large_margin(features)

# -- make data -- #
N = 100000
states = np.random.randint(low=0, high=S, size=N)
# fake some 'true' parameters
true_params = np.random.normal(size=k)
true_score_fn = np.dot(features, true_params)       # |A| x |S|
# use to predict labels
scores = true_score_fn[:, states]                   # |A| x N
labels = np.argmax(scores, axis=0)
# combine
data = np.vstack((states, labels)).transpose()

# -- fit ! -- #
clf.fit(data)

# --- compare true params --- #
print 'True objective:', clf.objective(data, lambd=0.5, params=true_params)
print 'Fitted objective:', clf.objective(data, lambd=0.5)
print 'True parameters:', true_params
print 'Fitted parameters:', clf.params<commit_msg>prettiness<commit_after>#!/bin/python
# just for testing the large-margin classifier

from SCIRL.SCIRL import clf_large_margin
import numpy as np

# -- make features -- #
A = 7
S = 10
k = 7
# not very reasonable
features = np.random.normal(size=(A, S, k))         # |A| x |S| x k (duh)

# -- define clf -- #
clf = clf_large_margin(features)
# -- make data -- #
N = 1000
states = np.random.randint(low=0, high=S, size=N)
# fake some 'true' parameters
true_params = np.random.normal(size=k)
true_score_fn = np.dot(features, true_params)       # |A| x |S|
# use to predict labels
scores = true_score_fn[:, states]                   # |A| x N
labels = np.argmax(scores, axis=0)
# combine
data = np.vstack((states, labels)).transpose()

# -- fit ! -- #
initial_objective = clf.objective(data)
clf.fit(data)

# --- compare true params --- #
print '\t\t\t\ttrue objective: %.3f' % clf.objective(data, lambd=0.5, params=true_params)
print 'initial objective: %.3f' % initial_objective, '===> fitted objective: %.3f' % clf.objective(data, lambd=0.5)
print '\nParameters:'
print 'True\tFitted'
for i in xrange(k):
    print '%+.3f' % true_params[i],'\t%+.3f' % clf.params[i]
{'fraction_non_alphanumeric': 0.16413793103448276, 'fraction_numerical': 0.016091954022988506, 'mean_word_length': 3.5523012552301254, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '5239921', 'n_tokens_mistral': 834, 'n_tokens_neox': 801, 'n_words': 213}