def METHOD_NAME(trace_code, matrix, seq_i, pos_i):
        code1 = trace_code[seq_i, pos_i]
        if code1 == -1:
            return np.nan
        similarities = np.zeros(trace_code.shape[0])
        for i in range(trace_code.shape[0]):
            code2 = trace_code[i, pos_i]
            if code2 == -1:
                similarities[i] = 0
            else:
                sim = matrix[code1, code2]
                # Normalize (range 0.0 - 1.0)
                min_sim = np.min(matrix[code1])
                max_sim = np.max(matrix[code1])
                sim = (sim - min_sim) / (max_sim - min_sim)
                similarities[i] = sim
        # Delete self-similarity
        similarities = np.delete(similarities, seq_i)
        return np.average(similarities)