Exemple #1
0
def _distance_2(misorientation, verbose, split_size=100):
    num_orientations = misorientation.shape[0]
    S_1, S_2 = misorientation._symmetry
    distance = np.full(misorientation.shape + misorientation.shape, np.infty)
    split_size = split_size // S_1.shape[0]
    outer_range = range(0, num_orientations, split_size)
    if verbose:
        from tqdm import tqdm
        outer_range = tqdm(outer_range,
                           total=np.ceil(num_orientations / split_size))
    S_1_outer_S_1 = S_1.outer(S_1)

    # Calculate the upper half of the distance matrix block by block
    for start_index_b in outer_range:
        # we use slice object for compactness
        index_slice_b = slice(
            start_index_b, min(num_orientations, start_index_b + split_size))
        o_sub_b = misorientation[index_slice_b]
        for start_index_a in range(0, start_index_b + split_size, split_size):
            index_slice_a = slice(
                start_index_a, min(num_orientations,
                                   start_index_a + split_size))
            o_sub_a = misorientation[index_slice_a]
            axis = (len(o_sub_a.shape), len(o_sub_a.shape) + 1)
            mis2orientation = (~o_sub_a).outer(S_1_outer_S_1).outer(o_sub_b)
            # This works through all the identity rotations
            for s_2_1, s_2_2 in icombinations(S_2, 2):
                m = s_2_1 * mis2orientation * s_2_2
                angle = m.angle.data.min(axis=axis)
                distance[index_slice_a, index_slice_b] = np.minimum(
                    distance[index_slice_a, index_slice_b], angle)
    # Symmetrize the matrix for convenience
    i_lower = np.tril_indices(distance.shape[0], -1)
    distance[i_lower] = distance.T[i_lower]
    return distance
Exemple #2
0
def _distance(misorientation, verbose, split_size=100):
    """Private function to find the symmetry reduced distance between
    all pairs of (mis)orientations

    Parameters
    ----------
    misorientation : orix.quaternion.Misorientation
        The misorientation to be considered.
    verbose : bool
        Output progress bar while computing.
    split_size : int
        Size of block to compute at a time.

    Returns
    -------
    distance : numpy.ndarray
        2D matrix containing the angular distance between every
        orientation, considering symmetries.
    """
    num_orientations = misorientation.shape[0]
    S_1, S_2 = misorientation._symmetry
    distance = np.full(misorientation.shape + misorientation.shape, np.infty)
    split_size = split_size // S_1.shape[0]
    outer_range = range(0, num_orientations, split_size)
    if verbose:
        outer_range = tqdm(outer_range, total=np.ceil(num_orientations / split_size))

    S_1_outer_S_1 = S_1.outer(S_1)

    # Calculate the upper half of the distance matrix block by block
    for start_index_b in outer_range:
        # we use slice object for compactness
        index_slice_b = slice(
            start_index_b, min(num_orientations, start_index_b + split_size)
        )
        o_sub_b = misorientation[index_slice_b]
        for start_index_a in range(0, start_index_b + split_size, split_size):
            index_slice_a = slice(
                start_index_a, min(num_orientations, start_index_a + split_size)
            )
            o_sub_a = misorientation[index_slice_a]
            axis = (len(o_sub_a.shape), len(o_sub_a.shape) + 1)
            mis2orientation = (~o_sub_a).outer(S_1_outer_S_1).outer(o_sub_b)
            # This works through all the identity rotations
            for s_2_1, s_2_2 in icombinations(S_2, 2):
                m = s_2_1 * mis2orientation * s_2_2
                angle = m.angle.data.min(axis=axis)
                distance[index_slice_a, index_slice_b] = np.minimum(
                    distance[index_slice_a, index_slice_b], angle
                )
    # Symmetrize the matrix for convenience
    i_lower = np.tril_indices(distance.shape[0], -1)
    distance[i_lower] = distance.T[i_lower]
    return distance
Exemple #3
0
def getRelationsChampions(dataframe):
    columns = dataframe.columns.tolist()

    betterRelations = {}

    for column in columns:
        notThisColumn = list(set(columns) - set([column]))

        combinations = set()

        for i in range(2, 6):
            comb = list(icombinations(notThisColumn, i))

            for value in comb:
                combinations.add(value)

        for otherColumn in notThisColumn:
            combinations.add((otherColumn, None))

        for combinationTuple in combinations:
            combination = list(combinationTuple)

            if None in combination:
                combination = [combination[0]]

            result = convert.filterAndSortedApriori(dataframe, combination,
                                                    column)

            if len(result) == 0:
                continue

            score = result[0].ordered_statistics[0].confidence

            relation = {'combination': combination, 'confidence': score}

            print(f'Relation found for {column}: {relation}')

            if column not in betterRelations.keys():
                betterRelations[column] = [relation]
            else:
                betterRelations[column].append(relation)

    for key in betterRelations:
        relationList = betterRelations[key]

        betterRelations[key] = sorted(relationList,
                                      key=lambda x: x['confidence'],
                                      reverse=True)

    return betterRelations
Exemple #4
0
def _distance_1(misorientation, verbose):
    from itertools import combinations_with_replacement as icombinations
    s_1, s_2 = misorientation._symmetry
    distance = np.empty((misorientation.size, misorientation.size))
    index_pairs = icombinations(range(misorientation.size), 2)
    if verbose:
        from tqdm import tqdm
        index_pairs = tqdm(index_pairs, total=misorientation.size**2)
    for i, j in index_pairs:
        idxi = np.unravel_index(i, misorientation.shape)
        idxj = np.unravel_index(j, misorientation.shape)
        m_1, m_2 = misorientation[idxi], misorientation[idxj]
        mis2orientation = (
            s_2.outer(~m_1).outer(s_1).outer(s_1).outer(m_2).outer(s_2))

        axis = (0, len(misorientation.shape) + 1,
                len(misorientation.shape) + 2, -1)
        d = mis2orientation.angle.data.min(axis=axis)
        distance[i, j] = d
        distance[j, i] = d
    return distance
Exemple #5
0
def _distance_1(misorientation, verbose):

    warnings.warn("Use _distance_2 instead", DeprecationWarning)
    s_1, s_2 = misorientation._symmetry
    distance = np.empty((misorientation.size, misorientation.size))
    index_pairs = icombinations(range(misorientation.size), 2)
    if verbose:
        from tqdm import tqdm

        index_pairs = tqdm(index_pairs, total=misorientation.size**2)
    for i, j in index_pairs:
        idxi = np.unravel_index(i, misorientation.shape)
        idxj = np.unravel_index(j, misorientation.shape)
        m_1, m_2 = misorientation[idxi], misorientation[idxj]
        mis2orientation = s_2.outer(~m_1).outer(s_1).outer(s_1).outer(
            m_2).outer(s_2)

        axis = (0, len(misorientation.shape) + 1,
                len(misorientation.shape) + 2, -1)
        d = mis2orientation.angle.data.min(axis=axis)
        distance[i, j] = d
        distance[j, i] = d
    return distance
def combinations(lst):
    return chain(*(icombinations(lst, i) for i in xrange(1, len(lst)+1)))
Exemple #7
0
def combinations(lst):
    return chain(*(icombinations(lst, i) for i in xrange(1, len(lst) + 1)))