Skip to content

Commit 61062be

Browse files
authored
Merge pull request #115 from SFI-Visual-Intelligence/mag-branch
Reduced python version requirement
2 parents 2c9ca54 + 42c3c37 commit 61062be

File tree

2 files changed

+8
-13
lines changed

2 files changed

+8
-13
lines changed

doc/Magnus_page.md

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,24 +26,19 @@ Each input is flattened over the channel, height and width channels. Then they a
2626

2727

2828
## Entropy Metric In-Depth
29-
30-
The EntropyPrediction class' main job is to take some inputs and return the Shannon Entropy metric of those inputs. The class has four methods with the following jobs:
29+
The EntropyPrediction class' main job is to take some inputs from the MetricWrapper class and store the batchwise Shannon Entropy metric of those inputs. The class has four methods with the following jobs:
3130
* __init__ : Initialize the class.
3231
* __call__ : Main method which is used to calculate and store the batchwise shannon entropy.
3332
* __returnmetric__ : Returns the collected metric.
3433
* __reset__ : Removes all the stored values up until that point. Readies the instance for storing values from a new epoch.
3534

36-
The class is initialized with a single parameter called "averages". This is inspired from other PyTorch and NumPy implementations and controlls how values from different batches or within batches will be combined. The __init__ method checks the value of this argument with an assertion, which must be one of three string. We only allow "mean", "sum" and "none" as methods of combining the different entropy values. We'll come back to the specifics here.
37-
Furthermore, this method will also store the different Shannon Entropy values as we pass values into the __call__ method.
35+
The __init__ method has two arguments, both present for compatability issues. However, the num_classes argument is used as a check in the __call__ method to assert the input is of correctly assumed size.
36+
37+
In __call__ we get both true labels and model logit scores for each sample in the batch as input. We're calculating Shannon Entropy, not KL-divergence, so the true labels aren't actually needed.
38+
With permission I've used the scipy implementation to calculate entropy here. We apply a softmax over the logit values, then calculate the Shannon Entropy, and make sure to remove any Inf values which might arise from a perfect guess/distribution.
39+
3840

39-
In __call__ we get both true labels and model logit scores for each sample in the batch as input. We're calculating Shannon Entropy, not KL-divergence, so the true labels aren't needed.
40-
With permission I've used the scipy implementation to calculate entropy here. We apply a softmax over the logit values, then calculate the Shannon Entropy, and make sure to remove any NaN or Inf values which might arise from a perfect guess/distribution.
4141

42-
Next we have the __returnmetric__ method which is used to retrive the stored metric. Here the averages argument comes into play.
43-
Depending on what has been chosen as the averaging metric when initializing the class, one of the following operations will be applied to the stored values:
44-
* Mean: Calculate the mean of the stored entropy values.
45-
* Sum: Sum the stored entropy values.
46-
* None: Do nothing with the stored entropy values.
47-
Then the value(s) are returned.
42+
Next we have the __returnmetric__ method which is used to retrive the stored metric. This returns the mean over all stored values. Effectively, this will return the average Shannon Entropy of the dataset.
4843

4944
Lastly we have the __reset__ method which simply emptied the variable which stores the entropy values to prepare it for the next epoch.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name = "collaborative-coding-exam"
33
version = "0.1.0"
44
description = "Exam project in the collaborative coding course."
55
readme = "README.md"
6-
requires-python = ">=3.12"
6+
requires-python = ">=3.11.5"
77
dependencies = [
88
"black>=25.1.0",
99
"h5py>=3.12.1",

0 commit comments

Comments
 (0)