本文整理汇总了Python中breze.learn.mlp.Mlp.predict方法的典型用法代码示例。如果您正苦于以下问题:Python Mlp.predict方法的具体用法?Python Mlp.predict怎么用?Python Mlp.predict使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类breze.learn.mlp.Mlp
的用法示例。
在下文中一共展示了Mlp.predict方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_mlp_pickle
# 需要导入模块: from breze.learn.mlp import Mlp [as 别名]
# 或者: from breze.learn.mlp.Mlp import predict [as 别名]
def test_mlp_pickle():
X = np.random.standard_normal((10, 2))
Z = np.random.standard_normal((10, 1))
X, Z = theano_floatx(X, Z)
mlp = Mlp(2, [10], 1, ['tanh'], 'identity', 'squared', max_iter=2)
climin.initialize.randomize_normal(mlp.parameters.data, 0, 1)
mlp.fit(X, Z)
Y = mlp.predict(X)
pickled = cPickle.dumps(mlp)
mlp2 = cPickle.loads(pickled)
Y2 = mlp2.predict(X)
assert np.allclose(Y, Y2)
示例2: test_mlp_predict
# 需要导入模块: from breze.learn.mlp import Mlp [as 别名]
# 或者: from breze.learn.mlp.Mlp import predict [as 别名]
def test_mlp_predict():
X = np.random.standard_normal((10, 2))
X, = theano_floatx(X)
mlp = Mlp(2, [10], 1, ['tanh'], 'identity', 'squared', max_iter=10)
mlp.predict(X)
示例3: open
# 需要导入模块: from breze.learn.mlp import Mlp [as 别名]
# 或者: from breze.learn.mlp.Mlp import predict [as 别名]
row = (
"%(n_iter)i\t%(time)g\t%(loss)f\t%(val_loss)f\t%(mae_train)g\t%(rmse_train)g\t%(mae_test)g\t%(rmse_test)g"
% info
)
results = open("result_gpu.txt", "a")
print row
results.write(row + "\n")
results.close()
m.parameters.data[...] = info["best_pars"]
cp.dump(info["best_pars"], open("best_pars.pkl", "w"))
Y = m.predict(m.transformedData(X))
TY = m.predict(TX)
output_train = Y * np.std(train_labels) + np.mean(train_labels)
output_test = TY * np.std(train_labels) + np.mean(train_labels)
print "TRAINING SET\n"
print ("MAE: %5.2f kcal/mol" % np.abs(output_train - train_labels).mean(axis=0))
print ("RMSE: %5.2f kcal/mol" % np.square(output_train - train_labels).mean(axis=0) ** 0.5)
print "TESTING SET\n"
print ("MAE: %5.2f kcal/mol" % np.abs(output_test - test_labels).mean(axis=0))
print ("RMSE: %5.2f kcal/mol" % np.square(output_test - test_labels).mean(axis=0) ** 0.5)
示例4: run_mlp
# 需要导入模块: from breze.learn.mlp import Mlp [as 别名]
# 或者: from breze.learn.mlp.Mlp import predict [as 别名]
#.........这里部分代码省略.........
weight_decay /= m.exprs['inpt'].shape[0]
m.exprs['true_loss'] = m.exprs['loss']
c_wd = wd
m.exprs['loss'] = m.exprs['loss'] + c_wd * weight_decay
'''
weight_decay = ((m.parameters.in_to_hidden**2).sum()
+ (m.parameters.hidden_to_out**2).sum()
+ (m.parameters.hidden_to_hidden_0**2).sum())
weight_decay /= m.exprs['inpt'].shape[0]
m.exprs['true_loss'] = m.exprs['loss']
c_wd = 0.1
m.exprs['loss'] = m.exprs['loss'] + c_wd * weight_decay
'''
mae = T.abs_((m.exprs['output'] * np.std(train_labels) + np.mean(train_labels))- m.exprs['target']).mean()
f_mae = m.function(['inpt', 'target'], mae)
rmse = T.sqrt(T.square((m.exprs['output'] * np.std(train_labels) + np.mean(train_labels))- m.exprs['target']).mean())
f_rmse = m.function(['inpt', 'target'], rmse)
start = time.time()
# Set up a nice printout.
keys = '#', 'seconds', 'loss', 'val loss', 'mae_train', 'rmse_train', 'mae_test', 'rmse_test'
max_len = max(len(i) for i in keys)
header = '\t'.join(i for i in keys)
print header
print '-' * len(header)
results = open('result.txt', 'a')
results.write(header + '\n')
results.write('-' * len(header) + '\n')
results.close()
for i, info in enumerate(m.powerfit((X, Z), (TX, TZ), stop, pause)):
if info['n_iter'] % n_report != 0:
continue
passed = time.time() - start
losses.append((info['loss'], info['val_loss']))
info.update({
'time': passed,
'mae_train': f_mae(m.transformedData(X), train_labels),
'rmse_train': f_rmse(m.transformedData(X), train_labels),
'mae_test': f_mae(TX, test_labels),
'rmse_test': f_rmse(TX, test_labels)
})
row = '%(n_iter)i\t%(time)g\t%(loss)f\t%(val_loss)f\t%(mae_train)g\t%(rmse_train)g\t%(mae_test)g\t%(rmse_test)g' % info
results = open('result.txt','a')
print row
results.write(row + '\n')
results.close()
m.parameters.data[...] = info['best_pars']
cp.dump(info['best_pars'], open('best_pars.pkl', 'w'))
Y = m.predict(m.transformedData(X))
TY = m.predict(TX)
output_train = Y * np.std(train_labels) + np.mean(train_labels)
output_test = TY * np.std(train_labels) + np.mean(train_labels)
print 'TRAINING SET\n'
print('MAE: %5.2f kcal/mol'%np.abs(output_train - train_labels).mean(axis=0))
print('RMSE: %5.2f kcal/mol'%np.square(output_train - train_labels).mean(axis=0) ** .5)
print 'TESTING SET\n'
print('MAE: %5.2f kcal/mol'%np.abs(output_test - test_labels).mean(axis=0))
print('RMSE: %5.2f kcal/mol'%np.square(output_test - test_labels).mean(axis=0) ** .5)
mae_train = np.abs(output_train - train_labels).mean(axis=0)
rmse_train = np.square(output_train - train_labels).mean(axis=0) ** .5
mae_test = np.abs(output_test - test_labels).mean(axis=0)
rmse_test = np.square(output_test - test_labels).mean(axis=0) ** .5
results = open('result.txt', 'a')
results.write('Training set:\n')
results.write('MAE:\n')
results.write("%5.2f" %mae_train)
results.write('\nRMSE:\n')
results.write("%5.2f" %rmse_train)
results.write('\nTesting set:\n')
results.write('MAE:\n')
results.write("%5.2f" %mae_test)
results.write('\nRMSE:\n')
results.write("%5.2f" %rmse_test)
results.close()
示例5: __init__
# 需要导入模块: from breze.learn.mlp import Mlp [as 别名]
# 或者: from breze.learn.mlp.Mlp import predict [as 别名]
class Predictor:
# initialize the object
def __init__(self):
with open('config.txt', 'r') as config_f:
for line in config_f:
if not line.find('mode='):
self.mode = line.replace('mode=', '').replace('\n', '')
if not line.find('robust='):
self.robust = line.replace('robust=', '').replace('\n', '')
print 'mode=%s\nrobustness=%s' %(self.mode, self.robust)
if self.robust == 'majority':
self.pred_count = 0
self.predictions = np.zeros((13,))
if self.robust == 'markov':
self.markov = Markov_Chain()
self.last_state = 0
self.current_state = 0
if self.robust == 'markov_2nd':
self.markov = Markov_Chain_2nd()
self.pre_last_state = 0
self.last_state = 0
self.current_state = 0
self.sample_count = 0
self.sample = []
if self.mode == 'cnn':
self.bin_cm = 10
self.max_x_cm = 440
self.min_x_cm = 70
self.max_y_cm = 250
self.max_z_cm = 200
self.nr_z_intervals = 2
self.x_range = (self.max_x_cm - self.min_x_cm)/self.bin_cm
self.y_range = self.max_y_cm*2/self.bin_cm
self.z_range = self.nr_z_intervals
self.input_size = 3700
self.output_size = 13
self.n_channels = 2
self.im_width = self.y_range
self.im_height = self.x_range
print 'initializing cnn model.'
self.model = Cnn(self.input_size, [16, 32], [200, 200], self.output_size, ['tanh', 'tanh'], ['tanh', 'tanh'],
'softmax', 'cat_ce', image_height=self.im_height, image_width=self.im_width,
n_image_channel=self.n_channels, pool_size=[2, 2], filter_shapes=[[5, 5], [5, 5]], batch_size=1)
self.model.parameters.data[...] = cp.load(open('./best_cnn_pars.pkl', 'rb'))
if self.mode == 'crafted':
self.input_size = 156
self.output_size = 13
self.means = cp.load(open('means_crafted.pkl', 'rb'))
self.stds = cp.load(open('stds_crafted.pkl', 'rb'))
print 'initializing crafted features model.'
self.model = Mlp(self.input_size, [1000, 1000], self.output_size, ['tanh', 'tanh'], 'softmax', 'cat_ce',
batch_size=1)
self.model.parameters.data[...] = cp.load(open('./best_crafted_pars.pkl', 'rb'))
# this is just a trick to make the internal C-functions compile before the first real sample arrives
compile_sample = np.random.random((1,self.input_size))
self.model.predict(compile_sample)
print 'starting to listen to topic.'
self.listener()
# build the full samples from the arriving point clouds
def build_samples(self, sample_part):
for point in read_points(sample_part):
self.sample.append(point)
self.sample_count += 1
if self.sample_count == 6:
if self.mode == 'cnn':
self.cnn_predict()
if self.mode == 'crafted':
self.crafted_predict()
self.sample = []
self.sample_count = 0
# start listening to the point cloud topic
def listener(self):
rospy.init_node('listener', anonymous=True)
rospy.Subscriber("/USArray_pc", PointCloud2, self.build_samples)
rospy.spin()
# let the model predict the output
def cnn_predict(self):
grid = np.zeros((self.z_range, self.x_range, self.y_range))
for point in self.sample:
if point[0]*100 < self.min_x_cm or point[0]*100 > self.max_x_cm-1 or point[1]*100 > self.max_y_cm-1 or point[1]*100 < -self.max_y_cm:
continue
x = (int(point[0]*100) - self.min_x_cm) / self.bin_cm
y = (int(point[1]*100) + self.max_y_cm) / self.bin_cm
z = int(point[2]*100) > (self.max_z_cm / self.nr_z_intervals)
#.........这里部分代码省略.........