neurali:pybrain_costruire_una_rete
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | |||
neurali:pybrain_costruire_una_rete [2015/07/05 18:56] – profpro | neurali:pybrain_costruire_una_rete [2020/06/08 22:20] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ======Costruire una rete====== | ||
+ | In questo tutorial vengono utilizzate delle funzioni matematiche python, come: | ||
+ | * numpy.random.multivariate_normal (funzione gaussiana) | ||
+ | * numpy.diag | ||
+ | * permette di costruire un' | ||
+ | * range | ||
+ | * For example, range(4) returns [0, 1, 2, 3]. | ||
+ | * xrange | ||
+ | * Like range(), but instead of returning a list, returns an object that generates the numbers in the range on demand | ||
+ | * numpy.arange | ||
+ | * Like range(), but instead of returning a list, returns an ndarray | ||
+ | |||
+ | ======classe FeedForwardNetwork====== | ||
+ | |||
+ | - creare la rete (costruttore) | ||
+ | - creare i layer (costruttore specificando: | ||
+ | - aggiungere i //moduli// alla rete a partire dai layer (segnando quali sono di input o di output) | ||
+ | - creare le connessioni tra percettroni i diversi moduli (esempio: [[neurali: | ||
+ | - aggiungere le // | ||
+ | - ordinare i moduli | ||
+ | - (i pesi sono inizialmente posti random?) | ||
+ | - attivazione (fornisci un input, ottieni un output) | ||
+ | |||
+ | Tutti i seguenti hanno nome iniziale maiuscola: sono costruttori: | ||
+ | - FeedForwardNetwork | ||
+ | - LinearLayer (vedere perché usare [[neurali: | ||
+ | - SigmoidLayer ((vedere perché usare [[neurali: | ||
+ | - FullConnection | ||
+ | |||
+ | <code python> | ||
+ | import pybrain.structure | ||
+ | n = pybrain.structure.FeedForwardNetwork() | ||
+ | |||
+ | layerInput = pybrain.structure.LinearLayer(2) | ||
+ | layerNasocosto = pybrain.structure.SigmoidLayer(3) | ||
+ | layerOutput = pybrain.structure.LinearLayer(1) | ||
+ | </ | ||
+ | |||
+ | {{ : | ||
+ | |||
+ | In alternativa, | ||
+ | layerInput = pybrain.structure.LinearLayer(2), | ||
+ | |||
+ | <code python> | ||
+ | n.addInputModule(layerInput) | ||
+ | n.addModule(layerNascosto) | ||
+ | n.addOutputModule(layerOutput) | ||
+ | | ||
+ | |||
+ | in_to_hidden = pybrain.structure.connections.full.FullConnection(layerInput, | ||
+ | hidden_to_out = pybrain.structure.connections.full.FullConnection(layerNascosto, | ||
+ | |||
+ | |||
+ | n.addConnection(in_to_hidden) | ||
+ | n.addConnection(hidden_to_out) | ||
+ | |||
+ | n.sortModules() | ||
+ | </ | ||
+ | | ||
+ | | ||
+ | {{ : | ||
+ | |||
+ | <code python> | ||
+ | print n # stampa i _nomi_ degli elementi, che non sono stati definiti, quindi sono random | ||
+ | </ | ||
+ | | ||
+ | Output | ||
+ | |||
+ | < | ||
+ | FeedForwardNetwork-6 | ||
+ | | ||
+ | [< | ||
+ | < | ||
+ | < | ||
+ | | ||
+ | [< | ||
+ | < | ||
+ | </ | ||
+ | |||
+ | |||
+ | In alternativa esiste una funzione scorciatoia | ||
+ | import buildNetwork | ||
+ | net = buildNetwork(2, | ||
+ | |||
+ | |||
+ | Questa istruzione esegue la funzione di rete fornendo in input la coppia (1,2) | ||
+ | |||
+ | <code python> | ||
+ | print n.activate([1, | ||
+ | </ | ||
+ | |||
+ | L' | ||
+ | |||
+ | <code python> | ||
+ | print n.params | ||
+ | </ | ||
+ | |||
+ | {{ : | ||
+ | |||
+ | Esempio di output dei due precedenti comandi | ||
+ | |||
+ | <code python> | ||
+ | [-2.3085972] | ||
+ | |||
+ | [-0.62274409 | ||
+ | | ||
+ | | ||
+ | 1.00736063 | ||
+ | | ||
+ | 1.06840813 | ||
+ | | ||
+ | | ||
+ | | ||
+ | </ | ||
+ | |||
+ | <code python> | ||
+ | print in_to_hidden.params # mostra solo i pesi delle prime 6 connessioni | ||
+ | </ | ||
+ | |||
+ | <code python> | ||
+ | |||
+ | </ |
neurali/pybrain_costruire_una_rete.txt · Last modified: 2020/06/08 22:20 by 127.0.0.1