Esempio n. 1
0
def create_cluster_from_neuralgasnetwork(model: model,
                                         a=0.5,
                                         passes=80,
                                         distance_toremove_edge=8):
    data = model.mesures().values
    model.setname("NEURALGAS avec distance_toremove=" +
                  str(distance_toremove_edge) + " passes=" + str(passes))

    if not model.load_cluster():
        model.start_treatment()
        gng = GrowingNeuralGas(data)
        gng.fit_network(e_b=0.05,
                        e_n=0.006,
                        distance_toremove_edge=distance_toremove_edge,
                        l=100,
                        a=0.5,
                        d=0.995,
                        passes=passes,
                        plot_evolution=False)
        model.end_treatment()
        print('Found %d clusters.' % gng.number_of_clusters())
        model.clusters_from_real(gng.cluster_data(), "NEURALGAS_")

    #gng.plot_clusters(gng.cluster_data())
    return model
Esempio n. 2
0
    values = normalize(values).values

    # returning values
    return values

if __name__ == '__main__':
    if os.path.exists('visualization/sequence'):
        shutil.rmtree('visualization/sequence')
        
    os.makedirs('visualization/sequence')
    n_samples = 1500

    data = None
    #data = dataset() # in case the user wants to use a specific dataset
    #data = datasets.load_breast_cancer()
    
    #data = datasets.load_iris(n_samples=n_samples, random_state=8)
    #data = datasets.make_blobs(n_samples=n_samples, random_state=8)
    data = datasets.make_moons(n_samples=n_samples, noise=.05)
    #data = datasets.make_circles(n_samples=n_samples, factor=.5, noise=.05)

    #data = StandardScaler().fit_transform(data.data) # depends on the data variable
    data = StandardScaler().fit_transform(data[0]) # depends on the data variable
    
    print('Done.')
    print('Fitting neural network...')
    gng = GrowingNeuralGas(data)
    gng.fit_network(e_b=0.1, e_n=0.006, a_max=10, l=200, a=0.5, d=0.995, passes=5, plot_evolution=True)
    
    print('Found %d clusters.' % gng.number_of_clusters())
    gng.plot_clusters(gng.cluster_data())
Esempio n. 3
0
from gng import GrowingNeuralGas
from sklearn import datasets
from sklearn.preprocessing import StandardScaler
import os
import shutil

__authors__ = 'Adrien Guille'
__email__ = '*****@*****.**'

if __name__ == '__main__':
    if os.path.exists('visualization/sequence'):
        shutil.rmtree('visualization/sequence')
    os.makedirs('visualization/sequence')
    n_samples = 2000
    dataset_type = 'moons'
    data = None
    print('Preparing data...')
    if dataset_type == 'blobs':
        data = datasets.make_blobs(n_samples=n_samples, random_state=8)
    elif dataset_type == 'moons':
        data = datasets.make_moons(n_samples=n_samples, noise=.05)
    elif dataset_type == 'circles':
        data = datasets.make_circles(n_samples=n_samples, factor=.5, noise=.05)
    data = StandardScaler().fit_transform(data[0])
    print('Done.')
    print('Fitting neural network...')
    gng = GrowingNeuralGas(data)
    gng.fit_network(e_b=0.1, e_n=0.006, a_max=10, l=200, a=0.5, d=0.995, passes=8, plot_evolution=True)
    print('Found %d clusters.' % gng.number_of_clusters())
    gng.plot_clusters(gng.cluster_data())