Commit 25b4fb66 authored by Bryson Howell's avatar Bryson Howell

Getting LPM heatmaps to work

parent c323afcb
...@@ -25,7 +25,14 @@ def main(exp_name='test', start_idx=0, n_envs=1, n_iter=10): ...@@ -25,7 +25,14 @@ def main(exp_name='test', start_idx=0, n_envs=1, n_iter=10):
#Size in meters of GIS datasets #Size in meters of GIS datasets
test_extent = 20000 test_extent = 20000
download_extent = 40000 download_extent = 40000
LL = [20000, 20000, 1]
#LPM Parameters
ts = 850 #walking speed
simT = 10 #hours
T = ts * simT
alpha = 0.55
p_behavior = [0.055,0.377,0.559,0.003,0.006,0.0] #from nature paper
#Pull incident locations #Pull incident locations
listname = './lp_data/indexed_incidents.csv' listname = './lp_data/indexed_incidents.csv'
...@@ -62,6 +69,7 @@ def main(exp_name='test', start_idx=0, n_envs=1, n_iter=10): ...@@ -62,6 +69,7 @@ def main(exp_name='test', start_idx=0, n_envs=1, n_iter=10):
#Iterate through search incidents #Iterate through search incidents
for incident in range(0,len(i_area)): for incident in range(0,len(i_area)):
#Get current IPP/Find pair
cur_ipp = ipp_latlons[i_area[incident]] cur_ipp = ipp_latlons[i_area[incident]]
ipp_xy = lat_lon2meters(cur_ipp[0],cur_ipp[1]) ipp_xy = lat_lon2meters(cur_ipp[0],cur_ipp[1])
find_ll = find_latlons[i_area[incident]] find_ll = find_latlons[i_area[incident]]
...@@ -86,13 +94,23 @@ def main(exp_name='test', start_idx=0, n_envs=1, n_iter=10): ...@@ -86,13 +94,23 @@ def main(exp_name='test', start_idx=0, n_envs=1, n_iter=10):
sub_inac = inac[x_index-half_test:x_index+half_test,y_index-half_test:y_index+half_test,:] sub_inac = inac[x_index-half_test:x_index+half_test,y_index-half_test:y_index+half_test,:]
sub_elev = elev[x_index-half_test:x_index+half_test,y_index-half_test:y_index+half_test] sub_elev = elev[x_index-half_test:x_index+half_test,y_index-half_test:y_index+half_test]
map_data = lf_format(sub_inac,sub_lf,sub_elev) map_data = lf_format(sub_inac,sub_lf,sub_elev)
plot_env(map_data,ipp_xy,find_xy,exp_name,env,incident)
#run LPM
#run_replicate(ipp, find, map, T, p_behavior, alpha, LL)
else: else:
map_data = lf_format(inac,lf,elev) map_data = lf_format(inac,lf,elev)
plot_env(map_data,ipp_xy,find_xy,exp_name,env,incident) #Run LPM
#run_replicate(ipp, find, map, T, p_behavior, alpha, LL) #plot_env(map_data,ipp_xy,find_xy,exp_name,env,incident)
start_t = time.time()
[x, y, behavior] = run_replicate(ipp_xy, find_xy, map_data, T, p_behavior, alpha, LL)
end_t = time.time()
end_t = end_t - start_t
print('Lost Person Simulation finished, it took %.2f seconds' % end_t)
behavior = behavior[0]
x = x[0]
y = y[0]
print('IPP = {}'.format(ipp_xy))
print('X values = {}'.format(x[0:20]))
print('Y values = {}'.format(y[0:20]))
print('Behaviors = {}'.format(behavior[0:20]))
#Locate find position from IPP #Locate find position from IPP
#Convert both to meters #Convert both to meters
...@@ -184,7 +202,7 @@ def plot_env(map_data, ipp, find, exp_name='test', env=0, incident=0): ...@@ -184,7 +202,7 @@ def plot_env(map_data, ipp, find, exp_name='test', env=0, incident=0):
#For visualizing all terrain features #For visualizing all terrain features
t = 'Area ' + str(env) + ' Incident ' + str(incident) + ' - Linear Features' t = 'Area ' + str(env) + ' Incident ' + str(incident) + ' - Linear Features'
plt.title(t) plt.title(t)
plt.imshow(lf) plt.imshow(lf,cmap='gray')
#Show initial position and find point #Show initial position and find point
plt.plot(1500,1500,'g*',label='IPP', ms=10) plt.plot(1500,1500,'g*',label='IPP', ms=10)
plt.plot(x_index,y_index,'yX',label='Find Position', ms=10) plt.plot(x_index,y_index,'yX',label='Find Position', ms=10)
...@@ -205,6 +223,42 @@ def plot_env(map_data, ipp, find, exp_name='test', env=0, incident=0): ...@@ -205,6 +223,42 @@ def plot_env(map_data, ipp, find, exp_name='test', env=0, incident=0):
return return
#Fill in later, skeleton for comparing two models
def comparison_plot():
fig, (ax1, ax2) = plt.subplots(1, 2)
# Scatter plot of path and track in the first subplot
ax1.scatter(x=np.array(path)[:,0], y=np.array(path)[:,1], label='Path')
ax1.imshow(heatmap)
ax1.set_xlim([0,48])
ax1.set_ylim([0,48])
ax1.set_xlabel('X')
ax1.set_ylabel('Y')
ax1.set_title('Lost Person Model')
ax1.legend()
# Scatter plot of path and track in the first subplot
ax2.scatter(x=np.array(path)[:,0], y=np.array(path)[:,1], label='Path')
ax2.imshow(ringmap)
ax2.set_xlim([0,48])
ax2.set_ylim([0,48])
ax2.set_xlabel('X')
ax2.set_ylabel('Y')
ax2.set_title('Ring Model')
ax2.legend()
# Plot of rewards in the second subplot
#ax2.plot(rews)
#ax2.set_xlabel('Step')
#ax2.set_ylabel('Reward')
#x2.set_title('Rewards')
plt.tight_layout()
plt.suptitle("LPM Reward Function with Ring Model Constraint (Trust = %.2f)" % trustval)
plt.show()
return
#TODO: Delete this, not needed any more #TODO: Delete this, not needed any more
#Combines Linear and Inacessible features for all map layers #Combines Linear and Inacessible features for all map layers
def test_lf_format(exp_name='test',force_save='False'): def test_lf_format(exp_name='test',force_save='False'):
...@@ -258,7 +312,7 @@ def test_lf_format(exp_name='test',force_save='False'): ...@@ -258,7 +312,7 @@ def test_lf_format(exp_name='test',force_save='False'):
#For visualizing all terrain features #For visualizing all terrain features
t = exp_name + ' Area ' + str(env) + ' - Linear Features' t = exp_name + ' Area ' + str(env) + ' - Linear Features'
plt.title(t) plt.title(t)
plt.imshow(bw_lf) plt.imshow(bw_lf,cmap='greys')
#Show initial position and find point #Show initial position and find point
plt.plot(1500,1500,'g*',label='IPP', ms=10) plt.plot(1500,1500,'g*',label='IPP', ms=10)
plt.plot(400,600,'yX',label='Find Position', ms=10) plt.plot(400,600,'yX',label='Find Position', ms=10)
...@@ -304,7 +358,7 @@ def test_lf_format(exp_name='test',force_save='False'): ...@@ -304,7 +358,7 @@ def test_lf_format(exp_name='test',force_save='False'):
if __name__ == "__main__": if __name__ == "__main__":
start = 7 #Environment to start at (0 is first, 8 is first large map) start = 7 #Environment to start at (0 is first, 8 is first large map)
n = 2 #Number of environments to test n = 1 #Number of environments to test
mc = 10 #Monte Carlo iterations mc = 10 #Monte Carlo iterations
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment