@staticmethod<EOL><INDENT>def sim_matrix(<EOL>src,<EOL>tar,<EOL>mat=None,<EOL>mismatch_cost=<NUM_LIT:0>,<EOL>match_cost=<NUM_LIT:1>,<EOL>symmetric=True,<EOL>alphabet=None,<EOL>):<DEDENT>
if alphabet:<EOL><INDENT>alphabet = tuple(alphabet)<EOL>for i in src:<EOL><INDENT>if i not in alphabet:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT><DEDENT>for i in tar:<EOL><INDENT>if i not in alphabet:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT><DEDENT><DEDENT>if src == tar:<EOL><INDENT>if mat and (src, src) in mat:<EOL><INDENT>return mat[(src, src)]<EOL><DEDENT>return match_cost<EOL><DEDENT>if mat and (src, tar) in mat:<EOL><INDENT>return mat[(src, tar)]<EOL><DEDENT>elif symmetric and mat and (tar, src) in mat:<EOL><INDENT>return mat[(tar, src)]<EOL><DEDENT>return mismatch_cost<EOL>
Return the matrix similarity of two strings.

        With the default parameters, this is identical to sim_ident.
        It is possible for sim_matrix to return values outside of the range
        :math:`[0, 1]`, if values outside that range are present in mat,
        mismatch_cost, or match_cost.

        Parameters
        ----------
        src : str
            Source string for comparison
        tar : str
            Target string for comparison
        mat : dict
            A dict mapping tuples to costs; the tuples are (src, tar) pairs of
            symbols from the alphabet parameter
        mismatch_cost : float
            The value returned if (src, tar) is absent from mat when src does
            not equal tar
        match_cost : float
            The value returned if (src, tar) is absent from mat when src equals
            tar
        symmetric : bool
            True if the cost of src not matching tar is identical to the cost
            of tar not matching src; in this case, the values in mat need only
            contain (src, tar) or (tar, src), not both
        alphabet : str
            A collection of tokens from which src and tar are drawn; if this is
            defined a ValueError is raised if either tar or src is not found in
            alphabet

        Returns
        -------
        float
            Matrix similarity

        Raises
        ------
        ValueError
            src value not in alphabet
        ValueError
            tar value not in alphabet

        Examples
        --------
        >>> NeedlemanWunsch.sim_matrix('cat', 'hat')
        0
        >>> NeedlemanWunsch.sim_matrix('hat', 'hat')
        1