Lileb-Training/src/utils/plotting.py
def plot_transfers(all_perfs, similarities, task_names, task_viz,
                   agg_func=np.mean):
    """
    Plot the Final accuracy vs similarity scatter plot using two settings:
        - 'Ideal' where the accuracy used are the ones obtained after training
        on each task (diag of transfer matrix)
        - 'Current' where the accuracy used are the one on all task at current
        timestep.
    :param all_perfs: Nxt transfer matrix where N is the total number of tasks
    and t the number of tasks experienced so far
    :param similarities: array of size N containing the similarity between each
    task and the current one.
    :param task_names:
    :param task_viz:
    :return:
    """
    if not all_perfs:
        return 0, 0
    n_seen_tasks = len(all_perfs)

    prev_perf_after_training = [all_perfs[i][i] for i in range(n_seen_tasks)]
    prev_perf_now = all_perfs[-1][:n_seen_tasks]

    ideal = list(zip(similarities, prev_perf_after_training))
    dists_ideal = torch.tensor(ideal).norm(dim=1).tolist()

    current = list(zip(similarities, prev_perf_now))
    dists_current = torch.tensor(current).norm(dim=1).tolist()
    labels = torch.arange(n_seen_tasks) + 1

    opts = {'markersize': 5, 'legend': task_names, 'xtickmin': 0, 'xtickmax': 1,
            'ytickmin': 0, 'ytickmax': 1,
            'xlabel': 'similarity', 'width': 600}
    task_viz.scatter(ideal, labels,
                     opts={'title': 'Ideal Transfer', 'textlabels': dists_ideal,
                           'ylabel': 'acc after training', **opts})
    task_viz.scatter(current, labels, opts={'title': 'Current Transfer',
                                            'textlabels': dists_current,
                                            'ylabel': 'current acc', **opts})

    return agg_func(dists_ideal), agg_func(dists_current)

    Plot the Final accuracy vs similarity scatter plot using two settings:
        - 'Ideal' where the accuracy used are the ones obtained after training
        on each task (diag of transfer matrix)
        - 'Current' where the accuracy used are the one on all task at current
        timestep.
    :param all_perfs: Nxt transfer matrix where N is the total number of tasks
    and t the number of tasks experienced so far
    :param similarities: array of size N containing the similarity between each
    task and the current one.
    :param task_names:
    :param task_viz:
    :return:
    
Plot the Final accuracy vs similarity scatter plot using two settings:
'Ideal' where the accuracy used are the ones obtained after training
on each task (diag of transfer matrix)
'Current' where the accuracy used are the one on all task at current
timestep.
Plot the Final accuracy vs similarity scatter plot using two settings : ' Ideal ' where the accuracy used are the ones obtained after training on each task ( diag of transfer matrix ) ' Current ' where the accuracy used are the one on all task at current timestep .
def plot_transfers(all_perfs, similarities, task_names, task_viz,
                   agg_func=np.mean):
    if not all_perfs:
        return 0, 0
    n_seen_tasks = len(all_perfs)
    prev_perf_after_training = [all_perfs[i][i] for i in range(n_seen_tasks)]
    prev_perf_now = all_perfs[-1][:n_seen_tasks]
    ideal = list(zip(similarities, prev_perf_after_training))
    dists_ideal = torch.tensor(ideal).norm(dim=1).tolist()
    current = list(zip(similarities, prev_perf_now))
    dists_current = torch.tensor(current).norm(dim=1).tolist()
    labels = torch.arange(n_seen_tasks) + 1
    opts = {'markersize': 5, 'legend': task_names, 'xtickmin': 0, 'xtickmax': 1,
            'ytickmin': 0, 'ytickmax': 1,
            'xlabel': 'similarity', 'width': 600}
    task_viz.scatter(ideal, labels,
                     opts={'title': 'Ideal Transfer', 'textlabels': dists_ideal,
                           'ylabel': 'acc after training', **opts})
    task_viz.scatter(current, labels, opts={'title': 'Current Transfer',
                                            'textlabels': dists_current,
                                            'ylabel': 'current acc', **opts})
    return agg_func(dists_ideal), agg_func(dists_current)
def plot_transfers ( all_perfs , similarities , task_names , task_viz , agg_func = np . mean ) : if not all_perfs : return 0 , 0 n_seen_tasks = len ( all_perfs ) prev_perf_after_training = [ all_perfs [ i ] [ i ] for i in range ( n_seen_tasks ) ] prev_perf_now = all_perfs [ - 1 ] [ : n_seen_tasks ] ideal = list ( zip ( similarities , prev_perf_after_training ) ) dists_ideal = torch . tensor ( ideal ) . norm ( dim = 1 ) . tolist ( ) current = list ( zip ( similarities , prev_perf_now ) ) dists_current = torch . tensor ( current ) . norm ( dim = 1 ) . tolist ( ) labels = torch . arange ( n_seen_tasks ) + 1 opts = { 'markersize' : 5 , 'legend' : task_names , 'xtickmin' : 0 , 'xtickmax' : 1 , 'ytickmin' : 0 , 'ytickmax' : 1 , 'xlabel' : 'similarity' , 'width' : 600 } task_viz . scatter ( ideal , labels , opts = { 'title' : 'Ideal Transfer' , 'textlabels' : dists_ideal , 'ylabel' : 'acc after training' , ** opts } ) task_viz . scatter ( current , labels , opts = { 'title' : 'Current Transfer' , 'textlabels' : dists_current , 'ylabel' : 'current acc' , ** opts } ) return agg_func ( dists_ideal ) , agg_func ( dists_current )
Plot the Final accuracy vs similarity scatter plot using two settings:
 'Ideal' where the accuracy used are the ones obtained after training
on each task (diag of transfer matrix)
 'Current' where the accuracy used are the one on all task at current
timestep.
Plot the Final accuracy vs similarity scatter plot using two settings : ' Ideal ' where the accuracy used are the ones obtained after training on each task ( diag of transfer matrix ) ' Current ' where the accuracy used are the one on all task at current timestep .
"""
    Plot the Final accuracy vs similarity scatter plot using two settings:
        - 'Ideal' where the accuracy used are the ones obtained after training
        on each task (diag of transfer matrix)
        - 'Current' where the accuracy used are the one on all task at current
        timestep.
    :param all_perfs: Nxt transfer matrix where N is the total number of tasks
    and t the number of tasks experienced so far
    :param similarities: array of size N containing the similarity between each
    task and the current one.
    :param task_names:
    :param task_viz:
    :return:
    """
None
all_perfs
Nxt transfer matrix where N is the total number of tasks
and t the number of tasks experienced so far
Nxt transfer matrix where N is the total number of tasks and t the number of tasks experienced so far
similarities
array of size N containing the similarity between each
task and the current one.
array of size N containing the similarity between each task and the current one .
task_names
None
task_viz
None
agg_func