本文整理汇总了Python中network.Network.create方法的典型用法代码示例。如果您正苦于以下问题:Python Network.create方法的具体用法?Python Network.create怎么用?Python Network.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类network.Network
的用法示例。
在下文中一共展示了Network.create方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: range
# 需要导入模块: from network import Network [as 别名]
# 或者: from network.Network import create [as 别名]
from network import Network
nn=Network.create([4, 1000, 1])
lamb=0.3
cost=1
alf = 0.2
xTrain = [[1, 2.3, 4.5, 5.3], [1.1, 1.3, 2.4, 2.4], [1.9, 1.7, 1.5, 1.3], [2.3, 2.9, 3.3, 4.9], [3, 5.2, 6.1, 8.2], [3.31, 2.9, 2.4, 1.5], [4.9, 5.7, 6.1, 6.3],
[4.85, 5.0, 7.2, 8.1], [5.9, 5.3, 4.2, 3.3], [7.7, 5.4, 4.3, 3.9], [6.7, 5.3, 3.2, 1.4], [7.1, 8.6, 9.1, 9.9], [8.5, 7.4, 6.3, 4.1], [9.8, 5.3, 3.1, 2.9]]
yTrain = [[1], [1], [0], [1], [1], [0], [1],
[1], [0], [0], [0], [1], [0], [0]]
xTest= [[0.4, 1.9, 2.5, 3.1], [1.51, 2.0, 2.4, 3.8], [2.6, 5.1, 6.2, 7.2], [3.23, 4.1, 4.3, 4.9], [7.1, 7.6, 8.2, 9.3],
[5.78, 5.1, 4.5, 3.55], [6.33, 4.8, 3.4, 2.5], [7.67, 6.45, 5.8, 4.31], [8.22, 6.32, 5.87, 3.59], [9.1, 8.5, 7.7, 6.1]]
yTest = [[1], [1], [1], [1], [1],
[0], [0], [0], [0], [0]]
while cost>0:
cost=Network.costTotal(False, nn, xTrain, yTrain, lamb)
costTest=Network.costTotal(False, nn, xTest, yTest, lamb)
delta=Network.backpropagation(False, nn, xTrain, yTrain, lamb)
nn['theta']=[nn['theta'][i]-alf*delta[i] for i in range(0,len(nn['theta']))]
print('Train cost ', cost[0,0], 'Test cost ', costTest[0,0])
print(Network.runAll(nn, xTest))
示例2: Network
# 需要导入模块: from network import Network [as 别名]
# 或者: from network.Network import create [as 别名]
from scipy import optimize
from network import Network
nt = Network()
nn=nt.create([4, 1000, 1])
lamb=0.3
cost=1
alf = 0.2
xTrain = [
[1, 2.3, 4.5, 5.3],
[1.1, 1.3, 2.4, 2.4],
[1.9, 1.7, 1.5, 1.3],
[2.3, 2.9, 3.3, 4.9],
[3, 5.2, 6.1, 8.2],
[3.31, 2.9, 2.4, 1.5],
[4.9, 5.7, 6.1, 6.3],
[4.85, 5.0, 7.2, 8.1],
[5.9, 5.3, 4.2, 3.3],
[7.7, 5.4, 4.3, 3.9],
[6.7, 5.3, 3.2, 1.4],
[7.1, 8.6, 9.1, 9.9],
[8.5, 7.4, 6.3, 4.1],
[9.8, 5.3, 3.1, 2.9],
[1.1, 3.5, 4.5, 7.6],
[2.1, 3.5, 5.5, 8.6],
[3.1, 5.5, 7.5, 9.6],
[0.1, 1.5, 2.5, 6.6],
[9.5, 8.1, 5.5, 3.6],
示例3: FFnetApp
# 需要导入模块: from network import Network [as 别名]
# 或者: from network.Network import create [as 别名]
class FFnetApp(HasTraits):
network = Instance(Network)
data = Instance(TrainingData)
training_data = Instance(TrainingData)
testing_data = Instance(TrainingData)
recall_data = Instance(TrainingData)
dumper = Instance(Dumper)
trainer = Instance(Trainer)
shared = Instance(Shared)
logs = Instance(Logger)
plots = Instance(MPLPlots, transient=True)
shell = PythonValue(Dict)
mode = Enum('train', 'test', 'recall')
algorithm = Enum('tnc') #, 'bfgs', 'cg')
running = DelegatesTo('trainer')
net = DelegatesTo('network')
data_status = DelegatesTo('data', prefix='status')
selected = DelegatesTo('plots')
def __init__(self, **traits):
super(FFnetApp, self).__init__(**traits)
self.network = Network(app = self)
self.training_data = TrainingData(app = self)
self.testing_data = TrainingData(app = self)
self.recall_data = TrainingData(app = self)
self.data = self.training_data # by default
self.dumper = Dumper(app=self)
self.trainer = TncTrainer(app = self) # default trainer
self.shared = Shared()
self.logs = Logger()
self.plots = MPLPlots()
self.logs.logger.info('Welcome! You are using ffnet-%s.' %ffnet_version)
self.shell = {'app':self}
def new(self):
net = self.network.create()
if net is not None:
self.mode = 'train'
self.data.normalize = True
self._new_net_setup()
def load(self):
net = self.network.load()
if net is not None:
self.mode = 'recall'
self._new_net_setup()
def save_as(self):
self.network.save_as()
def export(self):
self.network.export()
def dump(self):
self.dumper.configure_traits(kind='modal')
def settings(self):
if self.net:
self._pmode = self.mode
self.edit_traits(view='settings_view', kind='livemodal')
def train_start(self):
self.logs.logger.info('Training network: %s' %self.network.filename)
self.trainer.train()
def train_stop(self):
self.trainer.running = False
def reset(self):
if self.net:
self.net.randomweights()
self.logs.logger.info('Weights has been randomized!')
self.clear()
def about(self):
from about import about
about.open()
def donate(self):
import webbrowser
url = 'https://sourceforge.net/p/ffnet/donate'
webbrowser.open(url)
def cite(self):
from pyface.api import information
import os
try:
basedir = os.path.dirname(os.path.realpath(__file__)) + '/'
except NameError: #__file__ not defined if this is main script
basedir = ''
fname = basedir + 'data/cite.txt'
citations = open(fname, 'r').read()
msg = u'You are encouraged to cite in your papers one (or all) of the following:\n\n\n' + \
unicode(citations, 'utf-8').replace(u'\ufeff', '')
information(None, msg, title = "Citing ffnet/ffnetui")
def clear(self):
self.shared.populate()
self.plots.selected.replot()
#.........这里部分代码省略.........
示例4: Network
# 需要导入模块: from network import Network [as 别名]
# 或者: from network.Network import create [as 别名]
from scipy import optimize
from network import Network
nt = Network()
nn=nt.create([1, 1000, 1])
lamb=0.3
cost=1
alf = 0.2
xTrain = [[0], [1], [1.9], [2], [3], [3.31], [4], [4.7], [5], [5.1], [6], [7], [8], [9]]
yTrain = [[0], [0], [0], [0], [0], [0], [0], [0], [1], [1], [1], [1], [1], [1]]
xTest= [[0.4], [1.51], [2.6], [3.23], [4.87], [5.78], [6.334], [7.667], [8.22], [9.1]]
yTest = [[0], [0], [0], [0], [0], [1], [1], [1], [1], [1]]
theta = nt.unroll(nn['theta'])
print(nt.runAll(nn, xTest))
theta = optimize.fmin_cg(nt.costTotal, fprime=nt.backpropagation,
x0=theta, args=(nn, xTrain, yTrain, lamb), maxiter=200)
print(nt.runAll(nn, xTest))
示例5: list
# 需要导入模块: from network import Network [as 别名]
# 或者: from network.Network import create [as 别名]
y_train = list(map(lambda x: [x], y_train))
# y_train = y_train[:100]
# X_train = X_train[:100]
# http://rasbt.github.io/mlxtend/docs/data/mnist/
# def plot_digit(X, y, idx):
# img = X[idx].reshape(28,28)
# plt.imshow(img, cmap='Greys', interpolation='nearest')
# plt.title('true label: %d' % y[idx])
# plt.show()
# plot_digit(X_train, y_train, 4)
nt = Network()
nn = nt.create([784, 100, 1])
lamb = 0.3
cost = 1
alf = 0.005
i = 0
results = []
while cost > 0:
cost = nt.costTotal(False, nn, X_train, y_train, lamb)
delta = nt.backpropagation(False, nn, X_train, y_train, lamb)
nn["theta"] = [nn["theta"][i] - alf * delta[i] for i in range(0, len(nn["theta"]))]
i = i + 1
print("Train cost ", cost[0, 0], "Iteration ", i)
results = nt.runAll(nn, X_test)
print(results)