Beispiel #1
0
 def read_tree(self, line, label_line):
     # FIXED: tree.idx, also tree dict() use base 1 as it was in dataset
     # parents is list base 0, keep idx-1
     # labels is list base 0, keep idx-1
     parents = list(map(int,
                        line.split()))  # split each number and turn to int
     trees = dict()  # this is dict
     root = None
     labels = list(map(self.parse_dlabel_token, label_line.split()))
     for i in range(1, len(parents) + 1):
         #if not trees[i-1] and parents[i-1]!=-1:
         if i not in trees.keys() and parents[i - 1] != -1:
             idx = i
             prev = None
             while True:
                 parent = parents[idx - 1]
                 if parent == -1:
                     break
                 tree = Tree()
                 if prev is not None:
                     tree.add_child(prev)
                 trees[idx] = tree
                 tree.idx = idx  # -1 remove -1 here to prevent embs[tree.idx -1] = -1 while tree.idx = 0
                 tree.gold_label = labels[idx - 1]  # add node label
                 #if trees[parent-1] is not None:
                 if parent in trees.keys():
                     trees[parent].add_child(tree)
                     break
                 elif parent == 0:
                     root = tree
                     break
                 else:
                     prev = tree
                     idx = parent
     return root
Beispiel #2
0
 def read_tree(self, line):
     parents = map(int, line.split())
     trees = dict()
     root = None
     for i in xrange(1, len(parents) + 1):
         #if not trees[i-1] and parents[i-1]!=-1:
         if i - 1 not in trees.keys() and parents[i - 1] != -1:
             idx = i
             prev = None
             while True:
                 parent = parents[idx - 1]
                 if parent == -1:
                     break
                 tree = Tree()
                 if prev is not None:
                     tree.add_child(prev)
                 trees[idx - 1] = tree
                 tree.idx = idx - 1
                 #if trees[parent-1] is not None:
                 if parent - 1 in trees.keys():
                     trees[parent - 1].add_child(tree)
                     break
                 elif parent == 0:
                     root = tree
                     break
                 else:
                     prev = tree
                     idx = parent
     return root
Beispiel #3
0
def test_traverse_returns_none_when_operation_always_returns_false():
    t = Tree("a")
    t.add_child("b")

    node = t.traverse(lambda n: False)

    assert_that(node, is_(None))
Beispiel #4
0
 def read_tree(self, line):
     parents = list(map(int,line.split()))
     trees = dict()
     root = None
     for i in range(1,len(parents)+1):
         if i-1 not in trees.keys() and parents[i-1] != -1:
             idx = i
             prev = None
             while True:
                 parent = parents[idx-1]
                 if parent == -1:
                     break
                 tree = Tree()
                 if prev is not None:
                     tree.add_child(prev)
                 trees[idx-1] = tree
                 tree.idx = idx-1
                 #if trees[parent-1] is not None:
                 if parent-1 in trees.keys():
                     trees[parent-1].add_child(tree)
                     break
                 elif parent==0:
                     root = tree
                     break
                 else:
                     prev = tree
                     idx = parent
     #root = self.compact_tree(root, level=3)
     #print('root depth after compacting: ', root.depth())
     return root
Beispiel #5
0
class FileSystem:
    def __init__(self, root):
        self.file_system = Tree(root)
        self.level = []

    def add_root_dirs(self):
        for _dir in sorted(os.listdir('.')):
            self.file_system.add_child(self.file_system.root.value,
                                       os.path.abspath(_dir))
        self.level = self.file_system.root.children

    def add_next_level(self):
        while self.level != []:
            for child in self.level:
                if os.path.isdir(child.value):
                    os.chdir(child.value)
                    for c in os.listdir(child.value):
                        self.file_system.add_child(child.value,
                                                   os.path.realpath(c))
                os.chdir('..')
            self.level = [c for c in child.children for child in self.level]

    def flatten_file_system1(self):
        return self.flatten()

    def flatten(self):
        return [
            val for subxs in self.file_system.tree_levels() for val in subxs
        ]

    def flatten_file_system2(self):
        return self.file_system.DFS(self.file_system.root)
Beispiel #6
0
 def read_tree(self, parents):
     # 传入进来的parents是tensor,转化为list
     parents = parents.numpy().tolist()
     # parents = list(map(int,line.split()))
     trees = dict()
     root = None
     for i in range(1, len(parents) + 1):
         if i - 1 not in trees.keys() and parents[i - 1] != -1:
             idx = i
             prev = None
             while True:
                 parent = parents[idx - 1]
                 if parent == -1:
                     break
                 tree = Tree()
                 if prev is not None:
                     tree.add_child(prev)
                 trees[idx - 1] = tree
                 tree.idx = idx - 1
                 if parent - 1 in trees.keys():
                     trees[parent - 1].add_child(tree)
                     break
                 elif parent == 0:
                     root = tree
                     break
                 else:
                     prev = tree
                     idx = parent
     return root
Beispiel #7
0
    def build_prereq_tree(self, goal_conditions):
        """
        Builds a tree of courses and their prerequisites to pre-calculate the depths of paths in the search tree.

        :param goal_conditions: @see course_scheduler(course_descriptions, goal_conditions, initial_state)
        :return: Root of the tree
        """
        for course in goal_conditions:
            prereqs = self.get_prereqs(course)
            root = Tree(course)
            prereqSet = flatten(prereqs)
            if prereqSet == set():
                root.max_depth = 0
                self.heuristic_dictionary[course] = root.max_depth
                return root
            else:
                depths = []
                for prereq in prereqSet:
                    toAdd = self.build_prereq_tree([prereq])
                    root.add_child(toAdd)
                    self.heuristic_dictionary[prereq] = toAdd.max_depth
                    depths.append(toAdd.max_depth + 1)
                root.max_depth = max(depths)

                return root
Beispiel #8
0
 def read_tree(self, line, label_line):
     # TODO: read gold label
     parents = map(int, line.split())  # split each number and turn to int
     trees = dict()
     root = None
     labels = map(self.parse_dlabel_token, label_line.split())
     for i in xrange(1, len(parents) + 1):
         #if not trees[i-1] and parents[i-1]!=-1:
         if i - 1 not in trees.keys() and parents[i - 1] != -1:
             idx = i
             prev = None
             while True:
                 parent = parents[idx - 1]
                 if parent == -1:
                     break
                 tree = Tree()
                 if prev is not None:
                     tree.add_child(prev)
                 trees[idx - 1] = tree
                 tree.idx = idx - 1
                 tree.gold_label = labels[idx - 1]  # add node label
                 #if trees[parent-1] is not None:
                 if parent - 1 in trees.keys():
                     trees[parent - 1].add_child(tree)
                     break
                 elif parent == 0:
                     root = tree
                     break
                 else:
                     prev = tree
                     idx = parent
     return root
Beispiel #9
0
def predictTree(image_caption_model, img):

    device = torch.device("cuda:0")

    root = Tree("root")
    root = word_embedding(root)
    root.value = torch.tensor(root.value).to(device).float()
    while (1):
        sub_tree = Tree(image_caption_model(img, root).flatten())
        max = 0
        max_index = 0

        for i in range(14):
            if sub_tree.value[i] > max:
                max = sub_tree.value[i]
                max_index = i
        for i in range(14):
            if i != max_index:
                sub_tree.value[i] = 0
            else:
                sub_tree.value[i] = 1
        root.add_child(sub_tree)
        if sub_tree.value[2] == 1:
            break
    for child in root.children:
        if child.value[3] == 1 or child.value[7] == 1 or child.value[
                8] == 1 or child.value[9] == 1 or child.value[12] == 1:
            predictSubTree(image_caption_model, img, child, root, 1)
    return root
Beispiel #10
0
    def read_tree(self, line, rels):
        parents = list(map(int, line.split()))
        relations = list(map(str, rels.split()))

        trees = dict()
        root = None
        for i in range(1, len(parents) + 1):
            if i - 1 not in trees.keys() and parents[i - 1] != -1:
                idx = i
                prev = None
                while True:
                    parent = parents[idx - 1]
                    if parent == -1:
                        break
                    tree = Tree()
                    if prev is not None:
                        tree.add_child(prev)
                    trees[idx - 1] = tree
                    tree.idx = idx - 1
                    tree.rel = relations[tree.idx] 
                    #tree.rel  = self.rel_vocab.getIndex(relations[tree.idx]) ##ADDED Relation
                    #tree.hidden = None
                    if parent - 1 in trees.keys():
                        trees[parent - 1].add_child(tree)
                        break
                    elif parent == 0:
                        root = tree
                        break
                    else:
                        prev = tree
                        idx = parent
        return root
def build_sunet():
	# SUNET
	sunet = Tree("66a45.sunet.se")

	def build_kth():
		kth = Tree("kth2.sunet.se")
		kth_intranet = Tree("a5ef-6c.kth.se")
		for namn in ["red-12", "orange-5", "sport-3", "spel-15"]:
			kth_intranet.add_child(Tree(namn))
		kth_services = Tree("645ea5.kth.se")
		for namn in ["webmail.kth.se", "smtp.kth.se", "www.kth.se"]:
			kth_services.add_child(Tree(namn))
		kth.add_child(kth_intranet)
		kth.add_child(kth_services)
		return kth

	def build_su():
		su = Tree("sthlm-universitet.sunet.se")
		services = Tree("65efa64-65edb.su.se")
		for namn in ["www.su.se", "smtp.su.se", "webmail.su.se"]:
			services.add_child(Tree(namn))
		inst = Tree("56afd.f6425-cd8.su.se")
		for namn in ["biblioteket.su.se", "math.su.se", "fysik.su.se"]:
			inst.add_child(Tree(namn))
		su.add_child(services)
		su.add_child(inst)
		return su

	sunet.add_child(build_su())
	sunet.add_child(build_kth())
	return sunet
    def make_bfs_tree_from(self, vertex):
        if not(self.member(vertex)):
            raise ValueError("The vertex for bfs tree is not a member.")

        bfs_tree = Tree(vertex)
        visited = [vertex]

        splicer = None
        queue_ = Queue()

        queue_.push_back(vertex)
        queue_.push_back(splicer)

        while not(queue_.is_empty()):
            v = queue_.pop()
            if v is splicer:
                if queue_.is_empty():
                    return bfs_tree
                queue_.push_back(splicer)
            else:
                for neighboor in self.graph[v]:
                    if neighboor not in visited:
                        bfs_tree.add_child(v, neighboor)
                        queue_.push_back(neighboor)
                        visited.append(neighboor)
        return bfs_tree
Beispiel #13
0
 def read_tree(self, line):
     parents = map(int,line.split())
     trees = dict()
     root = None
     for i in xrange(1,len(parents)+1):
         #if not trees[i-1] and parents[i-1]!=-1:
         if i-1 not in trees.keys() and parents[i-1]!=-1:
             idx = i
             prev = None
             while True:
                 parent = parents[idx-1]
                 if parent == -1:
                     break
                 tree = Tree()
                 if prev is not None:
                     tree.add_child(prev)
                 trees[idx-1] = tree
                 tree.idx = idx-1
                 #if trees[parent-1] is not None:
                 if parent-1 in trees.keys():
                     trees[parent-1].add_child(tree)
                     break
                 elif parent==0:
                     root = tree
                     break
                 else:
                     prev = tree
                     idx = parent
     return root
Beispiel #14
0
def test_add_child_appends_node_to_the_child_list():
    t = Tree("a")
    t.add_child("b")

    t.add_child("c")

    assert_that(t.children[0].value, is_("b"))
    assert_that(t.children[1].value, is_("c"))
Beispiel #15
0
def test_find_returns_node_with_the_specified_value_when_such_exists():
    t = Tree("a")
    t.add_child("b")
    t.add_child("c").add_child("d").add_child("e")

    node = t.find("d")

    assert_that(node.children[0].value, is_("e"))
Beispiel #16
0
def get_root_node(str_parse_tree):
	str_json = convert_str_json(str_parse_tree)[0]
	print(str_json)
	root = Tree()
	for key, value in str_json.items():
		temp_dic = {}
		temp_dic[key] = value
		root.add_child(convert_json_tree(temp_dic))
	return root
Beispiel #17
0
def convert_json_tree(json):
	for key, val in json.items():
		node = Tree(pos_tag=key)

		if(type(val) == type("")):
			node.value = val
			node.children = None
		elif(type(val) == type([])):
			for child in val:
				node.add_child(convert_json_tree(child))
		else:
			continue
	return node
Beispiel #18
0
def test_traverse_uses_depth_first_strategy():
    t = Tree("a")
    child = t.add_child("b")
    child.add_child("d")
    child.add_child("e")
    t.add_child("c")

    visited = []

    def visit_all(node):
        visited.append(node.value)
        return False

    t.traverse(visit_all)

    assert_that(visited, is_(["a", "b", "d", "e", "c"]))
def build_verisign():
	verisign = Tree("5e7a-f.verisign.net")
	verisign.add_child(build_banana())
	
	rick_chain = ["Never.gonna.give.you.up.xbfzf.net",
				  "Never.gonna.let.you.down.xbfzf.net",
				  "Never.gonna.run.around.and.desert.you.xbfzf.net",
				  "Never.gonna.make.you.cry.xbfzf.net"]
	rick_top = Tree(rick_chain[0])
	prev = rick_top
	for curr in rick_chain[1:]:
		curr = Tree(curr)
		prev.add_child(curr)
		prev = curr
	verisign.add_child(rick_top)
		
	return verisign
	def build_su():
		su = Tree("sthlm-universitet.sunet.se")
		services = Tree("65efa64-65edb.su.se")
		for namn in ["www.su.se", "smtp.su.se", "webmail.su.se"]:
			services.add_child(Tree(namn))
		inst = Tree("56afd.f6425-cd8.su.se")
		for namn in ["biblioteket.su.se", "math.su.se", "fysik.su.se"]:
			inst.add_child(Tree(namn))
		su.add_child(services)
		su.add_child(inst)
		return su
Beispiel #21
0
 def test_insert(self):
     a = Tree('a')
     b = a.add_child('b')
     c = a.add_child('c')
     d = b.add_child('d')
     e = b.add_child('e')
     f = c.add_child('f')
     g = c.add_child('g')
     self.assertIn(b, a.children)
     self.assertIn(c, a.children)
Beispiel #22
0
def build_tree(event):
    '''
    input: a batch of events [prev, arg0, arg1, arg2], a list of vertex id

    shape: (batchsize x 4 x arg.max_word_length)

    '''
    # prev, arg0, arg1, arg2 = event

    tree = Tree()
    tree.idx = 0
    ev_len = event.shape[1]
    id_ls = list(range(ev_len))
    tree.parent = 0
    for arg in id_ls[1:]:
        argtree = Tree()
        argtree.idx = arg
        tree.add_child(argtree)
    return tree
def build_tree(math_exp_string):
    """
    This method is used to build a tree from given input mathematical expression.
    Following consideration has been taken
    1. higher order operations are given with complete parenthesis ex. 1 - (2*3)
    2. add left and right parenthesis if not given ex. (1 - (2 * 3))
    3. print error message for any exception

    """
    if not validate_math_exp(math_exp_string):
        raise InvalidInput('Validation Error, one or more parenthesis are not closed properly')
    
    exp_list = filter_exp_list(math_exp_string)
    stack = Stack()
    current_node = Tree()

    for token in exp_list:

        if token == '(':
            current_node.add_child()
            stack.push(current_node)
            current_node = current_node.get_newborn_child()

        elif token == ')':
            if stack.size():
                current_node = stack.pop()

        elif token in operator_map.keys():
            if current_node.get_val():
                if current_node.get_val() == token:
                    current_node.add_child()
                    stack.push(current_node)
                    current_node = current_node.get_newborn_child()
                else:
                    parent = Tree(token)
                    parent.update_child(current_node)
                    parent.add_child()
                    stack.push(parent)
                    current_node = parent.get_newborn_child()
            else:
                current_node.set_val(token)
                current_node.add_child()
                stack.push(current_node)
                current_node = current_node.get_newborn_child()

        else:
            try:
                current_node.set_val(float(token))
            except ValueError, e:
                logging.info(e.message)
                current_node.set_val(token)
            current_node = stack.pop()
def example_tree():
	ft = Tree("/")
	for directory in ["bin", "boot", "dev", "etc", "home", "proc"]:
		t = Tree(directory)
		ft.add_child(t)
		if directory == "home":
			for user in ["pelle", "stina", "tjorven"]:
				u = Tree(user)
				t.add_child(u)
				if user == "tjorven":
					d = Tree("sudata")
					u.add_child(d)
					for labb in range(3,8):
						d.add_child(Tree("labb{}".format(labb)))
	return ft
Beispiel #25
0
class treeTest(unittest.TestCase):
    def setUp(self):
        n = Node(5, parent=None)
        self.tree = Tree(n)
        self.tree.add_child(parent=5, child=4)
        self.tree.add_child(parent=5, child=3)
        self.tree.add_child(parent=4, child=2)

    def test_get_element(self):
        self.assertEqual(
            self.tree.get_element(5, start=self.tree.root).data, 5)

    # def test_find(self):
    #     self.assertTrue(self.tree.find(3))

    def test_count_nodes(self):
        self.assertEqual(self.tree.count_nodes(), 4)

    def test_height(self):
        self.assertEqual(self.tree.height(self.tree.root), 3)

    def test_walk(self):
        self.assertEqual(self.tree.walk(self.tree.root), [])
Beispiel #26
0
def test_traversal(mock_dfs):
    mock_dfs.side_effect = dfs
    root = Tree(1)
    first_child = Tree(2)
    root.add_child(first_child)
    first_child.add_child(Tree(4))
    root.add_child(Tree(3))
    # Traversal order verified with print statements, since the function is
    # only called once (no recursion).
    assert mock_dfs(root, 4)
    assert_equals(mock_dfs.call_count, 3)
	def build_kth():
		kth = Tree("kth2.sunet.se")
		kth_intranet = Tree("a5ef-6c.kth.se")
		for namn in ["red-12", "orange-5", "sport-3", "spel-15"]:
			kth_intranet.add_child(Tree(namn))
		kth_services = Tree("645ea5.kth.se")
		for namn in ["webmail.kth.se", "smtp.kth.se", "www.kth.se"]:
			kth_services.add_child(Tree(namn))
		kth.add_child(kth_intranet)
		kth.add_child(kth_services)
		return kth
def build_internet():
	global INTERNET
	INTERNET = Tree("internet")
	INTERNET.add_child(build_netnod())
	INTERNET.add_child(build_verisign())

	sw_chain = [
		"Episode.IV.A.NEW.HOPE.75eyjm.net",
		"It.is.a.period.of.civil.war.75eyjm.net",
		"Rebel.spaceships.striking.from.75eyjm.net",
		"a.hidden.base.have.won.their.first.75eyjm.net",
		"victory.against.the.evil.Galactic.Empire.75eyjm.net"
		]
	
	sw_top = Tree(sw_chain[0])
	prev = sw_top
	for curr in sw_chain[1:]:
		curr = Tree(curr)
		prev.add_child(curr)
		prev = curr    
	INTERNET.add_child(sw_top)
Beispiel #29
0
def maketree(lt):

    stack = []

    tree = Tree('html')

    for token in lt:
        if "<" in token and ("</" not in token or "/>" in token):
            tag = token.split(" ", 1)[0].replace("<", "")
            tag = tag.replace(">", "")
            new_node = Tree(token)
            tree.add_child(new_node)
            if tag not in SINGLE_TAGS:
                tree = new_node
                stack.append(tag)

        elif "</" in token:
            tag = token.split(" ", 1)[0].replace("<", "")
            tag = tag.replace(">", "").replace("/", "")
            results = [i for i, x in enumerate(stack) if x == tag]
            if len(results) != 0:
                pos = results[-1]
                del stack[pos]

            tree = tree.parent

        elif "/>" in token:
            new_node = Tree(token)
            tree.add_child(new_node)

        else:
            stack.append(token)
            new_node = Tree(token)
            tree.add_child(new_node)

    while tree.parent is not None:
        tree = tree.parent

    return tree
Beispiel #30
0
def inverse_kinematics(x,y,z,alpha,beta,gamma,**frame_file):
    angles = {}
    frames = []
    pos = [x,y,z]
    filename =  frame_file.pop('input', 'serial_manipulator_6.json')

    with open(filename) as input:
        data = json.load(input)

        dof = data.pop('dof',6) #6 dof by default

        frames_prototype = data['frames']

        if not frames_prototype:
            raise Exception('No frames in file')

        convention = data.pop('convention','xyz')

        for prototype in frames_prototype:
            frames.append(Frame(prototype['displacement'],prototype['previous_relation']))
  
    T = Axis.invert_zyz(alpha,beta,gamma)
    T[0].append(x)
    T[1].append(y)
    T[2].append(z)
    T.append([0,0,0,1])

    result = Tree(0)
#compute teta1
    result.add_child('teta1_a',atan2( -pos[0],pos[1] ))
    result.add_child('teta1_b',atan2( pos[0],-pos[1] ))

#compute teta2,teta3
#rotate plane around z to zy for each teta1

    for branch, teta1 in result.childs.items():
        ang = teta1.value
        p = [pos]

        #rotate plane to zy
        np = Utils.multiply_matrix(p,[[cos(ang),-sin(ang),0],
                                      [sin(ang), cos(ang), 0],
                                      [0,        0,        1]])
        
        new_p = [np[0][0],np[0][1],np[0][2] - 99]

        #we got a plane
        p_mag = Utils.magnitude(new_p)
        #intersect circunference with radius c centered in new_p
        #with one centered in [0,99] (due to the displacement from frame 1 to frame 2 )
        #and with radius of 120

        c = 155
        p2 = Utils.intersect_circunference(new_p[1],new_p[2],c,0,0,120)

        teta2_a = atan2(-p2[0][0],p2[0][1])
        teta2_b = atan2(-p2[1][0],p2[1][1])

        teta1.add_child('teta2_a',teta2_a)
        teta1.add_child('teta2_b',teta2_b)

        i = 0
        for branch2, teta2 in  teta1.childs.items():    
            p2_mag = Utils.magnitude(p2[i])

            cosalpha = -(p_mag**2 - c**2 - p2_mag**2) / (2*c*p2_mag)

            alpha = acos(cosalpha)
  
            if i == 0:
                teta3 = alpha -  pi/2
            else:
                teta3 = alpha + pi/2 -2 *pi

            
            t3_branch = teta2.add_child('teta3',teta3)
            i+=1

            frames[0].rotate_joint_z(teta1.value)
            frames[1].rotate_joint_z(teta2.value)
            frames[2].rotate_joint_z(teta3)

            T03 = [[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]]

            for frame in frames[0:3]:
                T03 = Utils.multiply_matrix(T03,frame.position_m)

            T30 = Utils.inv_4x4_matrix(T03)


            T36 = Utils.multiply_matrix(T30,T)

            costeta5 = T36[1][2]

            #two possible teta5 values
            teta5 = [0,0]

            teta5[0] = acos(costeta5)
            teta5[1]= -teta5[0]

            enum = ['a','b']
            j = 0
            for t5 in teta5:
                if round(sin(t5),4) == 0:
                    t3_branch.add_child('error','Configuration singularity sin(teta5) = 0')
                    continue
                else:
                    sinTeta6 = round(- T36[1][1] / sin(t5),4)
                    cosTeta6 = round(T36[1][0] / sin(t5),4)
                    cosTeta4 = round(- T36[0][2] / sin(t5),4)
                    sinTeta4 = round(- T36[2][2] / sin(t5),4)
                    
                    teta4 = acos(cosTeta4)
                    if sinTeta4 < 0:
                        teta4 = - teta4

                    teta6 = acos(cosTeta6)
                    if sinTeta6 < 0 :
                        teta6 = - teta6

                    t4_branch = t3_branch.add_child('teta4' + enum[j],teta4)
                    t5_branch = t4_branch.add_child('teta5',t5)
                    t5_branch.add_child('teta6',teta6)
                    j+=1

    return result
Beispiel #31
0

def fib(n):
    # replace the pass statement with your code
    pass


def find_root_sqrt2(epsilon, a, b):
    # replace the pass statement with your code
    pass


t0 = Tree("node0", 27)

t1 = Tree("node0", 1)
t1.add_child(Tree("node1", 2, children=[Tree("node2", 3)]))
t1.add_child(Tree("node3", 4))
t1.add_child(Tree("node4", 5))


def count_leaves(t):
    '''
    Count the number of leaves in the tree rooted at t
    
    Inputs: (Tree) a tree
    
    Returns: (integer) number of leaves in t
    '''
    assert t is not None

    if t.num_children() == 0:
Beispiel #32
0
    def create_tree(self,
                    current_x,
                    current_y,
                    current_feature_list,
                    impurity_measure,
                    parent_node=None):
        """
        A recursive method for generating decision-tree, using the ID3 algorithm.

        :param current_x: list, available dataset
        :param current_y: list, aavailable dataset labels
        :param current_feature_list: list, available features
        :param impurity_measure: string, impurity measure to generate tree
        :param parent_node: Tree, parent tree for this iteration.
        :return: Tree, A decision tree
        """
        if np.unique(current_y).size == 1:  # If pure subset, add leaf
            return Tree(label=np.unique(current_y)[0], parent=parent_node)

        if current_feature_list.size == 0 or len(
                np.unique(current_x)
        ) == 1:  # If impure subset and not able to split any further, or all x_elem equal
            label_list, label_count = np.unique(current_y, return_counts=True)
            max_label = label_list[np.argmax(label_count)]
            return Tree(label=max_label, parent=parent_node)

        if impurity_measure == "entropy":
            calc_function = self.entropy
        elif impurity_measure == "gini":
            calc_function = self.gini_index
        else:
            raise Exception("Unknown impurity measure")

        feature_gains = [
            self.information_gain(current_x, current_y, feature, calc_function)
            for feature in current_feature_list
        ]

        max_index = feature_gains.index(max(feature_gains))
        best_feature = current_feature_list[max_index]

        if current_feature_list.size == 1:
            current_feature_list = np.array([])
        else:
            current_feature_list = np.delete(current_feature_list, max_index)

        parent = Tree(feature_split=best_feature, parent=parent_node)

        child_labels = []
        for branch_option in np.unique(current_x[:, best_feature]):
            child_x = [
                entry for entry in current_x
                if entry[best_feature] == branch_option
            ]
            child_y = [
                current_y[ind] for ind, entry in enumerate(current_x)
                if entry[best_feature] == branch_option
            ]
            child_x = np.array(child_x)
            child_y = np.array(child_y)
            if child_y.size > 0:
                child = self.create_tree(child_x, child_y,
                                         current_feature_list,
                                         impurity_measure, parent)
                child.choice = branch_option
                parent.add_child(child)
                child_labels.append(child.label)

        labels, counts = np.unique(child_labels, return_counts=True)
        most_common_label = labels[np.argmax(counts)]
        parent.label = most_common_label

        return parent
Beispiel #33
0
class FCMdata(object):
    """
    Object representing flow cytometry data
    FCMdata.pnts : a numpy array of data points
    FCMdata.channels : a list of which markers/scatters are on which column of
    the array.
    FCMdata.scatters : a list of which indexes in fcmdata.channels are scatters
    """
    def __init__(self, name, pnts, channels, scatters=None, notes=None):
        """
        fcmdata(name, pnts, channels, scatters=None)
        name: name of corresponding FCS file minus extension
        pnts: array of data points
        channels: a list of which markers/scatters are on which column of
                    the array.
        scatters: a list of which indexes in channels are scatters

        """
        self.name = name
        self.tree = Tree(pnts, channels)

        #TODO add some default intelligence for determining scatters if None
        self.scatters = scatters
        self.markers = []
        if self.scatters is not None:
            for chan in range(len(channels)):
                if chan in self.scatters:
                    pass
                elif self.tree.root.channels[chan] in self.scatters:
                    pass
                else:
                    self.markers.append(chan)
        if notes == None:
            notes = Annotation()
        self.notes = notes

    def __unicode__(self):
        return self.name

    def __repr__(self):
        return self.name

    def _lookup_item(self, item):
        if isinstance(item, tuple):

            item = list(item)  # convert to be mutable.
            if isinstance(item[1], basestring):

                item[1] = self.name_to_index(item[1])
            elif isinstance(item[1], tuple) or isinstance(item[1], list):

                item[1] = list(item[1])  # convert to be mutable.
                for i, j in enumerate(item[1]):
                    if isinstance(j, basestring):
                        item[1][i] = self.name_to_index(j)
            item = tuple(item)
        return item

    def __getitem__(self, item):
        """return FCMdata points"""
        item = self._lookup_item(item)

        return self.tree.view()[item]

    def __setitem__(self, key, value):
        item = self._lookup_item(key)
        self.tree.view()[item] = value

    @property
    def channels(self):
        return [i for i in self.current_node.channels]

    def __len__(self):
        return self.current_node.view().__len__()

    def __getattr__(self, name):
        if name in dir(self.current_node.view()):
            #return Node.__getattribute__(self.current_node,'view')().__getattribute__(name)
            return self.current_node.view().__getattribute__(name)
        else:
            raise AttributeError("'%s' has no attribue '%s'" %
                                 (str(self.__class__), name))

    def __getstate__(self):
        return self.__dict__

    def __setstate__(self, dict):
        for i in dict.keys():
            self.__dict__[i] = dict[i]

    def name_to_index(self, channels):
        """Return the channel indexes for the named channels"""

        if isinstance(channels, basestring):
            try:
                if channels in self.channels:
                    return self.channels.index(channels)
                else:
                    raise ValueError('%s is not in list' % channels)

            except ValueError:
                for j in range(1, int(self.notes.text['par']) + 1):
                    if channels == self.notes.text['p%dn' % j]:
                        return self.channels.index(self.notes.text['p%ds' % j])
                raise ValueError('%s is not in list' % channels)

        idx = []
        for i in channels:
            if i in self.channels:
                idx.append(self.channels.index(i))
            else:
                raise ValueError('%s is not in list' % channels)

        if idx:
            return idx
        else:
            raise ValueError('field named a not found: %s' % str(channels))

    def get_channel_by_name(self, channels):
        """Return the data associated with specific channel names"""

        return self.tree.view()[:, self.name_to_index(channels)]

    def get_markers(self):
        """return the data associated with all the markers"""

        return self.view()[:, self.markers]

    def get_spill(self):
        """return the spillover matrix from the original fcs used in compisating"""

        try:
            return self.notes.text['spill']
        except KeyError:
            return None

    def view(self):
        """return the current view of the data"""

        return self.tree.view()

    def visit(self, name):
        """Switch current view of the data"""

        self.tree.visit(name)

    @property
    def current_node(self):
        """return the current node"""

        return self.tree.current

    def copy(self):
        """return a copy of fcm data object"""

        tname = self.name
        tpnts = self.tree.root.data
        tnotes = self.notes.copy()
        tchannels = self.channels[:]

        tscchannels = self.scatters[:]
        tmp = FCMdata(tname, tpnts, tchannels, tscchannels, tnotes)
        from copy import deepcopy
        tmp.tree = deepcopy(self.tree)
        return tmp

    def logicle(self,
                channels=None,
                T=262144,
                m=4.5,
                r=None,
                w=0.5,
                a=0,
                scale_max=1e5,
                scale_min=0,
                rquant=None):
        """return logicle transformed channels"""

        if channels is None:
            channels = self.markers
        return _logicle(self, channels, T, m, r, scale_max, scale_min, w, a,
                        rquant)

    def hyperlog(self, channels, b, d, r, order=2, intervals=1000.0):
        """return hyperlog transformed channels"""

        return _hyperlog(self, channels, b, d, r, order, intervals)

    def log(self, channels=None):
        """return log base 10 transformed channels"""

        if channels is None:
            channels = self.markers
        return _log(self, channels)

    def gate(self, g, chan=None):
        """return gated region of fcm data"""

        return g.gate(self, chan)

    def subsample(self, s, model='random', *args, **kwargs):
        """return subsampled/sliced fcm data"""
        if isinstance(s, Subsample):
            return s.subsample(self)
        elif isinstance(s, slice):
            r = Subsample(s)
            return r.subsample(self)
        else:
            if model == 'random':
                r = RandomSubsample(s)
            elif model == 'anomaly':
                r = AnomalySubsample(s, *args, **kwargs)
            elif model == 'bias':
                r = BiasSubsample(s, *args, **kwargs)
            return r.subsample(self, *args, **kwargs)

    def compensate(self, sidx=None, spill=None):
        """Compensate the fcm data"""

        compensate(self, S=spill, markers=sidx)
        return self

    def get_cur_node(self):
        """ get current node """

        return self.current_node

    def add_view(self, node):
        """add a new node to the view tree"""

        self.tree.add_child(node.name, node)
        return self

    def summary(self):
        """returns summary of current view"""

        pnts = self.view()
        means = pnts.mean(0)
        stds = pnts.std(0)
        mins = pnts.min(0)
        maxs = pnts.max(0)
        medians = median(pnts, 0)
        dim = pnts.shape[1]
        summary = ''
        for i in range(dim):
            summary = summary + self.channels[i] + ":\n"
            summary = summary + "    max: " + str(maxs[i]) + "\n"
            summary = summary + "   mean: " + str(means[i]) + "\n"
            summary = summary + " median: " + str(medians[i]) + "\n"
            summary = summary + "    min: " + str(mins[i]) + "\n"
            summary = summary + "    std: " + str(stds[i]) + "\n"
        return summary

    def boundary_events(self):
        """returns dictionary of fraction of events in first and last
        channel for each channel"""

        boundary_dict = {}
        for k, chan in enumerate(self.channels):
            col = self.view()[:, k]
            boundary_dict[chan] = \
                sum((col == min(col)) | (col == max(col))) / len(col)
        return boundary_dict

    def export(self, file_name):
        """
        export out current view to a fcs file
        """
        from fcm.io import export_fcs
        export_fcs(file_name, self.view(), self.current_node.channels,
                   self.notes.text)

    def extract_channels(self, channels, keep=False):
        """
        create a view without the specified channels or with if keep==True
        """
        if isinstance(channels, basestring) or isinstance(channels, int):
            channels = [channels]
        for i, j in enumerate(channels):
            if isinstance(j, str):
                channels[i] = self.name_to_index(j)
        if keep:
            channels = [
                i for i in range(len(self.channels)) if i not in channels
            ]
        d = DropChannel(channels)
        d.drop(self)
        return self

    def add_channel(self, name, channel=None):
        if channel is None:
            channel = zeros((self.shape[0], 1))

        print channel.shape

        node = AddChannel(channel, name)
        node.add(self)
        return self
Beispiel #34
0
class FCMdata(object):
    """
    Object representing flow cytometry data
    FCMdata.pnts : a numpy array of data points
    FCMdata.channels : a list of which markers/scatters are on which column of
    the array.
    FCMdata.scatters : a list of which indexes in fcmdata.channels are scatters
    """

    def __init__(self, name, pnts, channels, scatters=None, notes=None):
        """
        fcmdata(name, pnts, channels, scatters=None)
        name: name of corresponding FCS file minus extension
        pnts: array of data points
        channels: a list of which markers/scatters are on which column of
                    the array.
        scatters: a list of which indexes in channels are scatters

        """
        self.name = name
        self.tree = Tree(pnts, channels)

        #TODO add some default intelligence for determining scatters if None
        self.scatters = scatters
        self.markers = []
        if self.scatters is not None:
            for chan in range(len(channels)):
                if chan in self.scatters:
                    pass
                elif self.tree.root.channels[chan] in self.scatters:
                    pass
                else:
                    self.markers.append(chan)
        if notes == None:
            notes = Annotation()
        self.notes = notes

    def __unicode__(self):
        return self.name

    def __repr__(self):
        return self.name

    def _lookup_item(self,item):
        if isinstance(item, tuple):

            item = list(item) # convert to be mutable.
            if isinstance(item[1], basestring):

                item[1] = self.name_to_index(item[1])
            elif isinstance(item[1], tuple) or isinstance(item[1], list):

                item[1] = list(item[1])# convert to be mutable.
                for i, j in enumerate(item[1]):
                    if isinstance(j, basestring):
                        item[1][i] = self.name_to_index(j)
            item = tuple(item)
        return item
    
    def __getitem__(self, item):
        """return FCMdata points"""
        item = self._lookup_item(item)
        
        return self.tree.view()[item]

    def __setitem__(self,key,value):
        item = self._lookup_item(key)
        self.tree.view()[item] = value
    @property
    def channels(self):
        return [i for i in self.current_node.channels]
    
    def __len__(self):
        return self.current_node.view().__len__()
    
    def __getattr__(self, name):
            if name in dir(self.current_node.view()):
                #return Node.__getattribute__(self.current_node,'view')().__getattribute__(name)
                return self.current_node.view().__getattribute__(name)
            else:
                raise AttributeError("'%s' has no attribue '%s'" % (str(self.__class__), name))

    def __getstate__(self):
        return self.__dict__

    def __setstate__(self, dict):
        for i in dict.keys():
            self.__dict__[i] = dict[i]

    def name_to_index(self, channels):
        """Return the channel indexes for the named channels"""

        if isinstance(channels, basestring):
            try:
                if channels in self.channels:
                    return self.channels.index(channels)
                else:
                    raise ValueError('%s is not in list' % channels)

            except ValueError:
                for j in range(1, int(self.notes.text['par']) + 1):
                        if channels == self.notes.text['p%dn' % j]:
                            return self.channels.index(self.notes.text['p%ds' % j])
                raise ValueError('%s is not in list' % channels)

        idx = []
        for i in channels:
            if i in self.channels:
                idx.append(self.channels.index(i))
            else:
                raise ValueError('%s is not in list' % channels)

        if idx:
            return idx
        else:
            raise ValueError('field named a not found: %s' % str(channels))

    def get_channel_by_name(self, channels):
        """Return the data associated with specific channel names"""

        return self.tree.view()[:, self.name_to_index(channels)]

    def get_markers(self):
        """return the data associated with all the markers"""

        return self.view()[:, self.markers]

    def get_spill(self):
        """return the spillover matrix from the original fcs used in compisating"""

        try:
            return self.notes.text['spill']
        except KeyError:
            return None

    def view(self):
        """return the current view of the data"""

        return self.tree.view()

    def visit(self, name):
        """Switch current view of the data"""

        self.tree.visit(name)

    @property
    def current_node(self):
        """return the current node"""

        return self.tree.current

    def copy(self):
        """return a copy of fcm data object"""

        tname = self.name
        tpnts = self.tree.root.data
        tnotes = self.notes.copy()
        tchannels = self.channels[:]

        tscchannels = self.scatters[:]
        tmp = FCMdata(tname, tpnts, tchannels, tscchannels, tnotes)
        from copy import deepcopy
        tmp.tree = deepcopy(self.tree)
        return tmp

    def logicle(self, channels=None, T=262144, m=4.5, r=None, w=0.5, a=0, scale_max=1e5, scale_min=0, rquant=None):
        """return logicle transformed channels"""

        if channels is None:
            channels = self.markers
        return _logicle(self, channels, T, m, r, scale_max, scale_min, w, a, rquant)

    def hyperlog(self, channels, b, d, r, order=2, intervals=1000.0):
        """return hyperlog transformed channels"""

        return _hyperlog(self, channels, b, d, r, order, intervals)

    def log(self, channels=None):
        """return log base 10 transformed channels"""

        if channels is None:
            channels = self.markers
        return _log(self, channels)

    def gate(self, g, chan=None):
        """return gated region of fcm data"""

        return g.gate(self, chan)

    def subsample(self, s, model='random', *args, **kwargs):
        """return subsampled/sliced fcm data"""
        if isinstance(s, Subsample):
            return s.subsample(self)
        elif isinstance(s, slice):
            r = Subsample(s)
            return r.subsample(self)
        else:
            if model == 'random':
                r = RandomSubsample(s)
            elif model == 'anomaly':
                r = AnomalySubsample(s, *args, **kwargs)
            elif model == 'bias':
                r = BiasSubsample(s, *args, **kwargs)
            return r.subsample(self, *args, **kwargs)

    def compensate(self, sidx=None, spill=None):
        """Compensate the fcm data"""

        compensate(self, S=spill, markers=sidx)
        return self

    def get_cur_node(self):
        """ get current node """

        return self.current_node

    def add_view(self, node):
        """add a new node to the view tree"""

        self.tree.add_child(node.name, node)
        return self

    def summary(self):
        """returns summary of current view"""

        pnts = self.view()
        means = pnts.mean(0)
        stds = pnts.std(0)
        mins = pnts.min(0)
        maxs = pnts.max(0)
        medians = median(pnts, 0)
        dim = pnts.shape[1]
        summary = ''
        for i in range(dim):
            summary = summary + self.channels[i] + ":\n"
            summary = summary + "    max: " + str(maxs[i]) + "\n"
            summary = summary + "   mean: " + str(means[i]) + "\n"
            summary = summary + " median: " + str(medians[i]) + "\n"
            summary = summary + "    min: " + str(mins[i]) + "\n"
            summary = summary + "    std: " + str(stds[i]) + "\n"
        return summary

    def boundary_events(self):
        """returns dictionary of fraction of events in first and last
        channel for each channel"""

        boundary_dict = {}
        for k, chan in enumerate(self.channels):
            col = self.view()[:, k]
            boundary_dict[chan] = \
                sum((col == min(col)) | (col == max(col))) / len(col)
        return boundary_dict

    def export(self, file_name):
        """
        export out current view to a fcs file
        """
        from fcm.io import export_fcs
        export_fcs(file_name, self.view(), self.current_node.channels, self.notes.text)

    def extract_channels(self, channels, keep=False):
        """
        create a view without the specified channels or with if keep==True
        """
        if isinstance(channels, basestring) or isinstance(channels, int):
            channels = [channels]
        for i, j in enumerate(channels):
            if isinstance(j, str):
                channels[i] = self.name_to_index(j)
        if keep:
            channels = [ i  for i in range(len(self.channels)) if i not in channels]
        d = DropChannel(channels)
        d.drop(self)
        return self

    def add_channel(self, name, channel=None):
        if channel is None:
            channel = zeros((self.shape[0],1))
        
        print channel.shape
        
        node = AddChannel(channel, name)
        node.add(self)
        return self
Beispiel #35
0
def test_non_first_child():
    root = Tree(6)
    root.add_child(Tree(2))
    root.add_child(Tree(1))
    assert dfs(root, 1)
def build_netnod():
	netnod = Tree("62ef-425.netnod.com")
	netnod.add_child(build_pyttemjuk())
	netnod.add_child(build_sunet())
	netnod.add_child(build_telenor())
	return netnod
def build_telenor():
	telenor = Tree("a8f.9.telenor.se")
	# smallbandsbolaget
	sbbolaget = Tree("cce76-top.smalbandsbolaget.se")
	sb_sthlm = Tree("ns.645-52-stockholm.smalbandsbolaget.se")
	sbbolaget.add_child(sb_sthlm)
	for n in [ "Lisas router", "Familjen Larsson"]:
		sb_sthlm.add_child(Tree(n))
	telenor.add_child(sbbolaget)
	# Judiths nät
	judith = Tree("58.5-ce6.judith-och-judith.se")
	judith_sth = Tree("a-8ed.sth-63.judith-och-judith.se")
	judith.add_child(judith_sth)
	for n in ["dlink-653C", "Kalle hem"]:
		judith_sth.add_child(Tree(n))
	telenor.add_child(judith)
	
	return telenor
Beispiel #38
0
def test_add_child_returns_appended_node_instance():
    t = Tree("a")

    new_node = t.add_child("b")

    assert_that(new_node, equal_to(t.children[0]))
Beispiel #39
0
def test2():
    tree1 = Tree([1, 2, 3])
    tree1.add_child([4, 5, 6], tree1.root)
    tree2 = deepcopy(tree1)
    tree2.root.data[1] = 20000
    return tree1, tree2
Beispiel #40
0
def test_single_child():
    root = Tree(6)
    root.add_child(Tree(2))
    assert dfs(root, 2)
Beispiel #41
0
def test_not_in_tree():
    root = Tree(6)
    root.add_child(Tree(2))
    assert not dfs(root, 1)
Beispiel #42
0
class FCMdata(object):
    """
    Object representing flow cytometry data
    FCMdata.pnts : a numpy array of data points
    FCMdata.channels : a list of which markers/scatters are on which column of
    the array.
    FCMdata.scatters : a list of which indexes in fcmdata.channels are scatters

    """
    def __init__(self, name, pnts, channels, scatters=None, notes=None):
        """
        fcmdata(name, pnts, channels, scatters=None)
        name: name of corresponding FCS file minus extension
        pnts: array of data points
        channels: a list of which markers/scatters are on which column of
                    the array.
        scatters: a list of which indexes in channels are scatters
        
        """
        self.name = name
        #        if type(pnts) != type(array([])):
        #            raise BadFCMPointDataTypeError(pnts, "pnts isn't a numpy.array")
        self.tree = Tree(pnts, channels)
        #self.pnts = pnts
        #self.channels = channels
        #TODO add some default intelegence for determining scatters if None
        self.scatters = scatters
        self.markers = []
        if self.scatters is not None:
            for chan in range(len(channels)):
                if chan in self.scatters:
                    pass
                elif self.tree.root.channels[chan] in self.scatters:
                    pass
                else:
                    self.markers.append(chan)
        if notes == None:
            notes = Annotation()
        self.notes = notes

    def __unicode__(self):
        return self.name

    def __repr__(self):
        return self.name

    def __getitem__(self, item):
        """return FCMdata points"""

        if isinstance(item, tuple):

            item = list(item)  # convert to be mutable.
            if isinstance(item[1], str):

                item[1] = self.name_to_index(item[1])
            elif isinstance(item[1], tuple) or isinstance(item[1], list):

                item[1] = list(item[1])  # convert to be mutable.
                for i, j in enumerate(item[1]):
                    if isinstance(j, str):
                        print i, 'is string', j
                        item[1][i] = self.name_to_index(j)
            item = tuple(item)

        return self.tree.view()[item]

    @property
    def channels(self):
        return self.current_node.channels

    def __getattr__(self, name):
        if name in dir(self.current_node.view()):
            #return Node.__getattribute__(self.current_node,'view')().__getattribute__(name)
            return self.current_node.view().__getattribute__(name)
        else:
            raise AttributeError("'%s' has no attribue '%s'" %
                                 (str(self.__class__), name))

    def __getstate__(self):
        #        tmp = {}
        #        tmp['name'] = self.name
        #        tmp['tree'] = self.tree
        #        tmp['markers'] = self.markers
        #        tmp['scatters'] = self.scatters
        #        tmp['notes'] = self.notes
        #        return tmp
        return self.__dict__

    def __setstate__(self, dict):
        for i in dict.keys():
            self.__dict__[i] = dict[i]

    def name_to_index(self, channels):
        """Return the channel indexes for the named channels"""

        if isinstance(channels, str):
            return self.channels.index(channels)
        idx = []
        for i in channels:
            try:
                idx.append(self.channels.index(i))
            except ValueError:
                try:
                    for j in range(1, int(self.notes.text['par']) + 1):
                        if i == self.notes.text['p%dn' % j]:
                            idx.append(
                                self.channels.index(self.notes.text['p%ds' %
                                                                    j]))
                except ValueError:
                    raise ValueError('%s is not in list' % i)
        if idx:
            return idx
        else:
            raise ValueError('field named a not found: %s' % str(channels))

    def get_channel_by_name(self, channels):
        """Return the data associated with specific channel names"""

        return self.tree.view()[:, self.name_to_index(channels)]

    def get_markers(self):
        """return the data associated with all the markers"""

        return self.view()[:, self.markers]

    def get_spill(self):
        """return the spillover matrix from the original fcs used in compisating"""

        try:
            return self.notes.text['spill']
        except KeyError:
            return None

    def view(self):
        """return the current view of the data"""

        return self.tree.view()

    def visit(self, name):
        """Switch current view of the data"""

        self.tree.visit(name)

    @property
    def current_node(self):
        """return the current node"""

        return self.tree.current

    def copy(self):
        """return a copy of fcm data object"""

        tname = self.name
        tpnts = self.tree.root.data
        tnotes = self.notes.copy()
        tchannels = self.channels[:]

        tscchannels = self.scatters[:]
        tmp = FCMdata(tname, tpnts, tchannels, tscchannels, tnotes)
        from copy import deepcopy
        tmp.tree = deepcopy(self.tree)
        return tmp

    def logicle(self,
                channels=None,
                T=262144,
                m=4.5,
                r=None,
                scale_max=1e5,
                scale_min=0):
        """return logicle transformed channels"""

        if channels is None:
            channels = self.markers
        return _logicle(self, channels, T, m, r, scale_max, scale_min)

    def hyperlog(self, channels, b, d, r, order=2, intervals=1000.0):
        """return hyperlog transformed channels"""

        return _hyperlog(self, channels, b, d, r, order, intervals)

    def log(self, channels=None):
        """return log base 10 transformed channels"""

        if channels is None:
            channels = self.markers
        return _log(self, channels)

    def gate(self, g, chan=None):
        """return gated region of fcm data"""

        return g.gate(self, chan)

    def subsample(self, s):
        """return subsampled/sliced fcm data"""

        return s.subsample(self)

    def compensate(self, sidx=None, spill=None):
        '''Compensate the fcm data'''

        compensate(self, S=spill, markers=sidx)
        return self

    def get_cur_node(self):
        """ get current node """

        return self.current_node

    def add_view(self, node):
        """add a new node to the view tree"""

        self.tree.add_child(node.name, node)
        return self

    def summary(self):
        """returns summary of current view"""

        pnts = self.view()
        means = pnts.mean(0)
        stds = pnts.std(0)
        mins = pnts.min(0)
        maxs = pnts.max(0)
        medians = median(pnts, 0)
        dim = pnts.shape[1]
        summary = ''
        for i in range(dim):
            summary = summary + self.channels[i] + ":\n"
            summary = summary + "    max: " + str(maxs[i]) + "\n"
            summary = summary + "   mean: " + str(means[i]) + "\n"
            summary = summary + " median: " + str(medians[i]) + "\n"
            summary = summary + "    min: " + str(mins[i]) + "\n"
            summary = summary + "    std: " + str(stds[i]) + "\n"
        return summary

    def boundary_events(self):
        """returns dictionary of fraction of events in first and last
        channel for each channel"""

        boundary_dict = {}
        for k, chan in enumerate(self.channels):
            col = self.view()[:, k]
            boundary_dict[chan] = \
                sum((col == min(col)) | (col == max(col))) / len(col)
        return boundary_dict

    def export(self, file_name):
        '''
        export out current view to a fcs file
        '''
        from fcm.io import export_fcs
        export_fcs(file_name, self.view(), self.channels, self.notes.text)