GitLab Repo

amachine.am_create.am_isomorphic_to

 1from numba.cuda.simulator_init import reset
 2from ..am_hmm import HMM
 3
 4def isomorphic_to( 
 5    m : HMM, 
 6    alphabet : list[str],
 7    decorator : str = '@' ) -> HMM :
 8
 9    # make sure there are enough symbols
10    if len( alphabet ) < len( m.alphabet ) :
11        raise ValueError( "Not enough symbols in the alphabet" )
12
13    # take the as much of them as needed
14    alphabet_used = alphabet[ 0 : len( m.alphabet ) ]
15
16    states = [ 
17        s.modified_deep_copy( name=f"{s.name}{decorator}" )
18        for s in m.states
19    ]
20
21    transitions = [ 
22        tr.deepcopy()
23        for tr in m.transitions
24    ]
25
26    res = HMM(
27        states=states,
28        transitions=transitions,
29        start_state=0,
30        alphabet=alphabet_used
31    )
32
33    if not res.is_row_stochastic() :
34        raise Exception( "Isomorphic to m is not row stochastic" )
35
36    if not  res.is_unifilar() :
37        raise Exception( "Isomorphic to m is not unifilar" )
38
39    return res
def isomorphic_to( m: amachine.am_hmm.HMM, alphabet: list[str], decorator: str = '@') -> amachine.am_hmm.HMM:
 5def isomorphic_to( 
 6    m : HMM, 
 7    alphabet : list[str],
 8    decorator : str = '@' ) -> HMM :
 9
10    # make sure there are enough symbols
11    if len( alphabet ) < len( m.alphabet ) :
12        raise ValueError( "Not enough symbols in the alphabet" )
13
14    # take the as much of them as needed
15    alphabet_used = alphabet[ 0 : len( m.alphabet ) ]
16
17    states = [ 
18        s.modified_deep_copy( name=f"{s.name}{decorator}" )
19        for s in m.states
20    ]
21
22    transitions = [ 
23        tr.deepcopy()
24        for tr in m.transitions
25    ]
26
27    res = HMM(
28        states=states,
29        transitions=transitions,
30        start_state=0,
31        alphabet=alphabet_used
32    )
33
34    if not res.is_row_stochastic() :
35        raise Exception( "Isomorphic to m is not row stochastic" )
36
37    if not  res.is_unifilar() :
38        raise Exception( "Isomorphic to m is not unifilar" )
39
40    return res