test results on seperate dataset
This commit is contained in:
parent
b33121e428
commit
2218060664
4 changed files with 98 additions and 12 deletions
|
@ -90,7 +90,7 @@ class Simulation:
|
|||
|
||||
@property
|
||||
def testcase(self) -> bool:
|
||||
return not self.original_simulation and 489 <= self.runid <= 1000 # TODO: replace with real last testcase
|
||||
return not self.original_simulation and 529 <= self.runid <= 631
|
||||
|
||||
@property
|
||||
def simulation_key(self):
|
||||
|
|
|
@ -46,10 +46,10 @@ class SimulationList:
|
|||
def as_matrix(self):
|
||||
entrylist = []
|
||||
for sim in self.simlist:
|
||||
if sim.type == "original":
|
||||
if not sim.testcase:
|
||||
entrylist.append(
|
||||
[sim.mcode, sim.wpcode, sim.wtcode, sim.gammacode, sim.alphacode, sim.vcode,
|
||||
sim.water_retention_both]
|
||||
[sim.alpha, sim.v, sim.projectile_mass, sim.gamma, sim.target_water_fraction,
|
||||
sim.projectile_water_fraction, sim.water_retention_both]
|
||||
)
|
||||
return np.asarray(entrylist)
|
||||
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
from simulation import Simulation
|
||||
from simulation_list import SimulationList
|
||||
|
||||
simulations = SimulationList.jsonlines_load()
|
||||
|
||||
sim: Simulation
|
||||
for sim in simulations.simlist:
|
||||
print(sim.simulation_key)
|
94
testing.py
Normal file
94
testing.py
Normal file
|
@ -0,0 +1,94 @@
|
|||
from statistics import mean
|
||||
|
||||
from keras.engine.saving import load_model
|
||||
|
||||
from CustomScaler import CustomScaler
|
||||
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()
|
||||
|
||||
scaler = CustomScaler()
|
||||
scaler.fit(simulations.X)
|
||||
model = load_model("model.hd5")
|
||||
|
||||
|
||||
def squared_error(inter: float, correct: float) -> float:
|
||||
return (inter - correct) ** 2
|
||||
|
||||
|
||||
def absolute_error(inter: float, correct: float) -> float:
|
||||
return abs(inter - correct)
|
||||
|
||||
|
||||
def neural_network_test(scaled_input) -> float:
|
||||
nn_input = np.asarray([scaled_input])
|
||||
testoutput = model.predict(nn_input)[0][0]
|
||||
return testoutput
|
||||
|
||||
|
||||
def rbf_test(scaled_parameters) -> float:
|
||||
scaled_data = scaler.transform_data(simulations.X)
|
||||
interpolator = RbfInterpolator(scaled_data, simulations.Y)
|
||||
result = interpolator.interpolate(*scaled_parameters)
|
||||
|
||||
return result
|
||||
|
||||
|
||||
def grid_test(scaled_parameters) -> float:
|
||||
scaled_data = scaler.transform_data(simulations.X)
|
||||
interpolator = GriddataInterpolator(scaled_data, simulations.Y)
|
||||
result = interpolator.interpolate(*scaled_parameters)
|
||||
|
||||
return result
|
||||
|
||||
|
||||
nn_squared_errors = []
|
||||
nn_errors = []
|
||||
rbf_squared_errors = []
|
||||
rbf_errors = []
|
||||
grid_squared_errors = []
|
||||
grid_errors = []
|
||||
|
||||
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))
|
||||
nn_output = neural_network_test(scaled_input)
|
||||
nn_squared_errors.append(squared_error(nn_output, sim.water_retention_both))
|
||||
nn_errors.append(absolute_error(nn_output, sim.water_retention_both))
|
||||
|
||||
rbf_output = rbf_test(scaled_input)
|
||||
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))
|
||||
|
||||
print(nn_output, rbf_output, grid_output, sim.water_retention_both)
|
||||
print(a)
|
||||
print()
|
||||
|
||||
# print(nn_squared_errors)
|
||||
print(mean(nn_squared_errors))
|
||||
print(mean(nn_errors))
|
||||
print()
|
||||
# print(rbf_squared_errors)
|
||||
print(mean(rbf_squared_errors))
|
||||
print(mean(rbf_errors))
|
||||
print()
|
||||
|
||||
# print(grid_squared_errors)
|
||||
print(mean(grid_squared_errors))
|
||||
print(mean(grid_errors))
|
Reference in a new issue