Commit 93dfd2fa authored by Léo-Paul Géneau's avatar Léo-Paul Géneau 👾

erp5_wendelin_drone: automatically fetch the amount of parameters

parent 477cf068
......@@ -116,7 +116,7 @@ The next few section will display some information about the best 5 parameters a
## Table of Contents\n
- [Flow Chart](#flowchart)\n
- [Score Plot](#plot_div5)\n
- [Distance Deviation Plot](#plot_div)\n
- [Distance Deviation Plot](#plot_div1)\n
- [ASML Deviation Plot](#plot_div2)\n
- [Ground Speed Deviation Plot](#plot_div3)\n
- [Climb Rate Deviation Plot](#plot_div4)\n
......@@ -170,7 +170,7 @@ $$\n
# Deviation Plot\n
## Distance/Positional difference\n
This line plot illustrates the deviation between the simulation data and the ground truth values, focusing on the common timestamps. It\'s important to note that the simulations may end at different times, resulting in a representation of a shorter timeframe for some simulations compared to others.\n
<div class="plot_div" id="plot_div"/>\n
<div class="plot_div1" id="plot_div1"/>\n
\n
%% md\n
# Deviation Plot\n
......@@ -211,7 +211,7 @@ for (transformation of transformation_locations) {\n
.setAttribute("href", "https://" + window.location.host + transformation[1])\n
}\n
\n
hateoas_url = "https://" + window.location.host + "/erp5/web_site_module/renderjs_runner/hateoas/";\n
hateoas_url = "https://" + window.location.host + "/erp5/web_site_module/default_wendelin_front/hateoas/";\n
jio = jIO.createJIO({\n
type: "erp5",\n
url: hateoas_url,\n
......@@ -256,35 +256,26 @@ function findNewestIteration(arrayID, rank) {\n
return jio.allDocs({\n
query: \'portal_type:"Data Array Line" AND \' +\n
\'title: "\' + rank + \'"\'\n
\n
})\n
.then(function (result) {\n
.push(function (result) {\n
array_id = result.data.rows[0].id; //would be the correct thing, but as we have multiple data arrays with the same name, we need to fix it like this\n
return gadget.jio_get(array_id)\n
})\n
.then(function (result) {\n
\n
return result.index_expression.split(":")\n
\n
})\n
\n
return gadget.jio_get(array_id);\n
});\n
}\n
\n
\n
\n
\n
function getAllData(arrayID, ranks, column_names) {\n
\n
intervals = []\n
return RSVP.all(ranks.map((rank) => findNewestIteration(arrayID, rank)))\n
.then(function (result) {\n
intervals = []\n
for (interval of result) {\n
start_index = interval[0];\n
stop_index = interval[1];\n
for (data_array_line of result) {\n
[start_index, stop_index] = data_array_line.index_expression.split(":");\n
intervals.push([Number(start_index), Number(stop_index)]);\n
}\n
array_id = arrayID\n
array_id = arrayID;\n
return wendelin.getArrayRawSlice(gadget, array_id, intervals[0][0], intervals[4][1]);\n
})\n
.then(function (result) {\n
......@@ -297,9 +288,6 @@ function getAllData(arrayID, ranks, column_names) {\n
table_data = table_data.concat([nj.unpack(result.pick(i, null))])\n
}\n
\n
column_names = [\n
"ASML_diff", "ground_speed_diff", "climb_rate_diff", "climb_rate_reciprocal", "timestamp", "score_cosine_row", "score_cosine_column", "distance_reciprocal", "iteration", "score_reciprocal", "ground_speed_reciprocal", "distance_diff", "Param2", "Param1", "ASML_reciprocal"\n
]\n
for (i = 0; i < column_names.length; i += 1) {\n
column_data = []\n
for (row of table_data) {\n
......@@ -319,8 +307,7 @@ function getAllData(arrayID, ranks, column_names) {\n
})\n
}\n
\n
\n
function createLinePlotData(arrayData, column_names, label_list) {\n
function createPlotData(arrayData, column_names, label_list, parameters, type) {\n
all_trace_templates = []\n
const plotlyColors = [\n
\'rgb(31, 119, 180)\', // Blue\n
......@@ -329,82 +316,46 @@ function createLinePlotData(arrayData, column_names, label_list) {\n
\'rgb(214, 39, 40)\', // Red\n
\'rgb(148, 103, 189)\' // Purple\n
];\n
for (i = 0; i < arrayData.length; i = i + 1) {\n
trace_templates = []\n
for (j = 0; j < label_list.length; j = j + 1) {\n
if (label_list[j] != "timestamp") {\n
\n
name_string = "The parameters are (drone_speed, drone_max_roll): " + [arrayData[i][column_names.indexOf("Param1")][0], arrayData[i][column_names.indexOf("Param2")][0]].join(\', \')\n
arrayData.forEach(function (data) {\n
trace_templates = [];\n
label_list.forEach(function (label) {\n
if (label != "timestamp") {\n
name_string = "The parameters are (" + parameters.join(\', \') + "): " + parameters.map((param_name) => data[column_names.indexOf(param_name)][0]).join(\', \');\n
\n
trace_template = {\n
type: "scatter",\n
type: type,\n
name: name_string,\n
x: arrayData[i][column_names.indexOf("timestamp")],\n
y: arrayData[i][column_names.indexOf(label_list[j])],\n
x: data[column_names.indexOf("timestamp")],\n
y: data[column_names.indexOf(label)],\n
line: {\n
color: plotlyColors[i]\n
}\n
}\n
trace_templates = trace_templates.concat(trace_template);\n
}\n
}\n
});\n
all_trace_templates.push(trace_template)\n
}\n
});\n
\n
return all_trace_templates;\n
\n
}\n
\n
\n
\n
\n
function createBarPlotData(arrayData, column_names, label_list) {\n
all_trace_templates = []\n
const plotlyColors = [\n
\'rgb(31, 119, 180)\', // Blue\n
\'rgb(255, 127, 14)\', // Orange\n
\'rgb(44, 160, 44)\', // Green\n
\'rgb(214, 39, 40)\', // Red\n
\'rgb(148, 103, 189)\' // Purple\n
];\n
for (i = 0; i < arrayData.length; i = i + 1) {\n
trace_templates = []\n
for (j = 0; j < label_list.length; j = j + 1) {\n
if (label_list[j] != "timestamp") {\n
\n
name_string = "The parameters are (drone_speed, drone_max_roll): " + [arrayData[i][column_names.indexOf("Param1")][0], arrayData[i][column_names.indexOf("Param2")][0]].join(\', \')\n
\n
trace_template = {\n
type: "bar", // Set type to "bar" for a bar plot\n
name: name_string,\n
x: ["Value"], //arrayData[i][column_names.indexOf("timestamp")],\n
y: [arrayData[i][column_names.indexOf(label_list[j])][0]],\n
marker: {\n
color: plotlyColors[i]\n
}\n
};\n
trace_templates = trace_templates.concat(trace_template);\n
}\n
}\n
all_trace_templates.push(trace_template)\n
}\n
\n
return all_trace_templates;\n
\n
function createLinePlotData(arrayData, column_names, label_list, parameters) {\n
return createPlotData(arrayData, column_names, label_list, parameters, "scatter");\n
}\n
\n
\n
\n
function createBarPlotData(arrayData, column_names, label_list, parameters) {\n
return createPlotData(arrayData, column_names, label_list, parameters, "bar");\n
}\n
\n
function getColumnNames(arrayID) {\n
\n
return gadget.jio_get(arrayID)\n
.then(function (result) {\n
.push(function (result) {\n
column_names = result.array_dtype.match(/\\(\'(.*?)\',/g);\n
column_names = column_names.map(match => match.match(/\\(\'(.*?)\',/))\n
column_names = column_names.map(match => match.match(/\\(\'(.*?)\',/));\n
column_names = column_names.map(thing => thing[1]);\n
return column_names\n
})\n
return column_names;\n
});\n
}\n
\n
function plot(data, plotTitle = null, graph = null, layout = null) {\n
......@@ -429,31 +380,23 @@ function prepareData() {\n
\'title: "Recalculated Plots" AND \' +\n
\'simulation_state:"started"\'\n
})\n
.then(function (result) {\n
\n
.push(function (result) {\n
var data_analysis_line_id = result.data.rows[0].id;\n
return jio.allDocs({\n
query: \'portal_type:"Data Array" AND \' +\n
\'aggregate_related_relative_url:"\' + data_analysis_line_id + \'"\'\n
});\n
})\n
.then(function (result) {\n
\n
column_names = getColumnNames(result.data.rows[0].id)\n
return [column_names, result.data.rows[0].id]\n
})\n
.then(function (result) {\n
\n
return RSVP.all([result[0], getAllData(result[1], [1, 2, 3, 4, 5], result[0])])\n
.push(function (result) {\n
return RSVP.all([getColumnNames(result.data.rows[0].id), result.data.rows[0].id]);\n
})\n
.push(function (result) {\n
return RSVP.all([result[0], getAllData(result[1], [1, 2, 3, 4, 5], result[0])]);\n
});\n
}\n
\n
\n
\n
\n
prepareData()\n
.then(function (result) {\n
\n
const layout = {\n
barmode: \'group\',\n
title: \'Bar Chart\',\n
......@@ -465,31 +408,24 @@ prepareData()\n
}\n
};\n
\n
graph = document.getElementById(\'plot_div\')\n
data = createLinePlotData(result[1], result[0], ["distance_diff"])\n
plot(data, "", graph, null)\n
\n
graph = document.getElementById(\'plot_div2\')\n
data = createLinePlotData(result[1], result[0], ["ASML_diff"])\n
plot(data, "", graph, null)\n
\n
\n
graph = document.getElementById(\'plot_div3\')\n
data = createLinePlotData(result[1], result[0], ["ground_speed_diff"])\n
plot(data, "", graph, null)\n
\n
\n
graph = document.getElementById(\'plot_div4\')\n
data = createLinePlotData(result[1], result[0], ["climb_rate_diff"])\n
plot(data, "", graph, null)\n
\n
\n
graph = document.getElementById(\'plot_div5\')\n
data = createBarPlotData(result[1], result[0], ["score_reciprocal"])\n
plot(data, "", graph, layout)\n
const fixed_column_names = [\n
"ASML_diff", "ground_speed_diff", "climb_rate_diff",\n
"climb_rate_reciprocal", "timestamp", "distance_reciprocal",\n
"score_cosine_row", "score_cosine_column", "ground_speed_reciprocal",\n
"distance_diff", "score_reciprocal", "ASML_reciprocal", "name",\n
"iteration"\n
];\n
const parameters = column_names.filter(n => !fixed_column_names.includes(n));\n
\n
})\n
["distance_diff", "ASML_diff", "ground_speed_diff", "climb_rate_diff"].forEach(function (label, index) {\n
plot(createLinePlotData(result[1], result[0], [label], parameters),\n
"", document.getElementById(\'plot_div\' + (index + 1)), null);\n
});\n
\n
graph = document.getElementById(\'plot_div5\');\n
data = createBarPlotData(result[1], result[0], ["score_reciprocal"], parameters);\n
plot(data, "", graph, layout);\n
});\n
]]></string> </value>
......@@ -560,7 +496,7 @@ prepareData()\n
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>1013.42930.28344.22254</string> </value>
<value> <string>1019.57407.12828.21128</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -580,7 +516,7 @@ prepareData()\n
</tuple>
<state>
<tuple>
<float>1704461947.15</float>
<float>1728491943.46</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -74,32 +74,6 @@ seen_sims = progress_indicator_sim.getStringOffsetIndex()
new_seen = ""
if seen_sims is None:
seen_sims = ""
score_dtypes = {'name': 'S256', 'Param1': 'f16', 'Param2': 'f16',
'distance_reciprocal': 'f8', 'ASML_reciprocal': 'f8',
'ground_speed_reciprocal': 'f8', 'climb_rate_reciprocal': 'f8',
'score_reciprocal': 'f16', 'score_cosine_row': 'f16',
'score_cosine_column': 'f16'}
_ = out_array_scores["Data Array"].initArray(shape=(0,), dtype=list(score_dtypes.items()))
plot_dtypes = {
'name': 'S256',
'Param1': 'f8',
'Param2': 'f8',
'timestamp': 'f8',
'distance_diff': 'f8',
'ASML_diff': 'f8',
'ground_speed_diff': 'f8',
'climb_rate_diff': 'f8',
'distance_reciprocal': 'f8',
'ASML_reciprocal': 'f8',
'ground_speed_reciprocal': 'f8',
'climb_rate_reciprocal': 'f8',
'score_reciprocal': 'f16',
'score_cosine_row': 'f16',
'score_cosine_column': 'f16'
}
_ = out_array_plot_data["Data Array"].initArray(shape=(0,), dtype=list(plot_dtypes.items()))
simulated_flight_list = []
simulated_flights_value_dict_list = []
......@@ -135,11 +109,11 @@ for name in not_seen_list:
break
try:
under_timestamp = simulated_flight[simulated_flight['timestamp (ms)'] - timestamp_diff < row['timestamp (ms)']].tail(1)
under_timestamp = simulated_flight[simulated_flight['timestamp (ms)'] - timestamp_diff < row['timestamp (ms)']].tail(1).to_dict('records')[0]
except IndexError:
continue
over_timestamp = simulated_flight[simulated_flight['timestamp (ms)'] - timestamp_diff >= row['timestamp (ms)']].head(1)
rate = (over_timestamp["timestamp (ms)"] - timestamp_diff - row["timestamp (ms)"])/(over_timestamp["timestamp (ms)"] - under_timestamp["timestamp (ms)"])
over_timestamp = simulated_flight[simulated_flight['timestamp (ms)'] - timestamp_diff >= row['timestamp (ms)']].head(1).to_dict('records')[0]
rate = (over_timestamp['timestamp (ms)'] - timestamp_diff - row['timestamp (ms)'])/(over_timestamp['timestamp (ms)'] - under_timestamp['timestamp (ms)'])
for criterion in distance_criterion_tuple:
tmp_sim[criterion].append(rated_value(over_timestamp[criterion], under_timestamp[criterion], rate))
......@@ -154,8 +128,9 @@ for name in not_seen_list:
),
tmp_sim['AMSL (m)'][-1],
tmp_sim['ground speed (m/s)'][-1],
tmp_real['climb rate (m/s)'][-1],
tmp_real['climb rate (m/s)'][-1]
)):
distance_list_tuple[index].append(value)
# If we have at least 100 entries (timestamps) analysed, add the filename to the list
......@@ -163,25 +138,19 @@ for name in not_seen_list:
if len(distance_list_tuple[0]) > 0:
# Add it to the dictionary
# A list of simulations, and their values over time
pattern = r'\((.*?)\)'
match = re.search(pattern, name)
if match:
values_str = match.group(1)
parameters = [float(val.strip()) for val in values_str.split(',')]
parameters = {k: float(v) for _, k, v in re.findall(r'[_-](([a-zA-Z_]+)_(\d+))', name)}
if parameters:
reciprocal_of_difference = [1/(1+mean_operation(list(map(abs, x)))) for x in distance_list_tuple[1:]]
score_reciprocal = sum(reciprocal_of_difference)
tmp_df_sim = pd.DataFrame(tmp_sim)
tmp_df_real = pd.DataFrame(tmp_real)
# Uncomment once you can actually use np..norm
score_cosine_row =mean_cosine_similarity_custom(tmp_df_real, tmp_df_sim)# cosine_similarity_rows(tmp_df_real, tmp_df_sim).mean()
score_cosine_row = mean_cosine_similarity_custom(tmp_df_real, tmp_df_sim)# cosine_similarity_rows(tmp_df_real, tmp_df_sim).mean()
score_cosine_column = mean_cosine_similarity_custom(tmp_df_real.T, tmp_df_sim.T)#cosine_similarity_rows(tmp_df_real.T, tmp_df_sim.T).mean()
simulated_flights_value_dict_list.append({
flights_value_dict = {
"name": name,
"Param1" : parameters[0],
"Param2": parameters[1],
"timestamp": distance_list_tuple[0],
"distance_diff": distance_list_tuple[1],
"ASML_diff" : distance_list_tuple[2],
......@@ -193,21 +162,24 @@ for name in not_seen_list:
"climb_rate_reciprocal" : reciprocal_of_difference[3],
"score_reciprocal": score_reciprocal/4,
"score_cosine_row" : score_cosine_row,
"score_cosine_column" : score_cosine_column
})
"score_cosine_column" : score_cosine_column,
}
selected_simulation_data_dict_list.append({
simulation_data_dict = {
"name": name,
"Param1" : parameters[0],
"Param2": parameters[1],
"distance_reciprocal": reciprocal_of_difference[0],
"ASML_reciprocal" : reciprocal_of_difference[1],
"ground_speed_reciprocal" : reciprocal_of_difference[2],
"climb_rate_reciprocal" : reciprocal_of_difference[3],
"score_reciprocal": score_reciprocal/4,
"score_cosine_row" : score_cosine_row,
"score_cosine_column" : score_cosine_column
})
}
for flight_parameter, value in parameters.items():
flights_value_dict[flight_parameter] = value
simulation_data_dict[flight_parameter] = value
simulated_flights_value_dict_list.append(flights_value_dict)
selected_simulation_data_dict_list.append(simulation_data_dict)
combined_data = pd.DataFrame() # Initialize an empty DataFrame
......@@ -217,26 +189,7 @@ for data_dict in simulated_flights_value_dict_list:
tmp = pd.DataFrame(data_dict) # Wrap data_dict in a list and create a DataFrame
combined_data = pd.concat([combined_data, tmp], ignore_index=True)
plot_dtypes = {
'name': 'S256',
'Param1': 'float64',
'Param2': 'float64',
'timestamp': 'float64',
'distance_diff': 'float64',
'ASML_diff': 'float64',
'ground_speed_diff': 'float64',
'climb_rate_diff': 'float64',
'distance_reciprocal': 'float64',
'ASML_reciprocal': 'float64',
'ground_speed_reciprocal': 'float64',
'climb_rate_reciprocal': 'float64',
'score_reciprocal': 'float64',
'score_cosine_row': 'float64',
'score_cosine_column': 'float64',
}
plot_dtypes = {k: 'float64' if k != 'name' else 'S256' for k in simulated_flights_value_dict_list[0]}
plots_df = combined_data
if plots_df.empty:
......@@ -261,11 +214,7 @@ for data_dict in selected_simulation_data_dict_list:
score_dtypes = {'name': 'S256', 'Param1': 'float64', 'Param2': 'float64',
'distance_reciprocal': 'float64', 'ASML_reciprocal': 'float64',
'ground_speed_reciprocal': 'float64', 'climb_rate_reciprocal': 'float64',
'score_reciprocal': 'float64', 'score_cosine_row': 'float64',
'score_cosine_column': 'float64'}
score_dtypes = {k: 'float64' if k != 'name' else 'S256' for k in selected_simulation_data_dict_list[0]}
scores_df = pd.DataFrame(combined_data)
scores_df = scores_df.astype(score_dtypes)
###############################
......@@ -273,6 +222,9 @@ scores_df = scores_df.astype(score_dtypes)
zbigarray_scores = out_array_scores["Data Array"].getArray()
if zbigarray_scores is None:
out_array_scores["Data Array"].initArray(shape=(0,), dtype=list(score_dtypes.items()))
out_array_plot_data["Data Array"].initArray(shape=(0,), dtype=list(plot_dtypes.items()))
score_names = list(out_array_scores["Data Array"])
......@@ -281,7 +233,7 @@ score_names = list(out_array_scores["Data Array"])
scores_ndarray = scores_df.to_records(index = False)
scores_ndarray = scores_ndarray.astype([("name", "S256"),("Param1", "f8"), ("Param2", "f8"), ("distance_reciprocal", "f8"), ("ASML_reciprocal", "f8"), ("ground_speed_reciprocal", "f8"), ('climb_rate_reciprocal', 'f8'), ("score_reciprocal", "f8"), ("score_cosine_column", "f8"), ("score_cosine_row", "f8")])
scores_ndarray = scores_ndarray.astype([(k, 'f8' if k != 'name' else 'S256') for k in score_dtypes])
if zbigarray_scores is None:
......@@ -330,7 +282,7 @@ zbigarray_plots = out_array_plot_data["Data Array"].getArray()
plots_ndarray = plots_df.to_records(index = False)
plots_ndarray = plots_ndarray.astype([('name', 'S256'), ('Param1', 'f8'), ('Param2', 'f8'), ('timestamp', 'f8'), ('distance_diff', 'f8'), ('ASML_diff', 'f8'), ('ground_speed_diff', 'f8'), ('climb_rate_diff', 'f8'), ('distance_reciprocal', 'f8'), ('ASML_reciprocal', 'f8'), ('ground_speed_reciprocal', 'f8'), ('climb_rate_reciprocal', 'f8'), ('score_reciprocal', 'f8'), ('score_cosine_row', 'f8'), ('score_cosine_column', 'f8')])
plots_ndarray = plots_ndarray.astype([(k, 'f8' if k != 'name' else 'S256') for k in plot_dtypes])
if zbigarray_plots is None:
zbigarray_plots = out_array_plot_data["Data Array"].initArray(shape=(0,), dtype=plots_ndarray.dtype.fields)
......
......@@ -8,148 +8,64 @@ import re
# Now, to save space, we just overwrite the old array with the new one, that contains the new scores
# This new array will give us the final overview of the ranking of the parameters. This can be used by our genetic algorithm to decide when we can stop and which parameters worked the best.
score_dtypes = {'name': 'S256', 'Param1': 'f8', 'Param2': 'f8',
'distance_reciprocal': 'f8', 'ASML_reciprocal': 'f8',
'ground_speed_reciprocal': 'f8', 'climb_rate_reciprocal': 'f8',
'score_reciprocal': 'f8', 'score_cosine_row': 'f8',
'score_cosine_column': 'f8'}
new_score_dtypes= {'name': 'S256', 'Param1': 'f8', 'Param2': 'f8',
'distance_reciprocal': 'f8', 'ASML_reciprocal': 'f8',
'ground_speed_reciprocal': 'f8', 'climb_rate_reciprocal': 'f8',
'score_reciprocal': 'f8', 'score_cosine_row': 'f8',
'score_cosine_column': 'f8',
'iteration': 'i8'}
plot_dtypes = {
'name': 'S256',
'Param1': 'f8',
'Param2': 'f8',
'timestamp': 'f8',
'distance_diff': 'f8',
'ASML_diff': 'f8',
'ground_speed_diff': 'f8',
'climb_rate_diff': 'f8',
'distance_reciprocal': 'f8',
'ASML_reciprocal': 'f8',
'ground_speed_reciprocal': 'f8',
'climb_rate_reciprocal': 'f8',
'score_reciprocal': 'f8',
'score_cosine_row': 'f8',
'score_cosine_column': 'f8',
'iteration': 'i8'
}
new_plot_dtypes = {
'Param1': 'f8',
'Param2': 'f8',
'timestamp': 'f8',
'distance_diff': 'f8',
'ASML_diff': 'f8',
'ground_speed_diff': 'f8',
'climb_rate_diff': 'f8',
'distance_reciprocal': 'f8',
'ASML_reciprocal': 'f8',
'ground_speed_reciprocal': 'f8',
'climb_rate_reciprocal': 'f8',
'score_reciprocal': 'f8',
'score_cosine_row': 'f8',
'score_cosine_column': 'f8',
'iteration': 'i8'
}
score_array = input_array_scores["Data Array"]
new_score_array = out_array_scores["Data Array"]
plot_array = input_array_plot["Data Array"]
new_plot_array = out_array_plots["Data Array"]
# Should only look at the newest few
score_array = input_array_scores['Data Array']
score_nparray = score_array.getArray()
if score_nparray is None:
score_nparray = out_array_scores["Data Array"].initArray(shape=(0,), dtype=list(new_score_dtypes.items()))
return
plot_array = input_array_plot['Data Array']
plot_nparray = plot_array.getArray()
if plot_nparray is None:
plot_nparray = out_array_plots["Data Array"].initArray(shape=(0,), dtype=list(new_plot_dtypes.items()))
return
new_score_dtypes = [(k, v[0]) for k, v in dict(score_nparray.dtype.fields).items()]
new_score_dtypes.append(('iteration', 'i8'))
new_score_array = out_array_scores['Data Array']
new_score_nparray = new_score_array.getArray()
if new_score_nparray is None:
new_score_array.initArray(shape=(0,), dtype=new_score_dtypes)
new_plot_dtypes = [(k, v[0]) for k, v in dict(plot_nparray.dtype.fields).items()]
new_plot_dtypes.append(('iteration', 'i8'))
new_plot_array = out_array_plots['Data Array']
new_plot_nparray = new_plot_array.getArray()
if new_plot_nparray is None:
new_plot_array.initArray(shape=(0,), dtype=new_plot_dtypes)
old_score_df = pd.DataFrame.from_records(score_nparray[:].copy())
old_plot_df = pd.DataFrame.from_records(plot_nparray[:].copy())
progress_indicator = input_array_scores["Progress Indicator"]
progress_indicator = input_array_scores['Progress Indicator']
seen_sims = progress_indicator.getStringOffsetIndex()
if seen_sims is None:
seen_sims = ""
sim_flight_names = list(old_score_df["name"])
sim_flight_names = list(old_score_df['name'])
# We will only continue if there is new data available.
if len([x for x in sim_flight_names if x not in seen_sims]) == 0:
return
new_score_nparray = new_score_array.getArray()
if new_score_nparray is None:
new_score_nparray = out_array_scores["Data Array"].initArray(shape=(0,), dtype=list(new_score_dtypes.items()))
new_plot_nparray = new_plot_array.getArray()
if new_plot_nparray is None:
new_plot_nparray = out_array_plots["Data Array"].initArray(shape=(0,), dtype=list(new_plot_dtypes.items()))
new_score_df = pd.DataFrame.from_records(new_score_nparray[:].copy())
new_plot_df = pd.DataFrame.from_records(new_plot_nparray[:].copy())
new_score_iteration = new_score_df["iteration"].max()
new_score_iteration = new_score_df['iteration'].max()
if math.isnan(new_score_iteration):
new_score_iteration = 0
new_score_df = new_score_df.drop(["iteration"],axis=1)
new_score_df = new_score_df.drop(['iteration'], axis=1)
new_plot_iteration = new_plot_df["iteration"].max()
if math.isnan(new_plot_iteration):
new_plot_iteration = 0
#new_plot_df = new_plot_df.drop(columns=["iteration"])
answer_scores = pd.concat([old_score_df, new_score_df]).drop_duplicates(subset=['Param1','Param2'], keep='last')
answer_plots = pd.concat([old_plot_df, new_plot_df]).drop_duplicates(subset=['Param1','Param2'], keep='last')
answer_scores["score_reciprocal"] = answer_scores["score_reciprocal"].astype('float64')
answer_scores = answer_scores.nlargest(5, "score_reciprocal")
answer_plots = old_plot_df[old_plot_df["name"].isin(list(answer_scores["name"]))]
param_subset = [k for k in old_score_df.dtypes.keys().values if not 'reciprocal' in k and not 'score' in k and k != 'name']
answer_scores = pd.concat([old_score_df, new_score_df]).drop_duplicates(subset=param_subset, keep='last')
answer_plots = pd.concat([old_plot_df, new_plot_df]).drop_duplicates(subset=param_subset, keep='last')
answer_scores['score_reciprocal'] = answer_scores['score_reciprocal'].astype('float64')
answer_scores = answer_scores.nlargest(5, 'score_reciprocal')
answer_plots = old_plot_df[old_plot_df['name'].isin(list(answer_scores['name']))]
new_score_iteration = new_score_iteration + 1
new_plot_iteration = new_plot_iteration + 1
......@@ -158,24 +74,14 @@ answer_scores["iteration"] = new_score_iteration
answer_plots["iteration"] = new_plot_iteration
# We will remove all the data from the data arrays before we append the new data. Essentially we will be left with only the best few iterations
new_score_nparray = out_array_scores["Data Array"].initArray(shape=(0,), dtype=list(new_score_dtypes.items()))
new_plot_nparray = out_array_plots["Data Array"].initArray(shape=(0,), dtype=list(new_plot_dtypes.items()))
new_score_nparray = new_score_array.initArray(shape=(0,), dtype=new_score_dtypes)
new_plot_nparray = new_plot_array.initArray(shape=(0,), dtype=new_plot_dtypes)
new_score_nparray.append(answer_scores.to_records(index = False))
# Group the DataFrame by the 'name' column
grouped = answer_plots.groupby(['Param1', 'Param2'])
grouped = answer_plots.groupby(param_subset)
# Initialize a list to store the resulting DataFrames
resulting_dfs = []
......
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