graphid.core.mixin_loops module¶
- class graphid.core.mixin_loops.InfrLoops[source]¶
Bases:
object
Algorithm control flow loops
- main_gen(max_loops=None, use_refresh=True)[source]¶
The main outer loop.
This function is designed as an iterator that will execute the graph algorithm main loop as automatically as possible, but if user input is needed, it will pause and yield the decision it needs help with. Once feedback is given for this item, you can continue the main loop by calling next. StopIteration is raised once the algorithm is complete.
- Parameters:
max_loops (int) – maximum number of times to run the outer loop, i.e. ranking is run at most this many times.
use_refresh (bool) – allow the refresh criterion to stop the algo
Notes
Different phases of the main loop are implemented as subiterators
CommandLine
python -m graphid.core.mixin_loops InfrLoops.main_gen
Example
>>> from graphid.core.mixin_simulation import UserOracle >>> from graphid import demo >>> infr = demo.demodata_infr(num_pccs=3, size=5) >>> infr.params['manual.n_peek'] = 10 >>> infr.params['ranking.ntop'] = 1 >>> infr.oracle = UserOracle(.99, rng=0) >>> infr.simulation_mode = False >>> infr.reset() >>> gen = infr.main_gen() >>> while True: >>> try: >>> reviews = next(gen) >>> edge, priority, data = reviews[0] >>> feedback = infr.request_oracle_review(edge) >>> infr.add_feedback(edge, **feedback) >>> except StopIteration: >>> break
- hardcase_review_gen()[source]¶
Subiterator for hardcase review
Re-review non-confident edges that vsone did not classify correctly
- ranked_list_gen(use_refresh=True)[source]¶
Subiterator for phase1 of the main algorithm
Calls the underlying ranking algorithm and prioritizes the results
- incon_recovery_gen()[source]¶
Subiterator for recovery mode of the mainm algorithm
Iterates until the graph is consistent
Note
inconsistency recovery is implicitly handled by the main algorithm, so other phases do not need to call this explicitly. This exists for the case where the only mode we wish to run is inconsistency recovery.
- pos_redun_gen()[source]¶
Subiterator for phase2 of the main algorithm.
Searches for decisions that would commplete positive redundancy
CommandLine
python -m graphid.core.mixin_loops InfrLoops.pos_redun_gen
Example
>>> from graphid.core.mixin_loops import * >>> from graphid import demo >>> infr = demo.demodata_infr(num_pccs=3, size=5, pos_redun=1) >>> gen = infr.pos_redun_gen() >>> feedback = next(gen) >>> edge_ = feedback[0][0] >>> print(edge_) (1, 5)
- neg_redun_gen()[source]¶
Subiterator for phase3 of the main algorithm.
Searches for decisions that would commplete negative redundancy
- _inner_priority_gen(use_refresh=False, only_auto=False)[source]¶
Helper function that implements the general inner priority loop.
Executes reviews until the queue is empty or needs refresh
- Parameters:
user_refresh (bool) – if True enables the refresh criteria. (set to True in Phase 1)
only_auto (bool) – reviews unless the graph is inconsistent. (set to True in Phase 3)
Notes
The caller is responsible for populating the priority queue. This will iterate until the queue is empty or the refresh critieron is triggered.