python - Training a network to identify X^2 + Y^2 + Z^2 <= 25 -


i'm trying neural network predict whether or not point falls on or within sphere formed equation x^2 + y^2 + z^2 <= 25. i'm doing using pybrain , python, however, no matter how configure thing, can't accuracy above 10%. 9 times out of 10, network converge on error .06, .07, , refuse continue training... if can shed light on situation that'd great!

if faced problem, how many hidden nodes use? tanh or sigmoid? learning rate? momentum? p.s. have experience neural nets, coded 1 tic-tac-toe in java scratch, , wanted learn how use pybrain better , figured project! (3 dimensions, infinite data, clear cut)

could pybrain problem? should try set-up? if so, recommendations?

code below if want give shot - every variable can determined upon execution, can mess around (except tanh/sigmoid - if want try sigmoid, remove hiddenclass=tanhlayer argument in net's declaration, default)

from pybrain.tools.shortcuts import buildnetwork pybrain.datasets import superviseddataset pybrain.supervised.trainers import backproptrainer pybrain.structure import tanhlayer random import randint import random  def getanswer(decimal):     answer = -1     if decimal >= 0:         answer = 1      return answer  nodes = int(input("node number: ")) bias = bool(input("bias: ")) net = buildnetwork(3, nodes, 1, hiddenclass=tanhlayer, bias=bias) net.randomize()  #generate dataset ds = superviseddataset(3, 1) datasize = int(input("sample size: "))  #randomly generate points data set randrate = int(input("cluter probability: ")) in range(0, datasize):     randx = randint(-6, 6)     randy = randint(-6, 6)     randz = randint(-6, 6)     target = -1      if(randx**2 + randy**2 + randz**2) <= 25:         target = 1      if (random.random() < randrate) , target == 1:  #clutter data         target = -1      #print("adding ", randx, ", ", randy, ", ", randz, " - target: ", target)     ds.addsample([randx, randy, randz], [target, ])  #train model using user specified input ls = float(input('enter learning speed:')) mom = float(input('enter momentum: ')) epochs = input('enter training amount (enter "con" go until convergence"): ') disprate = int(input('enter display rate: '))  trainer = backproptrainer(net, ds, ls, mom) if epochs != 'con':     epochs = int(epochs)     in range(0, epochs):         error = trainer.train()         if(i % disprate == 0):             print("training ", (i/epochs) * 100, "% complete. error = ", error) else:     trainer.trainuntilconvergence(ds, verbose=true)  print("testing accuracy...") #test accuracy 1000 random test points correct = 0 n in range(0, 1000):     randx = randint(-6, 6)     randy = randint(-6, 6)     randz = randint(-6, 6)     answer = getanswer(net.activate([randx, randy, randz]))     insphere = randx**2 + randy**2 + randz**2 <= 25     if(answer == 1) , insphere == true:         correct += 1     elif(answer == -1) , insphere == false:         correct += 1 print("accuracy: ", 100 * (correct/1000), "%")  inp = '' #let user test model while inp != 'quit':     tx = input('sample x: ')     ty = input('sample y: ')     tz = input('sample z: ')     print(net.activate([tx, ty, tz]))     inp = input("keep going? (quit stop)") 


Comments