def main(): """ load training data""" inputs = np.loadtxt("../handwriting/X2_100samples.dat") targets = np.loadtxt("../handwriting/y2_100samples.dat") """ define network topology """ conec = mlgraph((inputs.shape[1], 10, 1)) # reg = 0.1 reg = False net = ffnet(conec) system = NNSystem(net, inputs, targets, reg=reg) database = system.create_database( # db="/home/ab2111/machine_learning_landscapes/neural_net/db_ffnet_100samples_reg"+str(reg) +".sqlite" db="../db/db_ffnet_100samples.sqlite") run_gui(system, database)
def RunSimulation(self, real_time_rate=1.0): ''' The Princess Diaries was a good movie. ''' builder = DiagramBuilder() scene_graph = builder.AddSystem(SceneGraph()) # object_file_path = FindResourceOrThrow( # "drake/examples/manipulation_station/models/061_foam_brick.sdf") # sdf_file = FindResourceOrThrow("drake/multibody/benchmarks/acrobot/acrobot.sdf") # urdf_file = FindResourceOrThrow("drake/multibody/benchmarks/acrobot/acrobot.urdf") sdf_file = "assets/acrobot.sdf" urdf_file = "assets/acrobot.urdf" plant = builder.AddSystem(MultibodyPlant()) plant.RegisterAsSourceForSceneGraph(scene_graph) Parser(plant, scene_graph).AddModelFromFile(sdf_file) plant.Finalize(scene_graph) assert plant.geometry_source_is_registered() builder.Connect( plant.get_geometry_poses_output_port(), scene_graph.get_source_pose_port(plant.get_source_id())) builder.Connect(scene_graph.get_query_output_port(), plant.get_geometry_query_input_port()) # Add nn_system = NNSystem(self.pytorch_nn_object) builder.AddSystem(nn_system) # NN -> plant builder.Connect(nn_system.NN_out_output_port, plant.get_actuation_input_port()) # plant -> NN builder.Connect(plant.get_continuous_state_output_port(), nn_system.NN_in_input_port) # Add meshcat visualizer meshcat = MeshcatVisualizer(scene_graph) builder.AddSystem(meshcat) # builder.Connect(scene_graph.GetOutputPort("lcm_visualization"), builder.Connect(scene_graph.get_pose_bundle_output_port(), meshcat.GetInputPort("lcm_visualization")) # build diagram diagram = builder.Build() meshcat.load() # time.sleep(2.0) RenderSystemWithGraphviz(diagram) # construct simulator simulator = Simulator(diagram) # context = diagram.GetMutableSubsystemContext( # self.station, simulator.get_mutable_context()) simulator.set_publish_every_time_step(False) simulator.set_target_realtime_rate(real_time_rate) simulator.Initialize() sim_duration = 5. simulator.StepTo(sim_duration) print("stepping complete")
def main(): """ load training data""" inputs = np.loadtxt("../handwriting/X2_100samples.dat") targets = np.loadtxt("../handwriting/y2_100samples.dat") """ define network topology """ conec = mlgraph((inputs.shape[1],10,1)) # reg = 0.1 reg=False net = ffnet(conec) system = NNSystem(net, inputs, targets, reg=reg) database = system.create_database( # db="/home/ab2111/machine_learning_landscapes/neural_net/db_ffnet_100samples_reg"+str(reg) +".sqlite" db="../db/db_ffnet_100samples.sqlite" ) run_gui(system, database)
def RunSimulation(self, real_time_rate=1.0): ''' Here we test using the NNSystem in a Simulator to drive an acrobot. ''' sdf_file = "assets/acrobot.sdf" urdf_file = "assets/acrobot.urdf" builder = DiagramBuilder() plant, scene_graph = AddMultibodyPlantSceneGraph(builder) parser = Parser(plant=plant, scene_graph=scene_graph) parser.AddModelFromFile(sdf_file) plant.Finalize(scene_graph) # Add nn_system = NNSystem(self.pytorch_nn_object) builder.AddSystem(nn_system) # NN -> plant builder.Connect(nn_system.NN_out_output_port, plant.get_actuation_input_port()) # plant -> NN builder.Connect(plant.get_continuous_state_output_port(), nn_system.NN_in_input_port) # Add meshcat visualizer meshcat = MeshcatVisualizer(scene_graph) builder.AddSystem(meshcat) # builder.Connect(scene_graph.GetOutputPort("lcm_visualization"), builder.Connect(scene_graph.get_pose_bundle_output_port(), meshcat.GetInputPort("lcm_visualization")) # build diagram diagram = builder.Build() meshcat.load() # time.sleep(2.0) RenderSystemWithGraphviz(diagram) # construct simulator simulator = Simulator(diagram) # context = diagram.GetMutableSubsystemContext( # self.station, simulator.get_mutable_context()) simulator.set_publish_every_time_step(False) simulator.set_target_realtime_rate(real_time_rate) simulator.Initialize() sim_duration = 5. simulator.StepTo(sim_duration) print("stepping complete")
dg.plot() dg.label_minima(labels) print labels plt.show() # dg.savefig("/home/ab2111/machine_learning_landscapes/neural_net/dg.png") from NNSystem import NNSystem """ load training data""" inputs = np.loadtxt("../handwriting/X2_100samples.dat") targets = np.loadtxt("../handwriting/y2_100samples.dat") from ffnet_validation import get_validation_data vinputs, vtargets = get_validation_data() """ define network topology """ conec = mlgraph((inputs.shape[1],10,1)) print inputs.shape # exit() net = ffnet(conec) system = NNSystem(net, inputs, targets) database = system.create_database(db="../db/db_ffnet_100samples.sqlite") # make_disconnectivity_graph(system, database, vinputs, vtargets) # plt.plot(ts.coords,'x') # plt.plot(ts.eigenvec,'o') # plt.show() make_validation_disconnectivity_graph(system, database)
def create_nn_policy_system(kNetConstructor, params_list): net = create_nn(kNetConstructor, params_list) net.eval() nn_policy = NNSystem(pytorch_nn_object=net) return nn_policy