Beispiel #1
0
def graph_error_mean_per_hour(dataset, pred, column):
    data = dataset.iloc[dataset.shape[0] - len(pred):]
    data["Pred"] = np.around(pred, 5)
    if column == "Diff":
        res = np.delete(data["Close"].to_numpy(), -1)
        res = np.insert(res, 0, 0)
        data["Pred"] = data["Pred"] + res
    data["AEM"] = np.abs(np.around(data.Close - data.Pred, 5))
    data['Hour'] = data.Date.apply(lambda x: x.hour)
    data["Diff"] = data.Close.diff().apply(abs).fillna(0)

    plt.figure(figsize=(14, 6))
    plt.hist(data.where((data.Hour > 5) & (data.Hour < 20)).dropna()["AEM"],
             150,
             density=True,
             range=(0, 0.003))
    plt.show()

    diff_mean = data.groupby("Hour").mean().Diff
    x_ch = diff_mean.index
    y_ch = diff_mean

    diff_mean_aem = data.groupby("Hour").mean().AEM
    x = diff_mean_aem.index
    y = diff_mean_aem

    plt.figure(figsize=(14, 6))
    plt.bar(x_ch, y_ch, color="green")
    plt.bar(x, y, color="r", alpha=0.7)
    plt.title(
        "Absolute mean of error in predictions per hour compared to absolute mean of price changes",
        fontsize=16)
    plt.show()
Beispiel #2
0
    def _plot(self):
        for label, sample in self.data.items():
            color = _COLOR_CYCLE.next()
            prediction, weight, style = sample
            if self.value_range is None:
                c_min, c_max = numpy.min(prediction), numpy.max(prediction)
            else:
                c_min, c_max = self.value_range
            histo = numpy.histogram(prediction, bins=self.bins, range=(c_min, c_max), weights=weight)
            norm = 1.0
            if self.normalization:
                norm = float(self.bins) / (c_max - c_min) / sum(weight)
            bin_edges = histo[1]
            bin_centers = (bin_edges[:-1] + bin_edges[1:]) / 2.
            bin_widths = (bin_edges[1:] - bin_edges[:-1])

            yerr = []
            for i in range(len(bin_edges) - 1):
                weight_bin = weight[(prediction > bin_edges[i]) * (prediction <= bin_edges[i + 1])]
                yerr.append(numpy.sqrt(sum(weight_bin * weight_bin)) * norm)

            if style == 'filled':
                plt.bar(bin_centers - bin_widths / 2., numpy.array(histo[0]) * norm, facecolor=color,
                        linewidth=0, width=bin_widths, label=label, alpha=0.5)
            else:
                plt.bar(bin_centers - bin_widths / 2., norm * numpy.array(histo[0]),
                        edgecolor=color, color=color, ecolor=color, linewidth=1,
                        width=bin_widths, label=label, alpha=0.5, hatch="/", fill=False)
Beispiel #3
0
    def _plot(self):
        length = len(self.data) + self.step
        if self.sortby is not None:
            inds = numpy.argsort(self.data[self.sortby].values())[::-1]
        else:
            inds = numpy.array(range(len(self.data[self.data.keys()[0]])))
        xticks_labels = numpy.array(self.data[self.data.keys()[0]].keys())[inds]
        for move, (label, sample) in enumerate(self.data.items()):
            color = _COLOR_CYCLE.next()
            index = numpy.arange(len(sample))
            plt.bar(length * index + move, numpy.array(sample.values())[inds], 1., alpha=self.alpha, color=color,
                    label=label)

        plt.xticks(length * numpy.arange(len(inds)), xticks_labels, rotation=90)
Beispiel #4
0
def graph_abs_mean(data):
    """
    This method shows absolute mean of hourly price changes per hour 
    :param data: dataframe with stock price history
    """
    data["Diff"] = data.Open.diff().apply(abs)
    data.Diff = data.Diff.fillna(0)
    data['Hour'] = data.Date.apply(lambda x: x.hour)
    diff_mean = data.groupby("Hour").mean().Diff

    x = diff_mean.index
    y = diff_mean
    plt.figure(figsize=(14, 6))
    plt.bar(x, y)
    plt.title("Absolute mean of hourly price changes from %s to %s" % (data.iloc[0].Date.strftime("%Y-%m-%d"),\
                                                                       data.iloc[-1].Date.strftime("%Y-%m-%d")), fontsize=16)
    plt.show()
def bars(scheme, verbose=None, norm='load'):
    """
    Figure to compare link proportional and usage proportional for a single
    scheme and put them in ./sensitivity/figures/scheme/
    """
    # Load data and results
    F = abs(np.load('./results/' + scheme + '-flows.npy'))
    quantiles = np.load('./results/quantiles_' + scheme + '_' + str(lapse) + '.npy')
    nNodes = 30

    names = node_namer(N)  # array of node labels
    links = range(len(F))
    nodes = np.linspace(0.5, 2 * nNodes - 1.5, nNodes)
    nodes_shift = nodes + .5

    for direction in directions:
        N_usages = np.load('./results/Node_contrib_' + scheme + '_' + direction + '_' + str(lapse) + '.npy')

        # Compare node transmission to mean load
        if verbose:
            print('Plotting node comparison - ' + scheme + ' - ' + direction)
        # sort node names for x-axis
        Total_usage = np.sum(N_usages, 1)
        node_ids = np.array(range(len(N))).reshape((len(N), 1))
        node_mean_load = [n.mean for n in N]

        # Vector for normalisation
        if norm == 'cap':
            normVec = np.ones(nNodes) * sum(quantiles)
        else:
            normVec = node_mean_load

        # Calculate node proportional
        EU_load = np.sum(node_mean_load)
        Total_caps = sum(quantiles)
        Node_proportional = node_mean_load / EU_load * Total_caps / normVec
        Node_proportional = np.reshape(Node_proportional, (len(Node_proportional), 1))

        # Calculate link proportional
        link_proportional = linkProportional(N, link_dic, quantiles)
        link_proportional = [link_proportional[i] / normVec[i] for i in range(nNodes)]

        # Calculate old usage proportional
        if direction == 'combined':
            old_usages = np.load('./linkcolouring/old_' + scheme + '_copper_link_mix_import_all_alpha=same.npy')
            old_usages += np.load('./linkcolouring/old_' + scheme + '_copper_link_mix_export_all_alpha=same.npy')
        else:
            old_usages = np.load('./linkcolouring/old_' + scheme + '_copper_link_mix_' + direction + '_all_alpha=same.npy')
        avg_node_usage = np.sum(np.sum(old_usages, axis=2), axis=0) / 70128.
        avg_EU_usage = np.sum(np.sum(np.sum(old_usages, axis=2), axis=0)) / 70128.
        avg_node_usage /= avg_EU_usage
        avg_node_usage /= normVec
        avg_node_usage *= 500000

        # Calculate usage and sort countries by mean load
        normed_usage = Total_usage / normVec
        normed_usage = np.reshape(normed_usage, (len(normed_usage), 1))
        node_mean_load = np.reshape(node_mean_load, (len(node_mean_load), 1))
        data = np.hstack([normed_usage, node_ids, node_mean_load, link_proportional, Node_proportional])
        data_sort = data[data[:, 2].argsort()]
        names_sort = [names[int(i)] for i in data_sort[:, 1]]
        # flip order so largest is first
        names_sort = names_sort[::-1]
        link_proportional = data_sort[:, 3][::-1]
        Node_proportional = data_sort[:, 4][::-1]
        data_sort = data_sort[:, 0][::-1]

        plt.figure(figsize=(10, 4), facecolor='w', edgecolor='k')
        ax = plt.subplot(111)
        green = '#009900'
        blue = '#000099'

        # Plot node proportional
        plt.rc('lines', lw=2)
        plt.rc('lines', dash_capstyle='round')
        plt.plot(np.linspace(0, len(N) * 2 + 2, len(N)), Node_proportional, '--k')
        # Plot link proportional
        #plt.bar(nodes, link_proportional, width=1, color=green, edgecolor='none')
        # Plot old usage proportional
        plt.bar(nodes, avg_node_usage[loadOrder], width=1, color=green, edgecolor='none')
        # Plot usage proportional
        plt.bar(nodes_shift, data_sort, width=1, color=blue, edgecolor='none')

        # Magic with ticks and labels
        ax.set_xticks(np.linspace(2, len(N) * 2 + 2, len(N) + 1))
        ax.set_xticklabels(names_sort, rotation=60, ha="right", va="top", fontsize=10.5)

        ax.xaxis.grid(False)
        ax.xaxis.set_tick_params(width=0)
        if norm == 'cap':
            ax.set_ylabel(r'$M_n/ \mathcal{K}^T$')
        else:
            # ax.set_ylabel(r'Network usage [MW$_T$/MW$_L$]')
            ax.set_ylabel(r'$M_n/\left\langle L_n \right\rangle$')
        maxes = [max(avg_node_usage), max(data_sort)]
        plt.axis([0, nNodes * 2 + .5, 0, 1.15 * max(maxes)])

        # Legend
        artists = [plt.Line2D([0, 0], [0, 0], ls='dashed', lw=2.0, c='k'), plt.Rectangle((0, 0), 0, 0, ec=green, fc=green), plt.Rectangle((0, 0), 0, 0, ec=blue, fc=blue)]
        LABS = ['$M^1$', '$M^{3}_{old}$', '$M^{3}_{new}$']
        leg = plt.legend(artists, LABS, loc='upper left', ncol=len(artists), columnspacing=0.6, borderpad=0.4, borderaxespad=0.0, handletextpad=0.2, handleheight=1.2)
        leg.get_frame().set_alpha(0)
        leg.get_frame().set_edgecolor('white')
        ltext = leg.get_texts()
        plt.setp(ltext, fontsize=12)    # the legend text fontsize

        plt.savefig(figPath + scheme + '/network-usage-' + direction + '-' + norm + '.png', bbox_inches='tight')
        if verbose:
            print('Saved figures to ./figures/compareUsage/' + scheme + '/network-usage-' + direction + '-' + norm + '.png')
Beispiel #6
0
figure()  # make separate figure

plt.subplot(2, 1, 1)

title('tf-idf results vs abstractive and extractive summaries',
      fontproperties=font_prop)
xlabel('scenario-based meetings', fontproperties=font_prop)
ylabel('accuracy', fontproperties=font_prop)

x1 = [(i + 1) * (3.0) for i in xrange(34)]
x2 = [x - 1.0 for x in x1]

xticks(x1, nucleotides)

plt.bar(x2, [item[0] for item in counts_tfidf],
        width=1.0,
        color="#87CEEB",
        label="w.r.t abstractive resume")
plt.bar(x1, [item[1] for item in counts_tfidf],
        width=1.0,
        color="#F4A460",
        label="w.r.t extractive resume")

plt.gca().yaxis.grid(True)
plt.xlim(0, 105)
plt.ylim(0, 1.2)

plt.legend()

plt.subplot(2, 1, 2)
plt.title(
    'NMF topic modelling results vs abstractive and extractive summaries',