<commit_before>#!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""
Checking the implementation of MLP
Data in points along two logarithmic spirals
@author: avaldes
"""

from __future__ import division, print_function

import numpy as np
import matplotlib.pyplot as plt
import time

from mlp import MLP

# create data

nb_black = 100
nb_red = 100
nb_data = nb_black + nb_red

s = np.linspace(0, 4*np.pi, nb_black)

x_black = np.vstack([np.log(1 + s) * np.cos(s),
                     np.log(1 + s) * np.sin(s)]).T
x_red = np.vstack([-np.log(1 + s) * np.cos(s),
                   -np.log(1 + s) * np.sin(s)]).T

x_data = np.vstack((x_black, x_red))

t_data = np.asarray([0]*nb_black + [1]*nb_red).reshape(nb_data, 1)


#  Net structure

D = x_data.shape[1]  # initial dimension
K = 1  # final dimension

#  You must find the best MLP structure in order to
#  misclassify as few points as possible. Training time will be
#  measured too.
#  You can use at most 3000 weights and 2000 epochs.
#  For example:

K_list = [D, 10, 10, K]  # list of dimensions of layers

activation_functions = [MLP.sigmoid,
                        MLP.sigmoid,
                        MLP.sigmoid]

diff_activation_functions = [MLP.dsigmoid,
                             MLP.dsigmoid,
                             MLP.dsigmoid]

# network training

time_begin = time.time()

mlp = MLP(K_list,
          activation_functions, diff_activation_functions)

mlp.train(x_data, t_data,
          epochs=1000, batch_size=10,
          epsilon=0.1,
          print_cost=True)

time_end = time.time()

print('Time used in training %f' % (time_end - time_begin))


# check if circles nearby the middle one are
# correctly classified
<commit_msg>Mejora en la espiral<commit_after>#!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""
Checking the implementation of MLP
Data in points along two logarithmic spirals
@author: avaldes
"""

from __future__ import division, print_function

import numpy as np
import matplotlib.pyplot as plt
import time

from mlp import MLP

# create data

nb_black = 100
nb_red = 100
nb_data = nb_black + nb_red

s = np.linspace(0, 4*np.pi, nb_black)

x_black = np.vstack([np.log(1 + s) * np.cos(s),
                     np.log(1 + s) * np.sin(s)]).T
x_red = np.vstack([-np.log(1 + s) * np.cos(s),
                   -np.log(1 + s) * np.sin(s)]).T

x_data = np.vstack((x_black, x_red))

t_data = np.asarray([0]*nb_black + [1]*nb_red).reshape(nb_data, 1)


#  Net structure

D = x_data.shape[1]  # initial dimension
K = 1  # final dimension

#  You must find the best MLP structure in order to
#  misclassify as few points as possible. Training time will be
#  measured too.
#  You can use at most 3000 weights and 2000 epochs.
#  For example:

K_list = [D, 10, 10, 10, 10, K]  # list of dimensions of layers

activation_functions = [np.tanh,
                        np.tanh,
                        np.tanh,
                        np.tanh,
                        np.tanh]

diff_activation_functions = [MLP.dtanh,
                             MLP.dtanh,
                             MLP.dtanh,
                             MLP.dtanh,
                             MLP.dtanh]

# network training

time_begin = time.time()

mlp = MLP(K_list,
          activation_functions, diff_activation_functions)

mlp.train(x_data, t_data,
          epochs=1000, batch_size=10,
          epsilon=0.1,
          beta = 0.001,
          print_cost=True)

time_end = time.time()

print('Time used in training %f' % (time_end - time_begin))


# check if circles nearby the middle one are
# correctly classified

{'fraction_non_alphanumeric': 0.10971524288107203, 'fraction_numerical': 0.02400893355667225, 'mean_word_length': 2.311460258780037, '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': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6870933', 'n_tokens_mistral': 1331, 'n_tokens_neox': 1245, 'n_words': 343}