Commit 18a37237 authored by Josef Brandt's avatar Josef Brandt

update_all() can now be forced, mpCountError is now in %

parent d6dc1dec
......@@ -25,7 +25,7 @@ def get_name_from_directory(dirPath: str) -> str:
class TotalResults(object):
methods: list = [meth.RandomSampling, meth.SizeBinFractioning, gmeth.CrossBoxSubSampling,
gmeth.SpiralBoxSubsampling]
measuredFreactions: list = [0.05, 0.1, 0.15, 0.2, 0.3, 0.5, 0.9]
measuredFreactions: list = [0.05, 0.1, 0.15, 0.2, 0.5, 0.75, 0.9]
def __init__(self):
super(TotalResults, self).__init__()
......@@ -47,9 +47,10 @@ class TotalResults(object):
return newResult
def update_all(self) -> None:
def update_all(self, force: bool = False) -> None:
"""
Updates all samples with all methods and all fractions
:param force: Wether to force an update of an already existing method.
:return:
"""
for index, sample in enumerate(self.sampleResults):
......@@ -58,7 +59,7 @@ class TotalResults(object):
possibleMethods = self._get_methods_for_fraction(sample.dataset, fraction)
for curMethod in possibleMethods:
# print(f'updating {sample.sampleName} with {curMethod.label} at fraction {fraction}')
sample.update_result_with_method(curMethod)
sample.update_result_with_method(curMethod, force=force)
print(f'processed {index+1} of {len(self.sampleResults)} samples')
def get_error_vs_fraction_data(self, attributes: list = [], methods: list = []) -> dict:
......@@ -206,6 +207,8 @@ class SubsamplingResult(object):
self.subSampledParticleCount: int = None
self.mpCountError: float = None
self.mpCountErrorPerBin: tuple = None
# TODO: UPDATE PATTERNS -> ARE THESE REASONABLE???
self.mpPatterns = ['poly', 'rubber', 'pb', 'pr', 'pg', 'py', 'pv']
def update(self) -> None:
"""
......@@ -248,15 +251,13 @@ class SubsamplingResult(object):
def _get_error_from_values(self, exact: float, estimate: float) -> float:
assert(exact != 0)
return abs(exact - estimate) / exact
return abs(exact - estimate) / exact * 100
def _get_number_of_MP_particles(self, particleList: list) -> int:
mpPatterns = ['poly', 'rubber', 'pb', 'pr', 'pg', 'py', 'pv']
numMPParticles = 0
for particle in particleList:
assignment = particle.getParticleAssignment()
for pattern in mpPatterns:
for pattern in self.mpPatterns:
if assignment.lower().find(pattern) != -1:
numMPParticles += 1
break
......
......@@ -4,6 +4,7 @@ from evaluation import TotalResults
def load_results(fname: str) -> TotalResults:
# TODO: REMVOE DATASET FROM SAMPLERESULTS, OTHERWISE THE FILESIZE IS GOING TO BE HUGE
res: TotalResults = None
if os.path.exists(fname):
with open(fname, "rb") as fp:
......
......@@ -25,18 +25,42 @@ SET GEPARD TO EVALUATION BRANCH (WITHOUT THE TILING STUFF), OTHERWISE SOME OF TH
#
# save_results('results1.res', results)
results: TotalResults = load_results('results1.res')
results.update_all(force=True)
# save_results('results1.res', results)
errorPerFraction: dict = results.get_error_vs_fraction_data(methods=['spiral', 'cross'])
plt.clf()
errorPerFraction: dict = results.get_error_vs_fraction_data(attributes=['air', 'water'],
methods=[])
# methods=['spiral', 'cross'])
plt.subplot(121)
for methodLabel in errorPerFraction.keys():
fractions: list = list(errorPerFraction[methodLabel].keys())
errors: list = list(errorPerFraction[methodLabel].values())
plt.plot(fractions, errors, label=methodLabel)
plt.plot(fractions, errors)
plt.scatter(fractions, errors, label=methodLabel)
plt.title('Spiral or Box Layouts')
plt.title('Spiral or Box Layouts on Air/Water sample', fontSize=15)
plt.xscale('log')
plt.xlabel('measured fraction')
plt.ylabel('mpCountError')
plt.xlabel('measured fraction', fontsize=12)
plt.ylabel('mpCountError (%)', fontsize=12)
# plt.ylim([0, 1])
plt.legend()
errorPerFraction: dict = results.get_error_vs_fraction_data(attributes=['sediment', 'soil', 'beach', 'slush'],
methods=[])
plt.subplot(122)
for methodLabel in errorPerFraction.keys():
fractions: list = list(errorPerFraction[methodLabel].keys())
errors: list = list(errorPerFraction[methodLabel].values())
plt.plot(fractions, errors)
plt.scatter(fractions, errors, label=methodLabel)
plt.title('Spiral or Box Layouts on Sedimant/Beach/Slush sample', fontSize=15)
plt.xscale('log')
plt.xlabel('measured fraction', fontsize=12)
plt.ylabel('mpCountError (%)', fontsize=12)
# plt.ylim([0, 1])
plt.legend()
plt.show()
......@@ -285,7 +285,7 @@ class TestSubsamplingResult(unittest.TestCase):
for binIndex, binError in enumerate(mpCountErrorsPerBin):
if binIndex <= 6:
self.assertEqual(binError, 0.5)
self.assertEqual(binError, 50)
else: # it's the last and largest bin, no particles where added there
self.assertEqual(binError, 0)
......@@ -314,7 +314,7 @@ class TestSubsamplingResult(unittest.TestCase):
mpParticles2 = self._get_MP_particles(30)
estimateParticles = mpParticles2 + nonMPparticles1
mpCountError = self.subsamplingResult._get_mp_count_error(origParticles, estimateParticles, 1.0)
self.assertEqual(mpCountError, 0.5)
self.assertEqual(mpCountError, 50)
mpParticles2 = self._get_MP_particles(20)
estimateParticles = mpParticles2 + nonMPparticles1
......@@ -322,24 +322,24 @@ class TestSubsamplingResult(unittest.TestCase):
self.assertEqual(mpCountError, 0)
mpCountError = self.subsamplingResult._get_mp_count_error(origParticles, estimateParticles, 0.5)
self.assertEqual(mpCountError, 1.0)
self.assertEqual(mpCountError, 100)
def test_get_error_from_values(self):
exact, estimate = 100, 90
error = self.subsamplingResult._get_error_from_values(exact, estimate)
self.assertEqual(error, 0.1)
self.assertEqual(error, 10)
exact, estimate = 100, 110
error = self.subsamplingResult._get_error_from_values(exact, estimate)
self.assertEqual(error, 0.1)
self.assertEqual(error, 10)
exact, estimate = 100, 50
error = self.subsamplingResult._get_error_from_values(exact, estimate)
self.assertEqual(error, 0.5)
self.assertEqual(error, 50)
exact, estimate = 100, 150
error = self.subsamplingResult._get_error_from_values(exact, estimate)
self.assertEqual(error, 0.5)
self.assertEqual(error, 50)
def _get_MP_particles(self, numParticles):
mpParticles = []
......
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