<commit_before>import numpy as np
import scipy.sparse as sp
from scipy.optimize import fmin_l_bfgs_b

from Orange import classification


def sigmoid(x):
    return 1.0 / (1.0 + np.exp(-x))


class MLPLearner(classification.Fitter):
    def __init__(self, layers, lambda_=1.0, dropout=None, **opt_args):
        if dropout is None:
            dropout = [0] * (len(layers) - 1)
        assert len(dropout) == len(layers) - 1

        self.layers = layers
        self.lambda_ = lambda_
        self.dropout = dropout
        self.opt_args = opt_args

    def unfold_params(self, params):
        T, b = [], []<commit_msg>Document neural networks. Closes #27<commit_after>import numpy as np
import scipy.sparse as sp
from scipy.optimize import fmin_l_bfgs_b

from Orange import classification


def sigmoid(x):
    return 1.0 / (1.0 + np.exp(-x))


class MLPLearner(classification.Fitter):
    def __init__(self, layers, lambda_=1.0, dropout=None, **opt_args):
        '''Multilayer perceptron (A.K.A. feedforward neural network)

        This model uses stochastic gradient descent and the
        backpropagation algorithm to train the weights of a feedforward
        neural network.  The network uses the sigmoid activation
        functions, except for the last layer which computes the softmax
        activation function. The network can be used for binary and
        multiclass classification. Stochastic gradient descent minimizes
        the L2 regularize categorical crossentropy cost function. The
        topology of the network can be customized by setting the layers
        attribute. When using this model you should:

        - Choose a suitable:
            * topology (layers)
            * regularization parameter (lambda_)
            * dropout (values of 0.2 for the input layer and 0.5 for the hidden layers
              usually work well)
            * The number of epochs of stochastic gradient descent (num_epochs)
            * The learning rate of stochastic gradient descent (learning_rate)
        - Continuize all discrete attributes
        - Transform the dataset so that the columns are on a similar scale

        :param layers: The topology of the network. A network with 
        layer=[10, 100, 100, 3] has two hidden layers with 100 neurons each, 10 features
        and a class value with 3 distinct values.
        :type layers: list

        :param lambda_: the regularization parameter. Higher values of lambda_
        force the coefficients to be small.
        :type lambda_: float

        :param dropout: The dropout rate for each, but the last,
        layer. The list should have one element less then the parameter layers.
        Values of 0.2 for the input layer and 0.5 for the hidden layers usually
        work well.
        :type dropout: list

        :param num_epochs: The number of epochs of stochastic gradient descent
        :type num_epochs: int

        :param learning_rate: The learning rate of stochastic gradient descent
        :type learning_rate: float

        :param batch_size: The batch size of stochastic gradient descent
        :type batch_size: int
        '''

        if dropout is None:
            dropout = [0] * (len(layers) - 1)
        assert len(dropout) == len(layers) - 1

        self.layers = layers
        self.lambda_ = lambda_
        self.dropout = dropout
        self.opt_args = opt_args

    def unfold_params(self, params):
        T, b = [], []
{'fraction_non_alphanumeric': 0.06460023174971032, 'fraction_numerical': 0.012746234067207415, 'mean_word_length': 2.487878787878788, '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': '2106014', 'n_tokens_mistral': 978, 'n_tokens_neox': 904, 'n_words': 386}