Repository navigation
Linear expansion pockets - #71
Conversation
TimKam
left a comment
There was a problem hiding this comment.
I added some remarks regarding aspects that can be improved or clarified.
While you are working on this, I can already take a preliminary look at how fast this runs.
| collection_index = 0 | ||
| new_args = list(new_arguments(qbaf_initial, qbaf_collection)) | ||
|
|
||
| while (collection_index < len(qbaf_collection)): |
There was a problem hiding this comment.
Can't this be a for loop? For loops are simpler than while loops so typically one should use for loops instead of while loops where possible.
| if (qbaf_initial.are_strength_consistent(qbaf_collection[collection_index], | ||
| topic_argument_1, | ||
| topic_argument_2) == False): | ||
| break |
There was a problem hiding this comment.
What does this loop do? It looks like it increments the index and executes the check for the if condition but nothing else. So I think it's best to wrap this into its own function and use a return instead of a break (and a for loop, that uses enumerate(list) such that you can use the index). This would also mean that you have to document that new function, which makes it easier to understand why you are doing this :)
| topic_argument_2: str) -> list[list[str]]: | ||
|
|
||
| """ | ||
| Determines the pockets when the qbaf_collection is a linear chain. |
|
|
||
|
|
||
| args = set(new_arguments(qbaf_initial,[qbaf_collection[collection_index]])) | ||
| p_set = [set(x) for x in combinations(new_args, len(new_args)-1)] |
There was a problem hiding this comment.
Can you rename this to something more descriptive?
| collection_index = collection_index+1 | ||
|
|
||
|
|
||
| args = set(new_arguments(qbaf_initial,[qbaf_collection[collection_index]])) |
There was a problem hiding this comment.
Add a comment above this line describing what the code in the lines below does.
|
|
||
| Returns: | ||
| set[list[str]]: returns the set of all maximal pockets with respect to qbaf_intial and qbaf-collection. | ||
| bool: Returns True if pocket is a pocket of consistency; False otherwise. |
There was a problem hiding this comment.
In the function signature above it says that it returns a list of strings.
| if depth != 0: | ||
| return pocket_list | ||
| else: | ||
| max_p = [x for x in pocket_list if (not any( (x != y and x.issubset(y)) for y in pocket_list))] |
There was a problem hiding this comment.
use a more descriptive variable name
| max_p = [x for x in pocket_list if (not any( (x != y and x.issubset(y)) for y in pocket_list))] | ||
| unique_pockets = [] | ||
|
|
||
| for x in max_p: |
There was a problem hiding this comment.
use a more descriptive variable name
| pocket_list, | ||
| depth + 1) | ||
|
|
||
| if depth != 0: |
There was a problem hiding this comment.
Why this condition? Can you add a code comment?
| len(considered_subset)-1)] | ||
|
|
||
| next_itr_modified = [x for x in next_itr if not any(x.issubset(y) | ||
| for y in pocket_list)] |
There was a problem hiding this comment.
Can you add a comment explaining what this does?
Also modified is not a good name.
|
Testing this empirically, I run into the following problems:
|
|
@Arunavo71 What about using this for the linear pocket algorithm: for index, qbaf in enumerate(qbaf_collection):
if not qbaf_initial.are_strength_consistent(qbaf, topic_argument_1, topic_argument_2):
previous_qbaf = qbaf_collection[index-1] if index > 0 else qbaf_initial
new_args_to_prev = list(new_arguments(qbaf_initial, [previous_qbaf]))
intermediate_max_pockets = determine_max_pockets(previous_qbaf, [qbaf], topic_argument_1, topic_argument_2)
return [pocket + new_args_to_prev for pocket in intermediate_max_pockets]
return [list(new_arguments(qbaf_initial, qbaf_collection))]
This algorithm does not return all maximal pockets but it returns some, which is pragmatically what we need for explanations. |
|
Sure, let's use this updated code. Thank you. :) |
|
I just noticed that the algorithm (and also previous variants) obviously does not guarantee maximality given the entire QBAF chain, i.e., it only gives us "local" maximality. This is important to mention. |
and update notebook
This pull request contains:
determine_linear_max_pocketsfor determing the maximal pockets when the expansion chain is linear.determine_max_pocketsfunction, which should run marginally faster.