Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
SINDyc And MCMC Framework
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
freba
SINDyc And MCMC Framework
Commits
4366bbfc
Commit
4366bbfc
authored
Sep 21, 2020
by
freba
Browse files
Options
Downloads
Patches
Plain Diff
Added docstrings: cls `Plotter`.
parent
0cff2bc8
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
Documentation.org
+202
-68
202 additions, 68 deletions
Documentation.org
with
202 additions
and
68 deletions
Documentation.org
+
202
−
68
View file @
4366bbfc
...
...
@@ -354,7 +354,7 @@ def rename(df0, df1, identifier="id"):
sns.set_palette([sns.color_palette("Blues_r")[1], sns.color_palette("Greens_r")[1]])
filename = plot_sns(
filename =
Plotter.
plot_sns(
dfs=dict(
ts_id=dict(system=df, model=dfm), ts_oos=dict(system=df_oos, model=dfm_oos)
),
...
...
@@ -636,8 +636,9 @@ filepath = Plotter.plot_density(stan_results,
#+END_SRC
This code block is associated with subfigure (b) in Figure 5.
#+NAME: c1_stan_ppc
#+begin_src python :exports
non
e :results file :tangle ./Scripts/c1_stan_ppc.py :noweb yes :return filepath
#+begin_src python :exports
cod
e :results file :tangle ./Scripts/c1_stan_ppc.py :noweb yes :return filepath
import numpy as np
<<paper_plotting_header>>
import arviz as az
...
...
@@ -686,8 +687,9 @@ filepath = Plotter.plot_ppc(
#+end_src
This code block is associated with Figure 6.
#+NAME: stan_cosimulate_ID_c0
#+begin_src python :results file :exports
results
:return filename :tangle ./Scripts/stan_cosimulate_ID_c0.py :noweb yes
#+begin_src python :results file :exports
both
:return filename :tangle ./Scripts/stan_cosimulate_ID_c0.py :noweb yes
from collections import OrderedDict
import numpy as np
...
...
@@ -739,7 +741,7 @@ filename = Plotter.plot_sectors(
#+end_src
*
TODO
Stan submodels
*
WAIT
Stan submodels
#+NAME: sindyc_stan_code_12
#+begin_src stan :exports code :results none :tangle ./Scripts/sindyc_stan_code_12.stan
...
...
@@ -836,7 +838,7 @@ generated quantities {
#+end_src
#+NAME: sindyc_stan_code_23
#+begin_src stan :exports
cod
e :results none :tangle ./Scripts/sindyc_stan_code_23.stan
#+begin_src stan :exports
non
e :results none :tangle ./Scripts/sindyc_stan_code_23.stan
functions {
real[] dy_dt(real t, real[] y, real[] xi, real[] params, int[] ncupoly) {
vector[ncupoly[1]] poly;
...
...
@@ -930,7 +932,7 @@ generated quantities {
#+end_src
#+NAME: sindyc_stan_code_34
#+begin_src stan :exports
cod
e :results none :tangle ./Scripts/sindyc_stan_code_34.stan
#+begin_src stan :exports
non
e :results none :tangle ./Scripts/sindyc_stan_code_34.stan
functions {
real[] dy_dt(real t, real[] y, real[] xi, real[] params, int[] ncupoly) {
vector[ncupoly[1]] poly;
...
...
@@ -1024,7 +1026,7 @@ generated quantities {
#+end_src
#+NAME: sindyc_stan_code_345
#+begin_src stan :exports
cod
e :results none :tangle ./Scripts/sindyc_stan_code_345.stan
#+begin_src stan :exports
non
e :results none :tangle ./Scripts/sindyc_stan_code_345.stan
functions {
real[] dy_dt(real t, real[] y, real[] xi, real[] params, int[] ncupoly) {
vector[ncupoly[1]] poly;
...
...
@@ -1122,7 +1124,7 @@ generated quantities {
#+end_src
#+NAME: sindyc_stan_code_124
#+begin_src stan :exports
cod
e :results none :tangle ./Scripts/sindyc_stan_code_124.stan
#+begin_src stan :exports
non
e :results none :tangle ./Scripts/sindyc_stan_code_124.stan
functions {
real[] dy_dt(real t, real[] y, real[] xi, real[] params, int[] ncupoly) {
vector[ncupoly[1]] poly;
...
...
@@ -1220,7 +1222,7 @@ generated quantities {
#+end_src
#+NAME: sindyc_stan_code_1234
#+begin_src stan :exports
cod
e :results none :tangle ./Scripts/sindyc_stan_code_1234.stan
#+begin_src stan :exports
non
e :results none :tangle ./Scripts/sindyc_stan_code_1234.stan
functions {
real[] dy_dt(real t, real[] y, real[] xi, real[] params, int[] ncupoly) {
vector[ncupoly[1]] poly;
...
...
@@ -1376,7 +1378,7 @@ def read_from_disc(filename="save.pkl"):
*** Prosumer dynamics
Common prosumer response dynamics
shared for both the SIMO as well as MIMO example
.
Common prosumer response dynamics.
#+NAME: paper_prosumerDynamics
#+begin_src python :results none :exports code
...
...
@@ -1478,7 +1480,9 @@ class Prosumer:
#+end_src
*** SINDyc identification
*** TODO SINDyc identification
#+NAME: code_identification
#+begin_src python
...
...
@@ -1557,7 +1561,7 @@ class Identification:
#+end_src
*** Stan identification
***
TODO
Stan identification
#+NAME: code_stan_fitModel
#+begin_src python :results none :exports code
...
...
@@ -1950,7 +1954,11 @@ y_init_rep[1] = normal_rng(z_init[1], sigma[1]);
#+end_src
*** Signal generator
*** TODO Signal generator
Signal generation:
- ...
#+NAME: code_signal_generator
#+begin_src python
...
...
@@ -2063,6 +2071,10 @@ class SignalGenerator:
*** Evaluation
Model performance evaluation routines:
- ...
#+NAME: code_evaluate_fit
#+begin_src python :exports code :results none
def evaluate(systraj, modeltraj, method='nrmse', n=None, t=5):
...
...
@@ -2159,8 +2171,10 @@ def evaluate(systraj, modeltraj, method='nrmse', n=None, t=5):
** Simulation
A common simulation header:
#+NAME: paper_simulation
#+begin_src python :noweb strip-export :exports
non
e
#+begin_src python :noweb strip-export :exports
cod
e
<<paper_simulation_header>>
<<code_signal_generator>>
<<code_identification>>
...
...
@@ -2172,7 +2186,11 @@ simulator = Simulator(simspec, mp) # Initialize simulation
#+end_src
*** System simulation
*** TODO System simulation
General system simulation routines:
- ...
#+NAME: code_system_simulator
#+begin_src python
...
...
@@ -2522,7 +2540,11 @@ class SystemSimulator:
#+end_src
*** Simulator class
*** TODO Simulator class
SINDyc system simulation routines:
- ...
#+NAME: paper_simulation_class
#+begin_src python :noweb strip-export :exports none
...
...
@@ -3507,7 +3529,22 @@ class Simulator(SystemSimulator):
#+end_src
** Plotting
** WAIT Plotting
Common plotting routines:
- =annotate= :: Annotate axis instance `ax` with `annotation`.
- =postprocess= :: Plotting postprocessing routines.
- =generate_filepath= :: Wrapper around `os.path.join`, concatenates the default `PLOTPATH` and provided `filename`.
- =savefig= :: Save current figure to absolute filepath via `generate_filepath`.
- =plot_y= :: Plot series `y` in list of pandas DataFrames `dfs` to `filename`.
- =plot_yu= :: Plot series `y` and `u` in list of pandas DataFrames `dfs` with defaults.
- =plot3D= :: Plot in three dimensions.
- =plot_density= :: Plot the posterior density of the variables specified in `var_names`.
- =plot_ppc= :: TODO
- =plot_draws :: TODO
- =plot_sectors= :: TODO
- =plot_sns= :: TODO
#+NAME: paper_plotting_header
#+begin_src python
...
...
@@ -3531,8 +3568,12 @@ class Plotter:
large = (10, 8)
@classmethod
def annotate(self, ax, annotation):
"""
def annotate(self, ax, annotation) -> None:
"""Annotate axis instance `ax` with `annotation`.
Args:
ax (obj): Instance of `matplotlib.pyplot.Axes`.
annotation (str): Text to be added as annotation.
"""
def set_text(ax, text):
...
...
@@ -3567,7 +3608,12 @@ class Plotter:
print("Failed to annotate axis.")
@classmethod
def postprocess(self, axs, **kwargs):
def postprocess(self, axs, **kwargs) -> None:
"""Plotting postprocessing routines.
Args:
axs (list): List of `matplotlib.pyplot.Axes` instances.
"""
ax_labels = kwargs.get("labels")
if ax_labels is not None:
if isinstance(ax_labels, list):
...
...
@@ -3608,17 +3654,43 @@ class Plotter:
sns.despine()
@classmethod
def generate_filepath(self, filename):
def generate_filepath(self, filename) -> str:
"""Wrapper around `os.path.join`, concatenates the default `PLOTPATH`
and provided `filename`.
Args:
filename (str): Filename.
Returns:
absolute_path (str): Absolute filepath.
"""
return os.path.join(PLOTPATH, filename)
@classmethod
def savefig(self, filename):
def savefig(self, filename) -> str:
"""Save current figure to absolute filepath via `generate_filepath`.
Args:
filename (str): Filename.
Returns:
filepath (str): Absolute filepath.
"""
filepath = self.generate_filepath(filename)
plt.savefig(filepath, transparent=True)
return filepath
@classmethod
def plot_y(self, dfs, filename, **kwargs):
def plot_y(self, dfs, filename, **kwargs) -> str:
"""Plot series `y` in list of pandas DataFrames `dfs` to `filename`.
Args:
dfs (list): Of pandas DataFrames.
filename (str): Filename to save to.
Returns:
absolute_filepath (str): Of saved plot.
"""
_, ax = plt.subplots(figsize=kwargs.get("figsize", (8, 4)))
for linestyle, df in zip(Plotter.linestyles, dfs):
...
...
@@ -3646,7 +3718,25 @@ class Plotter:
bw=True,
axs=None,
,**kwargs,
):
) -> str:
"""Plot series `y` and `u` in list of pandas DataFrames `dfs` with
defaults.
Args:
dfs (list): Of pandas DataFrames.
filename (str): Filename to save to.
show (bool): Whether or not to show plotted figure.
save (bool): Whether or not to save plotted figure.
df_P (None/pd.DataFrame): DataFrame with uncertainty estimates.
forcesingle_u (bool): When using a single excitation signal, plot
only this one.
bw (bool): Toggle black and white plotting.
axs (list): Of `matplotlib.pyplot.Axes` instances.
Returns:
absolute_filepath (str): Returned conditionally, based on argument
`save`.
"""
gridspec_kw = kwargs.get("gridspec_kw", None)
if axs is None:
_, axs = plt.subplots(
...
...
@@ -3718,6 +3808,29 @@ class Plotter:
filename="plot3D.pdf",
,**kwargs,
):
"""Plot in three dimensions.
Args:
ode_lin (fun): Linear functional, must accept two array arguments
corresponding to the `x` and `u` spaces (input spaces).
ode_nl (fun): Nonlinear functional, must accept two array arguments
corresponding to the `x` and `u` spaces (input spaces).
xmin (float): Lower boundary definition (`x` space).
xmax (float): Upper boundary definition (`x` space).
umin (float): Lower boundary definition (`u` space).
umax (float): Upper boundary definition (`u` space).
zlim (tuple): Boundary definition (`z` space).
step (float): Grid size.
show (bool): Flag indicating whether to show the plot.
save (bool): Flag indicating whether to save the plot.
fig (None/obj): Figure instance.
ax (None/obj): Axes instance.
filename (str): Filename.
Returns:
None/str/obj: Conditionally returns `None`, plot path (`str`) or
an object `obj`, depending on the input arguments.
"""
from matplotlib.ticker import LinearLocator, FormatStrFormatter
...
...
@@ -3799,6 +3912,26 @@ class Plotter:
):
"""Plot the posterior density of the variables specified in
`var_names`.
Args:
stan_results (dict): Dictionary with results keyed
`densities, fit, df`.
var_names (dict): Dictionary with variable name definitions.
filename (str): Filename specification.
resolution (int): Kernel density evaluation space specification.
var_prior (None): Prior values to plot.
mark_max_LL (bool): Specify whether to mark maximum likelihood in
the plot.
ci (list): Of floating point values defining confidence intervals.
original_model_obj (None): Obtain original model densities.
show (bool): Flag indicating whether to show the plot.
save (bool): Flag indicating whether to save the plot.
var_labels (None/list): If provided as list, specifies the variable
labels of the plot.
Returns:
None, str: Conditionally returns the absolute filepath to the plot
based on the input arguments.
"""
var_prior_ = var_prior[var_prior != 0]
from scipy import stats
...
...
@@ -4098,7 +4231,8 @@ class Plotter:
return ax, sm
def plot_sns(dfs, filename, show=False, save=True):
@classmethod
def plot_sns(self, dfs, filename, show=False, save=True):
"""Cosimulation and out of sample plot.
"""
filepath = os.path.join(PLOTPATH, filename)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment