File size: 1,753 Bytes
a241478
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import os
import matplotlib.pyplot as plt
import numpy as np 
import pandas as pd
import matplotlib.pyplot as plt
from scipy.stats import binom,gamma


def generate_binomial_probs(size = 5,n = 5, p= 0.5,plot = True):
    """
    To print the binomial distribtion vector and plot a discreate binomial distribution
    """
    plt.rcParams.update({'font.family':'times new roman'})

    rv = binom(n, p)

    x = np.arange(size)
    probs = rv.pmf(x)
    diff = 1 - sum(probs)
    diff = diff/len(probs)
    probs = probs + diff
    print('------binomial------')
    print(x)
    print(probs)
    if plot:
        plt.vlines(x, 0, probs, colors='k', linestyles='-', lw=1)
        plt.legend(loc='best', frameon=False)
        plt.savefig(os.path.join('results', 'binomial_dist_2.pdf'))
        plt.show()
        

def plot_ep_evol(folder = 'binomial_3',seed = 0,model_names = ['VI','VIMC','PPO','SP','PSO'],x_type = 'reward',y_label = 'Cost'):    
    plt.rcParams.update({'font.family':'times new roman'})
    fig, axs = plt.subplots(len(model_names),figsize=(20,10))

    i = 0
    for model in model_names:
        x = np.abs(
            np.load(
                    os.path.join(
                        'results',
                        'binomial',
                        f'{model}_{folder}_{x_type}_test_{seed}.npy'
                    )
                )
            )
        axs[i].plot(x[:100],label = model)
        axs[i].set_title(model)
        i += 1

    for ax in axs.flat:
        ax.set(xlabel='Time steps', ylabel=y_label)

    for ax in axs.flat:
        ax.label_outer()    
    plt.savefig(
        os.path.join(
            'results',
            f'evol_reward_{folder}_{seed}.pdf'
        ),
        bbox_inches='tight'
    )