<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def validate(self):
 """Check if the binary tree is malformed. :raise binarytree.exceptions.NodeReferenceError: If there is a cyclic reference to a node in the binary tree. :raise binarytree.exceptions.NodeTypeError: If a node is not an instance of :class:`binarytree.Node`. :raise binarytree.exceptions.NodeValueError: If a node value is not a number (e.g. int, float). **Example**: .. doctest:: Traceback (most recent call last):
 NodeReferenceError: cyclic node reference at index 0 """

        has_more_nodes = True
        visited = set()
        to_visit = [self]
        index = 0

        while has_more_nodes:
            has_more_nodes = False
            next_nodes = []

            for node in to_visit:
                if node is None:
                    next_nodes.extend((None, None))
                else:
                    if node in visited:
                        raise NodeReferenceError(
                            'cyclic node reference at index {}'.format(index))
                    if not isinstance(node, Node):
                        raise NodeTypeError(
                            'invalid node instance at index {}'.format(index))
                    if not isinstance(node.value, numbers.Number):
                        raise NodeValueError(
                            'invalid node value at index {}'.format(index))
                    if node.left is not None or node.right is not None:
                        has_more_nodes = True
                    visited.add(node)
                    next_nodes.extend((node.left, node.right))
                index += 1

            to_visit = next_nodes