<jupyter_start><jupyter_text>Initialise road model with single pedestrian<jupyter_code># Road parameters
road_length = 100
road_width = 10
n_lanes = 1
vehicle_flow = 3

# Ped parameters
o = (0,0)
d = (road_length*0.5, road_width)
s = 1.5
b = 0
g = 0.7
a = 0.05

cross_model = CrossingModel(road_length, road_width, vehicle_flow, n_lanes, o, d, g, a, s)

# Get ped and road

ped = cross_model.getPed()
road = cross_model.getRoad()<jupyter_output><empty_output><jupyter_text>Plot tilings for this environmentAlso plot the states: pedestrian starting location, destionation and unsignalised crossing<jupyter_code>ax = plt.figure(figsize=(road_length*0.5, road_width * 0.5)).gca()
colors = distinctipy.get_colors(ped._tg.ntilings)

plot_tiling_group(ped._tg, ax=ax, linewidth=0.5, colors=colors)

states = [ped._loc, d] + road.getCrossingCoords()
state_colors = ['blue', 'red'] + ['grey']*len(road.getCrossingCoords())
for i, s in enumerate(states):
    c = state_colors[i]
    highlight_tiling_group(ped._tg, s=s, ax=ax, colors=[c], op = 'intersection') 
    plot_state(s, ax=ax, color='k')<jupyter_output><empty_output><jupyter_text>Run MC updates and plot resulting value function<jupyter_code>n_updates = 500
for i in range(n_updates):
	ped.mc_update_of_internal_model()
figsize = (road_length*0.5, road_width)
fig = plot_ped_feature_values(ped, figsize, nbins = 10, cmaps = ['viridis', 'magma'], alpha = 0.5, op = 'intersection')<jupyter_output><empty_output><jupyter_text>Plot values and number of visits for different pedestrian positions<jupyter_code># Reset internal model values
ped.internal_model.reset_values()
ped.set_loc((25,0))
ped.set_internal_model_state_and_search_policy()

# Run updates and plot again
n_updates = 500
for i in range(n_updates):
	ped.mc_update_of_internal_model()
    

fig = plot_ped_feature_values(ped, figsize, nbins = 10, cmaps = ['viridis', 'magma'], alpha = 0.5, op = 'intersection')
# Reset internal model values
ped.internal_model.reset_values()
ped.set_loc((50,0))
ped.set_internal_model_state_and_search_policy()

# Run updates and plot again
n_updates = 500
for i in range(n_updates):
	ped.mc_update_of_internal_model()
    

fig = plot_ped_feature_values(ped, figsize, nbins = 10, cmaps = ['viridis', 'magma'], alpha = 0.5, op = 'intersection')
# Reset internal model values
ped.internal_model.reset_values()
ped.set_loc((75,0))
ped.set_internal_model_state_and_search_policy()

# Run updates and plot again
n_updates = 500
for i in range(n_updates):
	ped.mc_update_of_internal_model()
    

fig = plot_ped_feature_values(ped, figsize, nbins = 10, cmaps = ['viridis', 'magma'], alpha = 0.5, op = 'intersection')<jupyter_output><empty_output><jupyter_text>Now run trajectory<jupyter_code># Reset internal model values
ped.internal_model.reset_values()
ped.set_loc((0,0))
ped.set_internal_model_state_and_search_policy()
n_updates = 500
for i in range(n_updates):
	ped.mc_update_of_internal_model()

fig = plot_ped_feature_values(ped, figsize, nbins = 10, cmaps = ['viridis', 'magma'], alpha = 0.5, op = 'intersection')
i = 0
while (ped.internal_model.isTerminal() == False):
    ped.step(nupdates = 0)
    i+=1
    if (i > 500):
        break
for l in ped._loc_history:
    plot_state(l, fig=fig, color='red', markersize=12)
# Ped continues walking in a straigh line and past the edge of the road
fig
# Now repeat but allow the ped agent to update its value function as it walks along
# Reset internal model values
ped.internal_model.reset_values()
ped.set_loc((0,0))
ped.set_internal_model_state_and_search_policy()
i = 0
while (ped.internal_model.isTerminal() == False):
    ped.step(nupdates = 10)
    i+=1
    if (i > 500):
        break
for l in ped._loc_history:
    plot_state(l, fig=fig, color='blue', markersize=12)
fig
# Now repeat but allow the ped agent to update its value function as it walks along
# Reset internal model values
ped.internal_model.reset_values()
ped.set_loc((0,0))
ped.set_internal_model_state_and_search_policy()
i = 0
while (ped.internal_model.isTerminal() == False):
    ped.step(nupdates = 1)
    i+=1
    if (i > 500):
        break

for l in ped._loc_history:
    plot_state(l, fig=fig, color='green', markersize=12)
fig
# Now repeat but allow the ped agent to update its value function as it walks along
# Reset internal model values
ped.internal_model.reset_values()
ped.set_loc((0,0))
ped.set_internal_model_state_and_search_policy()
i = 0
while (ped.internal_model.isTerminal() == False):
    ped.step(nupdates = 7)
    i+=1
    if (i > 500):
        break

for l in ped._loc_history:
    plot_state(l, fig=fig, color='grey', markersize=12)
fig<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12022327179046802, 'fraction_numerical': 0.024044654358093602, 'mean_word_length': 5.4529085872576175, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '41273', 'license': 'MIT', 'n_tokens_mistral': 1765, 'n_tokens_neox': 1668, 'n_words': 421, 'path': 'plot_crossing_model.ipynb', 'repo_name': 'obisargoni/CrossingDynaAgent', 'size': '4658'}