def create_report_drone1_mass_cost(data): matplotlib_settings() cs = CommonStats(data) r = Report() figure_num_implementations2(r, data, cs, 'num_missions', 'endurance') figure_discrete_choices2(r, data, cs, 'num_missions', 'endurance') f = r.figure() with f.plot('total_cost', **fig) as pylab: ieee_spines_zoom3(pylab) x = cs.get_functionality('num_missions') y = cs.get_functionality('endurance') z = cs.get_min_resource('total_cost') plot_field(pylab, x, y, z, cmap=colormap) pylab.title('total_cost', color=color_resources, y=1.08) with f.plot('total_mass', **fig) as pylab: ieee_spines_zoom3(pylab) x = cs.get_functionality('num_missions') y = cs.get_functionality('endurance') z = cs.get_min_resource('total_mass') plot_field(pylab, x, y, z, cmap=colormap) pylab.title('total_mass', color=color_resources, y=1.08) return r
def create_report_min_mass(data): matplotlib_settings() cs = CommonStats(data) r = Report() figure_num_implementations2(r, data, cs, 'missions', 'capacity') figure_discrete_choices2(r, data, cs, 'missions', 'capacity') f = r.figure() with f.plot('mass', **fig) as pylab: ieee_spines_zoom3(pylab) x = cs.get_functionality('missions') y = cs.get_functionality('capacity') z = cs.get_min_resource('mass') plot_field(pylab, x, y, z, cmap=colormap) pylab.title('mass', color=color_resources, y=1.08) do_axes(pylab) return r
def go1(r, ns, dp, plot_nominal, axis): f = r.figure(cols=len(ns)) for n in ns: dpL, dpU = get_dp_bounds(dp, n, n) f0 = 1.0 R = dp.get_res_space() UR = UpperSets(R) space = PosetProduct((UR, UR)) urL = dpL.solve(f0) urU = dpU.solve(f0) value = urL, urU plotter = get_best_plotter(space) figsize = (4, 4) with f.plot('plot_n%d' % n, figsize=figsize) as pylab: ieee_spines_zoom3(pylab) plotter.plot(pylab, axis, space, value) plot_nominal(pylab) pylab.axis(axis)
def go1(r, ns, dp, plot_nominal, axis): f = r.figure(cols=len(ns)) for n in ns: dpL, dpU = get_dp_bounds(dp, n, n) f0 = 1.0 R = dp.get_res_space() UR = UpperSets(R) space = PosetProduct((UR, UR)) urL = dpL.solve(f0) urU = dpU.solve(f0) value = urL, urU plotter = get_best_plotter(space) figsize = (4, 4) with f.plot("plot_n%d" % n, figsize=figsize) as pylab: ieee_spines_zoom3(pylab) plotter.plot(pylab, axis, space, value) plot_nominal(pylab) pylab.axis(axis)
def report(data): print('report()') from matplotlib import pylab ieee_fonts_zoom3(pylab) r = Report() num = np.array(data['n']) print num print('reading iterations') num_iterations_L = [ get_num_iterations(res_i['traceL']) for res_i in data['results'] ] num_iterations_U = [ get_num_iterations(res_i['traceU']) for res_i in data['results'] ] def get_mass(res): if not res.minimals: return np.inf return list(res.minimals)[0] res_L = np.array([get_mass(res_i['resL']) for res_i in data['results']]) res_U = np.array([get_mass(res_i['resU']) for res_i in data['results']]) accuracy = np.array(res_U) - np.array(res_L) num_iterations = np.array(num_iterations_L) + np.array(num_iterations_U) print res_L print res_U print num_iterations_L print num_iterations_U print('Plotting') f = r.figure('fig1', cols=2) attrs = dict(clip_on=False) markers = dict(markeredgecolor='none', markerfacecolor='black', markersize=6, marker='o') LOWER = dict(color='orange', linewidth=4, linestyle='-', clip_on=False) UPPER = dict(color='purple', linewidth=4, linestyle='-', clip_on=False) LOWER.update(markers) UPPER.update(markers) color_resources = '#700000' # color_functions = '#007000' color_tolerance = '#000000' fig = dict(figsize=(4.5, 3.4)) with f.plot('fig_num_iterations', **fig) as pylab: ieee_spines_zoom3(pylab) pylab.plot(num, num_iterations_L, **LOWER) pylab.plot(num, num_iterations_U, **UPPER) pylab.ylabel('iterations') pylab.xlabel('n') if False: with f.plot('fig_num_iterations_log', **fig) as pylab: ieee_spines_zoom3(pylab) pylab.loglog(num, num_iterations_L, **LOWER) pylab.loglog(num, num_iterations_U, **UPPER) pylab.ylabel('iterations') pylab.xlabel('n') with f.plot('mass', **fig) as pylab: ieee_spines_zoom3(pylab) pylab.plot(num, res_L, **LOWER) pylab.plot(num, res_U, **UPPER) pylab.ylabel('total mass [g]') pylab.xlabel('n') set_axis_colors(pylab, color_tolerance, color_resources) with f.plot('mass2', **fig) as pylab: ieee_spines_zoom3(pylab) valid = np.isfinite(res_U) invalid = np.logical_not(valid) print valid res_L_valid = res_L[valid] res_U_valid = res_U[valid] num_valid = num[valid] mean = res_L_valid * 0.5 + res_U_valid * 0.5 err = (res_U_valid - res_L_valid) / 2 e = pylab.errorbar(num_valid, mean, yerr=err, color='black', linewidth=2, linestyle="None", **attrs) # plotline: Line2D instance # x, y plot markers and/or line # caplines: list of error bar cap# Line2D instances # barlinecols: list of LineCollection instances for the horizontal and vertical error ranges. e[0].set_clip_on(False) for b in e[1]: b.set_clip_on(False) for b in e[2]: b.set_clip_on(False) b.set_linewidth(2) num_invalid = num[invalid] res_L_invalid = res_L[invalid] max_y = pylab.axis()[3] for n, res_L in zip(num_invalid, res_L_invalid): pylab.plot([n, n], [max_y, res_L], '--', color='gray', **attrs) pylab.plot(num_invalid, res_L_invalid, 'ko', **attrs) pylab.xlabel('n') pylab.ylabel('total mass [g]') set_axis_colors(pylab, color_tolerance, color_resources) with f.plot('accuracy', **fig) as pylab: ieee_spines_zoom3(pylab) pylab.plot(num_iterations, accuracy, 'o', **attrs) pylab.xlabel('iterations') pylab.ylabel('solution uncertainty [g]') return r
def report_plane2(data): matplotlib_settings() cs = CommonStats(data) r = Report() what_to_plot_res = dict(total_mass="kg", total_cost="USD") what_to_plot_fun = dict(endurance="Wh", extra_payload="g") plot_all_directions(r, queries=data['queries'], results=data['results'], what_to_plot_res=what_to_plot_res, what_to_plot_fun=what_to_plot_fun) fig1 = dict(figsize=(3, 3)) fig2 = dict(figsize=(4, 4)) fnames = ('endurance', 'extra_payload') rnames = ('total_cost', 'total_mass') axis = (108, 145, 0.05, 0.8) axis2 = (105, 111.5, 0.05, 0.27) fs, rs = cs.iterate(fnames, rnames) colors = get_colors(len(fs)) f = r.figure() with f.plot('resources1', **fig1) as pylab: ieee_spines_zoom3(pylab) for i, ((f1, f2), resources) in enumerate(zip(fs, rs)): color = colors[i] if resources: marker = 'k.' else: marker = 'x' pylab.plot(f1, f2, marker, markerfacecolor=color, clip_on=False) pylab.xlabel('endurance [min]') pylab.ylabel('extra_payload [g]') # pylab.xticks([0, 30, 60, 90, 120]) set_axis_colors(pylab, color_functions, color_functions) params0 = dict(color_shadow=[1.0, 0.8, 0.8], markers='k.', markers_params={}) color_shadow = params0['color_shadow'] markers = params0['markers'] P = parse_poset('dimensionless x dimensionless') with f.plot('resources2', **fig2) as pylab: ieee_spines_zoom3(pylab) for i, resources in enumerate(rs): v = P.Us(resources) color = colors[i] plot_upset_R2(pylab, v, axis, extra_space_shadow=0, color_shadow=color, markers=markers, marker_params=dict(markerfacecolor=color)) pylab.ylabel('total mass [kg]') pylab.xlabel('total cost [USD]') pylab.xticks([110, 120, 130, 140, 150]) # pylab.yticks([0.2, 0.25, 0.3, 0.35]) set_axis_colors(pylab, color_resources, color_resources) pylab.axis(axis) rs_subset = rs[:3] with f.plot('resources3', **fig2) as pylab: ieee_spines_zoom3(pylab) for i, resources in enumerate(rs_subset): v = P.Us(resources) color = colors[i] plot_upset_R2(pylab, v, axis2, extra_space_shadow=0, color_shadow=color, markers=markers, marker_params=dict(markerfacecolor=color)) pylab.ylabel('total mass [kg]') pylab.xlabel('total cost [USD]') pylab.xticks([110, 110.5, 111,111.5,]) set_axis_colors(pylab, color_resources, color_resources) return r
def create_report1(data, model_name): all_min_throughput = [] all_resolution = [] all_num_solutions = [] all_min_budget = [] all_min_power = [] for query, query_results in zip(data['queries'], data['results']): resolution = query['resolution'] min_throughput = query['min_throughput'] num_solutions = len(query_results) if num_solutions == 0: min_power = np.nan min_budget = np.nan else: min_power = np.min([_['power'] for _ in query_results]) min_budget = np.min([_['budget'] for _ in query_results]) all_min_throughput.append(min_throughput) all_resolution.append(resolution) all_num_solutions.append(num_solutions) all_min_power.append(min_power) all_min_budget.append(min_budget) all_min_throughput = np.array(all_min_throughput) all_resolution = np.array(all_resolution) all_num_solutions = np.array(all_num_solutions) all_min_power = np.array(all_min_power) all_min_budget = np.array(all_min_budget) one_solution = all_num_solutions == 1 multiple_solutions = all_num_solutions > 1 is_not_feasible = all_num_solutions == 0 is_feasible = all_num_solutions > 0 from matplotlib import pylab ieee_fonts_zoom3(pylab) fig = dict(figsize=(4.5, 4)) popt = dict(clip_on=False) def do_axes(pylab): pylab.xlabel('resolution [pixels/deg]') pylab.ylabel('min_throughput [Hz]') set_axis_colors(pylab, color_functions, color_functions) r = Report(model_name) with r.plot('feasibility', **fig) as pylab: ieee_spines_zoom3(pylab) pylab.plot(all_resolution[one_solution], all_min_throughput[one_solution], 'k.', markersize=4, **popt) pylab.plot(all_resolution[multiple_solutions], all_min_throughput[multiple_solutions], 'ms', markersize=4, **popt) pylab.plot(all_resolution[is_not_feasible], all_min_throughput[is_not_feasible], 'r.', markersize=0.5, **popt) do_axes(pylab) with r.plot('power', **fig) as pylab: ieee_spines_zoom3(pylab) x = all_resolution y = all_min_throughput z = all_min_power plot_field(pylab, x, y, z, cmap='afmhot') pylab.title('power', color=color_resources) do_axes(pylab) with r.plot('budget', **fig) as pylab: ieee_spines_zoom3(pylab) x = all_resolution y = all_min_throughput z = all_min_budget plot_field(pylab, x, y, z, cmap='afmhot') pylab.title('budget', color=color_resources) do_axes(pylab) with r.plot('budget2', **fig) as pylab: ieee_spines_zoom3(pylab) unique_budgets = np.unique(all_min_budget[is_feasible]) markers = ['b.', 'g.', 'm.', 'y.'] for i, ub in enumerate(unique_budgets): which = all_min_budget == ub pylab.plot(all_resolution[which], all_min_throughput[which], markers[i], markersize=4, **popt) pylab.plot(all_resolution[is_not_feasible], all_min_throughput[is_not_feasible], 'r.', markersize=0.5, **popt) do_axes(pylab) r.text('about_budget', '%s = %s' % (unique_budgets, markers)) r.text( 'misc', 'min_power: %s W - %s W' % (np.min( all_min_power[is_feasible]), np.max(all_min_power[is_feasible]))) return r
def report(res): r = Report() dataL = res['dataL'] dataU = res['dataU'] what_to_plot_res = dict(total_cost="USD", total_mass='kg') what_to_plot_fun = dict(endurance="hour", extra_payload="g") queries = dataL['queries'] endurance = [q['endurance'] for q in queries] def get_value(data, field): for res in data['results']: a = to_numpy_array({field: 'kg'}, res) if len(a): a = min(a[field]) else: a = None yield a from matplotlib import pylab ieee_fonts_zoom3(pylab) markers = dict(markeredgecolor='none', markerfacecolor='black', markersize=6, marker='o') LOWER2 = dict(color='orange', linewidth=4, linestyle='-', clip_on=False) UPPER2 = dict(color='purple', linewidth=4, linestyle='-', clip_on=False) LOWER2.update(markers) UPPER2.update(markers) color_resources = '#700000' color_functions = '#007000' fig = dict(figsize=(4.5, 4)) with r.plot('total_mass', **fig) as pylab: ieee_spines_zoom3(pylab) total_massL = np.array(list(get_value(dataL, 'total_mass'))) total_massU = np.array(list(get_value(dataU, 'total_mass'))) print endurance print total_massL, total_massU pylab.plot(endurance, total_massL, **LOWER2) pylab.plot(endurance, total_massU, **UPPER2) set_axis_colors(pylab, color_functions, color_resources) pylab.xlabel('endurance [hours]') pylab.ylabel('total_mass [kg]') return r print('Plotting lower') with r.subsection('lower') as rL: plot_all_directions(rL, queries=dataL['queries'], results=dataL['results'], what_to_plot_res=what_to_plot_res, what_to_plot_fun=what_to_plot_fun) print('Plotting upper') with r.subsection('upper') as rU: plot_all_directions(rU, queries=dataU['queries'], results=dataU['results'], what_to_plot_res=what_to_plot_res, what_to_plot_fun=what_to_plot_fun) return r
def figure_num_implementations2(r, data, cs, fname1, fname2): assert isinstance(cs, CommonStats) f1 = cs.get_functionality(fname1) f2 = cs.get_functionality(fname2) def do_axes(pylab): pylab.xlabel(fname1) pylab.ylabel(fname2) set_axis_colors(pylab, color_functions, color_functions) with r.plot('feasibility', **fig) as pylab: ieee_spines_zoom3(pylab) pylab.plot(f1[cs.one_solution], f2[cs.one_solution], 'k.', markersize=4, **popt) pylab.plot(f1[cs.multiple_solutions], f2[cs.multiple_solutions], 'ms', markersize=4, **popt) pylab.plot(f1[cs.is_not_feasible], f2[cs.is_not_feasible], 'r.', markersize=0.5, **popt) do_axes(pylab) with r.plot('implementations', **fig) as pylab: ieee_spines_zoom3(pylab) pylab.plot(f1[cs.one_implementation], f2[cs.one_implementation], 'k.', markersize=4, **popt) pylab.plot(f1[cs.multiple_implementations], f2[cs.multiple_implementations], 'ms', markersize=4, **popt) pylab.plot(f1[cs.is_not_feasible], f2[cs.is_not_feasible], 'r.', markersize=0.5, **popt) do_axes(pylab) with r.plot('num_implementations', **fig) as pylab: ieee_spines_zoom3(pylab) x = f1 y = f2 z = cs.all_num_implementations plot_field(pylab, x, y, z, cmap='winter', vmin=0, vmax=5) pylab.title('num implementations', color=color_resources, y=1.08) do_axes(pylab) with r.plot('num_solutions', **fig) as pylab: ieee_spines_zoom3(pylab) x = f1 y = f2 z = cs.all_num_solutions plot_field(pylab, x, y, z, cmap='winter', vmin=0, vmax=5) pylab.title('num solutions', color=color_resources, y=1.08) do_axes(pylab) misc = 'num solutions: %s\n num implementations: %s' % (cs.all_num_solutions, cs.all_num_implementations) # r.text('misc', misc)
def figure_discrete_choices2(r, data, cs, fname1, fname2): num_solutions = cs.all_num_implementations all_discrete_choices = compute_discrete_choices(data) possible = ['', 'LCO', 'LFP', 'NiCad', 'NiMH', 'LiPo', 'LCO-LiPo-NiMH', 'LCO-LiPo-NiCad', 'LCO-LFP-LiPo-NiCad', 'LCO-LFP-LiPo', 'LCO-LFP-LiPo-NiMH', 'LCO-LiPo-NiCad-NiMH', 'LCO-LFP-LiPo-NiCad-NiMH', 'LCO-LiPo', 'LCO-LFP', 'LCO-LFP-NiMH', 'LCO-NiMH', 'LCO-NiCad', 'LCO-NiCad-NiMH', 'LCO-LFP-NiCad', 'LCO-LFP-NiCad-NiMH', 'LCO-NiCad-NiMH'] possible_this = sorted(np.unique(all_discrete_choices)) for p in possible_this: if not p in possible: msg = 'Did not anticipate %r as an option.' % p raise ValueError(msg) choice_as_int = np.zeros(dtype='int', shape=len(all_discrete_choices)) for i, x in enumerate(all_discrete_choices): choice_as_int[i] = possible.index(x) def do_axes(pylab): from mcdp_ipython_utils.plotting import set_axis_colors set_axis_colors(pylab, color_functions, color_functions) with r.plot('choice_as_int', **fig) as pylab: ieee_spines_zoom3(pylab) x = cs.get_functionality(fname1) y = cs.get_functionality(fname2) z = choice_as_int plot_field(pylab, x, y, z, cmap='viridis', vmin=0, vmax=len(possible)) pylab.title('choice_as_int', y=1.08) do_axes(pylab) possible_indiv = set() for p in possible: for x in p.split('-'): possible_indiv.add(x) f = r.figure() for p in sorted(possible_indiv): if not p: continue feasible = np.array([p in _ for _ in all_discrete_choices]) with f.plot('where_%s' % p, **fig) as pylab: ieee_spines_zoom3(pylab) x = cs.get_functionality(fname1) y = cs.get_functionality(fname2) AND = np.logical_and is_best = AND(feasible, num_solutions == 1) is_one_of_two = AND(feasible, num_solutions == 2) is_one_of_three = AND(feasible, num_solutions == 3) is_one_of_four_or_more = AND(feasible, num_solutions >= 4) grey = '#bbbbbb' color_infeasible = 'red' pylab.plot(x[cs.is_feasible], y[cs.is_feasible], '.', markersize=2, markerfacecolor=grey, markeredgecolor='none', color='none', clip_on=False) pylab.plot(x[cs.is_not_feasible], y[cs.is_not_feasible], '.', markersize=2, markerfacecolor=color_infeasible, markeredgecolor='none', color='none', clip_on=False) def plot(where, marker, color): markersize = 3.5 pylab.plot(x[where], y[where], marker, markersize=markersize, markeredgecolor='none', markerfacecolor=color, color='none', clip_on=False) plot(is_best, 'o', 'black') plot(is_one_of_two, 'd', '#000088') plot(is_one_of_three, '>','#880000') plot(is_one_of_four_or_more,'s', '#880088') pylab.title('%s' % p, y=1.08) do_axes(pylab) r.text('possible', possible) r.text('text_choice_as_int', choice_as_int) r.text('choices', all_discrete_choices)
def figure_num_implementations2(r, data, cs, fname1, fname2): assert isinstance(cs, CommonStats) f1 = cs.get_functionality(fname1) f2 = cs.get_functionality(fname2) def do_axes(pylab): pylab.xlabel(fname1) pylab.ylabel(fname2) set_axis_colors(pylab, color_functions, color_functions) with r.plot('feasibility', **fig) as pylab: ieee_spines_zoom3(pylab) pylab.plot(f1[cs.one_solution], f2[cs.one_solution], 'k.', markersize=4, **popt) pylab.plot(f1[cs.multiple_solutions], f2[cs.multiple_solutions], 'ms', markersize=4, **popt) pylab.plot(f1[cs.is_not_feasible], f2[cs.is_not_feasible], 'r.', markersize=0.5, **popt) do_axes(pylab) with r.plot('implementations', **fig) as pylab: ieee_spines_zoom3(pylab) pylab.plot(f1[cs.one_implementation], f2[cs.one_implementation], 'k.', markersize=4, **popt) pylab.plot(f1[cs.multiple_implementations], f2[cs.multiple_implementations], 'ms', markersize=4, **popt) pylab.plot(f1[cs.is_not_feasible], f2[cs.is_not_feasible], 'r.', markersize=0.5, **popt) do_axes(pylab) with r.plot('num_implementations', **fig) as pylab: ieee_spines_zoom3(pylab) x = f1 y = f2 z = cs.all_num_implementations plot_field(pylab, x, y, z, cmap='winter', vmin=0, vmax=5) pylab.title('num implementations', color=color_resources, y=1.08) do_axes(pylab) with r.plot('num_solutions', **fig) as pylab: ieee_spines_zoom3(pylab) x = f1 y = f2 z = cs.all_num_solutions plot_field(pylab, x, y, z, cmap='winter', vmin=0, vmax=5) pylab.title('num solutions', color=color_resources, y=1.08) do_axes(pylab) misc = 'num solutions: %s\n num implementations: %s' % ( cs.all_num_solutions, cs.all_num_implementations)
def report(data): from matplotlib import pylab ieee_fonts_zoom3(pylab) r = Report() print('reading iterations') num_iterations_L = [ get_num_iterations(res_i['traceL']) for res_i in data['results'] ] num_iterations_U = [ get_num_iterations(res_i['traceU']) for res_i in data['results'] ] def get_mass(res): if not res.minimals: return None return list(res.minimals)[0] res_L = np.array([get_mass(res_i['resL']) for res_i in data['results']]) res_U = np.array([get_mass(res_i['resU']) for res_i in data['results']]) accuracy = np.array(res_U) - np.array(res_L) num_iterations = np.array(num_iterations_L) + np.array(num_iterations_U) print res_L print res_U print num_iterations_L print num_iterations_U intervals = data['intervals'] print('Plotting') f = r.figure('fig1', cols=2) LOWER = 'bo-' UPPER = 'mo-' markers = dict(markeredgecolor='none', markerfacecolor='black', markersize=6, marker='o') LOWER2 = dict(color='orange', linewidth=4, linestyle='-', clip_on=False) UPPER2 = dict(color='purple', linewidth=4, linestyle='-', clip_on=False) LOWER2.update(markers) UPPER2.update(markers) color_resources = '#700000' # color_functions = '#007000' color_tolerance = '#000000' attrs = dict(clip_on=False) fig = dict(figsize=(4.5, 4)) fig_tall = dict(figsize=(3.5, 7)) label_tolerance = u'tolerance α [mW]' # label_tolerance = 'tolerance $\\alpha$ [mW]' with f.plot('fig_num_iterations', **fig) as pylab: ieee_spines_zoom3(pylab) pylab.plot(intervals, num_iterations_L, **LOWER2) pylab.plot(intervals, num_iterations_U, **UPPER2) pylab.xlabel(label_tolerance) pylab.ylabel('iterations') with f.plot('fig_num_iterations_log', **fig) as pylab: ieee_spines_zoom3(pylab) pylab.loglog(intervals, num_iterations_L, **LOWER2) pylab.loglog(intervals, num_iterations_U, **UPPER2) pylab.xlabel(label_tolerance) pylab.ylabel('iterations') with f.plot('mass', **fig_tall) as pylab: ieee_spines_zoom3(pylab) pylab.plot(intervals, res_L, LOWER, **attrs) pylab.plot(intervals, res_U, UPPER, **attrs) pylab.xlabel(label_tolerance) pylab.ylabel('total mass [g]') set_axis_colors(pylab, color_tolerance, color_resources) with f.plot('mass3', **fig_tall) as pylab: ieee_spines_zoom3(pylab) pylab.plot(intervals, res_L, **LOWER2) pylab.plot(intervals, res_U, **UPPER2) pylab.xlabel(label_tolerance) pylab.ylabel('total mass [g]') set_axis_colors(pylab, color_tolerance, color_resources) with f.plot('mass3log', **fig) as pylab: ieee_spines_zoom3(pylab) pylab.semilogx(intervals, res_L, **LOWER2) pylab.semilogx(intervals, res_U, **UPPER2) pylab.xlabel(label_tolerance) pylab.ylabel('total mass [g]') set_axis_colors(pylab, color_tolerance, color_resources) with f.plot('mass_log', **fig) as pylab: ieee_spines_zoom3(pylab) pylab.loglog(intervals, res_L, LOWER, **attrs) pylab.loglog(intervals, res_U, UPPER, **attrs) pylab.xlabel(label_tolerance) pylab.ylabel('total mass [g]') set_axis_colors(pylab, color_tolerance, color_resources) with f.plot('mass2', **fig) as pylab: ieee_spines_zoom3(pylab) mean = np.array(res_L) * 0.5 + np.array(res_U) * 0.5 err = (res_U - res_L) / 2 e = pylab.errorbar(intervals, mean, yerr=err, color='black', linewidth=2, linestyle="None", **attrs) # plotline: Line2D instance # x, y plot markers and/or line # caplines: list of error bar cap# Line2D instances # barlinecols: list of LineCollection instances for the horizontal and vertical error ranges. e[0].set_clip_on(False) for b in e[1]: b.set_clip_on(False) for b in e[2]: b.set_clip_on(False) b.set_linewidth(2) pylab.xlabel(label_tolerance) pylab.ylabel('total mass [g]') set_axis_colors(pylab, color_tolerance, color_resources) with f.plot('mass2_log', **fig) as pylab: ieee_spines_zoom3(pylab) pylab.loglog(intervals, res_L, LOWER, **attrs) pylab.loglog(intervals, res_U, UPPER, **attrs) pylab.xlabel(label_tolerance) pylab.ylabel('total mass [g]') set_axis_colors(pylab, color_tolerance, color_resources) with f.plot('accuracy', **fig) as pylab: ieee_spines_zoom3(pylab) pylab.plot(accuracy, num_iterations, 'o', **attrs) pylab.ylabel('iterations') pylab.xlabel('solution uncertainty [g]') with f.plot('accuracy_log', **fig) as pylab: ieee_spines_zoom3(pylab) pylab.loglog(accuracy, num_iterations, 'o', **attrs) pylab.ylabel('iterations') pylab.xlabel('solution uncertainty [g]') return r
def report(data): from matplotlib import pylab ieee_fonts_zoom3(pylab) r = Report() print('reading iterations') num_iterations_L = [get_num_iterations(res_i['traceL']) for res_i in data['results']] num_iterations_U = [get_num_iterations(res_i['traceU']) for res_i in data['results']] def get_mass(res): if not res.minimals: return None return list(res.minimals)[0] res_L = np.array([ get_mass(res_i['resL']) for res_i in data['results']]) res_U = np.array([ get_mass(res_i['resU']) for res_i in data['results']]) accuracy = np.array(res_U) - np.array(res_L) num_iterations = np.array(num_iterations_L) + np.array(num_iterations_U) print res_L print res_U print num_iterations_L print num_iterations_U intervals = data['intervals'] print('Plotting') f = r.figure('fig1', cols=2) LOWER = 'bo-' UPPER = 'mo-' markers = dict(markeredgecolor='none', markerfacecolor='black', markersize=6, marker='o') LOWER2 = dict(color='orange', linewidth=4, linestyle='-', clip_on=False) UPPER2 = dict(color='purple', linewidth=4, linestyle='-', clip_on=False) LOWER2.update(markers) UPPER2.update(markers) color_resources = '#700000' # color_functions = '#007000' color_tolerance = '#000000' attrs = dict(clip_on=False) fig = dict(figsize=(4.5, 4)) fig_tall = dict(figsize=(3.5 , 7)) label_tolerance = u'tolerance α [mW]' # label_tolerance = 'tolerance $\\alpha$ [mW]' with f.plot('fig_num_iterations', **fig) as pylab: ieee_spines_zoom3(pylab) pylab.plot(intervals, num_iterations_L, **LOWER2) pylab.plot(intervals, num_iterations_U, **UPPER2) pylab.xlabel(label_tolerance) pylab.ylabel('iterations') with f.plot('fig_num_iterations_log', **fig) as pylab: ieee_spines_zoom3(pylab) pylab.loglog(intervals, num_iterations_L, **LOWER2) pylab.loglog(intervals, num_iterations_U, **UPPER2) pylab.xlabel(label_tolerance) pylab.ylabel('iterations') with f.plot('mass', **fig_tall) as pylab: ieee_spines_zoom3(pylab) pylab.plot(intervals, res_L, LOWER, **attrs) pylab.plot(intervals, res_U, UPPER, **attrs) pylab.xlabel(label_tolerance) pylab.ylabel('total mass [g]') set_axis_colors(pylab, color_tolerance, color_resources) with f.plot('mass3', **fig_tall) as pylab: ieee_spines_zoom3(pylab) pylab.plot(intervals, res_L, **LOWER2) pylab.plot(intervals, res_U, **UPPER2) pylab.xlabel(label_tolerance) pylab.ylabel('total mass [g]') set_axis_colors(pylab, color_tolerance, color_resources) with f.plot('mass3log', **fig) as pylab: ieee_spines_zoom3(pylab) pylab.semilogx(intervals, res_L, **LOWER2) pylab.semilogx(intervals, res_U, **UPPER2) pylab.xlabel(label_tolerance) pylab.ylabel('total mass [g]') set_axis_colors(pylab, color_tolerance, color_resources) with f.plot('mass_log', **fig) as pylab: ieee_spines_zoom3(pylab) pylab.loglog(intervals, res_L, LOWER, **attrs) pylab.loglog(intervals, res_U, UPPER, **attrs) pylab.xlabel(label_tolerance) pylab.ylabel('total mass [g]') set_axis_colors(pylab, color_tolerance, color_resources) with f.plot('mass2', **fig) as pylab: ieee_spines_zoom3(pylab) mean = np.array(res_L) * 0.5 + np.array(res_U) * 0.5 err = (res_U - res_L) / 2 e = pylab.errorbar(intervals, mean, yerr=err, color='black', linewidth=2, linestyle="None", **attrs) # plotline: Line2D instance # x, y plot markers and/or line # caplines: list of error bar cap# Line2D instances # barlinecols: list of LineCollection instances for the horizontal and vertical error ranges. e[0].set_clip_on(False) for b in e[1]: b.set_clip_on(False) for b in e[2]: b.set_clip_on(False) b.set_linewidth(2) pylab.xlabel(label_tolerance) pylab.ylabel('total mass [g]') set_axis_colors(pylab, color_tolerance, color_resources) with f.plot('mass2_log', **fig) as pylab: ieee_spines_zoom3(pylab) pylab.loglog(intervals, res_L, LOWER, **attrs) pylab.loglog(intervals, res_U, UPPER, **attrs) pylab.xlabel(label_tolerance) pylab.ylabel('total mass [g]') set_axis_colors(pylab, color_tolerance, color_resources) with f.plot('accuracy', **fig) as pylab: ieee_spines_zoom3(pylab) pylab.plot(accuracy, num_iterations, 'o', **attrs) pylab.ylabel('iterations') pylab.xlabel('solution uncertainty [g]') with f.plot('accuracy_log', **fig) as pylab: ieee_spines_zoom3(pylab) pylab.loglog(accuracy, num_iterations, 'o', **attrs) pylab.ylabel('iterations') pylab.xlabel('solution uncertainty [g]') return r
def figure_discrete_choices2(r, data, cs, fname1, fname2): num_solutions = cs.all_num_implementations all_discrete_choices = compute_discrete_choices(data) possible = [ "", "LCO", "LFP", "NiCad", "NiMH", "LiPo", "LCO-LiPo-NiMH", "LCO-LiPo-NiCad", "LCO-LFP-LiPo-NiCad", "LCO-LFP-LiPo", "LCO-LFP-LiPo-NiMH", "LCO-LiPo-NiCad-NiMH", "LCO-LFP-LiPo-NiCad-NiMH", "LCO-LiPo", "LCO-LFP", "LCO-LFP-NiMH", "LCO-NiMH", "LCO-NiCad", "LCO-NiCad-NiMH", "LCO-LFP-NiCad", "LCO-LFP-NiCad-NiMH", "LCO-NiCad-NiMH", ] possible_this = sorted(np.unique(all_discrete_choices)) for p in possible_this: if not p in possible: msg = "Did not anticipate %r as an option." % p raise ValueError(msg) choice_as_int = np.zeros(dtype="int", shape=len(all_discrete_choices)) for i, x in enumerate(all_discrete_choices): choice_as_int[i] = possible.index(x) def do_axes(pylab): from mcdp_ipython_utils.plotting import set_axis_colors set_axis_colors(pylab, color_functions, color_functions) with r.plot("choice_as_int", **fig) as pylab: ieee_spines_zoom3(pylab) x = cs.get_functionality(fname1) y = cs.get_functionality(fname2) z = choice_as_int plot_field(pylab, x, y, z, cmap="viridis", vmin=0, vmax=len(possible)) pylab.title("choice_as_int", y=1.08) do_axes(pylab) possible_indiv = set() for p in possible: for x in p.split("-"): possible_indiv.add(x) f = r.figure() for p in sorted(possible_indiv): if not p: continue feasible = np.array([p in _ for _ in all_discrete_choices]) with f.plot("where_%s" % p, **fig) as pylab: ieee_spines_zoom3(pylab) x = cs.get_functionality(fname1) y = cs.get_functionality(fname2) AND = np.logical_and is_best = AND(feasible, num_solutions == 1) is_one_of_two = AND(feasible, num_solutions == 2) is_one_of_three = AND(feasible, num_solutions == 3) is_one_of_four_or_more = AND(feasible, num_solutions >= 4) grey = "#bbbbbb" color_infeasible = "red" pylab.plot( x[cs.is_feasible], y[cs.is_feasible], ".", markersize=2, markerfacecolor=grey, markeredgecolor="none", color="none", clip_on=False, ) pylab.plot( x[cs.is_not_feasible], y[cs.is_not_feasible], ".", markersize=2, markerfacecolor=color_infeasible, markeredgecolor="none", color="none", clip_on=False, ) def plot(where, marker, color): markersize = 3.5 pylab.plot( x[where], y[where], marker, markersize=markersize, markeredgecolor="none", markerfacecolor=color, color="none", clip_on=False, ) plot(is_best, "o", "black") plot(is_one_of_two, "d", "#000088") plot(is_one_of_three, ">", "#880000") plot(is_one_of_four_or_more, "s", "#880088") pylab.title("%s" % p, y=1.08) do_axes(pylab) r.text("possible", possible) r.text("text_choice_as_int", choice_as_int) r.text("choices", all_discrete_choices)
def report_plane2(data): matplotlib_settings() cs = CommonStats(data) r = Report() what_to_plot_res = dict(total_mass="kg", total_cost="USD") what_to_plot_fun = dict(endurance="Wh", extra_payload="g") plot_all_directions(r, queries=data['queries'], results=data['results'], what_to_plot_res=what_to_plot_res, what_to_plot_fun=what_to_plot_fun) fig1 = dict(figsize=(3, 3)) fig2 = dict(figsize=(4, 4)) fnames = ('endurance', 'extra_payload') rnames = ('total_cost', 'total_mass') axis = (108, 145, 0.05, 0.8) axis2 = (105, 111.5, 0.05, 0.27) fs, rs = cs.iterate(fnames, rnames) colors = get_colors(len(fs)) f = r.figure() with f.plot('resources1', **fig1) as pylab: ieee_spines_zoom3(pylab) for i, ((f1, f2), resources) in enumerate(zip(fs, rs)): color = colors[i] if resources: marker = 'k.' else: marker = 'x' pylab.plot(f1, f2, marker, markerfacecolor=color, clip_on=False) pylab.xlabel('endurance [min]') pylab.ylabel('extra_payload [g]') # pylab.xticks([0, 30, 60, 90, 120]) set_axis_colors(pylab, color_functions, color_functions) params0 = dict(color_shadow=[1.0, 0.8, 0.8], markers='k.', markers_params={}) color_shadow = params0['color_shadow'] markers = params0['markers'] P = parse_poset('dimensionless x dimensionless') with f.plot('resources2', **fig2) as pylab: ieee_spines_zoom3(pylab) for i, resources in enumerate(rs): v = P.Us(resources) color = colors[i] plot_upset_R2(pylab, v, axis, extra_space_shadow=0, color_shadow=color, markers=markers, marker_params=dict(markerfacecolor=color)) pylab.ylabel('total mass [kg]') pylab.xlabel('total cost [USD]') pylab.xticks([110, 120, 130, 140, 150]) # pylab.yticks([0.2, 0.25, 0.3, 0.35]) set_axis_colors(pylab, color_resources, color_resources) pylab.axis(axis) rs_subset = rs[:3] with f.plot('resources3', **fig2) as pylab: ieee_spines_zoom3(pylab) for i, resources in enumerate(rs_subset): v = P.Us(resources) color = colors[i] plot_upset_R2(pylab, v, axis2, extra_space_shadow=0, color_shadow=color, markers=markers, marker_params=dict(markerfacecolor=color)) pylab.ylabel('total mass [kg]') pylab.xlabel('total cost [USD]') pylab.xticks([ 110, 110.5, 111, 111.5, ]) set_axis_colors(pylab, color_resources, color_resources) return r