本文整理汇总了Python中NeuralNetwork.NeuralNetwork类的典型用法代码示例。如果您正苦于以下问题:Python NeuralNetwork类的具体用法?Python NeuralNetwork怎么用?Python NeuralNetwork使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了NeuralNetwork类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: createLocalizationNetwork
def createLocalizationNetwork(self):
if self.localizationType == "Rotary":
return RotaryLayer()
if self.localizationType == "Scaled":
return ScaledLayer()
if self.localizationType == "ScaledUp":
return ScaledUpLayer()
if self.localizationType == "ScaledWithOffset":
return ScaledWithOffsetLayer()
if self.localizationType == "Unitary":
return UnitaryLayer()
if self.localizationType == "FullyConnected":
network = NeuralNetwork()
network.addLayer(FullyConnectedLayer(self.inputW * self.inputH * self.inputC, 32, 0, "ReLu"))
network.addLayer(FullyConnectedLayer(32, 3*4, 1, "ReLu"))
return network
if self.localizationType == "ConvLayer":
network = NeuralNetwork()
network.addLayer(ConvLayer((self.inputW, self.inputH, self.inputC), (3, 3, self.inputC, self.inputC), 0, "ReLu"))
network.addLayer(FullyConnectedLayer(self.inputW * self.inputH * self.inputC, 3*4, 1, "ReLu"))
return network
开发者ID:sudnya,项目名称:misc,代码行数:28,代码来源:SpatialTransformerLayer.py
示例2: run_iris_comparison
def run_iris_comparison(num=25):
""" Compare a few different test and
training configurations
"""
print("Running neural network {} times each for three different sets of training and testing files".format(num))
test_files = ['iris_tes.txt', 'iris_tes50.txt',\
'iris_tes30.txt']
train_files = ['iris_tra.txt', 'iris_tra100.txt',\
'iris_tra120.txt']
for i in range(0, len(test_files)):
print("trainfile = {} testfile = {}".format(train_files[i], test_files[i]))
config_obj = openJsonConfig('conf/annconfig_iris.json')
summary = {}
for i in range(0, len(test_files)):
config_obj['testing_file'] = test_files[i]
config_obj['training_file'] = train_files[i]
config_obj['plot_error'] = False
config_obj['test'] = False
crates = []
for j in range(0, num):
nn = NeuralNetwork(config_obj)
nn.back_propagation()
cmat, crate, cout = nn.classification_test(nn.testing_data, nn.weights_best)
crates.append(crate)
summary[config_obj['testing_file']] =\
nn_stats(np.array(crates))
print print_stat_summary(summary)
开发者ID:beparadox,项目名称:neural_networks,代码行数:31,代码来源:runNN.py
示例3: test
def test(base_directory, ignore_word_file, filtered, nb_hidden_neurons, nb_max_iteration):
print("post reading...")
pr = PostReader(base_directory, ignore_word_file, filtered)
print("creating neural network...")
nn = NeuralNetwork(pr.get_word_set(), nb_hidden_neurons, nb_max_iteration)
print("training...")
training_set = pr.get_training_set()
t0 = time.clock()
nb_iteration = nn.train(training_set)
training_time = time.clock() - t0
print("verification...")
t0 = time.clock()
verification_set = pr.get_verification_set()
verification_time = time.clock() - t0
nb_correct = 0
for msg in verification_set:
final = NeuralNetwork.threshold(nn.classify(msg[0]))
if final == msg[1]:
nb_correct += 1
print("=======================")
print("training set length : %s" % len(training_set))
print("nb hidden neurons : %s" % nb_hidden_neurons)
print("nb max iterations : %s" % nb_max_iteration)
print("nb iterations : %s" % nb_iteration)
print("verification set length: %s posts" % len(verification_set))
print("nb correct classified : %s posts" % nb_correct)
print("rate : %i %%" % (nb_correct / len(verification_set) * 100))
print("training time : %i s" % training_time)
print("verification time : %i s" % verification_time)
print("=======================")
print("")
开发者ID:maeberli,项目名称:ClassificationPosts,代码行数:35,代码来源:ClassificationPosts.py
示例4: accuracy
def accuracy(self, number_layers, numbers_neurons, learning_rate):
"""Returns the accuracy of a neural network associated with an Individual"""
net = NeuralNetwork(number_layers, numbers_neurons, learning_rate, X_train=self.dataset.X_train, Y_train=self.dataset.Y_train, X_test=self.dataset.X_test, Y_test=self.dataset.Y_test)
#train neural NeuralNetwork
net.train()
#calcule accurate
acc = net.classify()
#set AUC
self.__auc = net.get_auc()
return acc
开发者ID:victorddiniz,项目名称:DecodingBrainSignalsProject,代码行数:10,代码来源:Individual.py
示例5: main
def main():
data = np.array([[1.0, 0.0, 0.0, 0.0, 0.0],
[0.0, 1.0, 0.0, 0.0, 0.0]
])
result = np.array([[0.0, 0.0, 0.0, 0.0, 1.0],
[0.0, 0.0, 0.0, 1.0, 0.0]
])
Nn = NeuralNetwork([5, 5, 5])
print Nn.feedforward(np.array([[5], [5], [5], [5], [5]]))
# to do trainning function
print Nn.feedforward(np.array([[5], [5], [5], [5], [5]]))
开发者ID:baptistejacob,项目名称:MachineLearningToolbox,代码行数:12,代码来源:example.py
示例6: __init__
def __init__(self, in_dim, hidden_dim, out_dim, activation, loss_type,
layer_num=0):
NeuralNetwork.__init__(self, activation, loss_type)
args = [self.activation, self.grad_activation]
self.layers = []
self.layers.append(FullyConnectedLayer(in_dim, hidden_dim, *args))
for _ in xrange(layer_num):
self.layers.append(FullyConnectedLayer(hidden_dim, hidden_dim, *args))
if loss_type == 'mse':
self.layers.append(FullyConnectedLayer(hidden_dim, out_dim, *args))
else:
from SoftmaxLayer import SoftmaxLayer
self.layers.append(SoftmaxLayer(hidden_dim, out_dim, *args))
开发者ID:dxmtb,项目名称:nn,代码行数:14,代码来源:MLP.py
示例7: main
def main():
print "Starting Support Vector Machine Simulations"
# svr = SupportVectorMachine()
# svr.simulate()
# basicNeuralNetwork = NeuralNetwork()
# basicNeuralNetwork.simulate()
# svr1 = SupportVectorMachine(20, 10, 500, 60)
# svr1.simulate()
# neuralNetwork1 = NeuralNetwork(20, 10, 500, 60)
# neuralNetwork1.simulate()
# # # larger window
# svr2 = SupportVectorMachine(48, 10, 200)
# svr2.simulate()
# neuralNetwork2 = NeuralNetwork(48, 10, 200)
# neuralNetwork2.simulate()
# # # large window
# svr3 = SupportVectorMachine(32, 10, 200)
# svr3.simulate()
# neuralNetwork3 = NeuralNetwork(32, 10, 200)
# neuralNetwork3.simulate()
# # # day sized window
# svr4 = SupportVectorMachine(24, 10, 200)
# svr4.simulate()
# neuralNetwork4 = NeuralNetwork(24, 10, 200)
# neuralNetwork4.simulate()
# half a day sized window
svr5 = SupportVectorMachine(12, 10, 200)
svr5.simulate()
neuralNetwork5 = NeuralNetwork(12, 10, 200)
neuralNetwork5.simulate()
开发者ID:EllenSebastian,项目名称:AI-bitcoin,代码行数:48,代码来源:SupportVector.py
示例8: createNeuralNetwork
def createNeuralNetwork(self, load = False):
listHidden1 = [Neuron("1", 6, load), Neuron("2", 6, load), Neuron("3", 6, load)]
listHidden2 = [Neuron("4", 3, load), Neuron("5", 3, load)]
listHidden3 = [Neuron("6", 2, load)]
listNetwork = [NeuronLayer(listHidden1), NeuronLayer(listHidden2), NeuronLayer(listHidden3)]
self.neuralNetwork = NeuralNetwork(listNetwork)
开发者ID:Nyrii,项目名称:-EPITECH-Zappy,代码行数:7,代码来源:AI.py
示例9: eventListener
def eventListener(self):
tickTime = pygame.time.Clock()
holdTime = 0
pygame.init()
DISPLAYSURF = pygame.display.set_mode((900, 900))
DISPLAYSURF.fill((255, 255, 255, 255))
while True:
for event in pygame.event.get():
if event.type == pygame.MOUSEBUTTONDOWN:
holdTime = tickTime.tick(60)
print self.alias, "DOWN: ", holdTime
if event.type == pygame.MOUSEBUTTONUP:
if holdTime < 3000:
print "----------------------------"
print self.alias, "CLASSIFYING... "
print "----------------------------"
pygame.mixer.music.load("perro.wav")
self.takePicture()
#Para pruebas de reproducción --- (En mi compu no furula)
self.play("perro")
self.play("gato")
self.play("desconocido")
# -------------------------------
self.startClasification()
print self.alias, "UP: ", holdTime
holdTime = 0
else:
print self.alias, ": ", holdTime, " miliSegundos"
networkModel, netMean, prototype, classes = self.netHandler.getNextNet()
self.neuralNetwork = NeuralNetwork(networkModel, netMean, prototype, classes)
holdTime = 0
if event.type == pygame.QUIT:
sys.exit(0)
开发者ID:ESCOM-PROYS,项目名称:ClasificadorEnLinea,代码行数:33,代码来源:Classifier.py
示例10: createFullyConnectedNetwork
def createFullyConnectedNetwork(parameters):
logger.info ("Creating a fully connected network")
network = NeuralNetwork()
idx = 0
for inputSize, outputSize in parameters:
isLastLayer = (idx == (len(parameters) - 1))
if isLastLayer:
nonlinearity = "Null"
else:
nonlinearity = "ReLu"
network.addLayer(FullyConnectedLayer(inputSize, outputSize, idx, nonlinearity))
idx += 1
return network
开发者ID:sudnya,项目名称:misc,代码行数:17,代码来源:NeuralNetworkBuilder.py
示例11: process
def process(self):
print '[ Prepare input images ]'
inputs = self.prepare_images()
print '[ Init Network ]'
network = NeuralNetwork(inputs, self.p, self.image_size, self.min_error)
print '[ Start training]'
network.training()
# network.load_weights()
print '[ Start recovering picture ]'
rec_images = network.process()
rec_picture = self.recover_image(rec_images)
print '[ Save recoverd image to file ]'
misc.imsave('images/rec_image.bmp', rec_picture)
开发者ID:alexkarpovich,项目名称:NeuralNetwork,代码行数:18,代码来源:Compressor.py
示例12: __init__
def __init__(self):
self.alias = "[CLASSIFIER]>> "
print self.alias , "Iniciando Clasificador..."
self.netHandler = NeuralNetworksHandler()
self.imageProcesor = ImagePreprocesor(wideSegment=150, highSegment=150, horizontalStride=50, verticalStride=50, withResizeImgOut=250, highResizeImgOut=250)
networkModel, netMean, prototype, classes = self.netHandler.getNetworkByIndex(0)
self.neuralNetwork = NeuralNetwork(networkModel, prototype, netMean, classes)
self.speaker = AudioPlayer()
self.eventListener()
开发者ID:ESCOM-PROYS,项目名称:ClasificadorEnLinea,代码行数:9,代码来源:Classifier.py
示例13: NeuralNetworkTestcase
class NeuralNetworkTestcase(unittest.TestCase):
def setUp(self):
self.nn = NeuralNetwork(['a', 'b'], 2)
self.nn.hidden_neurons[0].input_weights['a'] = 0.25
self.nn.hidden_neurons[0].input_weights['b'] = 0.50
self.nn.hidden_neurons[0].bias = 0.0
self.nn.hidden_neurons[1].input_weights['a'] = 0.75
self.nn.hidden_neurons[1].input_weights['b'] = 0.75
self.nn.hidden_neurons[1].bias = 0.0
self.nn.final_neuron.input_weights[0] = 0.5
self.nn.final_neuron.input_weights[1] = 0.5
self.nn.final_neuron.bias = 0.0
def test_calc(self):
self.nn.classify({'a': 1.0, 'b': 0.0})
self.assertAlmostEquals(self.nn.final_neuron.last_output, 0.650373, 5)
开发者ID:maeberli,项目名称:ClassificationPosts,代码行数:19,代码来源:NeuralNetworkTestcase.py
示例14: __trainbAction
def __trainbAction(self):
config = {'input_size': 30 * 30, 'hidden_size': 30 * 30, 'lambda': 1, 'num_labels': (len(self.learned))}
self.nn = NeuralNetwork(config=config)
cost_params_fscore = []
for i in range(self._k):
cost_params_fscore.append(self.nn.train(self.training_X[i], self.training_y[i], self.cross_validation_set[i], self.test_set, self.cross_validation_set_y[i], self.testing_y))
best_model = max(cost_params_fscore, key=itemgetter(2))
print best_model[0], best_model[2]
开发者ID:LucidComplex,项目名称:python-face-recognition,代码行数:10,代码来源:YourFaceSoundsFamiliar.py
示例15: Creature
class Creature(Entity):
BASE_SHAPE = [[10, 0], [0, -10], [-5, -5], [-5, 5], [0, 10]]
MAX_HEALTH = 100
def __init__(self, world, position, orientation, color):
self.polygonshape = PolygonShape(self.BASE_SHAPE)
self.position = position
self.orientation = orientation
self.color = color
self.movespeed = MoveSpeed(0)
self.turnspeed = TurnSpeed(0)
self.neuralnetwork = NeuralNetwork(2, 7, 2)
self.neuralnetwork.initialize_random_network()
self.health = Health(self.MAX_HEALTH)
self.foodseen = FoodSeen(0)
bounding_square = get_bounding_square(self.BASE_SHAPE)
self.collider = Collider(self, bounding_square, self.BASE_SHAPE)
开发者ID:jpinsonault,项目名称:creature_sim,代码行数:19,代码来源:Entities.py
示例16: createSpatialTransformerWithFullyConnectedNetwork
def createSpatialTransformerWithFullyConnectedNetwork(parameters, isVerbose):
logger.info ("Creating a fully connected network with a spatial transformer input layer")
network = NeuralNetwork()
idx = 0
for inputSize, outputSize in parameters:
isLastLayer = (idx == (len(parameters) - 1))
if isLastLayer:
nonlinearity = "Null"
else:
nonlinearity = "ReLu"
if idx == 0:
network.addLayer(SpatialTransformerLayer(inputSize[0], inputSize[1], inputSize[2],
outputSize[0], outputSize[1], outputSize[2], "ConvLayer"))
else:
network.addLayer(FullyConnectedLayer(inputSize, outputSize, idx, nonlinearity))
idx += 1
return network
开发者ID:sudnya,项目名称:misc,代码行数:21,代码来源:NeuralNetworkBuilder.py
示例17: exo8
def exo8():
print("\n\n>>EXERCICE 8 MNIST")
Xtrain, ytrain, Xvalid, yvalid, Xtest, ytest = utils.readMNISTfile()
default_h = 30
maxIter = 1
neuralNetwork = NeuralNetwork(len(Xtrain[0]), default_h, utils.getClassCount(ytrain),K=100)
neuralNetworkEfficient = NeuralNetworkEfficient(len(Xtrain[0]), default_h, utils.getClassCount(ytrain),K=100)
neuralNetworkEfficient._w1 = neuralNetwork._w1
neuralNetworkEfficient._w2 = neuralNetwork._w2
print("--- Reseau de depart ---")
t1 = datetime.now()
neuralNetwork.train(Xtrain, ytrain, maxIter)
t2 = datetime.now()
delta = t2 - t1
print("Cela a mis : " + str(delta.total_seconds()) + " secondes")
print("--- Reseau optimise ---")
t1 = datetime.now()
neuralNetworkEfficient.train(Xtrain, ytrain, maxIter)
t2 = datetime.now()
delta = t2 - t1
print("Cela a mis : " + str(delta.total_seconds()) + " secondes")
开发者ID:PierreGe,项目名称:neural-network,代码行数:21,代码来源:main.py
示例18: exo67
def exo67():
print("\n\n>>EXERCICE 6 et 7 : Calcul matriciel")
print(" --- K=1 ---")
#Xtrain, ytrain, Xvalid, yvalid, Xtest, ytest = utils.readMoonFile()
Xtrain = [[30, 20, 40, 50], [25, 15, 35, 45]]
ytrain = [0,0]
default_h = 2
nn = NeuralNetwork(len(Xtrain[0]), default_h, utils.getClassCount(ytrain), K=1, wd=0)
nne = NeuralNetworkEfficient(len(Xtrain[0]), default_h, utils.getClassCount(ytrain), K=1, wd=0)
nne._w1 = nn._w1 # trick pour que l'aleatoire soit egale
nne._w2 = nn._w2
nn.train(Xtrain,ytrain,1)
nne.train(Xtrain,ytrain,1)
utils.compareNN(nn,nne)
print(" --- K=10 ---")
Xtrain = [[30, 20, 40, 50], [25, 15, 35, 45],[30, 76, 45, 44],[89, 27, 42, 52],[30, 24, 44, 53],[89, 25, 45, 50],[30, 20, 40, 50],[30, 65, 47, 50],[30, 34, 40, 50],[39, 20, 29, 58]]
ytrain = [0,0,0,0,0,0,0,0,0,0]
default_h = 2
nn = NeuralNetwork(len(Xtrain[0]), default_h, utils.getClassCount(ytrain), K=10, wd=0)
nne = NeuralNetworkEfficient(len(Xtrain[0]), default_h, utils.getClassCount(ytrain), K=10, wd=0)
nne._w1 = nn._w1 # trick pour que l'aleatoire soit egale
nne._w2 = nn._w2
nn.train(Xtrain,ytrain,1)
nne.train(Xtrain,ytrain,1)
utils.compareNN(nn,nne,10)
开发者ID:PierreGe,项目名称:neural-network,代码行数:25,代码来源:main.py
示例19: train
def train(method, learningRate, momentum, numEpochs, output, samples, layers=None, minibatchsize=None):
trainImages, trainOutput, trainNumbers = loadData('training', samples)
nn = NeuralNetwork(layerCount=len(layers),
layerSize=np.array(layers),
actFunctions=np.array([1, 1]))
trainmethod = {
TRAININGMETHODS[0]: nn.trainBatch,
TRAININGMETHODS[1]: nn.trainStochastic
}
errors = trainmethod[method](
trainImages, trainOutput, learningRate=learningRate, momentum=momentum, numEpochs=numEpochs)
# Error did happen, we just return, error message would be printed by the
# train method
if not errors or len(errors) == 0:
return
# print 'Training done, errors:', errors
print 'Saving output to', output
nn.save(output)
print 'Testing...'
test(nn)
开发者ID:crysxd,项目名称:Parallel-Computing-and-Algorithms-X033537-Project,代码行数:22,代码来源:nnet.py
示例20: setUp
def setUp(self):
self.nn = NeuralNetwork(['a', 'b'], 2)
self.nn.hidden_neurons[0].input_weights['a'] = 1.0
self.nn.hidden_neurons[0].input_weights['b'] = 1.0
self.nn.hidden_neurons[0].bias = 0.0
self.nn.hidden_neurons[1].input_weights['a'] = 1.0
self.nn.hidden_neurons[1].input_weights['b'] = 1.0
self.nn.hidden_neurons[1].bias = 0.0
self.nn.final_neuron.input_weights[0] = -1
self.nn.final_neuron.input_weights[1] = 1
self.nn.final_neuron.bias = 0.0
开发者ID:maeberli,项目名称:ClassificationPosts,代码行数:14,代码来源:NeuralNetworkTestcase.py
注:本文中的NeuralNetwork.NeuralNetwork类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论