本文整理汇总了Python中pybrain.tools.xml.networkreader.NetworkReader.readFrom方法的典型用法代码示例。如果您正苦于以下问题:Python NetworkReader.readFrom方法的具体用法?Python NetworkReader.readFrom怎么用?Python NetworkReader.readFrom使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pybrain.tools.xml.networkreader.NetworkReader
的用法示例。
在下文中一共展示了NetworkReader.readFrom方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: loadFromFile
# 需要导入模块: from pybrain.tools.xml.networkreader import NetworkReader [as 别名]
# 或者: from pybrain.tools.xml.networkreader.NetworkReader import readFrom [as 别名]
def loadFromFile(self):
try:
if self.major:
self.net = NetworkReader.readFrom(TRAINED_DATA_FILEPATH_MAJOR)
else:
self.net = NetworkReader.readFrom(TRAINED_DATA_FILEPATH_MINOR)
except:
print "Could not find or open file"
示例2: usebp
# 需要导入模块: from pybrain.tools.xml.networkreader import NetworkReader [as 别名]
# 或者: from pybrain.tools.xml.networkreader.NetworkReader import readFrom [as 别名]
def usebp():
patterns = [
[[3158, 3503, 3342, 644, 937, 750, 546, 503, 593], [4751]],
[[3092, 3011, 3217, 675, 882, 881, 543, 598, 564], [4445]],
[[3180, 3043, 3031, 785, 830, 799, 448, 517, 564], [4514]],
[[3389, 3469, 3450, 794, 933, 804, 544, 556, 578], [4755]],
[[3224, 3201, 3433, 904, 737, 772, 522, 591, 585], [4864]],
[[3503, 3342, 3410, 937, 750, 725, 503, 593, 616], [4646]],
[[3011, 3217, 3143, 882, 881, 701, 598, 564, 601], [0]],
[[3043, 3031, 3209, 830, 799, 701, 517, 564, 604], [0]],
[[3469, 3450, 3446, 933, 804, 756, 556, 578, 553], [0]],
[[3201, 3433, 3436, 737, 772, 817, 591, 585, 611], [0]],
[[3342, 3410, 3277, 750, 725, 837, 593, 616, 532], [0]],
]
net = NetworkReader.readFrom('/home/wtq/BigData-MachineLearning/Bpnn/BusWorkNet.xml')
for p in patterns:
testInput = p[0]
targetOut = p[1]
testInput = tuple(map(lambda n: float(n) / 6000, testInput))
out = net.activate(testInput)
print"out->", (out * 6000)
distance = list(map(lambda x: 6000 * x[0] - x[1], zip(out, targetOut)))
print(distance)
示例3: __init__
# 需要导入模块: from pybrain.tools.xml.networkreader import NetworkReader [as 别名]
# 或者: from pybrain.tools.xml.networkreader.NetworkReader import readFrom [as 别名]
def __init__(self, port=None, baud=115200):
print("connecting to OpenBCI...")
self.board = OpenBCIBoard(port, baud)
self.bg_thread = None
self.bg_draw_thread = None
self.data = np.array([0]*8)
self.should_plot = False
self.control = np.array([0,0,0])
self.control_s = np.array([0,0,0])
self.control_f = np.array([0])
self.out_sig = np.array([0])
self.controls = np.array([[0]*4])
self.eye_r = np.array([0])
self.eye_l = np.array([0])
self.current = "baseline"
fnn = NetworkReader.readFrom('neural_net.xml')
self.good_indexes = joblib.load('neural_model_features.pkl')
# self.eye_l_temp, self.eye_r_temp = joblib.load('eye_blinks.pkl')
self.model = fnn
print("connecting to teensy...")
if TEENSY_ENABLED:
self.teensy = serial.Serial(TEENSY_PORT, 57600)
示例4: LoadBananaNeuralNetwork
# 需要导入模块: from pybrain.tools.xml.networkreader import NetworkReader [as 别名]
# 或者: from pybrain.tools.xml.networkreader.NetworkReader import readFrom [as 别名]
def LoadBananaNeuralNetwork(networkXML):
print "Loading Banana neural network: "+str(networkXML)
start = timer()
global banana
banana = NetworkReader.readFrom(networkXML)
end = timer()
print "Time taken to load Banana neural network: " + str(end-start)
示例5: LoadAppleNeuralNetwork
# 需要导入模块: from pybrain.tools.xml.networkreader import NetworkReader [as 别名]
# 或者: from pybrain.tools.xml.networkreader.NetworkReader import readFrom [as 别名]
def LoadAppleNeuralNetwork(networkXML):
print "Loading Apple neural network: "+str(networkXML)
start = timer()
global apple
apple = NetworkReader.readFrom(networkXML)
end = timer()
print "Time taken to load Apple neural network: " + str(end-start)
示例6: LoadCucumberNeuralNetwork
# 需要导入模块: from pybrain.tools.xml.networkreader import NetworkReader [as 别名]
# 或者: from pybrain.tools.xml.networkreader.NetworkReader import readFrom [as 别名]
def LoadCucumberNeuralNetwork(networkXML):
print "Loading Cucumber neural network: "+str(networkXML)
start = timer()
global cucumber
cucumber = NetworkReader.readFrom(networkXML)
end = timer()
print "Time taken to load Cucumber neural network: " + str(end-start)
示例7: startTrials
# 需要导入模块: from pybrain.tools.xml.networkreader import NetworkReader [as 别名]
# 或者: from pybrain.tools.xml.networkreader.NetworkReader import readFrom [as 别名]
def startTrials(ds, maxTrials = 2, maxExperiments = 2):
"""start and run the trials"""
hpCount = []
for i in range(0, maxExperiments):
for j in range(0, maxTrials):
enemyTestPos = runExperiments.makeTestDataset()
net = NetworkReader.readFrom("net.xml")
netResults = net.activate([val for pair in normalize(enemyTestPos) for val in pair])
netIter = iter(netResults)
allyTestPos = zip(netIter, netIter)
#undo normalization
allyTestPos = map(lambda p: (abs(p[0]*640), abs(p[1]*720)), allyTestPos)
print(allyTestPos)
runExperiments.writeTestData(allyTestPos)
runExperiments.run()
with open("exp_results_raw.txt", "r") as resultsFile:
lines = resultsFile.readlines()
if "Zerg_Zergling" in lines[1]:
x = normalize(enemyTestPos)
y = normalize(allyTestPos)
x = [val for pair in x for val in pair]
y = [val for pair in y for val in pair]
ds.addSample(x, y)
lineSplit = lines[1].split("Zerg_Zergling")[-1]
hpCount.append(lineSplit.split(" ")[2])
trainer = BackpropTrainer(net, ds)
trainer.trainUntilConvergence()
return hpCount
示例8: _InitNet
# 需要导入模块: from pybrain.tools.xml.networkreader import NetworkReader [as 别名]
# 或者: from pybrain.tools.xml.networkreader.NetworkReader import readFrom [as 别名]
def _InitNet(self):
# -----------------------------------------------------------------------
self._pr_line();
print("| _InitNet(self): \n");
start_time = time.time();
# -----------------------------------------------------------------------
if self._NET_NAME:
# -----------------------------------------------------------------------
self._SDS = SupervisedDataSet(900, 52);
if self._NET_NEW:
print('| Bulding new NET: '+self._NET_NAME)
self._NET = buildNetwork(self._SDS.indim, self._NET_HIDDEN, self._SDS.outdim, bias=True); #,hiddenclass=TanhLayer)
self._SaveNET();
else:
print('| Reading NET from: '+self._NET_NAME)
self._NET = NetworkReader.readFrom(self._NET_NAME)
# -----------------------------------------------------------------------
print('| Making AutoBAK: '+str(self._MK_AUTO_BAK))
if self._MK_AUTO_BAK:
NetworkWriter.writeToFile(self._NET, self._NET_NAME+".AUTO_BAK.xml");
# -----------------------------------------------------------------------
print("| Done in: "+str(time.time()-start_time)+'sec');
# -----------------------------------------------------------------------
else:
print('| Unknown NET name: >|'+self._NET_NAME+'|<')
exit();
示例9: getBoardImage
# 需要导入模块: from pybrain.tools.xml.networkreader import NetworkReader [as 别名]
# 或者: from pybrain.tools.xml.networkreader.NetworkReader import readFrom [as 别名]
def getBoardImage(img):
'''
Runs an image through processing and neural network to decode digits
img: an openCV image object
returns:
pil_im: a PIL image object with the puzzle isolated, cropped and straightened
boardString: string representing the digits and spaces of a Sudoku board (left to right, top to bottom)
'''
# Process image and extract digits
pil_im, numbers, parsed, missed = process(img, False)
if pil_im == None:
return None, None
net = NetworkReader.readFrom(os.path.dirname(os.path.abspath(__file__))+'/network.xml')
boardString = ''
for number in numbers:
if number is None:
boardString += ' '
else:
data=ClassificationDataSet(400, nb_classes=9, class_labels=['1','2','3','4','5','6','7','8','9'])
data.appendLinked(number.ravel(),[0])
boardString += str(net.activateOnDataset(data).argmax(axis=1)[0]+1)
return pil_im, boardString
示例10: trainNetwork
# 需要导入模块: from pybrain.tools.xml.networkreader import NetworkReader [as 别名]
# 或者: from pybrain.tools.xml.networkreader.NetworkReader import readFrom [as 别名]
def trainNetwork(epochs, rate, trndata, tstdata, network=None):
'''
epochs: number of iterations to run on dataset
trndata: pybrain ClassificationDataSet
tstdat: pybrain ClassificationDataSet
network: filename of saved pybrain network, or None
'''
if network is None:
net = buildNetwork(400, 25, 25, 9, bias=True, hiddenclass=SigmoidLayer, outclass=SigmoidLayer)
else:
net = NetworkReader.readFrom(network)
print "Number of training patterns: ", len(trndata)
print "Input and output dimensions: ", trndata.indim, trndata.outdim
print "First sample input:"
print trndata['input'][0]
print ""
print "First sample target:", trndata['target'][0]
print "First sample class:", trndata.getClass(int(trndata['class'][0]))
print ""
trainer = BackpropTrainer(net, dataset=trndata, learningrate=rate)
for i in range(epochs):
trainer.trainEpochs(1)
trnresult = percentError(trainer.testOnClassData(), trndata['class'])
tstresult = percentError(trainer.testOnClassData(dataset=tstdata), tstdata['class'])
print "epoch: %4d" % trainer.totalepochs, " train error: %5.2f%%" % trnresult, " test error: %5.2f%%" % tstresult
return net
示例11: load
# 需要导入模块: from pybrain.tools.xml.networkreader import NetworkReader [as 别名]
# 或者: from pybrain.tools.xml.networkreader.NetworkReader import readFrom [as 别名]
def load(self, path):
"""
This function loads the neural network.
Args:
:param path (String): the path where the neural network is going to be loaded from.
"""
self.network = NetworkReader.readFrom(path)
示例12: predict
# 需要导入模块: from pybrain.tools.xml.networkreader import NetworkReader [as 别名]
# 或者: from pybrain.tools.xml.networkreader.NetworkReader import readFrom [as 别名]
def predict(main_words):
cluster_to_words = pickle.load(open('myW2VModel_claster_1000.p', 'rb'))
if len(main_words.split()) > 7:
row_vector_array = [0] * 1000
for w in main_words.split():
if w in w2v_model.vocab:
row_vector_array[get_cluster_number(w, cluster_to_words)] = 1
net = NetworkReader.readFrom('trained_network_continue5.xml')
return net.activate(row_vector_array)
示例13: onTextEntered
# 需要导入模块: from pybrain.tools.xml.networkreader import NetworkReader [as 别名]
# 或者: from pybrain.tools.xml.networkreader.NetworkReader import readFrom [as 别名]
def onTextEntered(self):
model_name = "clean_text_model"
w2v_model = Word2Vec.load(model_name)
new_post_text = self.entry.get(1.0, END)
row_vector_array = []
for w in new_post_text.split():
if w in w2v_model.vocab:
row_vector_array.extend(w2v_model[w])
net = NetworkReader.readFrom('trained_network1.xml')
result = net.activate(row_vector_array[:100])
print result
self.labelVariable.set("Result : " + str(result))
示例14: _readNetworkFromFile
# 需要导入模块: from pybrain.tools.xml.networkreader import NetworkReader [as 别名]
# 或者: from pybrain.tools.xml.networkreader.NetworkReader import readFrom [as 别名]
def _readNetworkFromFile(self):
# -----------------------------------------------------------------------
self._pr_line();
print("| _readNetworkFromFile("+self._NET_NAME+"): \n");
start_time = time.time();
# -----------------------------------------------------------------------
self._NET = NetworkReader.readFrom(self._NET_NAME);
# -----------------------------------------------------------------------
print("| Done in: "+str(time.time()-start_time)+'sec');
示例15: checkPerformanceTestSet
# 需要导入模块: from pybrain.tools.xml.networkreader import NetworkReader [as 别名]
# 或者: from pybrain.tools.xml.networkreader.NetworkReader import readFrom [as 别名]
def checkPerformanceTestSet(tstFileName,numF,numC,minVals,maxVals,nnFile,threshold):
data = np.genfromtxt(tstFileName)
tstIn = data[:,0:5]
tstOut = data[:,6]
tstOut = [int(val) for val in tstOut]
for i in range(0,len(tstIn)):
for j in range(0,numF):
tstIn[i,j] = (tstIn[i,j]-minVals[j])/(maxVals[j]-minVals[j])
myNetwork = NetworkReader.readFrom(nnFile)
return checkPerformance(myNetwork,tstIn,tstOut,numC,threshold)