def plot_smoothed(size): trial = cd.shared.trial steps_per_cycle = trial['settings']['steps_per_cycle'] time = trial['times']['cycles'] couplings = trial['couplings']['lengths'] couplings = mstats.values.from_serialized(couplings) couplings = mstats.values.windowed_smooth(couplings, size, 256) values, uncertainties = mstats.values.unzip(couplings) plot = plotting.make_line_data( x=time, y=values, y_unc=uncertainties, color=plotting.get_color(0, 0.8), fill_color=plotting.get_color(0, 0.2) ) coverage = 100 * (2 * size + 1) / steps_per_cycle cd.display.plotly( data=plot['data'], layout=plotting.create_layout( title='Smoothed Coupling Lengths (Cycle Coverage {}%)'.format( coverage ), x_label='Cycle (#)', y_label='Coupling Length (m)' ) ) couplings = trial['couplings']['lengths'] couplings = mstats.values.from_serialized(couplings) couplings = mstats.values.box_smooth(couplings, 2 * size + 1, 256) values, uncertainties = mstats.values.unzip(couplings) plot = plotting.make_line_data( x=time, y=values, y_unc=uncertainties, color=plotting.get_color(1, 0.8), fill_color=plotting.get_color(1, 0.2) ) coverage = 100 * (2 * size + 1) / steps_per_cycle cd.display.plotly( data=plot['data'], layout=plotting.create_layout( title='Box Smoothed Coupling Lengths (Cycle Coverage {}%)'.format( coverage ), x_label='Cycle (#)', y_label='Coupling Length (m)' ) )
def plot_sizes_by_track(tracks_df, pes=True): prefix = 'pes' if pes else 'manus' limb_ids = ['lp', 'rp'] if pes else ['lm', 'rm'] length_measurements = cd.shared.to_measurements(tracks_df, limb_ids, 'l') length_dist = mstats.create_distribution( [x for x in length_measurements if x.value > 0]) pop = mstats.distributions.population(length_dist) length_median = mstats.ValueUncertainty( mstats.distributions.percentile(pop), mstats.distributions.weighted_median_average_deviation(pop)) width_measurements = cd.shared.to_measurements(tracks_df, limb_ids, 'w') width_dist = mstats.create_distribution( [x for x in width_measurements if x.value > 0]) pop = mstats.distributions.population(width_dist) width_median = mstats.ValueUncertainty( mstats.distributions.percentile(pop), mstats.distributions.weighted_median_average_deviation(pop)) label = prefix.capitalize() cd.display.plotly( [ cd.shared.create_density_trace(length_dist, 0, 'Length'), cd.shared.create_density_trace(width_dist, 1, 'Width'), ], plotting.create_layout( {}, title='{} Width & Length Distributions (by track)'.format(label), x_label='Size (m)', y_label='Probability Density')) print('Median {} Width: {}m'.format(label, width_median.label)) print('Median {} Length: {}m'.format(label, length_median.label))
def plot_pes_aspects_by_tracks(tracks_df): widths = cd.shared.to_measurements(tracks_df, ['lp', 'rp'], 'w') lengths = cd.shared.to_measurements(tracks_df, ['lp', 'rp'], 'l') measurements = [l / w for l, w in zip(lengths, widths)] dist = mstats.create_distribution( [x for x in measurements if x.value > 0] ) pop = mstats.distributions.population(dist) median = mstats.ValueUncertainty( mstats.distributions.percentile(pop), mstats.distributions.weighted_median_average_deviation(pop) ) cd.display.plotly( cd.shared.create_density_trace(dist), plotting.create_layout( {}, title='Pes Aspect Ratio Distribution (by track)', x_label='Aspect Ratio (width / length)', y_label='Probability Density' ) ) print('Median Pes Aspect Ratio:', median.label)
def plot_pes_aspects(trackway_df): measurements = mstats.values.join( trackway_df['pes_aspect'].tolist(), trackway_df['pes_daspect'].tolist() ) dist = mstats.create_distribution( [x for x in measurements if x.value > 0] ) pop = mstats.distributions.population(dist) median = mstats.ValueUncertainty( mstats.distributions.percentile(pop), mstats.distributions.weighted_median_average_deviation(pop) ) cd.display.plotly( cd.shared.create_density_trace(dist), plotting.create_layout( {}, title='Pes Aspect Ratio Distribution (by trackway)', x_label='Aspect Ratio (width / length)', y_label='Probability Density' ) ) print('Median Pes Aspect Ratio:', median.label)
def plot_smoothed(size): trial = cd.shared.trial steps_per_cycle = trial['settings']['steps_per_cycle'] time = trial['times']['cycles'] couplings = trial['couplings']['lengths'] couplings = mstats.values.from_serialized(couplings) couplings = mstats.values.windowed_smooth(couplings, size, 256) values, uncertainties = mstats.values.unzip(couplings) plot = plotting.make_line_data(x=time, y=values, y_unc=uncertainties, color=plotting.get_color(0, 0.8), fill_color=plotting.get_color(0, 0.2)) coverage = 100 * (2 * size + 1) / steps_per_cycle cd.display.plotly( data=plot['data'], layout=plotting.create_layout( title='Smoothed Coupling Lengths (Cycle Coverage {}%)'.format( coverage), x_label='Cycle (#)', y_label='Coupling Length (m)')) couplings = trial['couplings']['lengths'] couplings = mstats.values.from_serialized(couplings) couplings = mstats.values.box_smooth(couplings, 2 * size + 1, 256) values, uncertainties = mstats.values.unzip(couplings) plot = plotting.make_line_data(x=time, y=values, y_unc=uncertainties, color=plotting.get_color(1, 0.8), fill_color=plotting.get_color(1, 0.2)) coverage = 100 * (2 * size + 1) / steps_per_cycle cd.display.plotly( data=plot['data'], layout=plotting.create_layout( title='Box Smoothed Coupling Lengths (Cycle Coverage {}%)'.format( coverage), x_label='Cycle (#)', y_label='Coupling Length (m)'))
def plot(trial): plot_data = band.coupling(trial) cd.display.plotly(data=plot_data['data'], layout=plotting.create_layout( plot_data['layout'], title='{} Coupling Length'.format(trial['short_id']), x_label='Cycle (#)', y_label='Coupling Length (m)'))
def plot_couplings(df_row, trial): """ :param df_row: :param trial: :return: """ data = trial['couplings']['lengths'] median = mstats.ValueUncertainty(**trial['couplings']['value']) couplings = mstats.values.from_serialized( [v['value'] for v in data] ) min_value = mstats.values.minimum(couplings) max_value = mstats.values.maximum(couplings) y, unc = mstats.values.unzip(couplings) plot = plotting.make_line_data( x=[v['time'] for v in data], y=y, y_unc=unc, color=plotting.get_color(int(trial['id'][1]), 0.8), fill_color=plotting.get_color(int(trial['id'][1]), 0.3) ) cd.display.plotly( data=plot['data'], layout=plotting.create_layout( dict( showlegend=False ), title='{} Coupling Length'.format(trial['short_id']), x_label='Cycle (#)', y_label='Coupling Length (m)', y_bounds=[median.value - 0.5, median.value + 0.5] ) ) delta = abs(min_value - max_value) deviation = abs(min_value.value - max_value.value) / delta.uncertainty cd.display.markdown( """ Reference Statistics: * _Minimum:_ __{{ min }} m__ * _Median:_ __{{ median }} m__ * _Max:_ __{{ max }} m__ * _Deviations:_ __{{ deviation }}__ """, min=min_value.html_label, median=median.html_label, max=max_value.html_label, deviation=0.01 * round(100 * deviation) )
def plot(trial): plot_data = band.coupling(trial) cd.display.plotly( data=plot_data['data'], layout=plotting.create_layout( plot_data['layout'], title='{} Coupling Length'.format(trial['short_id']), x_label='Cycle (#)', y_label='Coupling Length (m)' ) )
def plot_couplings(*args, **kwargs): """ :param kwargs: :param args: :return: """ title = kwargs.get('title', 'Coupling Lengths') traces = [] for entry in args: trial = entry['trial'] times = entry.get('times', trial['times']['cycles']) lengths = entry.get('lengths', trial['couplings']['lengths']) index = entry['index'] if 'index' in entry else trial['group_index'] if 'color' in entry: color = entry['color'] elif index is None: color = plotting.get_gray_color(100, 0.8) else: color = plotting.get_color(index, 0.8) if 'fill_color' in entry: fill_color = entry['fill_color'] elif index is None: fill_color = plotting.get_gray_color(100, 0.1) else: fill_color = plotting.get_color(index, 0.1) plot = plotting.make_line_data( x=times, y=[v['value'] for v in lengths], y_unc=[v['uncertainty'] for v in lengths], color=color, fill_color=fill_color, name=entry.get('name', trial['id']) ) traces += plot['data'] layout = dict( showlegend = len(traces) > 0 ) cd.display.plotly( data=traces, layout=plotting.create_layout( layout, title=title, x_label='Cycle (#)', y_label='Coupling Length (m)' ) )
def plot_groupings(boarding_method, title): group_counts = [1, 2, 3, 4, 5, 6, 8, 10] elapsed = [] elapsed_uncertainties = [] for gc in group_counts: df_slice = df[ (df['boarding_method'] == boarding_method) & (df['group_count'] == gc) ] elapsed.append( np.median(df_slice['elapsed']) ) elapsed_uncertainties.append( np.median(np.abs( df_slice['elapsed'] - elapsed[-1] )) ) if boarding_method == 'r': c = 'rgba(150, 150, 150, 0.8)' fc = 'rgba(150, 150, 150, 0.2)' elif boarding_method == 'b': c = plotting.get_color(0, 0.8) fc = plotting.get_color(0, 0.2) else: c = plotting.get_color(1, 0.8) fc = plotting.get_color(1, 0.2) definition = dict( x=group_counts, y=elapsed, y_unc=elapsed_uncertainties, name=boarding_method.upper(), color=c, fill_color=fc ) plot = plotting.make_line_data(**definition) project.display.plotly( data=plot['data'], layout=plotting.create_layout( plot['layout'], title=title, x_label='Group Count (#)', y_label='Boarding Time (s)', ), scale=0.75 ) return plot['data']
def plot_couplings(*args, **kwargs): """ :param kwargs: :param args: :return: """ title = kwargs.get('title', 'Coupling Lengths') traces = [] for entry in args: trial = entry['trial'] times = entry.get('times', trial['times']['cycles']) lengths = entry.get('lengths', trial['couplings']['lengths']) index = entry['index'] if 'index' in entry else trial['group_index'] if 'color' in entry: color = entry['color'] elif index is None: color = plotting.get_gray_color(100, 0.8) else: color = plotting.get_color(index, 0.8) if 'fill_color' in entry: fill_color = entry['fill_color'] elif index is None: fill_color = plotting.get_gray_color(100, 0.1) else: fill_color = plotting.get_color(index, 0.1) plot = plotting.make_line_data( x=times, y=[v['value'] for v in lengths], y_unc=[v['uncertainty'] for v in lengths], color=color, fill_color=fill_color, name=entry.get('name', trial['id'])) traces += plot['data'] layout = dict(showlegend=len(traces) > 0) cd.display.plotly(data=traces, layout=plotting.create_layout( layout, title=title, x_label='Cycle (#)', y_label='Coupling Length (m)'))
def plot_couplings(df_row, trial): """ :param df_row: :param trial: :return: """ data = trial['couplings']['lengths'] median = mstats.ValueUncertainty(**trial['couplings']['value']) couplings = mstats.values.from_serialized([v['value'] for v in data]) min_value = mstats.values.minimum(couplings) max_value = mstats.values.maximum(couplings) y, unc = mstats.values.unzip(couplings) plot = plotting.make_line_data( x=[v['time'] for v in data], y=y, y_unc=unc, color=plotting.get_color(int(trial['id'][1]), 0.8), fill_color=plotting.get_color(int(trial['id'][1]), 0.3)) cd.display.plotly(data=plot['data'], layout=plotting.create_layout( dict(showlegend=False), title='{} Coupling Length'.format(trial['short_id']), x_label='Cycle (#)', y_label='Coupling Length (m)', y_bounds=[median.value - 0.5, median.value + 0.5])) delta = abs(min_value - max_value) deviation = abs(min_value.value - max_value.value) / delta.uncertainty cd.display.markdown(""" Reference Statistics: * _Minimum:_ __{{ min }} m__ * _Median:_ __{{ median }} m__ * _Max:_ __{{ max }} m__ * _Deviations:_ __{{ deviation }}__ """, min=min_value.html_label, median=median.html_label, max=max_value.html_label, deviation=0.01 * round(100 * deviation))
def test_create_layout(self): """Should create layout using supplied arguments""" title = 'Some Title' x_label = 'X Label' y_label = 'Y Label' x_bounds = [3, 97] y_bounds = [-32, 48] layout = plotting.create_layout(layout={}, title=title, x_label=x_label, y_label=y_label, x_bounds=x_bounds, y_bounds=y_bounds) self.assertIsInstance(layout, dict) self.assertIn('title', layout)
def plot_sizes(trackway_df, pes=True): prefix = 'pes' if pes else 'manus' length_measurements = mstats.values.join( trackway_df['{}_l'.format(prefix)].tolist(), trackway_df['{}_dl'.format(prefix)].tolist() ) length_dist = mstats.create_distribution( [x for x in length_measurements if x.value > 0] ) pop = mstats.distributions.population(length_dist) length_median = mstats.ValueUncertainty( mstats.distributions.percentile(pop), mstats.distributions.weighted_median_average_deviation(pop) ) width_measurements = mstats.values.join( trackway_df['{}_w'.format(prefix)].tolist(), trackway_df['{}_dw'.format(prefix)].tolist() ) width_dist = mstats.create_distribution( [x for x in width_measurements if x.value > 0] ) pop = mstats.distributions.population(width_dist) width_median = mstats.ValueUncertainty( mstats.distributions.percentile(pop), mstats.distributions.weighted_median_average_deviation(pop) ) label = prefix.capitalize() cd.display.plotly( [ cd.shared.create_density_trace(length_dist, 0, 'Length'), cd.shared.create_density_trace(width_dist, 1, 'Width'), ], plotting.create_layout( {}, title='{} Width & Length Distributions (by trackway)'.format(label), x_label='Size (m)', y_label='Probability Density' ) ) print('Median {} Width: {}m'.format(label, width_median.label)) print('Median {} Length: {}m'.format(label, length_median.label))
def test_create_layout(self): """Should create layout using supplied arguments""" title = 'Some Title' x_label = 'X Label' y_label = 'Y Label' x_bounds = [3, 97] y_bounds = [-32, 48] layout = plotting.create_layout( layout={}, title=title, x_label=x_label, y_label=y_label, x_bounds=x_bounds, y_bounds=y_bounds ) self.assertIsInstance(layout, dict) self.assertIn('title', layout)
def plot_pes_aspects(trackway_df): measurements = mstats.values.join(trackway_df['pes_aspect'].tolist(), trackway_df['pes_daspect'].tolist()) dist = mstats.create_distribution([x for x in measurements if x.value > 0]) pop = mstats.distributions.population(dist) median = mstats.ValueUncertainty( mstats.distributions.percentile(pop), mstats.distributions.weighted_median_average_deviation(pop)) cd.display.plotly( cd.shared.create_density_trace(dist), plotting.create_layout( {}, title='Pes Aspect Ratio Distribution (by trackway)', x_label='Aspect Ratio (width / length)', y_label='Probability Density')) print('Median Pes Aspect Ratio:', median.label)
def plot_comparison(data_frame, title, comparison_column, comparison_label): data_frame = data_frame.sort_values(by='trial_label') traces = [] for method in data_frame['boarding_method'].unique(): df_method = data_frame[data_frame['boarding_method'] == method] delays = [] times = [] for delay in sorted(df_method[comparison_column].unique()): x = df_method[df_method[comparison_column] == delay] times.append(np.median(x['elapsed'])) delays.append(delay) if method == 'r': c = 'rgba(204, 204, 204, 0.8)' elif method == 'b': c = plotting.get_color(0, 0.8) else: c = plotting.get_color(1, 0.8) traces.append(go.Scatter( x=times, y=delays, name=method, mode='lines+markers', marker=dict( color=c ) )) project.display.plotly( data=traces, layout=plotting.create_layout( title=title, x_label='Boarding Time (s)', y_label=comparison_label ), scale=0.75 )
def plot_sizes_by_track(tracks_df, pes=True): prefix = 'pes' if pes else 'manus' limb_ids = ['lp', 'rp'] if pes else ['lm', 'rm'] length_measurements = cd.shared.to_measurements(tracks_df, limb_ids, 'l') length_dist = mstats.create_distribution( [x for x in length_measurements if x.value > 0] ) pop = mstats.distributions.population(length_dist) length_median = mstats.ValueUncertainty( mstats.distributions.percentile(pop), mstats.distributions.weighted_median_average_deviation(pop) ) width_measurements = cd.shared.to_measurements(tracks_df, limb_ids, 'w') width_dist = mstats.create_distribution( [x for x in width_measurements if x.value > 0] ) pop = mstats.distributions.population(width_dist) width_median = mstats.ValueUncertainty( mstats.distributions.percentile(pop), mstats.distributions.weighted_median_average_deviation(pop) ) label = prefix.capitalize() cd.display.plotly( [ cd.shared.create_density_trace(length_dist, 0, 'Length'), cd.shared.create_density_trace(width_dist, 1, 'Width'), ], plotting.create_layout( {}, title='{} Width & Length Distributions (by track)'.format(label), x_label='Size (m)', y_label='Probability Density' ) ) print('Median {} Width: {}m'.format(label, width_median.label)) print('Median {} Length: {}m'.format(label, length_median.label))
def plot_pes_aspects_by_tracks(tracks_df): widths = cd.shared.to_measurements(tracks_df, ['lp', 'rp'], 'w') lengths = cd.shared.to_measurements(tracks_df, ['lp', 'rp'], 'l') measurements = [l / w for l, w in zip(lengths, widths)] dist = mstats.create_distribution([x for x in measurements if x.value > 0]) pop = mstats.distributions.population(dist) median = mstats.ValueUncertainty( mstats.distributions.percentile(pop), mstats.distributions.weighted_median_average_deviation(pop)) cd.display.plotly( cd.shared.create_density_trace(dist), plotting.create_layout( {}, title='Pes Aspect Ratio Distribution (by track)', x_label='Aspect Ratio (width / length)', y_label='Probability Density')) print('Median Pes Aspect Ratio:', median.label)
def test_create_layout(self): """ :return: """ title = 'Some Title' x_label = 'X Label' y_label = 'Y Label' x_bounds = [3, 97] y_bounds = [-32, 48] layout = plotting.create_layout(layout={}, title=title, x_label=x_label, y_label=y_label, x_bounds=x_bounds, y_bounds=y_bounds) self.assertIsInstance(layout, dict) self.assertIn('title', layout)
def plot_collection( data_frame, title, color_column='boarding_method', color_values=None ): data_frame = data_frame.sort_values(by='trial_label') times = data_frame['elapsed'] labels = data_frame['trial_label'] colors = [] if color_values is None: color_values = dict( r='rgba(204, 204, 204, 0.8)', b=plotting.get_color(0, 0.8), default=plotting.get_color(1, 0.8) ) for index, row in data_frame.iterrows(): method = row[color_column] colors.append( color_values.get(method, color_values.get('default')) ) project.display.plotly( data=go.Bar( y=times, x=labels, marker=dict(color=colors), ), layout=plotting.create_layout( title=title, y_label='Boarding Time (s)', x_label='Trial', y_bounds=[times.min() - 10, times.max() + 10] ), scale=0.75 )
def plot_sizes(trackway_df, pes=True): prefix = 'pes' if pes else 'manus' length_measurements = mstats.values.join( trackway_df['{}_l'.format(prefix)].tolist(), trackway_df['{}_dl'.format(prefix)].tolist()) length_dist = mstats.create_distribution( [x for x in length_measurements if x.value > 0]) pop = mstats.distributions.population(length_dist) length_median = mstats.ValueUncertainty( mstats.distributions.percentile(pop), mstats.distributions.weighted_median_average_deviation(pop)) width_measurements = mstats.values.join( trackway_df['{}_w'.format(prefix)].tolist(), trackway_df['{}_dw'.format(prefix)].tolist()) width_dist = mstats.create_distribution( [x for x in width_measurements if x.value > 0]) pop = mstats.distributions.population(width_dist) width_median = mstats.ValueUncertainty( mstats.distributions.percentile(pop), mstats.distributions.weighted_median_average_deviation(pop)) label = prefix.capitalize() cd.display.plotly( [ cd.shared.create_density_trace(length_dist, 0, 'Length'), cd.shared.create_density_trace(width_dist, 1, 'Width'), ], plotting.create_layout( {}, title='{} Width & Length Distributions (by trackway)'.format( label), x_label='Size (m)', y_label='Probability Density')) print('Median {} Width: {}m'.format(label, width_median.label)) print('Median {} Length: {}m'.format(label, length_median.label))
df = cd.shared.df # type: pd.DataFrame cd.display.header('Solution Fitness') traces = [] for gait_id in df.gait_id.unique(): df_slice = df[df.gait_id == gait_id] traces.append( go.Scatter(x=df_slice['persistence'], y=df_slice['swing'], mode='markers', marker={ 'size': 8, 'color': df_slice.iloc[0].color }, name=gait_id, text=df_slice.short_id)) cd.display.plotly(data=traces, layout=plotting.create_layout({'hovermode': 'closest'}, title='Fitness Parameters', x_label='PRSS Fitness', y_label='Swing Fitness')) df['fitness'] = coupling.compute_fitness_rankings(df) cd.display.plotly(stem.create(df, df['fitness']), layout=plotting.create_layout(title='Solution Fitness', x_label='Coupling Length (m)', y_label='Fitness'))
fitness=np.median(df_sub.fitness), coupling_length=np.median(df_sub.coupling_length), color=df_sub.iloc[0].color )) df = pd.DataFrame(entries).sort_values(by='coupling_length') cd.display.plotly( data=go.Bar( y=df.fitness, text=df.label, marker=dict( color=df.color ) ), layout=plotting.create_layout( title='Solution Fitness', x_label='Trial Index (#)', y_label='Fitness (%)' ) ) cd.display.plotly( data=traces, layout=plotting.create_layout( title='Solution Fitness', x_label='Trial Index (#)', y_label='Fitness (%)' ) )
We now return to the median deviations parameter discussed earlier. In the previous formulation, the median deviations was used to find statistically significant deviations... $$$ $$$ """) cd.display.plotly( data=go.Bar(y=[max(cd.shared.scaled_deviations[tid]) for tid in df.id], text=df.short_id, marker=dict(color=df.color)), layout=plotting.create_layout(title='Fractional Median Deviations', x_label='Trial Index (#)', y_label='Fractional Deviation')) def compute_deviations_per_cycle(): """ :return: """ out = [sum(cd.shared.deviations[tid]) for tid in df.id] for index, tid in enumerate(df.id): for trial in cd.shared.trials: if trial['id'] == tid: break start_time = trial['couplings']['lengths'][0]['time']
traces = [] for pi in df['print_interval'].unique(): sub_df = df[df.print_interval == pi] traces.append(go.Bar( x=sub_df.ordered_index, y=sub_df['deviation'], text=sub_df['uid'], name='Print Interval {}'.format(pi) )) cd.display.plotly( data=traces, layout=plotting.create_layout( title='Median Coupling Length Swing (Min, Max)', x_label='Trial Index (#)', y_label='Median Swing (%)' ) ) df = cd.shared.couplings_df df['deviation'] = 100.0 * df['smooth_swing'] / df['raw_median'] df = df[ (df.duty_cycle < 0.75) & (df.gait_number == 1) ] df = df.sort_values(by='gait_id') df['ordered_index'] = list(range(df.shape[0])) traces = []
def plot_deviations( df_row, trial, deviations, threshold: float = 1e6, title: str = None, y_label: str = None ): """ :param df_row: :param trial: :param deviations: :param threshold: :param title: :param y_label: :return: """ data = trial['couplings']['lengths'] times = [v['time'] for v in data] segments = [] for time, dev in zip(times, deviations): current = segments[-1] if segments else None significant = bool(dev > threshold) if not current or current['significant'] != significant: segments.append(dict( significant=significant, times=[time], devs=[dev] )) if not current or not current['times']: continue if significant: segments[-1]['times'].insert(0, current['times'][-1]) segments[-1]['devs'].insert(0, current['devs'][-1]) else: current['times'].append(time) current['devs'].append(dev) continue current['times'].append(time) current['devs'].append(dev) segments.sort(key=lambda x: 1 if x['significant'] else 0) traces = [] for segment in segments: sig = segment['significant'] traces.append(go.Scatter( x=segment['times'], y=segment['devs'], mode='lines+markers', line=dict( color='#CC3333' if sig else '#333' ), marker=dict( color='#CC3333' if sig else '#333' ), fill='tozeroy' )) cd.display.plotly( data=traces, layout=plotting.create_layout( dict( showlegend=False ), title='{} {}'.format( trial['short_id'], title if title else 'Deviations' ), x_label='Cycle (#)', y_label=y_label if y_label else 'Deviations' ) )
import cauldron as cd import plotly.graph_objs as go from cauldron import plotting import measurement_stats as mstats df = cd.shared.couplings_df variations = df['raw_mad'] / df['raw_median'] cd.display.plotly( data=go.Histogram( x=variations ), layout=plotting.create_layout( title='Coupling Length Fractional Deviations', x_label='Fractional Deviation', y_label='Frequency (#)' ) ) dist = mstats.create_distribution( measurements=variations.tolist(), uncertainties=0.01 ) x = mstats.distributions.uniform_range(dist, 3) y = dist.probabilities_at(x) cd.display.plotly( data=go.Scatter(
""") df = cd.shared.df data = prss.compute_many(cd.shared.trials) fitness = prss.to_fitness(data['prss_norm']) df['persistence'] = [fitness[tid] for tid in df.id] cd.display.plotly( data=scatter.create( data_frame=df, value_column=[data['prss'][tid].value for tid in df.id], uncertainty_column=[data['prss'][tid].uncertainty for tid in df.id], x_column='order'), layout=plotting.create_layout( {'hovermode': 'closest'}, title='Coupling Length Persistent Residual Sum of Squares', x_label='Trial Index (#)', y_label='Persistent RSS')) cd.display.plotly( data=scatter.create(df, [data['prss_norm'][tid].value for tid in df.id], [data['prss_norm'][tid].uncertainty for tid in df.id], x_column='order'), layout=plotting.create_layout( {'hovermode': 'closest'}, title='Normalized Coupling Length Persistent Residual Sum of Squares', x_label='Trial Index (#)', y_label='Persistent RSS')) cd.display.plotly(data=go.Bar(y=df.persistence, text=df.short_id,
def test_create_layout_defaults(self): """Should create a layout dictionary using default values.""" layout = plotting.create_layout() self.assertIsInstance(layout, dict) self.assertIsNone(layout['title'])
import cauldron as cd import plotly.graph_objs as go from cauldron import plotting import measurement_stats as mstats df = cd.shared.couplings_df variations = df['raw_mad'] / df['raw_median'] cd.display.plotly(data=go.Histogram(x=variations), layout=plotting.create_layout( title='Coupling Length Fractional Deviations', x_label='Fractional Deviation', y_label='Frequency (#)')) dist = mstats.create_distribution(measurements=variations.tolist(), uncertainties=0.01) x = mstats.distributions.uniform_range(dist, 3) y = dist.probabilities_at(x) cd.display.plotly(data=go.Scatter(x=x, y=y, mode='lines', fill='tozeroy'), layout=plotting.create_layout(title='Coupling Length KDE', x_label='Coupling Lengths (m)', y_label='Expectation Value'))
), go.Scatter( x=df['Year'], y=smooth_data(percentages, 1), mode='lines+markers', name='Smoothed 1' ), go.Scatter( x=df['Year'], y=smooth_data(percentages, 2), mode='lines+markers', name='Smoothed 2' ), go.Scatter( x=df['Year'], y=smooth_data(percentages, 4), mode='lines+markers', name='Smoothed 4' ) ], layout=plotting.create_layout( title='Female Time Covers', y_label='Percentage each Year (%)', x_label='Year' ) ) cd.shared.put( smooth_data=smooth_data )
name=key.split('-')[0], marker=dict( color=plotting.get_color(len(traces), 0.5) ) )) d = mstats.create_distribution(normalized_values) mad = mstats.distributions.weighted_median_average_deviation(d, count=2048) result = mstats.ValueUncertainty(0, mad) project.display.text( """ Finally, the overall width and height measurements were analyzed in the same fashion as the above results. The result is that they exhibit the same low and reasonable ±3% variance as the digit length measurements. """ ) project.display.plotly( data=traces, layout=plotting.create_layout( title='Size Measurements Deviations ({}%)'.format( result.html_label.split(' ', 1)[-1] ), x_label='Drawing Index (#)', y_label='Fractional Value (%)' ) ) project.shared.normalized_values += normalized_values
import measurement_stats as mstats from cauldron import project from cauldron import plotting import plotly.graph_objs as go d = mstats.create_distribution(project.shared.normalized_values) x_values = mstats.distributions.adaptive_range(d, 3.0, max_delta=0.1) y_values = d.probabilities_at(x_values) data = go.Scatter(x=x_values, y=y_values, fill='tozeroy') layout = plotting.create_layout( title='Combined Measurement Deviations Cumulative Distribution', x_label='Median Deviation (%)', y_label='Expectation Value (au)') project.display.markdown(""" Cumulative Distribution ----------------------- In this final plot, the median-deviation values for every previous measurement were combined into a single weighted distribution and plotted to inspect the structure of the variance. An important conclusion to take away from this distribution is that the small humps, particularly in the lower half of the graph, are the result of singular or small numbers of measurements. This indicates that the measurement distribution is not robustly sampled and that more samples should be added for additional statistical validation of the result. """)
""" ) cd.display.plotly( data=go.Scatter( x=trackways_df['length_spread'], y=trackways_df['width_spread'], mode='markers', marker=dict( color=plotting.get_color(2) ), text=trackways_df['trackway'] ), layout=plotting.create_layout( {'hovermode': 'closest'}, title='Width versus Length Spreads Per Trackway', x_label='Length Spreads (%)', y_label='Width Spreads (%)' ) ) cd.display.markdown( """ Looking at maximum spreads, we get a median value of {{ median }}%, which is larger than either the length or the width values. This fact, combined by the lack of strong correlation, means that we should not be classifying trackways by their length or width spreads, but by whichever one of the two has the maximum spread value. The distribution of maximum spreads looks like: """,
from cauldron import plotting df = project.shared.progress data = go.Scatter( x=df.index / 60.0, y=100.0 * df['progress'], mode='lines', fill='tozeroy' ) project.display.plotly( data=data, layout=plotting.create_layout( title='Seating Progress', x_label='Boarding Time (minutes)', y_label='Completion (%)' ) ) rate = [] for index in range(1, df.shape[0] - 1): before = df.iloc[index - 1]['progress'] after = df.iloc[index + 1]['progress'] rate.append(100.0 * (after - before) / 2.0) # Add values at beginning and end to maintain shape rate.append(rate[-1]) rate.insert(0, rate[0])
pes_length = cd.shared.calculate_median( np.concatenate((df['lp_l'].values, df['rp_l'].values)), np.concatenate((df['lp_dl'].values, df['rp_dl'].values)), color_index=1, plot_name='Length' ) cd.display.plotly( data=[ pes_width['trace'], pes_length['trace'] ], layout=plotting.create_layout( title='Pes Width: {} m & Length: {} m'.format( pes_width['median'].html_label, pes_length['median'].html_label ), x_label='Size (m)', y_label='Probability Density (AU)' ) ) manus_width = cd.shared.calculate_median( np.concatenate((df['lm_w'].values, df['rm_w'].values)), np.concatenate((df['lm_dw'].values, df['rm_dw'].values)), color_index=2, plot_name='Width' ) manus_length = cd.shared.calculate_median( np.concatenate((df['lm_l'].values, df['rm_l'].values)), np.concatenate((df['lm_dl'].values, df['rm_dl'].values)),
traces = [] for entry in df[color_name].unique(): sub_df = df[df[color_name] == entry] traces.append( go.Scatter(x=sub_df[x_name], y=sub_df[y_name], text=sub_df.uid, mode='markers', marker={ 'size': 10, 'color': plotting.get_color(len(traces), 0.75) }, name='{} == {}'.format(color_name, entry))) cd.display.plotly(data=traces, layout=layout) comparison_plot(x_name='raw_median', y_name='raw_mad', color_name='print_interval', layout=plotting.create_layout(title='Median vs MAD', x_label='Median (m)', y_label='MAD (m)')) comparison_plot(x_name='raw_median', y_name='raw_swing', color_name='print_interval', layout=plotting.create_layout(title='Median vs Swing', x_label='Median (m)', y_label='Swing (%)'))
cd.display.header('Deviation Comparisons') cd.display.markdown(""" We compute these median deviations for each trial and plot the maximum deviation of each trial for comparison. The trials remain ordered from shortest to longest median coupling lengths. """) df = cd.shared.df # type: pd.DataFrame df['deviation'] = [max(cd.shared.deviations[tid]) for tid in df.id] cd.display.plotly(data=go.Bar(y=df.deviation, text=df.short_id, marker=dict(color=df.color)), layout=plotting.create_layout( title='Fractional Median Deviations', x_label='Trial Index (#)', y_label='Fractional Deviation')) cd.display.markdown(""" A number of tested gaits have significant deviations from the median value. This implies either that the trackmaker's coupling length changed due to flexing, or that the trackmaker switched between gaits during transit. Either is possible, but we will limit ourselves to searching for single-gait solutions. Every trial with a maximum deviation greater than 2 is a candidate for removal from our solution space if it requires flexing beyond the estimated limits of the trackmaker. """)
marker={ 'size': 10, 'color': plotting.get_color(len(traces), 0.75) }, name='{} == {}'.format(color_name, entry) )) cd.display.plotly(data=traces, layout=layout) comparison_plot( x_name='raw_median', y_name='raw_mad', color_name='print_interval', layout=plotting.create_layout( title='Median vs MAD', x_label='Median (m)', y_label='MAD (m)' ) ) comparison_plot( x_name='raw_median', y_name='raw_swing', color_name='print_interval', layout=plotting.create_layout( title='Median vs Swing', x_label='Median (m)', y_label='Swing (%)' ) )
project.display.plotly( data=plot['data'], layout=plotting.create_layout( plot['layout'], title=title, x_label='Group Count (#)', y_label='Boarding Time (s)', ), scale=0.75 ) return plot['data'] traces = ( plot_groupings('b', 'Backward Boarding in Row Groups') + plot_groupings('f', 'Forward Boarding in Row Groups') + plot_groupings('r', 'Random Boarding in Row Groups') ) project.display.plotly( data=traces, layout=plotting.create_layout( title='Comparison Boarding in Row Groups', x_label='Group Count (#)', y_label='Boarding Time (s)', ), scale=0.75 )
), go.Scatter( x=df['Year'], y=smooth_data(percentages, 1), mode='lines+markers', name='Smoothed 1' ), go.Scatter( x=df['Year'], y=smooth_data(percentages, 2), mode='lines+markers', name='Smoothed 2' ), go.Scatter( x=df['Year'], y=smooth_data(percentages, 4), mode='lines+markers', name='Smoothed 4' ) ], layout=plotting.create_layout( title='Female Time Covers', y_label='Percentage each Year (%)', x_label='Year' ) ) cd.shared.put( smooth_data=smooth_data )
import cauldron as cd import plotly.graph_objs as go from cauldron import plotting from tracksim.coupling import swing from tracksim.coupling.plotting import scatter cd.refresh(swing) df = cd.shared.df swing_data = swing.compute_many(cd.shared.trials) fitness = swing.to_fitness(swing_data) df['swing'] = [fitness[tid] for tid in df.id] cd.display.plotly( data=scatter.create(df, [swing_data[tid].value for tid in df.id], [swing_data[tid].uncertainty for tid in df.id], x_column='order'), layout=plotting.create_layout(title='Normalized Swing by Trial', x_label='Trial Index (#)', y_label='Swing')) cd.display.plotly(data=go.Bar(y=df.swing, text=df.short_id, marker=dict(color=df.color)), layout=plotting.create_layout( title='Swing Deviation', x_label='Trial Index (#)', y_label='Fractional Deviation'))
gaussian_trace = go.Scatter( x=dist_data['gauss']['x'], y=dist_data['gauss']['y'], mode='lines', name='Region Fit', line=go.Line( color='rgba(0, 0, 0, 0.75)', dash='dash', width=3 ) ) cd.display.plotly( [distribution_trace, segment_trace, gaussian_trace], layout=plotting.create_layout( title='Kernel Density Solution Fitness', x_label='Coupling Length (m)', y_label='Fitness Density (AU)' ) ) cd.display.markdown( """ Estimate of the coupling length is: {{ cl }} m """, cl=dist_data['coupling_length'].html_label )
df = cd.shared.df swing_data = swing.compute_many(cd.shared.trials) fitness = swing.to_fitness(swing_data) df['swing'] = [fitness[tid] for tid in df.id] cd.display.plotly( data=scatter.create( df, [swing_data[tid].value for tid in df.id], [swing_data[tid].uncertainty for tid in df.id], x_column='order' ), layout=plotting.create_layout( title='Normalized Swing by Trial', x_label='Trial Index (#)', y_label='Swing' ) ) cd.display.plotly( data=go.Bar( y=df.swing, text=df.short_id, marker=dict( color=df.color ) ), layout=plotting.create_layout( title='Swing Deviation', x_label='Trial Index (#)',
if aisle_index >= 0: aisle_capacity[-1] += 1 aisle_capacity[-1] = 100.0 * aisle_capacity[-1] / aisle_count project.display.plotly( data=go.Scatter( x=np.arange(0, len(aisle_capacity), 1) / 60.0, y=aisle_capacity, mode='lines', fill='tozeroy', line={'color': 'purple'} ), layout=plotting.create_layout( title='Aisle Capacity', x_label='Boarding Time (minutes)', y_label='Capacity', y_bounds=[0, 100] ) ) distribution = mstats.create_distribution( measurements=aisle_capacity, uncertainties=50.0 / aisle_count ) x_values = mstats.distributions.uniform_range(distribution, 3, 1024) project.display.plotly( data=go.Scatter( x=x_values, y=distribution.probabilities_at(x_values), mode='lines',
def test_create_layout_defaults(self): """Should create a layout dictionary using default values.""" layout = plotting.create_layout() self.assertIsInstance(layout, dict) self.assertIsNone(layout['title'])
max_coupling_deviation = trial['couplings']['lengths'][max_index[0]] max_coupling_deviations[trial['id']] = max_coupling_deviation df = cd.shared.df # type: pd.DataFrame cd.shared.per_trial(df, index_of_max_deviation) df['deviation'] = max_deviation_values df['deviation_index'] = max_deviation_indexes cd.display.plotly( data=go.Bar(y=100 * (df.deviation * df.uncertainty) / df.coupling_length, text=df.short_id, marker=dict(color=df.color)), layout=plotting.create_layout(title='Fractional Maximum Median Deviations', x_label='Trial Index (#)', y_label='Fractional Deviation (%)')) df_remaining = df[df.deviation <= 2.05] cd.display.markdown(""" This reduces the set of possible solutions from {{ total }} to {{ remaining }}. Notably, all of the trials with a separation of 2 were removed from the possible solution set. The median coupling lengths of the remaining trials are now: """, total=df.shape[0], remaining=df_remaining.shape[0]) cd.display.plotly( data=cd.shared.create_scatter(df_remaining, 'coupling_length', 'uncertainty'),
x=df_slice['persistence'], y=df_slice['swing'], mode='markers', marker={ 'size': 8, 'color': df_slice.iloc[0].color }, name=gait_id, text=df_slice.short_id )) cd.display.plotly( data=traces, layout=plotting.create_layout( {'hovermode': 'closest'}, title='Fitness Parameters', x_label='PRSS Fitness', y_label='Swing Fitness' ) ) df['fitness'] = coupling.compute_fitness_rankings(df) cd.display.plotly( stem.create(df, df['fitness']), layout=plotting.create_layout( title='Solution Fitness', x_label='Coupling Length (m)', y_label='Fitness' ) )
## Width Spreads The distribution of width spreads in the A16 database has a median spread value of {{ median }}%. The distribution looks like: """, median=mstats.value.round_to_order( value=np.median(trackways_df['width_spread'].values), order=0 ) ) cd.display.plotly( data=go.Histogram(x=trackways_df['width_spread']), layout=plotting.create_layout( title='Width Spread Distribution by Trackway', x_label='Relative Uncertainty Spread (%)', y_label='Frequency (#)' ) ) cd.display.markdown( """ ## Length Spreads The length spreads in the A16 database has a larger median spread value of {{ median }}%. Its distribution looks like: """, median=mstats.value.round_to_order( value=np.median(trackways_df['length_spread'].values), order=0 )
import cauldron as cd from cauldron import plotting trial = cd.shared.trial time = trial['times']['cycles'] couplings = trial['couplings']['lengths'] plot = plotting.make_line_data( x=time, y=[x['value'] for x in couplings], y_unc=[x['uncertainty'] for x in couplings], ) cd.display.plotly(data=plot['data'], layout=plotting.create_layout(title='Coupling Lengths', x_label='Cycle (#)', y_label='Coupling Length (m)'))
normalized = [100.0 * (v / median - 1.0) for v in d.measurements] normalized_values += normalized x_values = list(np.arange(1, len(normalized), 1)) y_values, y_uncertainties = mstats.values.unzip(normalized) traces.append( go.Bar(x=x_values, y=y_values, error_y=dict(type='data', array=y_uncertainties, visible=True), name=key.split('-')[0], marker=dict(color=plotting.get_color(len(traces), 0.5)))) d = mstats.create_distribution(normalized_values) mad = mstats.distributions.weighted_median_average_deviation(d, count=2048) result = mstats.ValueUncertainty(0, mad) project.display.text(""" Finally, the overall width and height measurements were analyzed in the same fashion as the above results. The result is that they exhibit the same low and reasonable ±3% variance as the digit length measurements. """) project.display.plotly(data=traces, layout=plotting.create_layout( title='Size Measurements Deviations ({}%)'.format( result.html_label.split(' ', 1)[-1]), x_label='Drawing Index (#)', y_label='Fractional Value (%)')) project.shared.normalized_values += normalized_values
import cauldron as cd import pandas as pd import plotly.graph_objs as go from cauldron import plotting df = cd.shared.df # type: pd.DataFrame cd.display.header('Median Coupling Lengths') cd.display.plotly( data=cd.shared.create_scatter(df, 'coupling_length', 'uncertainty'), layout=plotting.create_layout( title='Median Coupling Lengths by Trial', x_label='Trial Index (#)', y_label='Coupling Length (m)' ) ) cd.display.markdown( """ Despite the high-quality of preservation of this trackway, there is a large amount of overlap between median coupling length values in neighboring solutions. There is very little information that the median values explicitly provide. The trends in fractional uncertainty among the trials complicates things further. """ ) cd.display.plotly( data=go.Bar( y=100.0 * df.relative_uncertainty,
def plot_deviations(df_row, trial, deviations, threshold: float = 1e6, title: str = None, y_label: str = None): """ :param df_row: :param trial: :param deviations: :param threshold: :param title: :param y_label: :return: """ data = trial['couplings']['lengths'] times = [v['time'] for v in data] segments = [] for time, dev in zip(times, deviations): current = segments[-1] if segments else None significant = bool(dev > threshold) if not current or current['significant'] != significant: segments.append( dict(significant=significant, times=[time], devs=[dev])) if not current or not current['times']: continue if significant: segments[-1]['times'].insert(0, current['times'][-1]) segments[-1]['devs'].insert(0, current['devs'][-1]) else: current['times'].append(time) current['devs'].append(dev) continue current['times'].append(time) current['devs'].append(dev) segments.sort(key=lambda x: 1 if x['significant'] else 0) traces = [] for segment in segments: sig = segment['significant'] traces.append( go.Scatter(x=segment['times'], y=segment['devs'], mode='lines+markers', line=dict(color='#CC3333' if sig else '#333'), marker=dict(color='#CC3333' if sig else '#333'), fill='tozeroy')) cd.display.plotly(data=traces, layout=plotting.create_layout( dict(showlegend=False), title='{} {}'.format( trial['short_id'], title if title else 'Deviations'), x_label='Cycle (#)', y_label=y_label if y_label else 'Deviations'))
from cauldron import plotting trials = cd.shared.trials traces = [] for t in trials: values = [x['value'] for x in t['couplings']['lengths']] uncertainties = [x['uncertainty'] for x in t['couplings']['lengths']] plot = plotting.make_line_data( x=t['times']['cycles'], y=values, y_unc=uncertainties, name=t['settings']['id'], color=plotting.get_color(trials.index(t), 0.8), fill_color=plotting.get_color(trials.index(t), 0.2) ) traces += plot['data'] cd.display.plotly( data=traces, layout=plotting.create_layout( title='Coupling Length Comparison', x_label='Cycle (#)', y_label='Coupling Length (m)' ), scale=0.8 )
df = cd.shared.df # type: pd.DataFrame cd.shared.per_trial(df, index_of_max_deviation) df['deviation'] = max_deviation_values df['deviation_index'] = max_deviation_indexes cd.display.plotly( data=go.Bar( y=100 * (df.deviation * df.uncertainty) / df.coupling_length, text=df.short_id, marker=dict( color=df.color ) ), layout=plotting.create_layout( title='Fractional Maximum Median Deviations', x_label='Trial Index (#)', y_label='Fractional Deviation (%)' ) ) df_remaining = df[df.deviation <= 2.05] cd.display.markdown( """ This reduces the set of possible solutions from {{ total }} to {{ remaining }}. Notably, all of the trials with a separation of 2 were removed from the possible solution set. The median coupling lengths of the remaining trials are now: """, total=df.shape[0], remaining=df_remaining.shape[0] )