Пример #1
0
def disl_boundary_fix(system,
                      bwidth,
                      bshape='circle',
                      m=[1, 0, 0],
                      n=[0, 1, 0]):
    """
    Creates a boundary region by changing atom types.
    
    Parameters
    ----------
    system : atomman.System
        The system to add the boundary region to.
    bwidth : float
        The minimum thickness of the boundary region.
    bshape : str, optional
        The shape to make the boundary region.  Options are 'circle' and
        'rect' (default is 'circle').
    """
    natypes = system.natypes
    atype = system.atoms_prop(key='atype')
    pos = system.atoms.pos
    x = np.dot(pos, np.asaray(m, dtype='float64'))
    y = np.dot(pos, np.asaray(n, dtype='float64'))

    if bshape == 'circle':
        # Find x or y bound closest to 0
        smallest_xy = min([
            abs(system.box.xlo),
            abs(system.box.xhi),
            abs(system.box.ylo),
            abs(system.box.yhi)
        ])

        radius = smallest_xy - bwidth
        xy_mag = np.linalg.norm(pos[:, :2], axis=1)
        atype[xy_mag > radius] += natypes

    elif bshape == 'rect':
        index = np.unique(
            np.hstack((np.where(pos[:, 0] < system.box.xlo + bwidth),
                       np.where(pos[:, 0] > system.box.xhi - bwidth),
                       np.where(pos[:, 1] < system.box.ylo + bwidth),
                       np.where(pos[:, 1] > system.box.yhi - bwidth))))
        atype[index] += natypes

    else:
        raise ValueError(
            "Unknown boundary shape type! Enter 'circle' or 'rect'")

    new_system = deepcopy(system)
    new_system.atoms.atype = atype
    new_system.symbols = list(system.symbols) * 2

    return new_system
def gain(col, tag_col):
    I_tab = Entropy(tag_col)
    tt_count = np.asarray(col).size
    dist_term = np.unique(col)
    tm_count = np.array(dist_term).size
    info = 0
    for i in range(tm_count):
        _listt = []

        for j in range(tt_count):
            if (col[j] == dist_term[i]):
                _list.append(tag_col[j])
        e = Entropy(_list)
        w = np.asaray(_list).size / tt_count
        info += e * w
    gain = I_tab - info
    return gain
    def text_to_instance(
            self,  # type: ignore
            answer: str,
            question: str,
            passages: List[str],
            passages_length: List[int],
            passages_is_selected: List[int],
            concatenated_passage: str) -> Instance:

        passage_field = TextField(tokenized_passage, self._token_indexers)

        passages_length_field = ArrayField(np.asaray(passages_length))
        passages_is_selected_field = ArrayField(
            np.asarray(passages_is_selected))

        fields = {
            'answer': answer_field,
            'question': question_field,
            'passage': passage_field,
            'passages_length': passages_length_field,
            'passages_is_selected': passages_is_selected_field
        }

        return Instance(fields)