-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Attempt to push the code for code review #1
base: main
Are you sure you want to change the base?
Conversation
src/alg_naive.py
Outdated
@@ -0,0 +1,39 @@ | |||
import tools as t | |||
|
|||
def sp(n, k, L_t, d, unit_indices, results): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Naming: I'd give the function a longer and hence more descriptive name (e.g. shapley_value
or compute_sv
or something like that). Replace the single-letter names with more descriptive ones as well (e.g. n
with num_units
). All names should be small caps and underscores (e.g. L_t
violates this, apart from violating the previous point as well).
src/alg_shapley.py
Outdated
units are turned on at the start, and in the second case, 3 need to be on at the | ||
start, so the computation of the DP table is different. | ||
''' | ||
def sp(n_unit, k, L_t, Dp, d, uI, res): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as in the other file: function name, variable names, usage of capital letters...
tests/inspection/test_random.py
Outdated
|
||
# Define the range for N we want to test and the number of repetition | ||
# for each pair (N, K) | ||
n_lower_bound = 2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All constants should be in ALL_CAPS.
tests/inspection/test_random.py
Outdated
N = n | ||
|
||
# K from KNN classifier | ||
K = k |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These assignments seem uneccessary. Also K on the left is a variable I guess, so it should be named with small caps.
src/tools.py
Outdated
return summ | ||
|
||
'Return a copy of the target vector' | ||
def copy_vector(target): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be done with the copy built-in library.
src/alg_naive.py
Outdated
# Compute the marginal contribution from the soft accuracy function | ||
diff = prop_with_q-prop_without_q | ||
vMv = diff/k | ||
count = t.count_ones(vector) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could be a simple single line, for example length([x for x in vector if x == 1])
. In those cases it is excessive to put it in a function. Alternatively, you could use numpy to do these vector operations. It might be faster as numpy is highly optimized.
src/tools.py
Outdated
tempScp.append(count(Di, D_c, 1, L_t)) | ||
return [tempTb, tempSc, tempTbp, tempScp] | ||
|
||
def minus(v): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These minus
and sum
functions could surely be replaced with numpy vector operations.
src/tools.py
Outdated
return j | ||
|
||
'Compute n choose k' | ||
def choose(n, k): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a single function in numpy.
src/tools.py
Outdated
array : | ||
array of tuple of the form [distance from D_t, label, id] | ||
''' | ||
def sort(array): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be solved using the sorted
built-in function with defining a custom key
, see here.
No description provided.