<commit_before>import numpy as np
from isotonic_regression import pav

def isotron(X, y, max_iter=100):
    n_samples, n_features = X.shape
    w = np.zeros(n_features)
    u = y.copy()
    for i in range(max_iter):
        idx = np.argsort(np.dot(X, w))
        u = pav(y[idx])
        w += (1. / n_samples) * np.sum((y[idx] - u) * X[idx].T, 1)
    order_inv = np.zeros(len(y), dtype=np.int)
    order_inv[idx] = np.arange(len(y))
    return w, u[order_inv]

if __name__ == '__main__':
    import pylab as pl
    n_samples = 300
    n_features = 25

    np.random.seed(0)
    rng = np.random.RandomState(42)
    w = np.abs(rng.randn(n_features))
    y_lin = 2 * np.random.rand(n_samples) - 1
    X = []
    y = []
    for i in range(n_samples):
        X.append(y_lin[i] * w + rng.rand(n_features))<commit_msg>docstring<commit_after>"""
The Isotron algorithm

Reference: "The Isotron Algorithm: High-Dimensional Isotonic Regression",
    <NAME>, <NAME>
"""

import numpy as np
from isotonic_regression import pav

def isotron(X, y, max_iter=100):
    """
    Parameters
    ----------
    X : array, shape (n_features, n_samples)
    y : array, shape (n_samples,)

    Returns
    -------
    w : coefficients of the model
    u : function u evaluated at Xw
    """
    n_samples, n_features = X.shape
    w = np.zeros(n_features)
    u = y.copy()
    for i in range(max_iter):
        idx = np.argsort(np.dot(X, w))
        u = pav(y[idx])
        w += (1. / n_samples) * np.sum((y[idx] - u) * X[idx].T, 1)
    order_inv = np.zeros(len(y), dtype=np.int)
    order_inv[idx] = np.arange(len(y))
    return w, u[order_inv]

if __name__ == '__main__':
    import pylab as pl
    n_samples = 300
    n_features = 25

    np.random.seed(0)
    rng = np.random.RandomState(42)
    w = np.abs(rng.randn(n_features))
    y_lin = 2 * np.random.rand(n_samples) - 1
    X = []
    y = []
    for i in range(n_samples):
        X.append(y_lin[i] * w + rng.rand(n_features))
{'fraction_non_alphanumeric': 0.15392456676860347, 'fraction_numerical': 0.01529051987767584, 'mean_word_length': 2.517921146953405, 'pattern_counts': {'":': 0, '<': 5, '<?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': '4897140', 'n_tokens_mistral': 807, 'n_tokens_neox': 769, 'n_words': 178}