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:
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)}
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))}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't understand this but it seems right 👍



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)
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

Copy link
Collaborator

Choose a reason for hiding this comment

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

this is fine

Copy link
Collaborator

Choose a reason for hiding this comment

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

According to the course content, you're meant to have more tests in this file. What you should have is:
Standard deviation for one patient with multiple observations.
Standard deviation for two patients.
Graph includes a standard deviation graph.
Standard deviation function should raise an error if given empty data.
Computing standard deviation where deviation is different from variance.
Standard deviation function should give correct result given negative inputs.
Function should work with numpy arrays

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)