<commit_before>import warnings
from theano import function, shared
from pylearn2.optimization import linear_cg as cg
from pylearn2.optimization import featuresign as fs
import numpy as N
import theano.tensor as T


class LocalCoordinateCoding(object):
    def __init__(self, nvis, nhid, coeff):
        self.nvis = nvis
        self.nhid = nhid
        self.coeff = float(coeff)
        self.rng = N.random.RandomState([1, 2, 3])

        self.redo_everything()

    def get_output_channels(self):
        return self.nhid

    def redo_everything(self):
        self.W = shared(self.rng.randn(self.nhid, self.nvis), name='W')
        self.W.T.name = 'W.T'

    def weights_format(self):
        return ['h', 'v']

    def optimize_gamma(self, example):

        #variable names chosen to follow the arguments to l1ls_featuresign

        Y = N.zeros((self.nvis, 1))
        Y[:, 0] = example
        c = (1e-10 + N.square(self.W.get_value(borrow=True) -
                              example).sum(axis=1))
        A = self.W.get_value(borrow=True).T / c
        x = fs.l1ls_featuresign(A, Y, self.coeff)[:, 0]
        g = x / c
        return g

    def learn(self, dataset, batch_size):<commit_msg>Modified LCC implementation to use new feature sign search code.<commit_after>import warnings
from theano import function, shared
from pylearn2.optimization import linear_cg as cg
from pylearn2.optimization.feature_sign import feature_sign_search
import numpy as N
import theano.tensor as T


class LocalCoordinateCoding(object):
    def __init__(self, nvis, nhid, coeff):
        self.nvis = nvis
        self.nhid = nhid
        self.coeff = float(coeff)
        self.rng = N.random.RandomState([1, 2, 3])

        self.redo_everything()

    def get_output_channels(self):
        return self.nhid

    def redo_everything(self):
        self.W = shared(self.rng.randn(self.nhid, self.nvis), name='W')
        self.W.T.name = 'W.T'

    def weights_format(self):
        return ['h', 'v']

    def optimize_gamma(self, example):

        #variable names chosen to follow the arguments to l1ls_featuresign

        Y = N.zeros((self.nvis,))
        Y[:] = example
        c = (1e-10 + N.square(self.W.get_value(borrow=True) -
                              example).sum(axis=1))
        A = self.W.get_value(borrow=True).T / c
        x = feature_sign_search(A, Y, self.coeff)
        g = x / c
        return g

    def learn(self, dataset, batch_size):
{'fraction_non_alphanumeric': 0.11079429735234216, 'fraction_numerical': 0.009775967413441956, 'mean_word_length': 2.468926553672316, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1549453', 'n_tokens_mistral': 837, 'n_tokens_neox': 807, 'n_words': 205}