本文整理汇总了Python中plot.Plot.save方法的典型用法代码示例。如果您正苦于以下问题:Python Plot.save方法的具体用法?Python Plot.save怎么用?Python Plot.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类plot.Plot
的用法示例。
在下文中一共展示了Plot.save方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run_bandit_experiment
# 需要导入模块: from plot import Plot [as 别名]
# 或者: from plot.Plot import save [as 别名]
def run_bandit_experiment(bandit, num_pulls, num_trials):
# specify bandit algorithms below
algorithm1 = IncrementalUniformAlgorithm(bandit)
algorithm2 = UCBAlgorithm(bandit)
algorithm3 = EpsilonGreedyAlgorithm(bandit)
algorithms = [algorithm1, algorithm2, algorithm3]
# keep track of data for plotting
plot_sample_rate = 1
plot = Plot(num_pulls, num_trials,
[a.get_name() for a in algorithms], plot_sample_rate)
# experiment loop
for a in algorithms:
print '\nRunning algorithm {0}...'.format(a.get_name())
plot.reset_trial()
best_arms = np.zeros(num_trials)
for t in range(num_trials):
print 'Running trial {0}...'.format(t)
start = time.time()
plot.begin_trial()
optimal_expected_reward = bandit.get_expected_reward_optimal_arm()
regret = Regret(optimal_expected_reward)
a.reset(bandit)
for i in range(num_pulls):
# pull arm according to algorithm
pulled_arm, _ = a.pull()
# update regrets
best_arm = a.get_best_arm()
expected_reward_pulled_arm = bandit.get_expected_reward_arm(pulled_arm)
expected_reward_best_arm = bandit.get_expected_reward_arm(best_arm)
regret.add(expected_reward_pulled_arm, expected_reward_best_arm)
# update plot
if i % plot_sample_rate == 0:
plot.add_point(i, regret.get_simple_regret(),
regret.get_cumulative_regret(), a.get_name())
end = time.time()
print '\telapsed: {0}'.format(end-start)
print '\tbest arm: {0}'.format(a.get_best_arm())
best_arms[t] = a.get_best_arm()
print "Best arm distribution: "
print np.histogram(best_arms, bins=range(21))
# create plot
plot.plot_simple_regret(bandit.get_name())
plot.plot_cumulative_regret(bandit.get_name())
# save
plot.save('{0}_data'.format(bandit.get_name()))
示例2: len
# 需要导入模块: from plot import Plot [as 别名]
# 或者: from plot.Plot import save [as 别名]
if len(sys.argv) < 5:
print "Usage: %s <edges.txt> <node-pos.txt> <w> <h>" % sys.argv[0]
sys.exit(1)
w = int(sys.argv[3])
h = int(sys.argv[4])
plot = Plot("/tmp/graph.png", w, h)
pos = {}
f = open(sys.argv[2])
for line in f:
(n, x, y) = line.strip().split(" ")
x = int(float(x))
y = int(float(y))
pos[n] = (x,y)
f = open(sys.argv[1])
for line in f:
(n1, n2) = line.strip().split(" ")
plot.draw_edge(pos[n1], pos[n2])
for n in pos:
plot.draw_node(pos[n])
plot.save()