Commit 8e822f99 authored by Ibrahim's avatar Ibrahim
Browse files

new feedback signal

parent b9eea286
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -2,10 +2,11 @@ name: esb-prod
channels:
  - conda-forge
dependencies:
  - python=3.7
  - python=3.9
  - numpy
  - scipy
  - pytorch::cpuonly
  - pytorch::pytorch=1.8
  - pytorch::pytorch=1.10
  - pandas
  - matplotlib
  - tqdm
+2 −1
Original line number Diff line number Diff line
@@ -96,7 +96,7 @@ def get_settings(parsed_args: Namespace, section: str='DEFAULT', write_settings=
        # and which had non empty values
        # if (setting not in settings) or (settings.get(setting) is None):
        # Float conversion
        if setting in ('stepsize', 'window', 'interval'):
        if setting in ('stepsize', 'window', 'interval', 'tolerance'):
            settings[setting] = float(value)
        # Integer conversion
        elif setting in ('logs_email_batchsize', 'port'):
@@ -161,6 +161,7 @@ def run(controller_name: str, ev_halt: th.Event):
    logger.debug(controller_name + '\n' \
                 + pformat({s:v for s, v in settings.items() if s not in('username', 'password')}))
    # Dynamically import controller functions from submodule
    logger.debug('CTRL MODULE: %s', 'controllers.%s' % settings['import_path'])
    ctrl_module = importlib.import_module('controllers.%s' % settings['import_path'])
    get_controller = getattr(ctrl_module, 'get_controller')
    get_current_state = getattr(ctrl_module, 'get_current_state')
+8 −7
Original line number Diff line number Diff line
@@ -12,14 +12,14 @@ the following interface:
from typing import Union, Tuple
from collections import deque

from sklearn.base import BaseEstimator
# from sklearn.base import BaseEstimator
import numpy as np
import pandas as pd
from scipy.optimize import minimize



class GridSearchController(BaseEstimator):
class GridSearchController:


    def __init__(self, model, bounds, resolution, vary_idx):
@@ -62,7 +62,7 @@ class GridSearchController(BaseEstimator):



class QuasiNewtonController(BaseEstimator):
class QuasiNewtonController:


    def __init__(self, model, bounds, resolution, vary_idx):
@@ -90,7 +90,7 @@ class QuasiNewtonController(BaseEstimator):



class BinaryApproachController(BaseEstimator):
class BinaryApproachController:
     # See: http://www.computrols.com/cooling-tower-control-based-approach/

    def __init__(self, model, bounds, resolution, vary_idx, margin):
@@ -111,7 +111,7 @@ class BinaryApproachController(BaseEstimator):



class FeedbackController(BaseEstimator):
class FeedbackController:

    def __init__(self, bounds, kp: float=1., ki: float=1., kd: float=1., window: int=1):
        self.bounds = np.asarray(bounds)
@@ -176,9 +176,10 @@ class FeedbackController(BaseEstimator):



class SimpleFeedbackController(BaseEstimator):
class SimpleFeedbackController:

    def __init__(self, bounds, stepsize:float=1, window: int=1, tolerance: float=0.5, seed=None):
    def __init__(self, bounds, stepsize:float=1, window: int=1, tolerance: float=0.1, seed=None):
        super().__init__()
        self.bounds = np.asarray(bounds) # 2D array of [(min, max)] for setpoint
        self.stepsize = stepsize
        self.window = window
+2 −2
Original line number Diff line number Diff line
@@ -10,7 +10,7 @@ import pandas as pd
import bdx

from .baseline_control import SimpleFeedbackController
from .rl_control import RLContinuousController
# from .rl_control import RLContinuousController



@@ -48,7 +48,7 @@ def get_controller(**settings):
    stepsize, window = settings['stepsize'], settings['window']
    setpoint_bounds = settings['bounds']
    ctrl = Controller(bounds=setpoint_bounds, stepsize=stepsize, window=window,
                      target=settings['target'])
                      target=settings['target'], tolerance=settings['tolerance'])
    return ctrl


+4 −4
Original line number Diff line number Diff line
@@ -17,13 +17,13 @@ from .esb import update_controller

class Controller(SimpleFeedbackController):

        def __init__(self, bounds, stepsize, window, target):
            super().__init__(bounds=bounds, stepsize=stepsize, window=window)
        def __init__(self, bounds, stepsize, window, tolerance, target):
            super().__init__(bounds=bounds, stepsize=stepsize, tolerance=tolerance, window=window)
            self.target = target

        def feedback(self, X):
            if self.target == 'temperature':
                f = -X['CT_1.TempCondIn']
                f = -(X['CT_1.TempCondIn'] - X['TempWetBulb'])
                if np.isnan(f):
                    raise ValueError('CT_1.TempCondIn is NaN. Could not calculate feedback.')
                return f
@@ -41,7 +41,7 @@ def get_controller(**settings):
    stepsize, window = settings['stepsize'], settings['window']
    setpoint_bounds = settings['bounds']
    ctrl = Controller(bounds=setpoint_bounds, stepsize=stepsize, window=window,
                      target=settings['target'])
                      target=settings['target'], tolerance=settings['tolerance'])
    return ctrl


Loading