def model(placeholders, node_output_dim=128): q = deque() layers = dict() sequence_features = features(placeholders['input1']) net = merge([sequence_features, placeholders['input2']]) layers[GO_ID] = {'net': slim.batch_norm(net)} for node_id in go[GO_ID]['children']: if node_id in func_set: q.append((node_id, node_output_dim)) while len(q) > 0: node_id, output_dim = q.popleft() parents = get_parents(go, node_id) parent_outputs = list() for parent_id in parents: if parent_id in layers: parent_outputs.append(layers[parent_id]['net']) net = merge(parent_outputs) net = slim.fully_connected(net, output_dim) logits = slim.fully_connected(net, 1) output = tf.nn.sigmoid(logits) layers[node_id] = {'net': net, 'output': output, 'logits': logits} for n_id in go[node_id]['children']: if n_id in func_set: q.append((n_id, output_dim)) return layers
def validate_no_cousin_marriage(fams, indis): ret_data = [] for fid in fams: if fams[fid]['HUSB'] is None or fams[fid]['WIFE'] is None: continue husb = fams[fid]['HUSB'] wife = fams[fid]['WIFE'] for id1, id2 in [(husb, wife), (wife, husb)]: id1_parents = utils.get_parents(id1, fams, indis) # this includes aunts as well id1_uncles = [ iid for pid in id1_parents for iid in utils.get_siblings(pid, fams, indis) ] if any( utils.is_descendant(id2, uncle, fams, indis) for uncle in id1_uncles): ret_data.append(( fid, f'Family fid={fid} is a marriage of first cousins id={husb} and id={wife}' )) break return ret_data
def validate_no_sibling_marriage(fams, indis): return_data = [] for fid in fams: if fams[fid]['HUSB'] is None or fams[fid]['WIFE'] is None: continue husb = fams[fid]['HUSB'] wife = fams[fid]['WIFE'] husb_parents = utils.get_parents(husb, fams, indis) wife_parents = utils.get_parents(wife, fams, indis) common_parent = any(par in wife_parents for par in husb_parents) if common_parent: return_data.append( (fid, f'Siblings {husb} and {wife} should not marry.')) return return_data
def get_layers(inputs): q = deque() layers = {} name = get_node_name(GO_ID) # each go term has: net = Dense(1024, activation='relu')(feature_model) ? layers[GO_ID] = {'net': inputs} for node_id in go[GO_ID]['children']: ## @node_id is child of @GO_ID if node_id in func_set: q.append((node_id, inputs)) ## get all children terms while len(q) > 0: node_id, net = q.popleft() parent_nets = [inputs] # for p_id in get_parents(go, node_id): # if p_id in func_set: # parent_nets.append(layers[p_id]['net']) # if len(parent_nets) > 1: # name = get_node_name(node_id) + '_parents' # net = merge( # parent_nets, mode='concat', concat_axis=1, name=name) name = get_node_name(node_id) # @net is Dense(feature->1024) @output is Dense(feature->1024->1) net, output = get_function_node(name, inputs) # @get_function_node returns output,output ... so net==output if node_id not in layers: layers[node_id] = {'net': net, 'output': output} ## add child to @layer dict, because @get_function_node returns output,output, we have net=Dense(feature->1024->1) for n_id in go[node_id]['children']: ## get children of child node if n_id in func_set and n_id not in layers: ok = True for p_id in get_parents(go, n_id): ## get parents of children of child node. ( so we don't double count these nodes, if we have seen their parents? ) if p_id in func_set and p_id not in layers: ok = False if ok: q.append((n_id, net)) for node_id in functions: childs = set(go[node_id]['children']).intersection(func_set) # children of given node if len(childs) > 0: outputs = [layers[node_id]['output']] for ch_id in childs: outputs.append(layers[ch_id]['output']) ## concat a @output Dense(feature->1024->1) name = get_node_name(node_id) + '_max' ## create layer that takes max over all children of current node layers[node_id]['output'] = merge( outputs, mode='max', name=name) ## replace @output with @merge layer. is this doing simple max pooling of @outputs ? ## what does layer look like ? """ layers[ GOid ] = {'net': Dense(feature->1024->1), 'output': maxpool( [ Dense(feature->1024->1) ... ] ) ... we iter maxpool over array output of @net from all children and current node} """ return layers
def get_layers(inputs): q = deque() layers = {} name = get_node_name(GO_ID) layers[GO_ID] = {'net': inputs} for node_id in go[GO_ID]['children']: if node_id in func_set: q.append((node_id, inputs)) while len(q) > 0: node_id, net = q.popleft() parent_nets = [inputs] for p_id in get_parents(go, node_id): if p_id in func_set: parent_nets.append(layers[p_id]['net']) if len(parent_nets) > 1: name = get_node_name(node_id) + '_parents' net = merge( parent_nets, mode='concat', concat_axis=1, name=name) name = get_node_name(node_id) net, output = get_function_node(name, net) if node_id not in layers: layers[node_id] = {'net': net, 'output': output} for n_id in go[node_id]['children']: if n_id in func_set and n_id not in layers: ok = True for p_id in get_parents(go, n_id): if p_id in func_set and p_id not in layers: ok = False if ok: q.append((n_id, net)) for node_id in functions: childs = set(go[node_id]['children']).intersection(func_set) if len(childs) > 0: outputs = [layers[node_id]['output']] for ch_id in childs: outputs.append(layers[ch_id]['output']) name = get_node_name(node_id) + '_max' layers[node_id]['output'] = merge( outputs, mode='max', name=name) return layers
def help(self): """Builds and returns default help text for this command.""" usage = '{}\n\n'.format(self.name) if self.description: usage += '{}\n\n'.format(self.description) usage += 'usage: ' if self.parent: parents = utils.get_parents(self.parent) usage += '{}'.format(''.join(map(lambda p: p + ' ... ', parents))) arg_strings = [] for arg in self._arguments: s = '<{}'.format(arg.name) s += '...>' if arg.variadic else '>' arg_strings.append(s) usage += '{} [options] {}'.format(self.name, ' '.join(arg_strings)) if len(self._commands): usage += ' {command}' usage += '\n' options = [] for option in self._options: names = ', '.join(option.aliases) args = ' '.join('<{}>'.format(a) for a in option.arguments) s = '{} {}'.format(names, args) options.append((s, option.description)) arguments = [] for arg in self._arguments: s = arg.name if arg.variadic: s += '...' arguments.append((s, arg.description)) commands = [] for command in self._commands: names = ', '.join(command.aliases) commands.append((names, command.description)) allNames = list(map(lambda o: o[0], options)) allNames += list(map(lambda a: a[0], arguments)) allNames += list(map(lambda c: c[0], commands)) maxlen = max(map(lambda e: len(e), allNames), default=0) options = list( map(lambda o: (o[0].ljust(maxlen + 2, ' '), o[1]), options)) arguments = list( map(lambda a: (a[0].ljust(maxlen + 2, ' '), a[1]), arguments)) commands = list( map(lambda c: (c[0].ljust(maxlen + 2, ' '), c[1]), commands)) if len(options): usage += '\n' usage += 'Options:\n' for option in options: usage += ' {}{}\n'.format(option[0], option[1] or '') if len(arguments): usage += '\n' usage += 'Arguments:\n' for argument in arguments: usage += ' {}{}\n'.format(argument[0], argument[1] or '') if len(commands): usage += '\n' usage += 'Commands:\n' for command in commands: usage += ' {}{}\n'.format(command[0], command[1] or '') return usage