Ejemplo n.º 1
0
def plt_heat_map_results(plt_file_name = None):
    opt = Options()
    opt.disp_on = False
    pob_siz_len = np.arange(start=3, stop=11,step=2) #not even steps needed
    hist_len = np.arange(start=1, stop=5)
    # pob_siz_len =[5,3,5,9,1]
    results_success_rate_map_zero = []
    results_astar_diff = []
    cnt_Test=0
    with K.get_session():
        for p in pob_siz_len:
            opt.pob_siz = p
            opt.state_siz = (p * opt.cub_siz) ** 2
            print("start with opt.pob_siz: {}".format(opt.pob_siz))
            print("start with opt.state_siz: {}".format(opt.state_siz))
            # get_data(opt)#generaten new data
            for l in hist_len:
                opt.hist_len = l
                print("start with opt.hist_len: {}".format(opt.hist_len))
                # train_model(opt, mdl_name,epochs=EPOCHS)
                # [success_rate, astar_diff] = test_model(opt,mdl_name)
                # results_success_rate_map_zero.append(success_rate)

                results_success_rate_map_zero.append(cnt_Test)
                cnt_Test1+=1
                # results_astar_diff.append(astar_diff)
    results_success_rate_map_zero=np.array(results_success_rate_map_zero)
    plt.imshow(results_success_rate_map_zero.reshape(len(pob_siz_len),len(hist_len)), cmap='hot', interpolation='nearest')
    plt.colorbar()
    # plt.show()
    helper_save(plt_file_name)
Ejemplo n.º 2
0
    default=1000)
parser.add_argument("-ss",
                    "--silent",
                    help="Runs test without displaying the simulation",
                    action="store_false")

args = parser.parse_args()

model_path = args.model

# --------------------------------------------------------
# 0. initialization
opt = Options()
sim = Simulator(opt.map_ind, opt.cub_siz, opt.pob_siz, opt.act_num)

opt.disp_on = args.silent

if args.steps:
    opt.steps = args.steps

# --------------------------------------------------------
# Input layer
image_dimension = opt.cub_siz * opt.pob_siz
img_rows = img_cols = image_dimension
input_shape = [img_rows, img_cols, opt.hist_len]

# --------------------------------------------------------
# Model
agent = model.model(input_shape)
agent.load_weights(model_path)
if not agent:
Ejemplo n.º 3
0
import numpy as np
np.random.seed(0)
from random import randrange
# custom modules
from utils import Options, rgb2gray
from simulator import Simulator

# 0. initialization
opt = Options()
sim = Simulator(opt.map_ind, opt.cub_siz, opt.pob_siz, opt.act_num)
states = np.zeros([opt.data_steps, opt.state_siz], float)
labels = np.zeros([opt.data_steps], int)

# Note I am forcing the display to be off here to make data collection fast
# you can turn it on again for debugging purposes
opt.disp_on = False

# 1. control loop
if opt.disp_on:
    win_all = None
    win_pob = None
epi_step = 0  # #steps in current episode
nepisodes = 1  # total #episodes executed

state = sim.newGame(opt.tgt_y, opt.tgt_x)
for step in range(opt.data_steps):
    if state.terminal or epi_step >= opt.early_stop:
        epi_step = 0
        nepisodes += 1
        state = sim.newGame(opt.tgt_y, opt.tgt_x)
    else:
Ejemplo n.º 4
0
args = parser.parse_args()
args.func(args)
'''if not args.cfg_file:
	opt.prefix = args.prefix
	opt.set_algo(args.algo)
	opt.steps = args.steps
	opt.mtype = args.mtype
	opt.rtype = args.rtype
	opt.hist_len = args.hlength
	from_file = False
else:
	opt.load_config_file(args.file)
	from_file = True'''

opt.disp_on = args.visualize
plot = args.plot_output
model_name = opt.generate_model_name()
run_name = opt.generate_run_name()

# Environment setup
opt.disp_on = args.visualize
sim = Simulator(opt.map_ind, opt.cub_siz, opt.pob_siz, opt.act_num)

if opt.rtype == opt.supported_rtypes[0]:
	opt.training = True
else:
	opt.testing = True

# Default model architecture
layer_params = [
hours = int(sec / 3600)
rem = int(sec - (hours * 3600))
mins = rem / 60
rem = rem - (mins * 60)
secs = rem

print 'Training time:', hours, ':', mins, ':', secs

#Save the weights
model.save_weights(opt.weights_fil, overwrite=True)
print('Saved weights')
with open(opt.network_fil, "w") as outfile:
    json.dump(model.to_json(), outfile)

#Testing
opt.disp_on = True
win_all = None
win_pob = None
action = np.argmax(
    model.predict((state_with_history).reshape(1, img_rows, img_cols,
                                               opt.hist_len)))
state_with_history = np.zeros((opt.hist_len, opt.state_siz))
append_to_hist(state_with_history, rgb2gray(state.pob).reshape(opt.state_siz))
next_state_with_history = np.copy(state_with_history)
epi_step = 0
nepisodes = 0
n_reached = 0.0
reward_acc_test = 0
reward_acc_list_test = []

print('Test Phase')
Ejemplo n.º 6
0
parser.add_argument(
    "-s",
    "--steps",
    help="(Optional) Number of steps to train the model for. Default is 1000",
    type=int,
    default=10000)
parser.add_argument("-ss",
                    "--silent",
                    help="Runs test without displaying the simulation",
                    action="store_false")
args = parser.parse_args()

# --------------------------------------------------------
# 0. initialization
opt = Options()
opt.disp_on = True
sim = Simulator(opt.map_ind, opt.cub_siz, opt.pob_siz, opt.act_num)

# Display
if opt.disp_on:
    win_all = None
    win_pob = None

opt.disp_on = args.silent
opt.steps = args.steps
run_name = args.model

sess = tf.Session()
agent = DqnAgent(sess, is_duelling_dqn=False)
sess.run(tf.global_variables_initializer())