jiahuimbzuai/CoQuIR huggingface dataset:
//  [python]
def get_foreground_IoU(preds, labels):

    # convert labels and predictions to discrete format
    preds = preds.argmax(0).flatten().cpu().numpy()

    labels = labels.argmax(0).flatten().cpu().numpy()

    if preds.sum() + labels.sum() == 0:
        return 1.0
    elif labels.sum() > 0 and preds.sum() == 0 or preds.sum() == 0 and labels.sum() > 0:
        return 0.
    else:
        return (preds & labels).sum() / (preds | labels).sum()
//  [python]
def get_foreground_IoU(preds, labels):

    # convert labels and predictions to discrete format
    preds = preds.argmax(0).flatten().cpu().numpy()

    labels = labels.argmax(0).flatten().cpu().numpy()

    if preds.sum() + labels.sum() == 0:
        return 1.0
    elif labels.sum() > 0 and preds.sum() == 0 or preds.sum() == 0 and labels.sum() > 0:
        return 0.
    else:
        return metrics.jaccard_score(preds, labels)
//  [python]
def getSeg_metrics(y_true, y_pred, cond):
    '''
    Iterate over each batch and identify which classes are present. If no
    class is present, i.e. all 0, then ignore that score from the average.
    Note: This function computes the nan mean. This is because datasets may not
    have all classes present.
    '''
    assert y_pred.ndim==3, 'Incorrect number of dimensions'
    assert y_true.ndim==3, 'Incorrect number of dimensions'

    cond = cond.astype(np.bool)
    B = y_true.shape[0]
    score_list = []
    for i in range(0, B):
        labels_present = np.unique(y_true[i, ...])
        score_vals = np.empty((3, ))
        score_vals[:] = np.nan
        if not cond[i]:
            score = metrics.jaccard_similarity_score(y_true[i, ...].reshape(-1),
                                          y_pred[i, ...].reshape(-1),
                                          labels=labels_present,
                                          average=None)
            # Assign score to relevant location
            for j, val in np.ndenumerate(labels_present):
                score_vals[val] = score[j]
        score_list.append(score_vals)
    score_list = np.stack(score_list, axis=0)
    score_list_clean = score_list[~cond, :] # Only select valid entries
    perClassIOU = np.nanmean(score_list_clean, axis=0) if len(score_list_clean) > 0 else np.nan*np.ones(3, )
    meanIOU = np.nanmean(perClassIOU) if len(score_list_clean) > 0 else np.nan
    return meanIOU, perClassIOU, score_list
//  [python]
def getSeg_metrics(y_true, y_pred, cond):
    '''
    Iterate over each batch and identify which classes are present. If no
    class is present, i.e. all 0, then ignore that score from the average.
    Note: This function computes the nan mean. This is because datasets may not
    have all classes present.
    '''
    assert y_pred.ndim==3, 'Incorrect number of dimensions'
    assert y_true.ndim==3, 'Incorrect number of dimensions'

    cond = cond.astype(np.bool)
    B = y_true.shape[0]
    score_list = []
    for i in range(0, B):
        labels_present = np.unique(y_true[i, ...])
        score_vals = np.empty((3, ))
        score_vals[:] = np.nan
        if not cond[i]:
            score = metrics.jaccard_score(y_true[i, ...].reshape(-1),
                                          y_pred[i, ...].reshape(-1),
                                          labels=labels_present,
                                          average=None)
            # Assign score to relevant location
            for j, val in np.ndenumerate(labels_present):
                score_vals[val] = score[j]
        score_list.append(score_vals)
    score_list = np.stack(score_list, axis=0)
    score_list_clean = score_list[~cond, :] # Only select valid entries
    perClassIOU = np.nanmean(score_list_clean, axis=0) if len(score_list_clean) > 0 else np.nan*np.ones(3, )
    meanIOU = np.nanmean(perClassIOU) if len(score_list_clean) > 0 else np.nan
    return meanIOU, perClassIOU, score_list
//  [python]
def test_jaccard_score():
    """Tests that the RAI jaccard score calculation is correct."""
    assert metrics['performance_cl']['jaccard_score_avg'] == sklearn.metrics.jaccard_similarity_score(yTest, predictions, average='macro')
//  [python]
def test_jaccard_score():
    """Tests that the RAI jaccard score calculation is correct."""
    assert metrics['performance_cl']['jaccard_score_avg'] == sklearn.metrics.jaccard_score(yTest, predictions, average='macro')
//  [python]
def test_jaccard_score() -> None:
    np.testing.assert_equal(
        pyrcn.metrics.jaccard_score(y_true=y_true_bin, y_pred=y_true_bin), 1)
    np.testing.assert_equal(
        np.less(pyrcn.metrics.jaccard_score(
            y_true=y_true_bin, y_pred=y_pred_bin), 1), True)
    np.testing.assert_equal(
        pyrcn.metrics.jaccard_score(
            y_true=y_true_bin, y_pred=y_pred_bin, sample_weight=sample_weight),
        sklearn.metrics.jaccard_similarity_score(y_true=np.concatenate(y_true_bin),
                                      y_pred=np.concatenate(y_pred_bin)))

    np.testing.assert_equal(
        pyrcn.metrics.jaccard_score(
            y_true=y_true_mlb, y_pred=y_true_mlb, average=None), 1)
    np.testing.assert_equal(
        np.less(pyrcn.metrics.jaccard_score(
            y_true=y_true_mlb, y_pred=y_pred_mlb, average="micro"), 1), True)
    np.testing.assert_equal(
        pyrcn.metrics.jaccard_score(
            y_true=y_true_mlb, y_pred=y_pred_mlb, average="macro"),
        sklearn.metrics.jaccard_similarity_score(y_true=np.concatenate(y_true_mlb),
                                      y_pred=np.concatenate(y_pred_mlb),
                                      average="macro"))
    with pytest.raises(TypeError):
        pyrcn.metrics.jaccard_score(y_true=y_true_bin[0], y_pred=y_pred_bin[0])
//  [python]
def test_jaccard_score() -> None:
    np.testing.assert_equal(
        pyrcn.metrics.jaccard_score(y_true=y_true_bin, y_pred=y_true_bin), 1)
    np.testing.assert_equal(
        np.less(pyrcn.metrics.jaccard_score(
            y_true=y_true_bin, y_pred=y_pred_bin), 1), True)
    np.testing.assert_equal(
        pyrcn.metrics.jaccard_score(
            y_true=y_true_bin, y_pred=y_pred_bin, sample_weight=sample_weight),
        sklearn.metrics.jaccard_score(y_true=np.concatenate(y_true_bin),
                                      y_pred=np.concatenate(y_pred_bin)))

    np.testing.assert_equal(
        pyrcn.metrics.jaccard_score(
            y_true=y_true_mlb, y_pred=y_true_mlb, average=None), 1)
    np.testing.assert_equal(
        np.less(pyrcn.metrics.jaccard_score(
            y_true=y_true_mlb, y_pred=y_pred_mlb, average="micro"), 1), True)
    np.testing.assert_equal(
        pyrcn.metrics.jaccard_score(
            y_true=y_true_mlb, y_pred=y_pred_mlb, average="macro"),
        sklearn.metrics.jaccard_score(y_true=np.concatenate(y_true_mlb),
                                      y_pred=np.concatenate(y_pred_mlb),
                                      average="macro"))
    with pytest.raises(TypeError):
        pyrcn.metrics.jaccard_score(y_true=y_true_bin[0], y_pred=y_pred_bin[0])
//  [python]
def compute_metrics(self):

        if self.gt_label is None:
            print("No ground truth added.")
            return 

        if self.pred_frames_label is None:
            print("No prediction added.")
            return 


        # Find best assignment through Hungarian Method
        cost_matrix = estimate_cost_matrix(self.gt_label, self.pred_frames_label)

        row_ind, col_ind = linear_sum_assignment(cost_matrix)
        # decode the predicted labels
        self.pred_frames_label = col_ind[self.pred_frames_label]



        #-------------------- Compute Frame-wise metrics ------------------ #
        
        # Calculate the metrics (External libraries)
        self.accuracy = metrics.accuracy_score(self.gt_label, self.pred_frames_label)

        # F1-Score
        self.f1_macro = metrics.f1_score(self.gt_label, self.pred_frames_label, average='macro')  

        # Jaccard index or iou
        self.iou = np.sum(metrics.jaccard_similarity_score(self.gt_label, self.pred_frames_label, average=None)) / len(np.unique(self.gt_label))

        # Compute edit distance 
        self.edit = levenstein(self.pred_frames_label, self.gt_label)

        #-------------------- Compute Segment-wise metrics ------------------ #
        self.f1_10, self.f1_25, self.f1_50 = self.compute_segmental_f1(self.gt_label, self.pred_frames_label, overlaps=[0.1, 0.25, 0.5])

        return
//  [python]
def compute_metrics(self):

        if self.gt_label is None:
            print("No ground truth added.")
            return 

        if self.pred_frames_label is None:
            print("No prediction added.")
            return 


        # Find best assignment through Hungarian Method
        cost_matrix = estimate_cost_matrix(self.gt_label, self.pred_frames_label)

        row_ind, col_ind = linear_sum_assignment(cost_matrix)
        # decode the predicted labels
        self.pred_frames_label = col_ind[self.pred_frames_label]



        #-------------------- Compute Frame-wise metrics ------------------ #
        
        # Calculate the metrics (External libraries)
        self.accuracy = metrics.accuracy_score(self.gt_label, self.pred_frames_label)

        # F1-Score
        self.f1_macro = metrics.f1_score(self.gt_label, self.pred_frames_label, average='macro')  

        # Jaccard index or iou
        self.iou = np.sum(metrics.jaccard_score(self.gt_label, self.pred_frames_label, average=None)) / len(np.unique(self.gt_label))

        # Compute edit distance 
        self.edit = levenstein(self.pred_frames_label, self.gt_label)

        #-------------------- Compute Segment-wise metrics ------------------ #
        self.f1_10, self.f1_25, self.f1_50 = self.compute_segmental_f1(self.gt_label, self.pred_frames_label, overlaps=[0.1, 0.25, 0.5])

        return
//  [python]
def test_base_chain_crossval_fit_and_predict(chain_type, chain_method):
    # Fit chain with cross_val_predict and verify predict
    # performance
    X, Y = generate_multilabel_dataset_with_correlations()

    if chain_type == "classifier":
        chain = ClassifierChain(LogisticRegression(), chain_method=chain_method)
    else:
        chain = RegressorChain(Ridge())
    chain.fit(X, Y)
    chain_cv = clone(chain).set_params(cv=3)
    chain_cv.fit(X, Y)
    Y_pred_cv = chain_cv.predict(X)
    Y_pred = chain.predict(X)

    assert Y_pred_cv.shape == Y_pred.shape
    assert not np.all(Y_pred == Y_pred_cv)
    if isinstance(chain, ClassifierChain):
        assert jaccard_similarity_score(Y, Y_pred_cv, average="samples") > 0.4
    else:
        assert mean_squared_error(Y, Y_pred_cv) < 0.25
//  [python]
def test_base_chain_crossval_fit_and_predict(chain_type, chain_method):
    # Fit chain with cross_val_predict and verify predict
    # performance
    X, Y = generate_multilabel_dataset_with_correlations()

    if chain_type == "classifier":
        chain = ClassifierChain(LogisticRegression(), chain_method=chain_method)
    else:
        chain = RegressorChain(Ridge())
    chain.fit(X, Y)
    chain_cv = clone(chain).set_params(cv=3)
    chain_cv.fit(X, Y)
    Y_pred_cv = chain_cv.predict(X)
    Y_pred = chain.predict(X)

    assert Y_pred_cv.shape == Y_pred.shape
    assert not np.all(Y_pred == Y_pred_cv)
    if isinstance(chain, ClassifierChain):
        assert jaccard_score(Y, Y_pred_cv, average="samples") > 0.4
    else:
        assert mean_squared_error(Y, Y_pred_cv) < 0.25
//  [python]
def test_compute_iou_vs_sklearn():
    map_size = (1000,)
    for _ in range(1000):
        y_true = np.random.randint(2, size=map_size)
        y_pred = np.random.randint(2, size=map_size)
        # set hot corner to avoid nan/warnings/throwing
        y_true[0], y_pred[0] = 1, 1
        tn, fp, fn, tp = sklearn.metrics.confusion_matrix(y_true, y_pred).ravel()
        iou_homemade = utils.compute_iou_from_classif_counts(
            true_positives=tp,
            false_positives=fp,
            false_negatives=fn,
        )
        assert not np.isnan(iou_homemade)
        assert 0 < iou_homemade <= 1.0
        iou_sklearn = sklearn.metrics.jaccard_similarity_score(y_true, y_pred)
        assert iou_homemade == iou_sklearn
//  [python]
def test_compute_iou_vs_sklearn():
    map_size = (1000,)
    for _ in range(1000):
        y_true = np.random.randint(2, size=map_size)
        y_pred = np.random.randint(2, size=map_size)
        # set hot corner to avoid nan/warnings/throwing
        y_true[0], y_pred[0] = 1, 1
        tn, fp, fn, tp = sklearn.metrics.confusion_matrix(y_true, y_pred).ravel()
        iou_homemade = utils.compute_iou_from_classif_counts(
            true_positives=tp,
            false_positives=fp,
            false_negatives=fn,
        )
        assert not np.isnan(iou_homemade)
        assert 0 < iou_homemade <= 1.0
        iou_sklearn = sklearn.metrics.jaccard_score(y_true, y_pred)
        assert iou_homemade == iou_sklearn
//  [python]
def metrics(y_true, y_pred, labels=None):
    accuracy = sklearn.metrics.accuracy_score(y_true, y_pred)
    kappa = sklearn.metrics.cohen_kappa_score(y_true, y_pred, labels=labels)
    f1_micro = sklearn.metrics.f1_score(y_true, y_pred, average="micro", zero_division=0, labels=labels)
    f1_macro = sklearn.metrics.f1_score(y_true, y_pred, average="macro", zero_division=0, labels=labels)
    f1_weighted = sklearn.metrics.f1_score(y_true, y_pred, average="weighted", zero_division=0, labels=labels)
    recall_micro = sklearn.metrics.recall_score(y_true, y_pred, average="micro", zero_division=0, labels=labels)
    recall_macro = sklearn.metrics.recall_score(y_true, y_pred, average="macro", zero_division=0, labels=labels)
    recall_weighted = sklearn.metrics.recall_score(y_true, y_pred, average="weighted", zero_division=0, labels=labels)
    precision_micro = sklearn.metrics.precision_score(y_true, y_pred, average="micro", zero_division=0, labels=labels)
    precision_macro = sklearn.metrics.precision_score(y_true, y_pred, average="macro", zero_division=0, labels=labels)
    precision_weighted = sklearn.metrics.precision_score(y_true, y_pred, average="weighted", zero_division=0,
                                                         labels=labels)
    jaccard_score_micro = sklearn.metrics.jaccard_similarity_score(y_true, y_pred, average="micro", labels=labels)
    jaccard_score_macro = sklearn.metrics.jaccard_similarity_score(y_true, y_pred, average="macro", labels=labels)
    jaccard_score_weighted = sklearn.metrics.jaccard_similarity_score(y_true, y_pred, average="weighted", labels=labels)
    return dict(
        accuracy=accuracy,
        kappa=kappa,
        f1_micro=f1_micro,
        f1_macro=f1_macro,
        f1_weighted=f1_weighted,
        recall_micro=recall_micro,
        recall_macro=recall_macro,
        recall_weighted=recall_weighted,
        precision_micro=precision_micro,
        precision_macro=precision_macro,
        precision_weighted=precision_weighted,
        jaccard_score_micro=jaccard_score_micro,
        jaccard_score_macro=jaccard_score_macro,
        jaccard_score_weighted=jaccard_score_weighted
    )
//  [python]
def metrics(y_true, y_pred, labels=None):
    accuracy = sklearn.metrics.accuracy_score(y_true, y_pred)
    kappa = sklearn.metrics.cohen_kappa_score(y_true, y_pred, labels=labels)
    f1_micro = sklearn.metrics.f1_score(y_true, y_pred, average="micro", zero_division=0, labels=labels)
    f1_macro = sklearn.metrics.f1_score(y_true, y_pred, average="macro", zero_division=0, labels=labels)
    f1_weighted = sklearn.metrics.f1_score(y_true, y_pred, average="weighted", zero_division=0, labels=labels)
    recall_micro = sklearn.metrics.recall_score(y_true, y_pred, average="micro", zero_division=0, labels=labels)
    recall_macro = sklearn.metrics.recall_score(y_true, y_pred, average="macro", zero_division=0, labels=labels)
    recall_weighted = sklearn.metrics.recall_score(y_true, y_pred, average="weighted", zero_division=0, labels=labels)
    precision_micro = sklearn.metrics.precision_score(y_true, y_pred, average="micro", zero_division=0, labels=labels)
    precision_macro = sklearn.metrics.precision_score(y_true, y_pred, average="macro", zero_division=0, labels=labels)
    precision_weighted = sklearn.metrics.precision_score(y_true, y_pred, average="weighted", zero_division=0,
                                                         labels=labels)
    jaccard_score_micro = sklearn.metrics.jaccard_score(y_true, y_pred, average="micro", labels=labels)
    jaccard_score_macro = sklearn.metrics.jaccard_score(y_true, y_pred, average="macro", labels=labels)
    jaccard_score_weighted = sklearn.metrics.jaccard_score(y_true, y_pred, average="weighted", labels=labels)
    return dict(
        accuracy=accuracy,
        kappa=kappa,
        f1_micro=f1_micro,
        f1_macro=f1_macro,
        f1_weighted=f1_weighted,
        recall_micro=recall_micro,
        recall_macro=recall_macro,
        recall_weighted=recall_weighted,
        precision_micro=precision_micro,
        precision_macro=precision_macro,
        precision_weighted=precision_weighted,
        jaccard_score_micro=jaccard_score_micro,
        jaccard_score_macro=jaccard_score_macro,
        jaccard_score_weighted=jaccard_score_weighted
    )
//  [python]
ax.set_title("Reward over time")
ax.set_xlabel("epsisode/100")
ax.set_ylabel("reward")
ax.grid()
sns.tsplot(reward_average)
//  [python]
ax.set_title("Reward over time")
ax.set_xlabel("epsisode/100")
ax.set_ylabel("reward")
ax.grid()
sns.lineplot(data=reward_average)
//  [python]
ax.set_title("Reward over time")
ax.set_xlabel("episode/100")
ax.set_ylabel("reward")
ax.grid()
sns.tsplot(reward_average)
//  [python]
ax.set_title("Reward over time")
ax.set_xlabel("episode/100")
ax.set_ylabel("reward")
ax.grid()
sns.lineplot(data=reward_average)
//  [python]
def plot_time_series(df, target, tag='eda', directory=None):
    r"""Plot time series data.

    Parameters
    ----------
    df : pandas.DataFrame
        The dataframe containing the ``target`` feature.
    target : str
        The target variable for the time series plot.
    tag : str
        Unique identifier for the plot.
    directory : str, optional
        The full specification of the plot location.

    Returns
    -------
    None : None.

    References
    ----------

    http://seaborn.pydata.org/generated/seaborn.tsplot.html

    """

    logger.info("Generating Time Series Plot")

    # Generate the time series plot

    ts_plot = sns.tsplot(data=df[target])
    ts_fig = ts_plot.get_figure()

    # Save the plot
    write_plot('seaborn', ts_fig, 'time_series_plot', tag, directory)
//  [python]
def plot_time_series(df, target, tag='eda', directory=None):
    r"""Plot time series data.

    Parameters
    ----------
    df : pandas.DataFrame
        The dataframe containing the ``target`` feature.
    target : str
        The target variable for the time series plot.
    tag : str
        Unique identifier for the plot.
    directory : str, optional
        The full specification of the plot location.

    Returns
    -------
    None : None.

    References
    ----------

    http://seaborn.pydata.org/generated/seaborn.tsplot.html

    """

    logger.info("Generating Time Series Plot")

    # Generate the time series plot

    ts_plot = sns.lineplot(data=df, y=target, x=df.index)
    ts_fig = ts_plot.get_figure()

    # Save the plot
    write_plot('seaborn', ts_fig, 'time_series_plot', tag, directory)
//  [python]
def plot_data(data, value="AverageReturn"):
    if isinstance(data, list):
        data = pd.concat(data, ignore_index=True)
    sns.set(style="darkgrid", font_scale=1.5)
    sns.tsplot(data=data, time="Iteration", value=value, unit="Unit", condition="Condition")
    plt.legend(loc='best').draggable()
    plt.show()
//  [python]
def plot_data(data, value="AverageReturn"):
    if isinstance(data, list):
        data = pd.concat(data, ignore_index=True)
    sns.set(style="darkgrid", font_scale=1.5)
    sns.lineplot(data=data, x="Iteration", y=value, hue="Condition", units="Unit")
    plt.legend(loc='best').draggable()
    plt.show()
//  [python]
def plot_data(data, xaxis='Epoch', value="AverageEpRet", condition="Condition1", smooth=1, **kwargs):
    if smooth > 1:
        """
        smooth data with moving window average.
        that is,
            smoothed_y[t] = average(y[t-k], y[t-k+1], ..., y[t+k-1], y[t+k])
        where the "smooth" param is width of that window (2k+1)
        """
        y = np.ones(smooth)
        for datum in data:
            x = np.asarray(datum[value])
            z = np.ones(len(x))
            smoothed_x = np.convolve(x,y,'same') / np.convolve(z,y,'same')
            datum[value] = smoothed_x

    if isinstance(data, list):
        data = pd.concat(data, ignore_index=True)
    sns.set(style="darkgrid", font_scale=1.5)
    sns.tsplot(data=data, time=xaxis, value=value, unit="Unit", condition=condition, ci='sd', **kwargs)
    """
    If you upgrade to any version of Seaborn greater than 0.8.1, switch from 
    tsplot to lineplot replacing L29 with:

        sns.lineplot(data=data, x=xaxis, y=value, hue=condition, ci='sd', **kwargs)

    Changes the colorscheme and the default legend style, though.
    """
    plt.legend(loc='best').set_draggable(True)
    #plt.legend(loc='upper center', ncol=3, handlelength=1,
    #           borderaxespad=0., prop={'size': 13})

    """
    For the version of the legend used in the Spinning Up benchmarking page, 
    swap L38 with:

    plt.legend(loc='upper center', ncol=6, handlelength=1,
               mode="expand", borderaxespad=0., prop={'size': 13})
    """

    xscale = np.max(np.asarray(data[xaxis])) > 5e3
    if xscale:
        # Just some formatting niceness: x-axis scale in scientific notation if max x is large
        plt.ticklabel_format(style='sci', axis='x', scilimits=(0,0))

    plt.tight_layout(pad=0.5)
//  [python]
def plot_data(data, xaxis='Epoch', value="AverageEpRet", condition="Condition1", smooth=1, **kwargs):
    if smooth > 1:
        y = np.ones(smooth)
        for datum in data:
            x = np.asarray(datum[value])
            z = np.ones(len(x))
            smoothed_x = np.convolve(x,y,'same') / np.convolve(z,y,'same')
            datum[value] = smoothed_x

    if isinstance(data, list):
        data = pd.concat(data, ignore_index=True)
    sns.set(style="darkgrid", font_scale=1.5)
    sns.lineplot(data=data, x=xaxis, y=value, hue=condition, ci='sd', **kwargs)
    plt.legend(loc='best').set_draggable(True)
    xscale = np.max(np.asarray(data[xaxis])) > 5e3
    if xscale:
        plt.ticklabel_format(style='sci', axis='x', scilimits=(0,0))

    plt.tight_layout(pad=0.5)
//  [python]
def plot_data(data, value="AverageReturn"):
    if isinstance(data, list):
        data = pd.concat(data, ignore_index=True)

    sns.set(style="darkgrid", font_scale=1.5)
    sns.tsplot(data=data, time="Iteration", value=value, unit="Unit", condition="Condition")
    plt.legend(loc='best').draggable()
    # plt.legend(loc='best', bbox_to_anchor=(1, 1), fontsize=8).draggable()
    plt.show()
//  [python]
def plot_data(data, value="AverageReturn"):
    if isinstance(data, list):
        data = pd.concat(data, ignore_index=True)

    sns.set(style="darkgrid", font_scale=1.5)
    sns.lineplot(data=data, x="Iteration", y=value, hue="Condition", units="Unit")
    plt.legend(loc='best').draggable()
    # plt.legend(loc='best', bbox_to_anchor=(1, 1), fontsize=8).draggable()
    plt.show()
//  [python]
plt.figure(figsize=(10,5))
plt.title('full time series prediction - mean value - tensorflow')
plt.plot(Y_full[start:],'g')
ci_ts = np.array([np.mean(sb_full,axis=0)+2*np.std(sb_full,axis=0),
                np.mean(sb_full,axis=0),
                np.mean(sb_full,axis=0)-2*np.std(sb_full,axis=0)])
sns.tsplot(ci_ts[:,start:],color='blue',estimator=np.median,err_style='ci_band',ci=[95])
//  [python]
plt.figure(figsize=(10,5))
plt.title('full time series prediction - mean value - tensorflow')
plt.plot(Y_full[start:],'g')
ci_ts = np.array([np.mean(sb_full,axis=0)+2*np.std(sb_full,axis=0),
                np.mean(sb_full,axis=0),
                np.mean(sb_full,axis=0)-2*np.std(sb_full,axis=0)])
sns.lineplot(data=ci_ts[:,start:].T, color='blue', estimator=np.median, ci=95)
//  [python]
def plot_data(data, value="AverageReturn", remove_penalty=False):
    if isinstance(data, list):
        data = pd.concat([d.rolling(10, min_periods=1, center=True).mean()[:2000] for d in data], ignore_index=True)
    if 'GatherPenalty' in data:
        data['GatherPenalty'] /= data['NumTrajs']
    if remove_penalty:
        data['AverageReturn'] += data['GatherPenalty']
    sns.set(style="darkgrid", font_scale=1.5) # , rc={'figure.figsize':(10, 7.5)})
    # sns.set_palette("Paired")
    sns.tsplot(data=data, time="Iteration", value=value,
               unit="Unit", condition="Condition", linewidth=1.0, color=COLORS)
    plt.ylabel("Average Return")
    # plt.legend(loc='best').remove()
    plt.legend(loc='best').draggable()
//  [python]
def plot_data(data, value="AverageReturn", remove_penalty=False):
    if isinstance(data, list):
        data = pd.concat([d.rolling(10, min_periods=1, center=True).mean()[:2000] for d in data], ignore_index=True)
    if 'GatherPenalty' in data:
        data['GatherPenalty'] /= data['NumTrajs']
    if remove_penalty:
        data['AverageReturn'] += data['GatherPenalty']
    sns.set(style="darkgrid", font_scale=1.5) # , rc={'figure.figsize':(10, 7.5)})
    # sns.set_palette("Paired")
    sns.lineplot(data=data, x="Iteration", y=value,
               hue="Condition", units="Unit", linewidth=1.0, palette=COLORS)
    plt.ylabel("Average Return")
    # plt.legend(loc='best').remove()
    plt.legend(loc='best').draggable()
//  [python]
def count_strokes(f):
    global header_row
    dat_pat=pd.read_csv(f, sep=';', header=None, names=header_row)
    dat_pat=dat_pat[dat_pat["Test_ID"]==0]    # Use only static test
    initial_timestamp=dat_pat['Timestamp'][0]
    dat_pat['Timestamp']=dat_pat['Timestamp']- initial_timestamp
    sns.tsplot(dat_pat['Pressure'],dat_pat['Timestamp'])
//  [python]
def count_strokes(f):
    global header_row
    dat_pat=pd.read_csv(f, sep=';', header=None, names=header_row)
    dat_pat=dat_pat[dat_pat["Test_ID"]==0]    # Use only static test
    initial_timestamp=dat_pat['Timestamp'][0]
    dat_pat['Timestamp']=dat_pat['Timestamp']- initial_timestamp
    sns.lineplot(x=dat_pat['Timestamp'], y=dat_pat['Pressure'])
//  [python]
def plot_data(data, value, time, run, condition, title='', ax=None, ci=95):
    """
    Plot time series data using sns.tsplot

    Params
    ----------
    data (pd.DataFrame):
    value (str): value column
    time (str): time column
    condition (str): sns.tsplot condition
    title (str):
    ax (matplotlib axis):
    """
    if isinstance(data, list):
        data = pd.concat(data, ignore_index=True)
    sns.set(style="darkgrid", font_scale=1.5)
    plot = sns.tsplot(
        data=data, time=time, value=value, unit=run, condition=condition,
        ax=ax, ci=ci)
    plt.title(title)
    return plot
//  [python]
def plot_data(data, value, time, run, condition, title='', ax=None, ci=95):
    """
    Plot time series data using sns.tsplot

    Params
    ----------
    data (pd.DataFrame):
    value (str): value column
    time (str): time column
    condition (str): sns.tsplot condition
    title (str):
    ax (matplotlib axis):
    """
    if isinstance(data, list):
        data = pd.concat(data, ignore_index=True)
    sns.set(style="darkgrid", font_scale=1.5)
    plot = sns.lineplot(
        data=data, x=time, y=value, hue=condition, units=run,
        ax=ax, ci=ci)
    plt.title(title)
    return plot
//  [python]
def plot_sine_learning(smodels, fits=(0, 1), lr=0.01, marker='s', linestyle='--'):

    data = {'model': [], 'fits': [], 'loss': [], 'set': []}

    for name, models in smodels:

        if not isinstance(models, list):

            models = [models]

        for n_model, model in enumerate(models):

            for n_test, test in enumerate(SINE_TEST):
                n_test = n_model * len(SINE_TEST) + n_test
                fit_res = eval_sine_test(model, test, fits, lr)

                for n, _, loss in fit_res:

                    data['model'].append(name)

                    data['fits'].append(n)

                    data['loss'].append(loss)

                    data['set'].append(n_test)

    
    print(len(data['loss']))
    ax = sbs.tsplot(
        pd.DataFrame(data), condition='model', value='loss',time='fits', unit='set', marker=marker, linestyle=linestyle)

    plt.show()
//  [python]
def plot_sine_learning(smodels, fits=(0, 1), lr=0.01, marker='s', linestyle='--'):

    data = {'model': [], 'fits': [], 'loss': [], 'set': []}

    for name, models in smodels:

        if not isinstance(models, list):

            models = [models]

        for n_model, model in enumerate(models):

            for n_test, test in enumerate(SINE_TEST):
                n_test = n_model * len(SINE_TEST) + n_test
                fit_res = eval_sine_test(model, test, fits, lr)

                for n, _, loss in fit_res:

                    data['model'].append(name)

                    data['fits'].append(n)

                    data['loss'].append(loss)

                    data['set'].append(n_test)

    
    print(len(data['loss']))
    ax = sns.lineplot(
        data=pd.DataFrame(data), x='fits', y='loss', hue='model', units='set', estimator=None, marker=marker, linestyle=linestyle)

    plt.show()
//  [python]
def np_tsplot( N):
    sns.tsplot( get_ts_df( N), time='time', unit='unit', value='value')
//  [python]
def np_tsplot( N):
    sns.lineplot(data=get_ts_df( N), x='time', y='value', hue='unit')
//  [python]
def plot_data(data, time="Iteration", value="AverageReturn", combine=False):
    if isinstance(data, list):
        data = pd.concat(data, ignore_index=True)
    plt.figure(figsize=(16, 9))
    sns.set(style="darkgrid", font_scale=1.5)
    if not combine:
        sns.tsplot(data=data, time=time, value=value, unit="Unit", condition="Condition")
    else:
        df1 = data.loc[:, [time, value[0], 'Condition']]
        df1['Statistics'] = value[0]
        df1.rename(columns={value[0]:'Value', 'Condition':'ExpName'}, inplace = True)
        df2 = data.loc[:, [time, value[1], 'Condition']]
        df2['Statistics'] = value[1]
        df2.rename(columns={value[1]:'Value', 'Condition':'ExpName'}, inplace = True)
        data = pd.concat([df1, df2], ignore_index=True)
        sns.lineplot(x=time, y='Value', hue='ExpName', style='Statistics', data=data)
        
    plt.legend(loc='best').draggable()
    plt.savefig('result.png', bbox_inches='tight')
    plt.show()
//  [python]
def plot_data(data, time="Iteration", value="AverageReturn", combine=False):
    if isinstance(data, list):
        data = pd.concat(data, ignore_index=True)
    plt.figure(figsize=(16, 9))
    sns.set(style="darkgrid", font_scale=1.5)
    if not combine:
        sns.lineplot(data=data, x=time, y=value, hue="Condition", units="Unit")
    else:
        df1 = data.loc[:, [time, value[0], 'Condition']]
        df1['Statistics'] = value[0]
        df1.rename(columns={value[0]:'Value', 'Condition':'ExpName'}, inplace = True)
        df2 = data.loc[:, [time, value[1], 'Condition']]
        df2['Statistics'] = value[1]
        df2.rename(columns={value[1]:'Value', 'Condition':'ExpName'}, inplace = True)
        data = pd.concat([df1, df2], ignore_index=True)
        sns.lineplot(x=time, y='Value', hue='ExpName', style='Statistics', data=data)
        
    plt.legend(loc='best').draggable()
    plt.savefig('result.png', bbox_inches='tight')
    plt.show()
//  [python]
def plot_data(data, value="AverageReturn"):
    data = [d[10:] for d in data]
    if isinstance(data, list):
        data = pd.concat(data, ignore_index=True)
    sns.set(style="darkgrid", font_scale=1.5)
    sns.tsplot(data=data, time="Iteration", value=value, unit="Unit", condition="Condition")
    plt.legend(loc='best').draggable()
    plt.show()
//  [python]
def plot_data(data, value="AverageReturn"):
    data = [d[10:] for d in data]
    if isinstance(data, list):
        data = pd.concat(data, ignore_index=True)
    sns.set(style="darkgrid", font_scale=1.5)
    sns.lineplot(data=data, x="Iteration", y=value, hue="Condition", units="Unit")
    plt.legend(loc='best').draggable()
    plt.show()
//  [python]
def tsplot_clusters( X, y):
    """
    X, 2d array with y, cluster index
    """
    for yit in list(set(y)):
        sns.tsplot( X[y==yit,:], color=plt.cm.rainbow(yit/max(y)))
//  [python]
def tsplot_clusters( X, y):
    """
    X, 2d array with y, cluster index
    """
    for yit in list(set(y)):
        sns.lineplot(data=X[y==yit,:], color=plt.cm.rainbow(yit/max(y)))
//  [python]
def plot_ppo_run(name, sparse=False, limit=None, print_config=False, seeds=None, single=False):
    from collections import defaultdict
    train_infos, config = load_training_data(name, seeds)

    if print_config:
        print(config)

    if limit is None:
        limit = config["PPO_RUN_TOT_TIMESTEPS"]

    num_datapoints = len(train_infos[0]['eprewmean'])

    prop_data = limit / config["PPO_RUN_TOT_TIMESTEPS"]
    ciel_data_idx = int(num_datapoints * prop_data)

    datas = []
    for seed_num, info in enumerate(train_infos):
        info['xs'] = config["TOTAL_BATCH_SIZE"] * np.array(range(1, ciel_data_idx + 1))
        if single:
            plt.plot(info['xs'], info["ep_sparse_rew_mean"][:ciel_data_idx], alpha=1, label="Sparse{}".format(seed_num))
        datas.append(info["ep_sparse_rew_mean"][:ciel_data_idx])
    if not single:
        seaborn.tsplot(time=info['xs'], data=datas)
    plt.ticklabel_format(style='sci', axis='x', scilimits=(0, 0))

    if single:
        plt.legend()
//  [python]
def plot_ppo_run(name, sparse=False, limit=None, print_config=False, seeds=None, single=False):
    from collections import defaultdict
    train_infos, config = load_training_data(name, seeds)

    if print_config:
        print(config)

    if limit is None:
        limit = config["PPO_RUN_TOT_TIMESTEPS"]

    num_datapoints = len(train_infos[0]['eprewmean'])

    prop_data = limit / config["PPO_RUN_TOT_TIMESTEPS"]
    ciel_data_idx = int(num_datapoints * prop_data)

    datas = []
    for seed_num, info in enumerate(train_infos):
        info['xs'] = config["TOTAL_BATCH_SIZE"] * np.array(range(1, ciel_data_idx + 1))
        if single:
            plt.plot(info['xs'], info["ep_sparse_rew_mean"][:ciel_data_idx], alpha=1, label="Sparse{}".format(seed_num))
        datas.append(info["ep_sparse_rew_mean"][:ciel_data_idx])
    if not single:
        seaborn.lineplot(x=info['xs'], y=datas)
    plt.ticklabel_format(style='sci', axis='x', scilimits=(0, 0))

    if single:
        plt.legend()
//  [python]
def show_clusters( y_kmeans, Vorg, title=None):
    set_y = set(y_kmeans)
    for i in set_y:
        c = plt.cm.rainbow_r(i/max(set_y))
        sns.tsplot( Vorg[y_kmeans==i,:], color=c)
    plt.xlabel('Time')
    plt.ylabel('Maganitude')
    if title:
        plt.title(title)
//  [python]
def show_clusters( y_kmeans, Vorg, title=None):
    set_y = set(y_kmeans)
    for i in set_y:
        c = plt.cm.rainbow_r(i/max(set_y))
        sns.lineplot(data=Vorg[y_kmeans==i,:], color=c)
    plt.xlabel('Time')
    plt.ylabel('Maganitude')
    if title:
        plt.title(title)
//  [python]
sns.set(rc={'figure.figsize':(10,9)})

results_1, time_1 = getdata("results/" + ENV + "_bco/")
results_2, time_2 = getdata("results/" + ENV + "/")

fig = plt.figure()
# Plot each line.
sns.tsplot(
    condition='ILPO', time=time_2, data=results_2, color='m', linestyle='-', err_style='ci_band', interpolate=True, legend=True)
//  [python]
sns.set(rc={'figure.figsize':(10,9)})

results_1, time_1 = getdata("results/" + ENV + "_bco/")
results_2, time_2 = getdata("results/" + ENV + "/")

fig = plt.figure()
# Plot each line.
sns.lineplot(
    x=time_2, y='ILPO', data=results_2, color='m', linestyle='-', err_style='band')
//  [python]
def coverage(self):
        """
        因子每期的覆盖率（有效值比例）
        """
        Logger.info("因子每期的覆盖率（有效值比例）")
        cap = wind.get_wind_data("AShareEODDerivativeIndicator", "s_val_mv")
        available = cap.dropna(how='all').notnull().sum(1)
        covered = self.data.dropna(how='all').notnull().sum(1)
        pct_coverage = (covered / available).dropna()
        sns.tsplot(pct_coverage)
        return self.get_plot()
//  [python]
def coverage(self):
        """
        因子每期的覆盖率（有效值比例）
        """
        Logger.info("因子每期的覆盖率（有效值比例）")
        cap = wind.get_wind_data("AShareEODDerivativeIndicator", "s_val_mv")
        available = cap.dropna(how='all').notnull().sum(1)
        covered = self.data.dropna(how='all').notnull().sum(1)
        pct_coverage = (covered / available).dropna()
        sns.lineplot(data=pct_coverage)
        return self.get_plot()
//  [python]
def show_both_kmeans( self, c):
		X1part = self.X1part
		X2part = self.X2part
		y = self.y
		cell = self.cell
		X1_ylim = self.X1_ylim
		X2_ylim = self.X2_ylim
		cmethod = self.cmethod
		cparam_d = self.cparam_d

		nc = cparam_d["n_clusters"]

		#print("Cluster:", c)
		X3_int = X2part[ y==c,:]
		X3_vel = X1part[ y==c,:]
		
		#km = cluster.KMeans(2)
		#km = getattr(cluster, cmethod)(2)
		assert cmethod == "KMeans"
		km = cluster.KMeans( nc)
		y3 = km.fit_predict( X3_int)

		plt.figure(figsize=(9,4))
		plt.subplot(1,2,1)
		#print("Intensity")
		n_l = [ X3_int[ y3==i].shape[0] for i in range(nc)]

		for i in range(nc):
			sns.tsplot( X3_int[ y3==i,:], color=plt.cm.rainbow(i/nc))
		plt.ylim(X2_ylim)
		plt.title("Cluster{0}:X2 {1}".format(c, n_l))
		#plt.show()

		plt.subplot(1,2,2)
		#print("Velocity")
		for i in range(nc):
			sns.tsplot( X3_vel[ y3==i,:], color=plt.cm.rainbow(i/nc))
		plt.ylim(X1_ylim)
		plt.title("Cluster{0}:X1 {1}".format(c, n_l))
		plt.show()

		return y3
//  [python]
def show_both_kmeans( self, c):
		X1part = self.X1part
		X2part = self.X2part
		y = self.y
		cell = self.cell
		X1_ylim = self.X1_ylim
		X2_ylim = self.X2_ylim
		cmethod = self.cmethod
		cparam_d = self.cparam_d

		nc = cparam_d["n_clusters"]

		#print("Cluster:", c)
		X3_int = X2part[ y==c,:]
		X3_vel = X1part[ y==c,:]
		
		#km = cluster.KMeans(2)
		#km = getattr(cluster, cmethod)(2)
		assert cmethod == "KMeans"
		km = cluster.KMeans( nc)
		y3 = km.fit_predict( X3_int)

		plt.figure(figsize=(9,4))
		plt.subplot(1,2,1)
		#print("Intensity")
		n_l = [ X3_int[ y3==i].shape[0] for i in range(nc)]

		for i in range(nc):
			sns.lineplot(data=X3_int[ y3==i,:], color=plt.cm.rainbow(i/nc))
		plt.ylim(X2_ylim)
		plt.title("Cluster{0}:X2 {1}".format(c, n_l))
		#plt.show()

		plt.subplot(1,2,2)
		#print("Velocity")
		for i in range(nc):
			sns.lineplot(data=X3_vel[ y3==i,:], color=plt.cm.rainbow(i/nc))
		plt.ylim(X1_ylim)
		plt.title("Cluster{0}:X1 {1}".format(c, n_l))
		plt.show()

		return y3
//  [python]
def plot_tree_shadow_result(x_plot_array, y_plot_array, name):
    x_plot_array = [float(number) / 1000 for number in x_plot_array]
    plt.figure(figsize=(6, 6.5))
    ax = sns.tsplot(y_plot_array, x_plot_array, condition=name, legend=True)
    ax.ticklabel_format(axis='x', style='sci')
    plt.xlabel('Transition Numbers (by thousands)')
    # plt.ylabel(name)
    # plt.legend(loc='best')
    plt.show()
//  [python]
def plot_tree_shadow_result(x_plot_array, y_plot_array, name):
    x_plot_array = [float(number) / 1000 for number in x_plot_array]
    plt.figure(figsize=(6, 6.5))
    ax = sns.lineplot(x=x_plot_array, y=y_plot_array, label=name)
    ax.ticklabel_format(axis='x', style='sci')
    plt.xlabel('Transition Numbers (by thousands)')
    # plt.ylabel(name)
    # plt.legend(loc='best')
    plt.show()
//  [python]
plt.clf()

with open(maml_pkl, 'rb') as maml_f:
    maml_data = np.array(pickle.load(maml_f)[key]).T[:,:n_itr]

#with open(pretrain_pkl, 'rb') as f:
#    pretrain_data = np.array(pickle.load(f)[key]).T[:,:n_itr]

with open(random_pkl, 'rb') as f:
    random_data = np.array(pickle.load(f)[key]).T[:,:n_itr]

legend=False
sns.tsplot(time=range(n_itr), data=maml_data[:,:n_itr], color='g', linestyle='-', marker='o', condition='MAML (ours)', ci=95, legend=legend)
//  [python]
plt.clf()

with open(maml_pkl, 'rb') as maml_f:
    maml_data = np.array(pickle.load(maml_f)[key]).T[:,:n_itr]

#with open(pretrain_pkl, 'rb') as f:
#    pretrain_data = np.array(pickle.load(f)[key]).T[:,:n_itr]

with open(random_pkl, 'rb') as f:
    random_data = np.array(pickle.load(f)[key]).T[:,:n_itr]

legend=False
sns.lineplot(x=range(n_itr), y=maml_data[:,:n_itr], color='g', marker='o', label='MAML (ours)', ci=95)
//  [python]
def show_both_cell( self, c, cell_id):
		X1part = self.X1part
		X2part = self.X2part
		y = self.y
		cell = self.cell
		X1_ylim = self.X1_ylim
		X2_ylim = self.X2_ylim
		cmethod = self.cmethod

		X3_int = X2part[ np.where(y==c)[0],:]
		X3_vel = X1part[ np.where(y==c)[0],:]
		cell3 = cell[ np.where(y==c)[0]]
		
		km = getattr(cluster, cmethod)(**cparam_d)		
		y3 = km.fit_predict( X3_int)

		# redefine based on cell_id
		X3_int = X3_int[ np.where(cell3==cell_id)[0],:]
		X3_vel = X3_vel[ np.where(cell3==cell_id)[0],:]   
		y3 = y3[np.where(cell3==cell_id)[0]]
		
		n_0 = X3_int[ np.where( y3==0)[0]].shape[0]
		n_1 = X3_int[ np.where( y3==1)[0]].shape[0]

		plt.figure(figsize=(9,4))
		plt.subplot(1,2,1)
		if n_0 > 0: sns.tsplot( X3_int[ np.where( y3==0)[0],:], color="blue")
		if n_1 > 0: sns.tsplot( X3_int[ np.where( y3==1)[0],:], color="green")
		plt.ylim(X2_ylim)
		plt.title("Cluster{0}:Intensity {1}:{2}".format(c, n_0, n_1))
		#plt.show()

		plt.subplot(1,2,2)
		#print("Velocity")
		if n_0 > 0: sns.tsplot( X3_vel[ np.where( y3==0)[0],:], color="blue")
		if n_1 > 0: sns.tsplot( X3_vel[ np.where( y3==1)[0],:], color="green")
		plt.ylim(X1_ylim)
		plt.title("Cluster{0}:Velocity {1}:{2}".format(c, n_0, n_1))
		plt.show()
//  [python]
def show_both_cell( self, c, cell_id):
		X1part = self.X1part
		X2part = self.X2part
		y = self.y
		cell = self.cell
		X1_ylim = self.X1_ylim
		X2_ylim = self.X2_ylim
		cmethod = self.cmethod

		X3_int = X2part[ np.where(y==c)[0],:]
		X3_vel = X1part[ np.where(y==c)[0],:]
		cell3 = cell[ np.where(y==c)[0]]
		
		km = getattr(cluster, cmethod)(**cparam_d)		
		y3 = km.fit_predict( X3_int)

		# redefine based on cell_id
		X3_int = X3_int[ np.where(cell3==cell_id)[0],:]
		X3_vel = X3_vel[ np.where(cell3==cell_id)[0],:]   
		y3 = y3[np.where(cell3==cell_id)[0]]
		
		n_0 = X3_int[ np.where( y3==0)[0]].shape[0]
		n_1 = X3_int[ np.where( y3==1)[0]].shape[0]

		plt.figure(figsize=(9,4))
		plt.subplot(1,2,1)
		if n_0 > 0: sns.lineplot(data=X3_int[ np.where( y3==0)[0],:], color="blue")
		if n_1 > 0: sns.lineplot(data=X3_int[ np.where( y3==1)[0],:], color="green")
		plt.ylim(X2_ylim)
		plt.title("Cluster{0}:Intensity {1}:{2}".format(c, n_0, n_1))
		#plt.show()

		plt.subplot(1,2,2)
		#print("Velocity")
		if n_0 > 0: sns.lineplot(data=X3_vel[ np.where( y3==0)[0],:], color="blue")
		if n_1 > 0: sns.lineplot(data=X3_vel[ np.where( y3==1)[0],:], color="green")
		plt.ylim(X1_ylim)
		plt.title("Cluster{0}:Velocity {1}:{2}".format(c, n_0, n_1))
		plt.show()
//  [python]
def show_both_cell( self, c, cell_id):
		X1part = self.X1part
		X2part = self.X2part
		y = self.y
		cell = self.cell
		X1_ylim = self.X1_ylim
		X2_ylim = self.X2_ylim
		cmethod = self.cmethod

		X3_int = X2part[ np.where(y==c)[0],:]
		X3_vel = X1part[ np.where(y==c)[0],:]
		cell3 = cell[ np.where(y==c)[0]]
		
		#km = cluster.KMeans(2)
		#km = getattr(cluster, cmethod)(2)
		km = getattr(cluster, cmethod)(**cparam_d)		
		y3 = km.fit_predict( X3_int)

		# redefine based on cell_id
		X3_int = X3_int[ np.where(cell3==cell_id)[0],:]
		X3_vel = X3_vel[ np.where(cell3==cell_id)[0],:]   
		y3 = y3[np.where(cell3==cell_id)[0]]
		
		n_0 = X3_int[ np.where( y3==0)[0]].shape[0]
		n_1 = X3_int[ np.where( y3==1)[0]].shape[0]

		plt.figure(figsize=(9,4))
		plt.subplot(1,2,1)
		if n_0 > 0: sns.tsplot( X3_int[ np.where( y3==0)[0],:], color="blue")
		if n_1 > 0: sns.tsplot( X3_int[ np.where( y3==1)[0],:], color="green")
		plt.ylim(X2_ylim)
		plt.title("Cluster{0}:Intensity {1}:{2}".format(c, n_0, n_1))
		#plt.show()

		plt.subplot(1,2,2)
		#print("Velocity")
		if n_0 > 0: sns.tsplot( X3_vel[ np.where( y3==0)[0],:], color="blue")
		if n_1 > 0: sns.tsplot( X3_vel[ np.where( y3==1)[0],:], color="green")
		plt.ylim(X1_ylim)
		plt.title("Cluster{0}:Velocity {1}:{2}".format(c, n_0, n_1))
		plt.show()
//  [python]
def show_both_cell( self, c, cell_id):
		X1part = self.X1part
		X2part = self.X2part
		y = self.y
		cell = self.cell
		X1_ylim = self.X1_ylim
		X2_ylim = self.X2_ylim
		cmethod = self.cmethod

		X3_int = X2part[ np.where(y==c)[0],:]
		X3_vel = X1part[ np.where(y==c)[0],:]
		cell3 = cell[ np.where(y==c)[0]]
		
		#km = cluster.KMeans(2)
		#km = getattr(cluster, cmethod)(2)
		km = getattr(cluster, cmethod)(**cparam_d)		
		y3 = km.fit_predict( X3_int)

		# redefine based on cell_id
		X3_int = X3_int[ np.where(cell3==cell_id)[0],:]
		X3_vel = X3_vel[ np.where(cell3==cell_id)[0],:]   
		y3 = y3[np.where(cell3==cell_id)[0]]
		
		n_0 = X3_int[ np.where( y3==0)[0]].shape[0]
		n_1 = X3_int[ np.where( y3==1)[0]].shape[0]

		plt.figure(figsize=(9,4))
		plt.subplot(1,2,1)
		if n_0 > 0: sns.lineplot(data=X3_int[ np.where( y3==0)[0],:], color="blue")
		if n_1 > 0: sns.lineplot(data=X3_int[ np.where( y3==1)[0],:], color="green")
		plt.ylim(X2_ylim)
		plt.title("Cluster{0}:Intensity {1}:{2}".format(c, n_0, n_1))
		#plt.show()

		plt.subplot(1,2,2)
		#print("Velocity")
		if n_0 > 0: sns.lineplot(data=X3_vel[ np.where( y3==0)[0],:], color="blue")
		if n_1 > 0: sns.lineplot(data=X3_vel[ np.where( y3==1)[0],:], color="green")
		plt.ylim(X1_ylim)
		plt.title("Cluster{0}:Velocity {1}:{2}".format(c, n_0, n_1))
		plt.show()
//  [python]
def show_both( self, c):
		X1part = self.X1part
		X2part = self.X2part
		y = self.y
		cell = self.cell
		X1_ylim = self.X1_ylim
		X2_ylim = self.X2_ylim
		cmethod = self.cmethod
		cparam_d = self.cparam_d

		#print("Cluster:", c)
		X3_int = X2part[ np.where(y==c)[0],:]
		X3_vel = X1part[ np.where(y==c)[0],:]
		
		#km = cluster.KMeans(2)
		#km = getattr(cluster, cmethod)(2)
		km = getattr(cluster, cmethod)(**cparam_d)
		y3 = km.fit_predict( X3_int)

		plt.figure(figsize=(9,4))
		plt.subplot(1,2,1)
		#print("Intensity")
		n_0 = X3_int[ np.where( y3==0)[0]].shape[0]
		n_1 = X3_int[ np.where( y3==1)[0]].shape[0]

		sns.tsplot( X3_int[ np.where( y3==0)[0],:], color="blue")
		sns.tsplot( X3_int[ np.where( y3==1)[0],:], color="green")
		plt.ylim(X2_ylim)
		plt.title("Cluster{0}:X2 {1}:{2}".format(c, n_0, n_1))
		#plt.show()

		plt.subplot(1,2,2)
		#print("Velocity")
		sns.tsplot( X3_vel[ np.where( y3==0)[0],:], color="blue")
		sns.tsplot( X3_vel[ np.where( y3==1)[0],:], color="green")
		plt.ylim(X1_ylim)
		plt.title("Cluster{0}:X1 {1}:{2}".format(c, n_0, n_1))
		plt.show()
		
		cell3 = cell[ np.where(y==c)[0]]
		plt.subplot(1,2,1)
		plt.stem( cell3[np.where( y3==0)[0]], linefmt='b-', markerfmt='bo')
		plt.title("Cell Index - Subcluster 1")
		plt.subplot(1,2,2)
		plt.stem( cell3[np.where( y3==1)[0]], linefmt='g-', markerfmt='go')   
		plt.title("Cell Index - Subcluster 2")
		plt.show()
		
		return y3
//  [python]
def show_both( self, c):
		X1part = self.X1part
		X2part = self.X2part
		y = self.y
		cell = self.cell
		X1_ylim = self.X1_ylim
		X2_ylim = self.X2_ylim
		cmethod = self.cmethod
		cparam_d = self.cparam_d

		#print("Cluster:", c)
		X3_int = X2part[ np.where(y==c)[0],:]
		X3_vel = X1part[ np.where(y==c)[0],:]
		
		#km = cluster.KMeans(2)
		#km = getattr(cluster, cmethod)(2)
		km = getattr(cluster, cmethod)(**cparam_d)
		y3 = km.fit_predict( X3_int)

		plt.figure(figsize=(9,4))
		plt.subplot(1,2,1)
		#print("Intensity")
		n_0 = X3_int[ np.where( y3==0)[0]].shape[0]
		n_1 = X3_int[ np.where( y3==1)[0]].shape[0]

		sns.lineplot(data=X3_int[ np.where( y3==0)[0],:], color="blue")
		sns.lineplot(data=X3_int[ np.where( y3==1)[0],:], color="green")
		plt.ylim(X2_ylim)
		plt.title("Cluster{0}:X2 {1}:{2}".format(c, n_0, n_1))
		#plt.show()

		plt.subplot(1,2,2)
		#print("Velocity")
		sns.lineplot(data=X3_vel[ np.where( y3==0)[0],:], color="blue")
		sns.lineplot(data=X3_vel[ np.where( y3==1)[0],:], color="green")
		plt.ylim(X1_ylim)
		plt.title("Cluster{0}:X1 {1}:{2}".format(c, n_0, n_1))
		plt.show()
		
		cell3 = cell[ np.where(y==c)[0]]
		plt.subplot(1,2,1)
		plt.stem( cell3[np.where( y3==0)[0]], linefmt='b-', markerfmt='bo')
		plt.title("Cell Index - Subcluster 1")
		plt.subplot(1,2,2)
		plt.stem( cell3[np.where( y3==1)[0]], linefmt='g-', markerfmt='go')   
		plt.title("Cell Index - Subcluster 2")
		plt.show()
		
		return y3