1
0
Fork 0

testing cache

This commit is contained in:
Lukas Winkler 2019-08-20 12:51:31 +02:00
parent 27090d9ad8
commit 05576ba8cc
Signed by: lukas
GPG key ID: 54DE4D798D244853

View file

@ -1,5 +1,7 @@
import json
from statistics import mean
import numpy as np
from keras.engine.saving import load_model
from CustomScaler import CustomScaler
@ -7,7 +9,6 @@ from interpolators.griddata import GriddataInterpolator
from interpolators.rbf import RbfInterpolator
from simulation import Simulation
from simulation_list import SimulationList
import numpy as np
simulations = SimulationList.jsonlines_load()
@ -43,7 +44,7 @@ def grid_test(scaled_parameters) -> float:
interpolator = GriddataInterpolator(scaled_data, simulations.Y)
result = interpolator.interpolate(*scaled_parameters)
return result
return float(result)
nn_squared_errors = []
@ -52,14 +53,18 @@ rbf_squared_errors = []
rbf_errors = []
grid_squared_errors = []
grid_errors = []
try:
with open("grid-testing-cache.json") as f:
raw_data = json.load(f)
grid_testing_cache = {int(key): value for key, value in raw_data.items()}
except FileNotFoundError:
grid_testing_cache = {}
sim: Simulation
a = 0
for sim in simulations.simlist:
if not sim.testcase:
continue
a += 1
continue
testinput = [sim.alpha, sim.v, sim.projectile_mass, sim.gamma,
sim.target_water_fraction, sim.projectile_water_fraction]
scaled_input = list(scaler.transform_parameters(testinput))
@ -71,10 +76,18 @@ for sim in simulations.simlist:
rbf_squared_errors.append(squared_error(rbf_output, sim.water_retention_both))
rbf_errors.append(absolute_error(rbf_output, sim.water_retention_both))
# grid_output = grid_test(scaled_input)
grid_output = 1 # dummy to speed up calculation
grid_squared_errors.append(squared_error(grid_output, sim.water_retention_both))
grid_errors.append(absolute_error(grid_output, sim.water_retention_both))
if sim.runid in grid_testing_cache:
grid_output = grid_testing_cache[sim.runid]
else:
grid_output = grid_test(scaled_input)
if np.isnan(grid_output):
grid_output = False
grid_testing_cache[sim.runid] = grid_output
with open("grid-testing-cache.json", "w") as f:
json.dump(grid_testing_cache, f)
if grid_output:
grid_squared_errors.append(squared_error(grid_output, sim.water_retention_both))
grid_errors.append(absolute_error(grid_output, sim.water_retention_both))
print(nn_output, rbf_output, grid_output, sim.water_retention_both)
print(a)