GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — DeepLearning/python/MLP.py at master · cdingding/DeepLearning Expand file tree/ Copy pathMLP.pyMore file actions executable file ·81 lines (55 loc) · 2 KB / Copy pathMLP.pyFile metadata and controlsexecutable file ·81 lines (55 loc) · 2 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 # -*- coding: utf-8 -*- import sys import numpy from HiddenLayer import HiddenLayer from LogisticRegression import LogisticRegression from utils import * class MLP(object): def __init__(self, input, label, n_in, n_hidden, n_out, rng=None): self.x = input self.y = label if rng is None: rng = numpy.random.RandomState(1234) # construct hidden_layer self.hidden_layer = HiddenLayer(input=self.x, n_in=n_in, n_out=n_hidden, rng=rng, activation=tanh) # construct log_layer self.log_layer = LogisticRegression(input=self.hidden_layer.output, label=self.y, n_in=n_hidden, n_out=n_out) def train(self): # forward hidden_layer layer_input = self.hidden_layer.forward() # forward & backward log_layer # self.log_layer.forward(input=layer_input) self.log_layer.train(input=layer_input) # backward hidden_layer self.hidden_layer.backward(prev_layer=self.log_layer) # backward log_layer # self.log_layer.backward() def predict(self, x): x = self.hidden_layer.output(input=x) return self.log_layer.predict(x) def test_mlp(n_epochs=5000): x = numpy.array([[0, 0], [0, 1], [1, 0], [1, 1]]) y = numpy.array([[0, 1], [1, 0], [1, 0], [0, 1]]) rng = numpy.random.RandomState(123) # construct MLP classifier = MLP(input=x, label=y, n_in=2, n_hidden=3, n_out=2, rng=rng) # train for epoch in xrange(n_epochs): classifier.train() # test print classifier.predict(x) if __name__ == "__main__": test_mlp() |
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |