Пример #1
0
def test_nauty(verbose=0):
    if verbose:
        print('test_nauty: test reduction to normal form')
    al = oapackage.exampleArray(0, verbose)
    alr = al.randomperm()
    tr = oapackage.reduceOAnauty(alr)
    alx = tr.apply(alr)
    assert (alx == al)
Пример #2
0
def selectIsomorphismClasses(sols, verbose=1):
    """ Select isomorphism classes from a list of designs 

    Args:
        sols (list of arrays)
        verbose (int)
    Return:
        indices (list of integers): indices of the isomorphism classes
        mm (list of arrays): the arrays in normal form


    Example:
        >>> sols=[oapackage.exampleArray(i) for i in [26,26,27,26]]
        >>> idx, mm = selectIsomorphismClasses(sols)

    To select one representative array from each isomorphism class one can use:
        >>> _, ui = np.unique(idx, return_index=True)
        >>> representatives = [sols[i] for i in ui]

    """

    # perform check on array data type
    mm = []
    for ii, al in enumerate(sols):
        if verbose:
            oapackage.tprint('selectIsomorphismClasses: process aray %d/%d' %
                             (ii, len(sols)))
        al = oapackage.makearraylink(al)

        tt = oapackage.reduceOAnauty(al, verbose >= 2)

        #pp, tt = reduceBliss(al, arrayclass, verbose >= 2)
        #tt = graph2arrayTransformation(pp, arrayclass)
        alx = tt.apply(al)
        mm.append(np.array(alx))
        pass

    # perform uniqueness check
    nn = len(mm)
    qq = np.array([None] * nn, dtype=object)
    for ii in range(nn):
        qq[ii] = mm[ii].flatten()

    # Trick to make unique work...
    nx = qq[0].size
    dt = qq[0].dtype.descr * nx
    qqq = np.array(qq, dtype=dt)

    a, indices = np.unique(qqq, return_inverse=True)

    if verbose >= 1:
        print('selectIsomorphismClasses: reduce %d to %d' %
              (len(sols), np.unique(indices).size))

    return indices, mm
Пример #3
0
def selectIsomorphismClasses(sols, verbose=1):
    """ Select isomorphism classes from a list of designs 
    
    Args:
        sols (list of arrays)
        verbose (int)
    Return:
        indices (list of integers): indices of the isomorphism classes
        mm (list of arrays): the arrays in normal form

        
    """

    # perform check on array data type
    mm = []
    for ii, al in enumerate(sols):
        if verbose:
            oapackage.tprint('selectIsomorphismClasses: process aray %d/%d' %
                             (ii, len(sols)),
                             dt=4)
        al = oapackage.makearraylink(al)

        tt = oapackage.reduceOAnauty(al, verbose >= 2)

        #pp, tt = reduceBliss(al, arrayclass, verbose >= 2)
        #tt = graph2arrayTransformation(pp, arrayclass)
        alx = tt.apply(al)
        mm.append(np.array(alx))
        pass

    # perform uniqueness check
    nn = len(mm)
    qq = np.array([None] * nn, dtype=object)
    for ii in range(nn):
        qq[ii] = mm[ii].flatten()

    if 0:
        # Trick to make unique work...
        # old code
        nx = qq[0].size
        dt = qq[0].dtype.descr * nx
        qqq = [np.array(q, dtype=dt) for q in qq]
        qqq = np.array(qq, dtype=dt)
        a, indices = np.unique(qqq, return_inverse=True)

    # Trick to make unique work...
    a, indices = np.unique(np.vstack(qq), axis=0, return_inverse=True)

    if verbose >= 1:
        print('selectIsomorphismClasses: %d reduced to %d' %
              (len(sols), np.unique(indices).size))

    return indices, mm
Пример #4
0
def selectIsomorphismClasses(sols, verbose=1):
    """ Select isomorphism classes from a list of designs

    Args:
        sols (list of arrays): list of arrays from which to determine the unique ones
        verbose (int): verbosity level
    Return:
        indices (list of integers): indices of the isomorphism classes
        mm (list of arrays): the arrays in normal form


    Example:
        >>> import oapackage.graphtools; import numpy as np
        >>> sols=[oapackage.exampleArray(idx) for idx in [26,26,27,26]]
        >>> idx, mm = oapackage.graphtools.selectIsomorphismClasses(sols, verbose=0)
        >>> _, unique_indices = np.unique(idx, return_index=True)
        >>> print('found %d isomorphism classes from %d arrays' % (len(unique_indices), len(sols)) )
        found 2 isomorphism classes from 4 arrays
        >>> representatives = [sols[idx] for idx in unique_indices]

    """

    mm = []
    for ii, al in enumerate(sols):
        if verbose:
            oapackage.tprint('selectIsomorphismClasses: process aray %d/%d' %
                             (ii, len(sols)))
        al = oapackage.makearraylink(al)

        tt = oapackage.reduceOAnauty(al, verbose >= 2)

        alx = tt.apply(al)
        mm.append(np.array(alx))

    # perform uniqueness check
    nn = len(mm)
    qq = np.array([None] * nn, dtype=object)
    for ii in range(nn):
        qq[ii] = mm[ii].flatten()

    # Trick to make unique work...
    _, indices = np.unique(np.vstack(qq), axis=0, return_inverse=True)

    if verbose >= 1:
        print('selectIsomorphismClasses: reduce %d to %d' %
              (len(sols), np.unique(indices).size))

    return indices, mm