<commit_before>#!/usr/bin/env python
#-*-coding:utf-8-*-

import numpy as np


class PassiveAggressive:
    def __init__(self, feat_dim):
        self.t = 0
        self.w = np.ones(feat_dim)

    def train(self, y_vec, feats_vec):
        for i in range(len(y_vec)):
            self.update(y_vec[i], feats_vec[i,])

    def predict(self, feats):
        return np.dot(self.w, feats)

    def update(self, y, feats):
        l = max([0, 1-y*np.dot(self.w, feats)])
        eta = l/np.dot(feats, feats)
        self.w += eta*y*feats
        self.t += 1
        return 1 if l == 0 else 0
<commit_msg>change eta derivation process to static method<commit_after>#!/usr/bin/env python
#-*-coding:utf-8-*-

import numpy as np


class PassiveAggressive:
    def __init__(self, feat_dim):
        self.t = 0
        self.w = np.ones(feat_dim)

    @staticmethod
    def _get_eta(l, feats):
        return l/np.dot(feats, feats)

    def train(self, y_vec, feats_vec):
        for i in range(len(y_vec)):
            self.update(y_vec[i], feats_vec[i,])

    def predict(self, feats):
        return np.dot(self.w, feats)

    def update(self, y, feats):
        l = max([0, 1-y*np.dot(self.w, feats)])
        eta = self._get_eta(l, feats)
        self.w += eta*y*feats
        self.t += 1
        return 1 if l == 0 else 0

{'fraction_non_alphanumeric': 0.14502657555049356, 'fraction_numerical': 0.012148823082763858, 'mean_word_length': 2.230392156862745, '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': '7019443', 'n_tokens_mistral': 532, 'n_tokens_neox': 499, 'n_words': 121}