本文整理汇总了Python中utool.get_list_column函数的典型用法代码示例。如果您正苦于以下问题:Python get_list_column函数的具体用法?Python get_list_column怎么用?Python get_list_column使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_list_column函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: group_review
def group_review():
prefill = request.args.get('prefill', '')
if len(prefill) > 0:
ibs = current_app.ibs
aid_list = ibs.get_valid_aids()
bad_species_list, bad_viewpoint_list = ibs.validate_annot_species_viewpoint_cnn(aid_list)
GROUP_BY_PREDICTION = True
if GROUP_BY_PREDICTION:
grouped_dict = ut.group_items(bad_viewpoint_list, ut.get_list_column(bad_viewpoint_list, 3))
grouped_list = grouped_dict.values()
regrouped_items = ut.flatten(ut.sortedby(grouped_list, map(len, grouped_list)))
candidate_aid_list = ut.get_list_column(regrouped_items, 0)
else:
candidate_aid_list = [ bad_viewpoint[0] for bad_viewpoint in bad_viewpoint_list]
elif request.args.get('aid_list', None) is not None:
aid_list = request.args.get('aid_list', '')
if len(aid_list) > 0:
aid_list = aid_list.replace('[', '')
aid_list = aid_list.replace(']', '')
aid_list = aid_list.strip().split(',')
candidate_aid_list = [ int(aid_.strip()) for aid_ in aid_list ]
else:
candidate_aid_list = ''
else:
candidate_aid_list = ''
return appf.template(None, 'group_review', candidate_aid_list=candidate_aid_list, mode_list=appf.VALID_TURK_MODES)
开发者ID:Erotemic,项目名称:ibeis,代码行数:28,代码来源:routes.py
示例2: parse_items
def parse_items(cfg):
r"""
Returns:
list: param_list
CommandLine:
python -m dtool.base --exec-parse_items
Example:
>>> # ENABLE_DOCTEST
>>> from dtool.base import * # NOQA
>>> from dtool.example_depcache import DummyVsManyConfig
>>> cfg = DummyVsManyConfig()
>>> param_list = cfg.parse_items()
>>> result = ('param_list = %s' % (ut.repr2(param_list, nl=1),))
>>> print(result)
"""
namespace_param_list = cfg.parse_namespace_config_items()
param_names = ut.get_list_column(namespace_param_list, 1)
needs_namespace_keys = ut.find_duplicate_items(param_names)
param_list = ut.get_list_column(namespace_param_list, [1, 2])
# prepend namespaces to variables that need it
for idx in ut.flatten(needs_namespace_keys.values()):
name = namespace_param_list[idx][0]
param_list[idx][0] = name + '_' + param_list[idx][0]
duplicate_keys = ut.find_duplicate_items(ut.get_list_column(param_list, 0))
# hack to let version through
import utool
with utool.embed_on_exception_context:
assert len(duplicate_keys) == 0, (
'Configs have duplicate names: %r' % duplicate_keys)
return param_list
开发者ID:Erotemic,项目名称:dtool,代码行数:32,代码来源:base.py
示例3: get_name_rowid_edges_from_nids
def get_name_rowid_edges_from_nids(ibs, nids):
aids_list = ibs.get_name_aids(nids)
import itertools
unflat_edges = (list(itertools.product(aids, aids)) for aids in aids_list)
aid_pairs = [tup for tup in ut.iflatten(unflat_edges) if tup[0] != tup[1]]
aids1 = ut.get_list_column(aid_pairs, 0)
aids2 = ut.get_list_column(aid_pairs, 1)
return aids1, aids2
开发者ID:Erotemic,项目名称:ibeis,代码行数:8,代码来源:viz_graph.py
示例4: get_name_rowid_edges_from_aids2
def get_name_rowid_edges_from_aids2(ibs, aids_list):
# grouped version
import itertools
unflat_edges = (list(itertools.product(aids, aids)) for aids in aids_list)
#if full:
aid_pairs = [tup for tup in ut.iflatten(unflat_edges) if tup[0] != tup[1]]
aids1 = ut.get_list_column(aid_pairs, 0)
aids2 = ut.get_list_column(aid_pairs, 1)
return aids1, aids2
开发者ID:heroinlin,项目名称:ibeis,代码行数:9,代码来源:viz_graph.py
示例5: draw_map_histogram
def draw_map_histogram(top_assignments, fnum=None, pnum=(1, 1, 1)):
import plottool as pt
bin_labels = ut.get_list_column(top_assignments, 0)
bin_vals = ut.get_list_column(top_assignments, 1)
fnum = pt.ensure_fnum(fnum)
# bin_labels = ['\n'.join(ut.textwrap.wrap(_lbl, width=30)) for _lbl in bin_labels]
pt.draw_histogram(bin_labels, bin_vals, fnum=fnum, pnum=pnum,
transpose=True,
use_darkbackground=False,
#xtick_rotation=-10,
ylabel='Prob', xlabel='assignment')
pt.set_title('Assignment probabilities')
开发者ID:heroinlin,项目名称:ibeis,代码行数:12,代码来源:pgm_viz.py
示例6: get_namescore_nonvoting_feature_flags
def get_namescore_nonvoting_feature_flags(fm_list, fs_list, dnid_list, name_groupxs, kpts1=None):
r"""
fm_list = [fm[:min(len(fm), 10)] for fm in fm_list]
fs_list = [fs[:min(len(fs), 10)] for fs in fs_list]
"""
fx1_list = [fm.T[0] for fm in fm_list]
# Group annotation matches by name
name_grouped_fx1_list = vt.apply_grouping_(fx1_list, name_groupxs)
name_grouped_fs_list = vt.apply_grouping_(fs_list, name_groupxs)
# Stack up all matches to a particular name, keep track of original indicies via offets
name_invertable_flat_fx1_list = list(map(ut.invertible_flatten2_numpy, name_grouped_fx1_list))
name_grouped_fx1_flat = ut.get_list_column(name_invertable_flat_fx1_list, 0)
name_grouped_invertable_cumsum_list = ut.get_list_column(name_invertable_flat_fx1_list, 1)
name_grouped_fs_flat = list(map(np.hstack, name_grouped_fs_list))
if kpts1 is not None:
xys1_ = vt.get_xys(kpts1).T
kpts_xyid_list = vt.compute_unique_data_ids(xys1_)
# Make nested group for every name by query feature index (accounting for duplicate orientation)
name_grouped_xyid_flat = list(kpts_xyid_list.take(fx1) for fx1 in name_grouped_fx1_flat)
xyid_groupxs_list = list(vt.group_indices(xyid_flat)[1] for xyid_flat in name_grouped_xyid_flat)
name_group_fx1_groupxs_list = xyid_groupxs_list
else:
# Make nested group for every name by query feature index
fx1_groupxs_list = [vt.group_indices(fx1_flat)[1] for fx1_flat in name_grouped_fx1_flat]
name_group_fx1_groupxs_list = fx1_groupxs_list
name_grouped_fid_grouped_fs_list = [
vt.apply_grouping(fs_flat, fid_groupxs)
for fs_flat, fid_groupxs in zip(name_grouped_fs_flat, name_group_fx1_groupxs_list)
]
# Flag which features are valid in this grouped space. Only one keypoint should be able to vote
# for each group
name_grouped_fid_grouped_isvalid_list = [
np.array([fs_group.max() == fs_group for fs_group in fid_grouped_fs_list])
for fid_grouped_fs_list in name_grouped_fid_grouped_fs_list
]
# Go back to being grouped only in name space
#dtype = np.bool
name_grouped_isvalid_flat_list = [
vt.invert_apply_grouping2(fid_grouped_isvalid_list, fid_groupxs, dtype=np.bool)
for fid_grouped_isvalid_list, fid_groupxs in zip(name_grouped_fid_grouped_isvalid_list, name_group_fx1_groupxs_list)
]
name_grouped_isvalid_unflat_list = [
ut.unflatten2(isvalid_flat, invertable_cumsum_list)
for isvalid_flat, invertable_cumsum_list in zip(name_grouped_isvalid_flat_list, name_grouped_invertable_cumsum_list)
]
# Reports which features were valid in name scoring for every annotation
featflag_list = vt.invert_apply_grouping(name_grouped_isvalid_unflat_list, name_groupxs)
return featflag_list
开发者ID:Erotemic,项目名称:ibeis,代码行数:52,代码来源:name_scoring.py
示例7: define_named_aid_cfgs
def define_named_aid_cfgs():
"""
Definitions for common aid configurations
TODO: potentially move to experiment configs
"""
from ibeis.expt import annotation_configs
named_defaults_dict = ut.dict_take(annotation_configs.__dict__, annotation_configs.TEST_NAMES)
named_qcfg_defaults = dict(zip(annotation_configs.TEST_NAMES, ut.get_list_column(named_defaults_dict, "qcfg")))
named_dcfg_defaults = dict(zip(annotation_configs.TEST_NAMES, ut.get_list_column(named_defaults_dict, "dcfg")))
alias_keys = annotation_configs.alias_keys
named_cfg_dict = {"qcfg": named_qcfg_defaults, "dcfg": named_dcfg_defaults}
return named_cfg_dict, alias_keys
开发者ID:Erotemic,项目名称:ibeis,代码行数:13,代码来源:old_main_helpers.py
示例8: group_aids_by_featweight_species
def group_aids_by_featweight_species(ibs, aid_list, config2_=None):
""" helper
Example:
>>> # ENABLE_DOCTEST
>>> from ibeis.algo.preproc.preproc_probchip import * # NOQA
>>> import ibeis
>>> ibs = ibeis.opendb('testdb1')
>>> config2_ = None
>>> aid_list = ibs.get_valid_aids()
>>> grouped_aids, unique_species, groupxs = group_aids_by_featweight_species(ibs, aid_list, config2_)
"""
if config2_ is None:
featweight_species = ibs.cfg.featweight_cfg.featweight_species
else:
featweight_species = config2_.get('featweight_species')
assert featweight_species is not None
if featweight_species == 'uselabel':
# Use the labeled species for the detector
species_list = ibs.get_annot_species_texts(aid_list)
else:
species_list = [featweight_species]
aid_list = np.array(aid_list)
species_list = np.array(species_list)
species_rowid = np.array(ibs.get_species_rowids_from_text(species_list))
unique_species_rowids, groupxs = vtool.group_indices(species_rowid)
grouped_aids = vtool.apply_grouping(aid_list, groupxs)
grouped_species = vtool.apply_grouping(species_list, groupxs)
unique_species = ut.get_list_column(grouped_species, 0)
return grouped_aids, unique_species, groupxs
开发者ID:heroinlin,项目名称:ibeis,代码行数:30,代码来源:preproc_probchip.py
示例9: testdb2_stuff
def testdb2_stuff():
"""
tar -zcvf testdb2.tar.gz testdb2/
"""
import ibeis
ibs = ibeis.opendb('testdb2')
#ibs.ensure_contributor_rowids()
gid_list = ibs.get_valid_gids()
# Group gids by species
image_species_list = ut.get_list_column(
ibs.unflat_map(ibs.get_annot_species_rowids, ibs.get_image_aids(gid_list)), 0)
new_contrib_rowid1 = ibs.add_new_temp_contributor(offset=len(ibs.get_valid_contrib_rowids()))
new_contrib_rowid2 = ibs.add_new_temp_contributor(offset=len(ibs.get_valid_contrib_rowids()))
gids1, gids2 = list(ut.group_items(gid_list, image_species_list).values())
party_rowids = ibs.add_party(['TestCar1', 'TestCar2'])
partyid1, partyid2 = party_rowids
ibs.set_image_contributor_rowid(gids1, [new_contrib_rowid1] * len(gids1))
ibs.set_image_contributor_rowid(gids2, [new_contrib_rowid2] * len(gids2))
ibs.set_image_party_rowids(gids1, [partyid1] * len(gids1))
ibs.set_image_party_rowids(gids2, [partyid2] * len(gids2))
开发者ID:heroinlin,项目名称:ibeis,代码行数:26,代码来源:reset_testdbs.py
示例10: get_oracle_name_decision
def get_oracle_name_decision(metatup, ibs, qaid, choicetup, oracle_method=1):
"""
Find what the correct decision should be ibs is the database we are working
with ibs_gt has pristine groundtruth
"""
if ut.VERBOSE:
print('Oracle is making decision using oracle_method=%r' % oracle_method)
if metatup is None:
print('WARNING METATUP IS NONE')
return None
MAX_LOOK = 3 # the oracle should only see what the user sees
(sorted_nids, sorted_nscore, sorted_rawscore, sorted_aids, sorted_ascores) = choicetup
(ibs_gt, aid1_to_aid2) = metatup
# Get the annotations that the user can see
aid_list2 = ut.get_list_column(sorted_aids, 0)
# Get the groundtruth name of the query
aid2_to_aid1 = ut.invert_dict(aid1_to_aid2)
qnid1 = ibs_gt.get_annot_name_rowids(aid2_to_aid1[qaid])
# Make an oracle decision by choosing a name (like a user would)
if oracle_method == 1:
chosen_names = oracle_method1(ibs_gt, ibs, qnid1, aid_list2, aid2_to_aid1, sorted_nids, MAX_LOOK)
elif oracle_method == 2:
chosen_names = oracle_method2(ibs_gt, qnid1)
else:
raise AssertionError('unknown oracle method %r' % (oracle_method,))
if ut.VERBOSE:
print('Oracle decision is chosen_names=%r' % (chosen_names,))
return chosen_names
开发者ID:Erotemic,项目名称:ibeis,代码行数:28,代码来源:automated_oracle.py
示例11: _get_annot_pair_info
def _get_annot_pair_info(ibs, aid1, aid2, qreq_, draw_fmatches, **kwargs):
kpts1 = kwargs.get('kpts1', None)
kpts2 = kwargs.get('kpts2', None)
kpts2_list = None if kpts2 is None else [kpts2]
rchip1, kpts1 = get_query_annot_pair_info(ibs, aid1, qreq_, draw_fmatches,
kpts1=kpts1)
annot2_data_list = get_data_annot_pair_info(ibs, [aid2], qreq_,
draw_fmatches,
kpts2_list=kpts2_list)
rchip2, kpts2 = ut.get_list_column(annot2_data_list , 0)
return rchip1, rchip2, kpts1, kpts2
开发者ID:Erotemic,项目名称:ibeis,代码行数:11,代码来源:viz_matches.py
示例12: get_aids_and_scores
def get_aids_and_scores(qres, name_scoring=False, ibs=None):
""" returns a chip index list and associated score list """
if name_scoring:
assert ibs is not None, 'must specify ibs for name_scoring'
nscoretup = qres.get_nscoretup(ibs)
(sorted_nids, sorted_nscore, sorted_aids, sorted_scores) = nscoretup
score_arr = np.array(sorted_nscore)
aid_arr = np.array(ut.get_list_column(sorted_aids, 0))
else:
aid_arr, score_arr = qres.get_aids_and_chip_scores()
return aid_arr, score_arr
开发者ID:heroinlin,项目名称:ibeis,代码行数:11,代码来源:hots_query_result.py
示例13: test_training_data
def test_training_data(varydict, nDaids_basis):
varydict['nDaids'] = nDaids_basis
cfgdict_list = ut.all_dict_combinations(varydict)
K_list = ut.get_list_column(cfgdict_list, 'K')
nDaids_list = ut.get_list_column(cfgdict_list, 'nDaids')
max_error = min(nDaids_basis)
nError_perterb = np.random.rand(len(K_list))
#def distance_point_polynomial(point, poly_coeff):
# """
# References:
# http://kitchingroup.cheme.cmu.edu/blog/2013/02/14/Find-the-minimum-distance-from-a-point-to-a-curve/
# """
# def f(x):
# return x ** 2
# def objective(X, *args):
# point = args[0]
# x, y = X
# px, py = point
# return np.sqrt((x - px) ** 2 + (y - py) ** 2)
# def c1(X, *args):
# x, y = X
# return f(x) - y
# X = sp.optimize.fmin_cobyla(objective, x0=[0.5, 0.5], args=(point,), cons=[c1], disp=False)
# return X
#point_list = np.array([point for point in zip(nDaids_list, K_list)])
#poly_coeff = [0.2, 0.5] # K model_params
#closest_point_list = np.array([distance_point_polynomial(point, poly_coeff) for point in point_list])
#dist_list = np.sqrt(((point_list - closest_point_list) ** 2).sum(axis=1))
#nError_list = max_error * dist_list / dist_list.max() + nError_perterb
nError_list = (np.array(nDaids_list) * .00001)
nError_list /= nError_list.max()
nError_list *= (max_error - 2)
nError_list += 1 + nError_perterb
#K_list = np.array([ 1, 1, 1, 4, 4, 4, 7, 7, 7, 10, 10, 10, 13, 13, 13])
#nDaids_list = np.array([100, 500, 1000, 100, 500, 1000, 100, 500, 1000, 100, 500, 1000, 100, 500, 1000])
#nError_list = np.array([ 5, 54, 130, 50, 50, 70, 14, 54, 40, 20, 9, 43, 90, 20, 130])
return nDaids_list, K_list, nError_list
开发者ID:Erotemic,项目名称:ibeis,代码行数:39,代码来源:optimize_k.py
示例14: setup_pzmtest_subgraph
def setup_pzmtest_subgraph():
import ibeis
ibs = ibeis.opendb(db='PZ_MTEST')
nids = ibs.get_valid_nids()
aids_list = ibs.get_name_aids(nids)
import itertools
unflat_edges = (list(itertools.product(aids, aids)) for aids in aids_list)
aid_pairs = [tup for tup in ut.iflatten(unflat_edges) if tup[0] != tup[1]]
aids1 = ut.get_list_column(aid_pairs, 0)
aids2 = ut.get_list_column(aid_pairs, 1)
rng = np.random.RandomState(0)
flags = rng.rand(len(aids1)) > .878
aids1 = ut.compress(aids1, flags)
aids2 = ut.compress(aids2, flags)
for aid1, aid2 in zip(aids1, aids2):
ibs.set_annot_pair_as_positive_match(aid1, aid2)
ibs.set_annot_pair_as_positive_match(aid2, aid1)
rowids = ibs._get_all_annotmatch_rowids()
aids1 = ibs.get_annotmatch_aid1(rowids)
aids2 = ibs.get_annotmatch_aid2(rowids)
开发者ID:heroinlin,项目名称:ibeis,代码行数:24,代码来源:annotmatch_funcs.py
示例15: compute_fgweights
def compute_fgweights(ibs, aid_list, config2_=None):
"""
Example:
>>> # SLOW_DOCTEST
>>> from ibeis.algo.preproc.preproc_featweight import * # NOQA
>>> import ibeis
>>> ibs = ibeis.opendb('testdb1')
>>> aid_list = ibs.get_valid_aids()[1:2]
>>> config2_ = None
>>> featweight_list = compute_fgweights(ibs, aid_list)
>>> result = np.array_str(featweight_list[0][0:3], precision=3)
>>> print(result)
[ 0.125 0.061 0.053]
"""
nTasks = len(aid_list)
print('[preproc_featweight.compute_fgweights] Preparing to compute %d fgweights' % (nTasks,))
probchip_fpath_list = preproc_probchip.compute_and_write_probchip(ibs,
aid_list,
config2_=config2_)
chipsize_list = ibs.get_annot_chip_sizes(aid_list, config2_=config2_)
#if ut.DEBUG2:
# from PIL import Image
# probchip_size_list = [Image.open(fpath).size for fpath in probchip_fpath_list] # NOQA
# #with ut.embed_on_exception_context:
# # does not need to happen anymore
# assert chipsize_list == probchip_size_list, 'probably need to clear chip or probchip cache'
kpts_list = ibs.get_annot_kpts(aid_list, config2_=config2_)
# Force grayscale reading of chips
probchip_list = [vt.imread(fpath, grayscale=True) if exists(fpath) else None
for fpath in probchip_fpath_list]
print('[preproc_featweight.compute_fgweights] Computing %d fgweights' % (nTasks,))
arg_iter = zip(aid_list, kpts_list, probchip_list, chipsize_list)
featweight_gen = ut.generate(gen_featweight_worker, arg_iter,
nTasks=nTasks, ordered=True, freq=10)
featweight_param_list = list(featweight_gen)
#arg_iter = zip(aid_list, kpts_list, probchip_list)
#featweight_param_list1 = [gen_featweight_worker((aid, kpts, probchip)) for
#aid, kpts, probchip in arg_iter]
#featweight_aids = ut.get_list_column(featweight_param_list, 0)
featweight_list = ut.get_list_column(featweight_param_list, 1)
print('[preproc_featweight.compute_fgweights] Done computing %d fgweights' % (nTasks,))
return featweight_list
开发者ID:Erotemic,项目名称:ibeis,代码行数:47,代码来源:preproc_featweight.py
示例16: group_review_submit
def group_review_submit():
"""
CommandLine:
python -m ibeis.web.app --exec-group_review_submit
Example:
>>> # UNSTABLE_DOCTEST
>>> from ibeis.web.app import * # NOQA
>>> import ibeis
>>> import ibeis.web
>>> ibs = ibeis.opendb('testdb1')
>>> aid_list = ibs.get_valid_aids()[::2]
>>> ibs.start_web_annot_groupreview(aid_list)
"""
ibs = current_app.ibs
method = request.form.get("group-review-submit", "")
if method.lower() == "populate":
redirection = request.referrer
if "prefill" not in redirection:
# Prevent multiple clears
if "?" in redirection:
redirection = "%s&prefill=true" % (redirection,)
else:
redirection = "%s?prefill=true" % (redirection,)
return redirect(redirection)
aid_list = request.form.get("aid_list", "")
if len(aid_list) > 0:
aid_list = aid_list.replace("[", "")
aid_list = aid_list.replace("]", "")
aid_list = aid_list.strip().split(",")
aid_list = [int(aid_.strip()) for aid_ in aid_list]
else:
aid_list = []
src_ag, dst_ag = ibs.prepare_annotgroup_review(aid_list)
valid_modes = ut.get_list_column(appf.VALID_TURK_MODES, 0)
mode = request.form.get("group-review-mode", None)
assert mode in valid_modes
return redirect(url_for(mode, src_ag=src_ag, dst_ag=dst_ag))
开发者ID:Erotemic,项目名称:ibeis,代码行数:38,代码来源:routes_submit.py
示例17: compute_and_write_chips_lazy
def compute_and_write_chips_lazy(ibs, aid_list, config2_=None):
r"""
Spanws compute chip procesess if a chip does not exist on disk
DEPRICATE
This is regardless of if it exists in the SQL database
Args:
ibs (IBEISController):
aid_list (list):
"""
if ut.VERBOSE:
print("[preproc_chip] compute_and_write_chips_lazy")
# Mark which aid's need their chips computed
cfpath_list = make_annot_chip_fpath_list(ibs, aid_list, config2_=config2_)
missing_flags = [not exists(cfpath) for cfpath in cfpath_list]
invalid_aids = ut.compress(aid_list, missing_flags)
if ut.VERBOSE:
print("[preproc_chip] %d / %d chips need to be computed" % (len(invalid_aids), len(aid_list)))
chip_result_list = list(compute_and_write_chips(ibs, invalid_aids))
chip_fpath_list = ut.get_list_column(chip_result_list, 0)
return chip_fpath_list
开发者ID:Erotemic,项目名称:ibeis,代码行数:23,代码来源:old_chip_preproc.py
示例18: convert_name_suggestion_to_aids
def convert_name_suggestion_to_aids(ibs, choicetup, name_suggest_tup):
"""
Example:
>>> # DISABLE_DOCTEST
>>> from ibeis.algo.hots.user_dialogs import * # NOQA
>>> import ibeis
>>> # build test data
>>> ibs = ibeis.opendb('testdb1')
>>> comp_aids = [2, 3, 4]
>>> comp_names = ['fred', 'sue', 'alice']
>>> chosen_names = ['fred']
>>> # execute function
>>> result = convert_name_suggestion_to_aids(ibs, choicetup, name_suggest_tup)
>>> # verify results
>>> print(result)
"""
num_top = 3
autoname_msg, chosen_names, name_confidence = name_suggest_tup
comp_aids_all = ut.get_list_column(choicetup.sorted_aids, 0)
comp_aids = ut.listclip(comp_aids_all, num_top)
comp_names = ibs.get_annot_names(comp_aids)
issuggested = ut.list_cover(comp_names, chosen_names)
suggest_aids = ut.compress(comp_aids, issuggested)
return comp_aids, suggest_aids
开发者ID:Erotemic,项目名称:ibeis,代码行数:24,代码来源:user_dialogs.py
示例19: show_model
def show_model(model, evidence={}, soft_evidence={}, **kwargs):
"""
References:
http://stackoverflow.com/questions/22207802/pygraphviz-networkx-set-node-level-or-layer
Ignore:
pkg-config --libs-only-L libcgraph
sudo apt-get install libgraphviz-dev -y
sudo apt-get install libgraphviz4 -y
# sudo apt-get install pkg-config
sudo apt-get install libgraphviz-dev
# pip install git+git://github.com/pygraphviz/pygraphviz.git
pip install pygraphviz
python -c "import pygraphviz; print(pygraphviz.__file__)"
sudo pip3 install pygraphviz --install-option="--include-path=/usr/include/graphviz" --install-option="--library-path=/usr/lib/graphviz/"
python3 -c "import pygraphviz; print(pygraphviz.__file__)"
CommandLine:
python -m ibeis.algo.hots.bayes --exec-show_model --show
Example:
>>> # DISABLE_DOCTEST
>>> from ibeis.algo.hots.bayes import * # NOQA
>>> model = '?'
>>> evidence = {}
>>> soft_evidence = {}
>>> result = show_model(model, evidence, soft_evidence)
>>> print(result)
>>> ut.quit_if_noshow()
>>> import plottool as pt
>>> ut.show_if_requested()
"""
if ut.get_argval('--hackmarkov') or ut.get_argval('--hackjunc'):
draw_tree_model(model, **kwargs)
return
import plottool as pt
import networkx as netx
fnum = pt.ensure_fnum(None)
netx_graph = (model)
#netx_graph.graph.setdefault('graph', {})['size'] = '"10,5"'
#netx_graph.graph.setdefault('graph', {})['rankdir'] = 'LR'
pos_dict = get_hacked_pos(netx_graph)
#pos_dict = netx.pygraphviz_layout(netx_graph)
#pos = netx.pydot_layout(netx_graph, prog='dot')
#pos_dict = netx.graphviz_layout(netx_graph)
textprops = {
'family': 'monospace',
'horizontalalignment': 'left',
#'horizontalalignment': 'center',
#'size': 12,
'size': 8,
}
netx_nodes = model.nodes(data=True)
node_key_list = ut.get_list_column(netx_nodes, 0)
pos_list = ut.dict_take(pos_dict, node_key_list)
var2_post = {f.variables[0]: f for f in kwargs.get('factor_list', [])}
prior_text = None
post_text = None
evidence_tas = []
post_tas = []
prior_tas = []
node_color = []
has_infered = evidence or var2_post
if has_infered:
ignore_prior_with_ttype = ['score', 'match']
show_prior = False
else:
ignore_prior_with_ttype = []
#show_prior = True
show_prior = False
dpy = 5
dbx, dby = (20, 20)
takw1 = {'bbox_align': (.5, 0), 'pos_offset': [0, dpy], 'bbox_offset': [dbx, dby]}
takw2 = {'bbox_align': (.5, 1), 'pos_offset': [0, -dpy], 'bbox_offset': [-dbx, -dby]}
name_colors = pt.distinct_colors(max(model.num_names, 10))
name_colors = name_colors[:model.num_names]
#cmap_ = 'hot' #mx = 0.65 #mn = 0.15
cmap_, mn, mx = 'plasma', 0.15, 1.0
_cmap = pt.plt.get_cmap(cmap_)
def cmap(x):
return _cmap((x * mx) + mn)
for node, pos in zip(netx_nodes, pos_list):
variable = node[0]
cpd = model.var2_cpd[variable]
prior_marg = (cpd if cpd.evidence is None else
cpd.marginalize(cpd.evidence, inplace=False))
#.........这里部分代码省略.........
开发者ID:heroinlin,项目名称:ibeis,代码行数:101,代码来源:bayes.py
示例20: collapse_labels
def collapse_labels(model, evidence, reduced_variables, reduced_row_idxs,
reduced_values):
import vtool as vt
#assert np.all(reduced_joint.values.ravel() == reduced_joint.values.flatten())
reduced_ttypes = [model.var2_cpd[var].ttype for var in reduced_variables]
evidence_vars = list(evidence.keys())
evidence_state_idxs = ut.dict_take(evidence, evidence_vars)
evidence_ttypes = [model.var2_cpd[var].ttype for var in evidence_vars]
ttype2_ev_indices = dict(zip(*ut.group_indices(evidence_ttypes)))
ttype2_re_indices = dict(zip(*ut.group_indices(reduced_ttypes)))
# ttype2_ev_indices = ut.group_items(range(len(evidence_vars)), evidence_ttypes)
# ttype2_re_indices = ut.group_items(range(len(reduced_variables)), reduced_ttypes)
# Allow specific types of labels to change
# everything is the same, only the names have changed.
# TODO: allow for multiple different label_ttypes
# for label_ttype in label_ttypes
if 'name' not in model.ttype2_template:
return reduced_row_idxs, reduced_values
label_ttypes = ['name']
for label_ttype in label_ttypes:
ev_colxs = ttype2_ev_indices[label_ttype]
re_colxs = ttype2_re_indices[label_ttype]
ev_state_idxs = ut.take(evidence_state_idxs, ev_colxs)
ev_state_idxs_tile = np.tile(ev_state_idxs, (len(reduced_values), 1)).astype(np.int)
num_ev_ = len(ev_colxs)
aug_colxs = list(range(num_ev_)) + (np.array(re_colxs) + num_ev_).tolist()
aug_state_idxs = np.hstack([ev_state_idxs_tile, reduced_row_idxs])
# Relabel rows based on the knowledge that
# everything is the same, only the names have changed.
num_cols = len(aug_state_idxs.T)
mask = vt.index_to_boolmask(aug_colxs, num_cols)
other_colxs, = np.where(~mask)
relbl_states = aug_state_idxs.compress(mask, axis=1)
other_states = aug_state_idxs.compress(~mask, axis=1)
tmp_relbl_states = np.array(list(map(make_temp_state, relbl_states)))
max_tmp_state = -1
min_tmp_state = tmp_relbl_states.min()
# rebuild original state structure with temp state idxs
tmp_state_cols = [None] * num_cols
for count, colx in enumerate(aug_colxs):
tmp_state_cols[colx] = tmp_relbl_states[:, count:count + 1]
for count, colx in enumerate(other_colxs):
tmp_state_cols[colx] = other_states[:, count:count + 1]
tmp_state_idxs = np.hstack(tmp_state_cols)
data_ids = np.array(
vt.compute_unique_data_ids_(list(map(tuple, tmp_state_idxs))))
unique_ids, groupxs = vt.group_indices(data_ids)
print('Collapsed %r states into %r states' % (
len(data_ids), len(unique_ids),))
# Sum the values in the cpd to marginalize the duplicate probs
new_values = np.array([
g.sum() for g in vt.apply_grouping(reduced_values, groupxs)
])
# Take only the unique rows under this induced labeling
unique_tmp_groupxs = np.array(ut.get_list_column(groupxs, 0))
new_aug_state_idxs = tmp_state_idxs.take(unique_tmp_groupxs, axis=0)
tmp_idx_set = set((-np.arange(-max_tmp_state,
(-min_tmp_state) + 1)).tolist())
true_idx_set = set(range(len(model.ttype2_template[label_ttype].basis)))
# Relabel the rows one more time to agree with initial constraints
for colx, true_idx in enumerate(ev_state_idxs):
tmp_idx = np.unique(new_aug_state_idxs.T[colx])
assert len(tmp_idx) == 1
tmp_idx_set -= {tmp_idx[0]}
true_idx_set -= {true_idx}
new_aug_state_idxs[new_aug_state_idxs == tmp_idx] = true_idx
# Relabel the remaining idxs
remain_tmp_idxs = sorted(list(tmp_idx_set))[::-1]
remain_true_idxs = sorted(list(true_idx_set))
for tmp_idx, true_idx in zip(remain_tmp_idxs, remain_true_idxs):
new_aug_state_idxs[new_aug_state_idxs == tmp_idx] = true_idx
# Remove evidence based augmented labels
new_state_idxs = new_aug_state_idxs.T[num_ev_:].T
return new_state_idxs, new_values
开发者ID:heroinlin,项目名称:ibeis,代码行数:87,代码来源:bayes.py
注:本文中的utool.get_list_column函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论