add yapf style and apply yapf to format all Python files

This recreates pull request #2192
This commit is contained in:
Erwin Coumans
2019-04-27 07:31:15 -07:00
parent c591735042
commit ef9570c315
347 changed files with 70304 additions and 22752 deletions

View File

@@ -1,4 +1,3 @@
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
@@ -22,9 +21,7 @@ def main(unused_argv):
# fix random seed for reproducibility
numpy.random.seed(7)
# load pima indians dataset
dataset = numpy.loadtxt(
FLAGS.input_filename,
delimiter=",")
dataset = numpy.loadtxt(FLAGS.input_filename, delimiter=",")
# split into input (X) and output (Y) variables
x = dataset[:, 0:3]
y = dataset[:, 3]
@@ -38,28 +35,27 @@ def main(unused_argv):
model.add(Dense(1, activation="linear"))
# Compile model (use adam or sgd)
model.compile(
loss="mean_squared_error",
optimizer="adam",
metrics=["mean_squared_error"])
model.compile(loss="mean_squared_error", optimizer="adam", metrics=["mean_squared_error"])
# checkpoint
filepath = "/tmp/keras/weights-improvement-{epoch:02d}-{val_loss:.2f}.hdf5"
checkpoint = ModelCheckpoint(
filepath, monitor="val_loss", verbose=1, save_best_only=True, mode="min")
checkpoint = ModelCheckpoint(filepath,
monitor="val_loss",
verbose=1,
save_best_only=True,
mode="min")
callbacks_list = [checkpoint]
# Fit the model
# model.fit(X, Y, epochs=150, batch_size=10)
# model.fit(X, Y, epochs=150, batch_size=10, callbacks=callbacks_list)
model.fit(
x,
y,
validation_split=0.34,
epochs=4500,
batch_size=1024,
callbacks=callbacks_list,
verbose=0)
model.fit(x,
y,
validation_split=0.34,
epochs=4500,
batch_size=1024,
callbacks=callbacks_list,
verbose=0)
# evaluate the model
scores = model.evaluate(x, y)

View File

@@ -75,8 +75,8 @@ reframed = series_to_supervised(scaled, lag_steps, 1)
print("reframed before drop=", reframed)
# drop columns we don't want to predict
reframed.drop(reframed.columns[[3,7,11,15,19]], axis=1, inplace=True)
print("after drop=",reframed.head())
reframed.drop(reframed.columns[[3, 7, 11, 15, 19]], axis=1, inplace=True)
print("after drop=", reframed.head())
#dummy = scaler.inverse_transform(reframed)
#print(dummy)
@@ -104,17 +104,17 @@ test = values[n_train_hours:, :]
train_X, train_y = train[:, :-1], train[:, -1]
test_X, test_y = test[:, :-1], test[:, -1]
print("train_X.shape[1]=",train_X.shape[1])
print("train_X.shape[1]=", train_X.shape[1])
# design network
useLSTM=True
useLSTM = True
if useLSTM:
# reshape input to be 3D [samples, timesteps, features]
train_X = train_X.reshape((train_X.shape[0], lag_steps+1, int(train_X.shape[1]/(lag_steps+1))))
test_X = test_X.reshape((test_X.shape[0], lag_steps+1, int(test_X.shape[1]/(lag_steps+1))))
train_X = train_X.reshape(
(train_X.shape[0], lag_steps + 1, int(train_X.shape[1] / (lag_steps + 1))))
test_X = test_X.reshape((test_X.shape[0], lag_steps + 1, int(test_X.shape[1] / (lag_steps + 1))))
model = Sequential()
model.add(LSTM(40, input_shape=(train_X.shape[1], train_X.shape[2])))
model.add(LSTM(40, input_shape=(train_X.shape[1], train_X.shape[2])))
model.add(Dropout(0.05))
model.add(Dense(8, activation='sigmoid'))
model.add(Dense(8, activation='sigmoid'))
@@ -128,39 +128,37 @@ else:
model.add(Dense(1, activation="linear"))
#model.compile(loss='mae', optimizer='adam')
model.compile(
loss='mean_squared_error', optimizer='adam', metrics=['mean_squared_error'])
model.compile(loss='mean_squared_error', optimizer='adam', metrics=['mean_squared_error'])
# checkpoint
filepath = '/tmp/keras/weights-improvement-{epoch:02d}-{val_loss:.2f}.hdf5'
checkpoint = ModelCheckpoint(
filepath, monitor='val_loss', verbose=1, save_best_only=True, mode='min')
checkpoint = ModelCheckpoint(filepath,
monitor='val_loss',
verbose=1,
save_best_only=True,
mode='min')
callbacks_list = [checkpoint]
# fit network
history = model.fit(
train_X,
train_y,
epochs=1500,
batch_size=32,
callbacks=callbacks_list,
validation_data=(test_X, test_y),
verbose=2,
shuffle=False)
history = model.fit(train_X,
train_y,
epochs=1500,
batch_size=32,
callbacks=callbacks_list,
validation_data=(test_X, test_y),
verbose=2,
shuffle=False)
# plot history
data = np.array([[[1.513535008329887299,3.234624992847829894e-01,1.731481043119239782,1.741165415165205399,
1.534267104753672228e+00,1.071354965017878635e+00,1.712386127673626302e+00]]])
data = np.array([[[
1.513535008329887299, 3.234624992847829894e-01, 1.731481043119239782, 1.741165415165205399,
1.534267104753672228e+00, 1.071354965017878635e+00, 1.712386127673626302e+00
]]])
#prediction = model.predict(data)
#print("prediction=",prediction)
pyplot.plot(history.history['loss'], label='train')
pyplot.plot(history.history['val_loss'], label='test')
pyplot.legend()
pyplot.show()

View File

@@ -15,9 +15,8 @@ FLAGS = tf.app.flags.FLAGS
flags.DEFINE_float("motor_kp", 1.0, "The position gain of the motor.")
flags.DEFINE_float("motor_kd", 0.015, "The speed gain of the motor.")
flags.DEFINE_float(
"control_latency", 0.006, "The latency between sensor measurement and action"
" execution the robot.")
flags.DEFINE_float("control_latency", 0.006, "The latency between sensor measurement and action"
" execution the robot.")
flags.DEFINE_string("log_path", ".", "The directory to write the log file.")
@@ -31,37 +30,34 @@ def speed(t):
def main(argv):
del argv
env = minitaur_gym_env.MinitaurGymEnv(
urdf_version=minitaur_gym_env.RAINBOW_DASH_V0_URDF_VERSION,
control_time_step=0.006,
action_repeat=6,
pd_latency=0.0,
control_latency=FLAGS.control_latency,
motor_kp=FLAGS.motor_kp,
motor_kd=FLAGS.motor_kd,
remove_default_joint_damping=True,
leg_model_enabled=False,
render=True,
on_rack=False,
accurate_motor_model_enabled=True,
log_path=FLAGS.log_path)
env.reset()
del argv
env = minitaur_gym_env.MinitaurGymEnv(urdf_version=minitaur_gym_env.RAINBOW_DASH_V0_URDF_VERSION,
control_time_step=0.006,
action_repeat=6,
pd_latency=0.0,
control_latency=FLAGS.control_latency,
motor_kp=FLAGS.motor_kp,
motor_kd=FLAGS.motor_kd,
remove_default_joint_damping=True,
leg_model_enabled=False,
render=True,
on_rack=False,
accurate_motor_model_enabled=True,
log_path=FLAGS.log_path)
env.reset()
controller = minitaur_raibert_controller.MinitaurRaibertTrottingController(
env.minitaur)
controller = minitaur_raibert_controller.MinitaurRaibertTrottingController(env.minitaur)
tstart = env.minitaur.GetTimeSinceReset()
for _ in range(1000):
t = env.minitaur.GetTimeSinceReset() - tstart
controller.behavior_parameters = (
minitaur_raibert_controller.BehaviorParameters(
desired_forward_speed=speed(t)))
controller.update(t)
env.step(controller.get_action())
tstart = env.minitaur.GetTimeSinceReset()
for _ in range(1000):
t = env.minitaur.GetTimeSinceReset() - tstart
controller.behavior_parameters = (minitaur_raibert_controller.BehaviorParameters(
desired_forward_speed=speed(t)))
controller.update(t)
env.step(controller.get_action())
#env.close()
#env.close()
if __name__ == "__main__":
tf.app.run(main)

View File

@@ -35,12 +35,11 @@ def main(argv):
#print("motorState.velocity=",motorState.velocity)
#print("motorState.action=",motorState.action)
#print("motorState.torque=",motorState.torque)
recs.append([motorState.angle,motorState.velocity,motorState.action,motorState.torque])
recs.append([motorState.angle, motorState.velocity, motorState.action, motorState.torque])
a = numpy.array(recs)
numpy.savetxt(FLAGS.csv_file, a, delimiter=",")
if __name__ == "__main__":
tf.app.run(main)