|
# Create a function that manipulates the grid world derived from the data |
|
# captured in the 'df_intrinsic_analysis' DataFrame. Populating, all the 2D coordinates and visits |
|
# associated with the 6x6 grid in to their own coordinate DataFrames. Each coordinate (e.g., (0,0), (0,1), etc.) |
|
# will have its own DataFrame |
|
|
|
import pandas as pd |
|
import numpy as np |
|
|
|
# Load the intrinsic analysis DataFrame |
|
df_intrinsic_analysis = pd.read_csv('intrinsic_analysis.csv') |
|
|
|
# Function to manipulate the grid world and populate coordinate DataFrames |
|
def create_coordinate_dataframes(df_intrinsic_analysis): |
|
# Initialize a dictionary to store DataFrames for each coordinate |
|
coordinate_dataframes = {} |
|
|
|
# Iterate through the DataFrame and populate the dictionary |
|
for index, row in df_intrinsic_analysis.iterrows(): |
|
# Convert the string representation of the tuple to an actual tuple |
|
state_2d = eval(row['State_2D']) |
|
x, y = state_2d |
|
coordinate = (x, y) |
|
|
|
# Create a DataFrame for the coordinate if it doesn't exist |
|
if coordinate not in coordinate_dataframes: |
|
coordinate_dataframes[coordinate] = pd.DataFrame(columns=df_intrinsic_analysis.columns) |
|
|
|
# Append the row to the corresponding DataFrame |
|
coordinate_dataframes[coordinate] = pd.concat([coordinate_dataframes[coordinate], row.to_frame().T], ignore_index=True) |
|
|
|
return coordinate_dataframes |
|
|
|
# Call the function to create coordinate DataFrames |
|
coordinate_dataframes = create_coordinate_dataframes(df_intrinsic_analysis) |
|
|
|
# Print the DataFrames for each coordinate |
|
for coordinate, df in coordinate_dataframes.items(): |
|
print(f"Coordinate: {coordinate}") |
|
print(df) |
|
print("\n") |
|
|
|
# Example: Accessing the DataFrame for coordinate (0,0) |
|
if (0, 0) in coordinate_dataframes: |
|
df_0_0 = coordinate_dataframes[(0, 0)] |
|
df_0_0.to_csv('df_0_0.csv', index=False) |
|
|
|
|
|
import plotly.graph_objects as go |
|
import plotly.express as px |
|
import numpy as np |
|
|
|
# Define the grid and visitations |
|
grid = np.zeros((6, 6)) |
|
visitations = { |
|
(0, 0): 7035, (1, 0): 3579, (2, 0): 1359, (2, 1): 1707, (3, 1): 520, (4, 1): 227, |
|
(4, 2): 243, (5, 1): 217, (5, 2): 181, (5, 0): 241, (4, 0): 267, (5, 3): 179, |
|
(4, 3): 1034, (3, 3): 2163, (2, 3): 2080, (0, 1): 3313, (1, 1): 3015, (0, 2): 1846, |
|
(0, 3): 1104, (0, 4): 351, (1, 4): 518, (1, 3): 1497, (1, 2): 2236, (2, 2): 2239, |
|
(2, 4): 842, (1, 5): 238, (2, 5): 217, (0, 5): 341, (3, 5): 382, (4, 5): 1872, |
|
(4, 4): 2038, (3, 4): 1684, (3, 0): 383, (3, 2): 1102, (5, 4): 198 |
|
} |
|
|
|
# At coordinates (0,0): 7035 Intrinsic reward formulation manipulations are required for deconstructing math |
|
# increasing state s at a time t count each time coordinates (0,0) are visited. |
|
|
|
# At coordinates (1,0): 3579 Intrinsic reward formulation manipulations are required for deconstructing math |
|
# increasing state s at a time t count each time coordinates (1,0) are visited. |
|
|
|
# At coordinates (2,0): 1359 Intrinsic reward formulation manipulations are required for deconstructing math |
|
# increasing state s at a time t count each time coordinates (2,0) are visited. |
|
|
|
# At coordinates (2,1): 1707 Intrinsic reward formulation manipulations are required for deconstructing math |
|
# increasing state s at a time t count each time coordinates (2,1) are visited. |
|
|
|
# At coordinates (3,1): 520 Intrinsic reward formulation manipulations are required for deconstructing math |
|
# increasing state s at a time t count each time coordinates (3,1) are visited. |
|
|
|
# At coordinates (4,1): 227 Intrinsic reward formulation manipulations are required for deconstructing math |
|
# increasing state s at a time t count each time coordinates (4,1) are visited. |
|
|
|
# At coordinates (4,2): 243 Intrinsic reward formulation manipulations are required for deconstructing math |
|
# increasing state s at a time t count each time coordinates (4,2) are visited. |
|
|
|
# At coordinates (5,1): 217 Intrinsic reward formulation manipulations are required for deconstructing math |
|
# increasing state s at a time t count each time coordinates (5,1) are visited. |
|
|
|
# At coordinates (5,2): 181 Intrinsic reward formulation manipulations are required for deconstructing math |
|
# increasing state s at a time t count each time coordinates (5,2) are visited. |
|
|
|
# At coordinates (5,0): 241 Intrinsic reward formulation manipulations are required for deconstructing math |
|
# increasing state s at a time t count each time coordinates (5,0) are visited. |
|
|
|
# At coordinates (4,0): 267 Intrinsic reward formulation manipulations are required for deconstructing math |
|
# increasing state s at a time t count each time coordinates (4,0) are visited. |
|
|
|
# At coordinates (5,3): 179 Intrinsic reward formulation manipulations are required for deconstructing math |
|
# increasing state s at a time t count each time coordinates (5,3) are visited. |
|
|
|
# At coordinates (4,3): 1034 Intrinsic reward formulation manipulations are required for deconstructing math |
|
# increasing state s at a time t count each time coordinates (4,3) are visited. |
|
|
|
# At coordinates (3,3): 2163 Intrinsic reward formulation manipulations are required for deconstructing math |
|
# increasing state s at a time t count each time coordinates (3,3) are visited. |
|
|
|
# At coordinates (2,3): 2080 Intrinsic reward formulation manipulations are required for deconstructing math |
|
# increasing state s at a time t count each time coordinates (2,3) are visited. |
|
|
|
# At coordinates (0,1): 3313 Intrinsic reward formulation manipulations are required for deconstructing math |
|
# increasing state s at a time t count each time coordinates (0,1) are visited. |
|
|
|
# At coordinates (1,1): 3015 Intrinsic reward formulation manipulations are required for deconstructing math |
|
# increasing state s at a time t count each time coordinates (1,1) are visited. |
|
|
|
# At coordinates (0,2): 1846 Intrinsic reward formulation manipulations are required for deconstructing math |
|
# increasing state s at a time t count each time coordinates (0,2) are visited. |
|
|
|
# At coordinates (0,3): 1104 Intrinsic reward formulation manipulations are required for deconstructing math |
|
# increasing state s at a time t count each time coordinates (0,3) are visited. |
|
|
|
# At coordinates (0,4): 351 Intrinsic reward formulation manipulations are required for deconstructing math |
|
# increasing state s at a time t count each time coordinates (0,4) are visited. |
|
|
|
# At coordinates (1,4): 518 Intrinsic reward formulation manipulations are required for deconstructing math |
|
# increasing state s at a time t count each time coordinates (1,4) are visited. |
|
|
|
# At coordinates (1,3): 1497 Intrinsic reward formulation manipulations are required for deconstructing math |
|
# increasing state s at a time t count each time coordinates (1,3) are visited. |
|
|
|
# At coordinates (1,2): 2236 Intrinsic reward formulation manipulations are required for deconstructing math |
|
# increasing state s at a time t count each time coordinates (1,2) are visited. |
|
|
|
# At coordinates (2,2): 2239 Intrinsic reward formulation manipulations are required for deconstructing math |
|
# increasing state s at a time t count each time coordinates (2,2) are visited. |
|
|
|
# At coordinates (2,4): 842 Intrinsic reward formulation manipulations are required for deconstructing math |
|
# increasing state s at a time t count each time coordinates (2,4) are visited. |
|
|
|
# At coordinates (1,5): 238 Intrinsic reward formulation manipulations are required for deconstructing math |
|
# increasing state s at a time t count each time coordinates (1,5) are visited. |
|
|
|
# At coordinates (2,5): 217 Intrinsic reward formulation manipulations are required for deconstructing math |
|
# increasing state s at a time t count each time coordinates (2,5) are visited. |
|
|
|
# At coordinates (0,5): 341 Intrinsic reward formulation manipulations are required for deconstructing math |
|
# increasing state s at a time t count each time coordinates (0,5) are visited. |
|
|
|
# At coordinates (3,5): 382 Intrinsic reward formulation manipulations are required for deconstructing math |
|
# increasing state s at a time t count each time coordinates (3,5) are visited. |
|
|
|
# At coordinates (4,5): 1872 Intrinsic reward formulation manipulations are required for deconstructing math |
|
# increasing state s at a time t count each time coordinates (4,5) are visited. |
|
|
|
# At coordinates (4,4): 2038 Intrinsic reward formulation manipulations are required for deconstructing math |
|
# increasing state s at a time t count each time coordinates (4,4) are visited. |
|
|
|
# At coordinates (3,4): 1684 Intrinsic reward formulation manipulations are required for deconstructing math |
|
# increasing state s at a time t count each time coordinates (3,4) are visited. |
|
|
|
# At coordinates (3,0): 383 Intrinsic reward formulation manipulations are required for deconstructing math |
|
# increasing state s at a time t count each time coordinates (2,0) are visited. |
|
|
|
# At coordinates (3,2): 1102 Intrinsic reward formulation manipulations are required for deconstructing math |
|
# increasing state s at a time t count each time coordinates (3,2) are visited. |
|
|
|
# At coordinates (5,4): 198 Intrinsic reward formulation manipulations are required for deconstructing math |
|
# increasing state s at a time t count each time coordinates (5,4) are visited. |
|
|
|
The Intrinsic reward equation manipulations create the State Visitations Visualization in each square (6x6) grid |
|
|
|
# Fill the grid with visitations |
|
for (x, y), count in visitations.items(): |
|
grid[x, y] = count |
|
|
|
# Calculate the total number of visitations |
|
total_visitations = sum(visitations.values()) |
|
|
|
# Calculate the percentages |
|
percentages = {state: (count / total_visitations) * 100 for state, count in visitations.items()} |
|
|
|
# Print the percentages in the specified order |
|
order = [ |
|
(0, 0), (0, 1), (0, 2), (0, 3), (0, 4), (0, 5), |
|
(1, 0), (1, 1), (1, 2), (1, 3), (1, 4), (1, 5), |
|
(2, 0), (2, 1), (2, 2), (2, 3), (2, 4), (2, 5), |
|
(3, 0), (3, 1), (3, 2), (3, 3), (3, 4), (3, 5), |
|
(4, 0), (4, 1), (4, 2), (4, 3), (4, 4), (4, 5), |
|
(5, 0), (5, 1), (5, 2), (5, 3), (5, 4), (5, 5) |
|
] |
|
|
|
print("State Visitations Percentages:") |
|
for state in order: |
|
print(f"State {state}: {percentages.get(state, 0):.2f}%") |
|
|
|
# Create a pie chart |
|
labels = [f"State {state}" for state in visitations.keys()] |
|
values = list(visitations.values()) |
|
|
|
fig_pie = go.Figure(data=[go.Pie(labels=labels, values=values)]) |
|
fig_pie.update_layout(title_text="State Visitations Pie Chart") |
|
fig_pie.show() |
|
|
|
# Create a heatmap |
|
fig_heatmap = px.imshow(grid, labels=dict(x="Column", y="Row", color="Visitations"), |
|
x=list(range(6)), y=list(range(6)), title="State Visitations Heatmap") |
|
fig_heatmap.update_xaxes(side="top") |
|
fig_heatmap.show() |