Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion inflammation-analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ def main(args):
for filename in InFiles:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test standard deviation for two patients.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Brilliant, I'll raise this as an issue on my repo for future work when I work out how.

inflammation_data = models.load_csv(filename)

view_data = {'average': models.daily_mean(inflammation_data), 'max': models.daily_max(inflammation_data), 'min': models.daily_min(inflammation_data)}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possible test to complete, test standard deviation for one patient with multiple observations.

view_data = {'average': models.daily_mean(inflammation_data), 'max': models.daily_max(inflammation_data), 'min': models.daily_min(inflammation_data), **(models.s_dev(inflammation_data))}


views.visualize(view_data)

Expand Down
10 changes: 10 additions & 0 deletions inflammation/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,13 @@ def daily_min(data):
"""Calculate the daily min of a 2d inflammation data array."""
return np.min(data, axis=0)


def s_dev(data):
"""Computes and returns standard deviation for data."""
mmm = np.mean(data, axis=0)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, no changes from me. Maybe more comments in code

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah will do

devs = []
for entry in data:
devs.append((entry - mmm) * (entry - mmm))

s_dev2 = sum(devs) / len(data)
return {'standard deviation': s_dev2}
13 changes: 12 additions & 1 deletion tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import numpy as np
import numpy.testing as npt
import os

import pytest

def test_daily_mean_zeros():
"""Test that mean function works for an array of zeros."""
Expand Down Expand Up @@ -37,3 +37,14 @@ def test_load_from_json(tmpdir):
temp_json_file.write('[{"observations":[1, 2, 3]},{"observations":[4, 5, 6]}]')
result = load_json(example_path)
npt.assert_array_equal(result, [[1, 2, 3], [4, 5, 6]])


@pytest.mark.parametrize('data, expected_standard_deviation', [
([0, 0, 0], 0.0),
([1.0, 1.0, 1.0], 0),
([0.0, 2.0], 1.0)
])
def test_daily_standard_deviation(data, expected_standard_deviation):
from inflammation.models import s_dev
result_data = s_dev(data)['standard deviation']
npt.assert_approx_equal(result_data, expected_standard_deviation)