Example #1
0
# Launch the learning
with tf.Session() as session:
    session.run(init)
    
    # Iterate all the episodes
    for i in range(episodes):
        print("\nEPISODE: ",i)
        
        # Store cummulative reward per episode
        cumm_r_list.append(cumm_r)
        cumm_r = 0
        
        # Instances of the environment
        generator = dn.Node(powerSetPoint=3.15)
        load = dn.Node(powerSetPoint=-3.15+ (-0.25+np.random.rand()/2))
        area = dn.Area(frequencySetPoint=50,M=1,D=0)
        area.calculateDeltaF([generator,load])
        
        # Iterate all over the steps
        for j in range(steps):
            
            # Choose the greedy action and the Q values
            current_f = area.getDeltaF()
            a,Q_values = session.run([mainNet.predict,mainNet.Qout],
                                     feed_dict={mainNet.inputs:np.array(current_f).reshape(1,1)})
            a = a[0]
            
            # Explore if epsilon parameter agrees
            if np.random.rand() < epsilon:
                a = np.random.randint(0,2)
            
Example #2
0
import matplotlib.pyplot as plt
import architectures
import numpy as np
import dynamics as dn
import rl

# Model and reward to test algorithms
model_path = "../models/dueling_ddqn"
reward_path = "cummulative_reward_dueling_ddqn.pickle"

reward = rl.readData(reward_path)

# Instances of the environment
generator = dn.Node(powerSetPoint=3.15)
load = dn.Node(powerSetPoint=-3.30)
area = dn.Area(frequencySetPoint=50, M=0.1, D=0.0160)
area.calculateDeltaF([generator, load])

# Define list of powers and frequencies
power = []
frequencies = []

# Let's tensorflow this
tf.reset_default_graph()
graph = tf.train.import_meta_graph(model_path + ".meta")

steps = 100

with tf.Session() as session:
    # Restore values of the graph
    graph.restore(session, model_path)
Example #3
0
import tensorflow as tf
import matplotlib.pyplot as plt
import matplotlib
import architecture
import numpy as np
import dynamics as dn
import pickle as pck

with open("rewards/two_gens.pickle", "rb") as handle:
    reward = pck.load(handle)

generator_1 = dn.Generator(1.5, alpha=2)
generator_2 = dn.Generator(1.5, alpha=1)

area = dn.Area(f_set_point=50, m=0.1, d=0.0160, t_g=30, r_d=0.1)
area.set_load(3.15)
area.set_generation(3.0)
area.calculate_delta_f(wiener=True)

z_1 = []
z_2 = []
dz_1 = []
dz_2 = []
ps = []
fs = []
dw = []

tf.reset_default_graph()
graph = tf.train.import_meta_graph("model/model_two_gens.meta")

steps = 100