Skip to content

Commit

Permalink
SysID v1.0.0
Browse files Browse the repository at this point in the history
- Minor improvements
- Empty worksheet warning
- Performance improvements
  • Loading branch information
imanbabaei committed Apr 5, 2023
1 parent 9f7dfae commit 29a050c
Show file tree
Hide file tree
Showing 19 changed files with 158 additions and 33 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,14 @@ run `developer_notebook.ipynb` notebook there.

# Changelog

## v1.0.0
- Minor improvements
- Empty worksheet warning
- Performance improvements

## v0.7.1
- Hotfix: dependencies updated for R57>=

## v0.7.0
- Performance improvement in TF identification
- Progress bar added to TF identification
Expand Down
8 changes: 8 additions & 0 deletions SysID Addon/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,14 @@ run `developer_notebook.ipynb` notebook there.

# Changelog

## v1.0.0
- Minor improvements
- Empty worksheet warning
- Performance improvements

## v0.7.1
- Hotfix: dependencies updated for R57>=

## v0.7.0
- Performance improvement in TF identification
- Progress bar added to TF identification
Expand Down
2 changes: 1 addition & 1 deletion SysID Addon/seeq_sysid/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.7.0'
__version__ = '1.0.0'
40 changes: 36 additions & 4 deletions SysID Addon/seeq_sysid/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@
from seeq_sysid.gui._backend import *
import urllib.parse as urlparse
from urllib.parse import parse_qs
from seeq import spy

try:
from seeq import spy
except:
from seeq_sysid.model.utils import SPY as spy

import warnings
warnings.filterwarnings('ignore')
Expand Down Expand Up @@ -61,6 +65,14 @@ def __init__(self, sdl_notebook_url=''):
self.signal_df = DataFrame()
self.capsule_df = DataFrame()
self.tags_df = DataFrame()

# Empty df warning
self.not_enough_data = v.Snackbar(v_model=False,
class_='ma-4 pa-4',
children=['Not enough data. Please add at least two numerical signals.'],
color='rgba(0, 0, 0, 0.8)',
multi_line=True,
timeout=8000)

# Local Mode
# self.signal_df = read_csv('data/TE_signal_lite.csv', index_col='Time')
Expand Down Expand Up @@ -142,7 +154,11 @@ def __init__(self, sdl_notebook_url=''):
def run(self):
clear_output()
display(HTML("""<style>.container {width:100% !important}</style>"""))
self.app.children = [self.app_bar, SYSID.additional_styles]
self.app.children = [self.app_bar, SYSID.additional_styles, self.not_enough_data]

if len(self.signal_df.columns) < 2:
self.not_enough_data.v_model = True

return self.app


Expand All @@ -156,6 +172,7 @@ def load_worksheet(self):
self.signal_df, self.capsule_df, self.tags_df = pull_signals(self.worksheet_url)
else:
self.signal_df = self.app_bar.ham_menu.local_data



self.arx_sheet = ARXAppSheet()
Expand Down Expand Up @@ -193,6 +210,10 @@ def load_worksheet(self):

items = [self.tf_tab_items, self.arx_tab_item, self.ss_tab_items, self.nn_tab_items]

if self.app_bar.ham_menu.sl_switch.v_model:
if not self.signal_df.empty:
self.sl_switch()

self.app_bar = AppBar(self.tabs, items)

self.worksheet_url_box = self.app_bar.ham_menu.worksheet_url
Expand All @@ -208,8 +229,12 @@ def load_worksheet(self):

clear_output()
display(HTML("""<style>.container {width:100% !important}</style>"""))
self.app.children = [self.app_bar, SYSID.additional_styles]
display(self.app)
self.app.children = [self.app_bar, SYSID.additional_styles, self.not_enough_data]

display(self.app)

if len(self.signal_df.columns) < 2:
self.not_enough_data.v_model = True

def close_url_action(self, *args):
self.worksheet_url_box.v_model = self.worksheet_url
Expand All @@ -223,6 +248,13 @@ def ok_url_action(self, *args):
self.ok_url_dialog_btn.loading = False
self.app_bar.ham_menu.url_dialog.v_model = None

def sl_switch(self):
self.arx_sheet.panel.push_model_btn.on_event('click', lambda _, *args: _)
self.ss_sheet.panel.push_model_btn.on_event('click', lambda _, *args: _)
self.nn_sheet.panel.push_model_btn.on_event('click', lambda _, *args: _)
self.tf_sheet.app_bar.push_btn.on_event('click', lambda _, *args: _)
self.app_bar.ham_menu.sl_switch.show()

# DataEditor event functions (Post)
def load_data_editor_action(self, *args):
self.app_bar.ham_menu.data_editor.set_data(self.signal_df)
Expand Down
11 changes: 7 additions & 4 deletions SysID Addon/seeq_sysid/gui/_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
from IPython.display import clear_output

from pandas import DataFrame
from seeq import spy

try:
from seeq import spy
except:
from seeq_sysid.model.utils import SPY as spy

def pull_signals(url, grid='auto'):
worksheet = spy.utils.get_analysis_worksheet_from_url(url)
Expand All @@ -20,9 +23,6 @@ def pull_signals(url, grid='auto'):
except:
search_df = spy.search(url, estimate_sample_period=worksheet.display_range, status=spy.Status(quiet=True))

capsules_list = search_df[search_df['Type'].str.contains('CalculatedCondition')]['Name'].to_list()
signal_list = search_df[search_df['Type'].str.contains('Signal')]['Name'].to_list()

if search_df.empty:
return DataFrame(), DataFrame(), DataFrame()
search_all_df = search_df[search_df['Type'].str.contains('al')]
Expand All @@ -38,6 +38,9 @@ def pull_signals(url, grid='auto'):
if all_df.empty:
return DataFrame(), DataFrame(), DataFrame()

signal_list = search_df[search_df['Type'].str.contains('Signal')]['Name'].to_list()
capsules_list = search_df[search_df['Type'].str.contains('CalculatedCondition')]['Name'].to_list()

# if hasattr(all_df, 'spy') and hasattr(all_df.spy, 'query_df'):
# all_df.columns = all_df.spy.query_df['Name']
# elif hasattr(all_df, 'query_df'):
Expand Down
5 changes: 4 additions & 1 deletion SysID Addon/seeq_sysid/model/arx.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from gekko import GEKKO
from seeq import spy

from numpy import vstack, zeros, ones, reshape, array, zeros_like, diff
from pandas import DataFrame
Expand All @@ -8,6 +7,10 @@
from re import split
from scipy.linalg import lstsq

try:
from seeq import spy
except:
from seeq_sysid.model.utils import SPY as spy

def create_formula_variable_name(names):
formula_name = []
Expand Down
12 changes: 7 additions & 5 deletions SysID Addon/seeq_sysid/model/nn.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ def identify(self, df: DataFrame = None):
self.option_maker()

# Early Stopping
tune_es = callbacks.EarlyStopping(monitor='val_loss', patience=3)
fit_es = callbacks.EarlyStopping(monitor='val_loss', patience=15)
tune_es = callbacks.EarlyStopping(monitor='val_loss', patience=3, verbose=0)
fit_es = callbacks.EarlyStopping(monitor='val_loss', patience=15, verbose=0)

# Number of Inputs & Outputs
self.p = len(self.mv + self.cv)
Expand Down Expand Up @@ -130,7 +130,9 @@ def identify(self, df: DataFrame = None):
# Get the optimal hyperparameters
best_hps = tuner.get_best_hyperparameters(num_trials=1)[0]


model = tuner.hypermodel.build(best_hps)


# Training Performance
self.history = model.fit(x_train, y_train, epochs=1000, validation_split=0.2, callbacks=[fit_es], verbose=0)
Expand All @@ -146,8 +148,8 @@ def forecast(self, df: DataFrame = None):
in_df = df_norm[self.mv+self.cv]
x_train, _ = self.create_snapshot(in_df=in_df)

yp_norm = self.model.predict(x_train)

yp_norm = self.model.predict(x_train, verbose=0)
yp_norm_df = DataFrame(yp_norm, columns=self.cv)
yp_df = self.denormalize(yp_norm_df)
dummy_rows = df[self.cv].iloc[:self.window].shift(self.window)
Expand Down Expand Up @@ -199,4 +201,4 @@ def __init__(self, auto_bs: list, *args, **kwargs):

def run_trial(self, trial, *args, **kwargs):
kwargs['batch_size'] = trial.hyperparameters.Choice('batch_size', self.auto_bs)
super(HyperTuner, self).run_trial(trial, *args, **kwargs)
return super(HyperTuner, self).run_trial(trial, *args, **kwargs)
7 changes: 5 additions & 2 deletions SysID Addon/seeq_sysid/model/tf.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
from seeq import spy

from .tf_item import TransferItem, TransferOption
from numpy import empty, array, zeros, arange, linspace, zeros_like, isnan
from pandas import DataFrame
from scipy.signal import TransferFunction
from .arx import create_formula_variable_name

try:
from seeq import spy
except:
from seeq_sysid.model.utils import SPY as spy


class TF(TransferItem):
def __init__(self):
Expand Down
36 changes: 36 additions & 0 deletions SysID Addon/seeq_sysid/model/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,39 @@ def shifter(df_o: DataFrame, dummy_state) -> DataFrame:
df_n.fillna(method='bfill', inplace=True)

return df_n


class SPY:
def __init__(self):
pass

class utils:
def get_analysis_worksheet_from_url(self, url=''):
pass

def get_data_lab_project_url(self, url=''):
pass

def get_workbook_id_from_url(self, worksheet_url=''):
pass

def get_worksheet_id_from_url(self, worksheet_url=''):
pass

def pull(self, df=None, start=None, end=None, grid='auto',
header='Name', quiet=True, status=None):
pass

def Status(self, quiet=True):
pass

def push(df, metadata=None, workbook='', worksheet='', quiet=True,
status=None):
pass

def search(url=None, estimate_sample_period=None, quiet=True,
status=None):
pass



11 changes: 4 additions & 7 deletions SysID Addon/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setup(
name='seeq_sysid',
version='0.7.0',
version='1.0.0',
packages=find_packages(),
url='https://github.com/BYU-PRISM/Seeq',
license='MIT',
Expand All @@ -16,18 +16,15 @@
long_description_content_type='text/markdown',
install_requires=[
'ipyvuetify>=1.5.1',
'gekko~=1.0.6',
'gekko>=1.0.6',
'numpy',
'pandas>=1.2.1',
'plotly>=4.5.0',
'python-dateutil>=2.8.1',
'tensorflow~=2.5',
'tensorflow>=2.5',
'keras-tuner==1.0.4',
'scipy',
'seeq',
'seeq-spy',
'jupyter',
'voila'
'protobuf~=3.20',
],
keywords='Seeq Prism System Identification ARX FIR ARIMAX Subspace State-Space Neural-Network Addon Time-Series Transfer Function',
include_package_data=True,
Expand Down
9 changes: 4 additions & 5 deletions SysID Addon/sysid_notebook.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@
"outputs": [],
"source": [
"from seeq_sysid.app import SYSID\n",
"from seeq import spy\n",
"from IPython.display import Javascript\n",
"# from IPython.display import Javascript\n",
"\n",
"jv = '''$('#header-container').hide();'''\n",
"Javascript(jv)"
"# jv = '''$('#header-container').hide();'''\n",
"# Javascript(jv)"
]
},
{
Expand Down Expand Up @@ -92,7 +91,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.9"
"version": "3.8.10"
},
"vscode": {
"interpreter": {
Expand Down
8 changes: 8 additions & 0 deletions docs/_sources/pages/changelog.md.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## v1.0.0
- Minor improvements
- Empty worksheet warning
- Performance improvements

## v0.7.1
- Hotfix: dependencies updated for R57>=

## v0.7.0
- Performance improvement in TF identification
- Progress bar added to TF identification
Expand Down
2 changes: 1 addition & 1 deletion docs/_sources/pages/citation.md.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Please cite this work as:

```shell
seeq-sysid v0.7.0
seeq-sysid v1.0.0
BYU PRISM Group https://apm.byu.edu/prism/
https://github.com/BYU-PRISM/Seeq
```
2 changes: 2 additions & 0 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ <h2>Contents<a class="headerlink" href="#contents" title="Permalink to this head
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="pages/changelog.html">Changelog</a><ul>
<li class="toctree-l2"><a class="reference internal" href="pages/changelog.html#v1-0-0">v1.0.0</a></li>
<li class="toctree-l2"><a class="reference internal" href="pages/changelog.html#v0-7-1">v0.7.1</a></li>
<li class="toctree-l2"><a class="reference internal" href="pages/changelog.html#v0-7-0">v0.7.0</a></li>
<li class="toctree-l2"><a class="reference internal" href="pages/changelog.html#v0-6-1">v0.6.1</a></li>
<li class="toctree-l2"><a class="reference internal" href="pages/changelog.html#v0-6-0">v0.6.0</a></li>
Expand Down
16 changes: 16 additions & 0 deletions docs/pages/changelog.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
<li class="toctree-l1"><a class="reference internal" href="user_guide.html">User Guide</a></li>
<li class="toctree-l1"><a class="reference internal" href="examples.html">Examples</a></li>
<li class="toctree-l1 current"><a class="current reference internal" href="#">Changelog</a><ul>
<li class="toctree-l2"><a class="reference internal" href="#v1-0-0">v1.0.0</a></li>
<li class="toctree-l2"><a class="reference internal" href="#v0-7-1">v0.7.1</a></li>
<li class="toctree-l2"><a class="reference internal" href="#v0-7-0">v0.7.0</a></li>
<li class="toctree-l2"><a class="reference internal" href="#v0-6-1">v0.6.1</a></li>
<li class="toctree-l2"><a class="reference internal" href="#v0-6-0">v0.6.0</a></li>
Expand Down Expand Up @@ -91,6 +93,20 @@

<section id="changelog">
<h1>Changelog<a class="headerlink" href="#changelog" title="Permalink to this headline"></a></h1>
<section id="v1-0-0">
<h2>v1.0.0<a class="headerlink" href="#v1-0-0" title="Permalink to this headline"></a></h2>
<ul class="simple">
<li><p>Minor improvements</p></li>
<li><p>Empty worksheet warning</p></li>
<li><p>Performance improvements</p></li>
</ul>
</section>
<section id="v0-7-1">
<h2>v0.7.1<a class="headerlink" href="#v0-7-1" title="Permalink to this headline"></a></h2>
<ul class="simple">
<li><p>Hotfix: dependencies updated for R57&gt;=</p></li>
</ul>
</section>
<section id="v0-7-0">
<h2>v0.7.0<a class="headerlink" href="#v0-7-0" title="Permalink to this headline"></a></h2>
<ul class="simple">
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/citation.html
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
<section id="citation">
<h1>Citation<a class="headerlink" href="#citation" title="Permalink to this headline"></a></h1>
<p>Please cite this work as:</p>
<div class="highlight-shell notranslate"><div class="highlight"><pre><span></span>seeq-sysid v0.7.0
<div class="highlight-shell notranslate"><div class="highlight"><pre><span></span>seeq-sysid v1.0.0
BYU PRISM Group https://apm.byu.edu/prism/
https://github.com/BYU-PRISM/Seeq
</pre></div>
Expand Down
Loading

0 comments on commit 29a050c

Please sign in to comment.