SISO Study I



In [1]:
# Import Pandas
import pandas as pd
# Import Numpy
import numpy as np
# Import Bokeh
import bokeh.plotting as bk
import bokeh.io as bi
from bokeh.io import export_svgs
bi.output_notebook()


Loading BokehJS ...

In [2]:
# Read the Data
Data = pd.read_csv('./Experiments/SISO/SISO_22082017_2.csv', sep=';')
Data2 = pd.read_csv('./Experiments/SISO/SISO_22082017.csv', sep=';')
Data = Data.append(Data2, ignore_index = True)
# Give the Columns
Data.columns


Out[2]:
Index(['Unnamed: 0', 'Sample No.', 'Order', 'K', 'T', 'KM', 'TM', 'LM',
       'MS Real', 'MS Ideal', 'Tr_RSW', 'Mp_RSW', 'Ts_RSW', 'Ys_RSW', 'Tr_R',
       'Mp_R', 'Ts_R', 'Ys_R', 'Tr_ISW', 'Mp_ISW', 'Ts_ISW', 'Ys_ISW', 'Tr_I',
       'Mp_I', 'Ts_I', 'Ys_I'],
      dtype='object')

In [4]:
# Look at Errors in Step response
error_data = Data[['Ys_RSW','Ys_R','Ys_ISW','Ys_I']]
step_error = error_data.isnull().sum()

# Sample Count
msreal_sample = Data['MS Real']
msreal_sample = msreal_sample.notnull().sum()

# Get Data above 2
msreal_unstable = Data[Data['MS Real']>2.0]
msreal_unstable = msreal_unstable['MS Real'].notnull().sum()

Plot the Evaluation


In [5]:
# select a palette
from bokeh.palettes import Plasma9  as palette
# itertools handles the cycling
import itertools  
from bokeh.models import Range1d, Label

# create a color iterator
colors = itertools.cycle(palette)
# count higher then MS > 5
mscount_real = 0
mscount_iden = 0
x = []
y = []
order=[]
x2 = []
y2 = []

p2 = bk.figure(plot_width = 800, plot_height = 800, x_range=(0.9, 1.6), y_range=(0.9, 1.6), x_axis_label='Maximum Sensitivity Real System', y_axis_label='Maximum Sensitivity Identified System')
for i, color in zip(range(1,10), colors):
    # Load the Data
    ms_id = Data[((Data['Order'] == i))]['MS Ideal']
    ms_re = Data[((Data['Order'] == i))]['MS Real']
    x.append(np.mean(ms_id))
    x2.append(np.var(ms_id))
    y.append(np.mean(ms_re))
    y2.append(np.var(ms_re))
    order.append(i)
    p2.scatter(ms_re,ms_id, color = color, alpha = 1, legend='Order '+str(i))

# Get the legend horizontal    
p2.legend.orientation='horizontal'
# Make a copy for later plot
p3 = p2

# Add annotation
label1 = Label(x=1.4, y=1.0, text='No. of samples: '+str(msreal_sample))
label2 = Label(x=1.4, y=0.975, text='Critical Systems: '+str(msreal_unstable))
p2.add_layout(label1)
p2.add_layout(label2)
# Show and Export
p2.output_backend = "svg"
export_svgs(p2, filename="SISO_Robustness.svg")

bk.show(p2)



In [6]:
# Edit Plot to show everything
p3.x_range= Range1d(0.9,8)
p3.y_range= Range1d(0.9,2)
p3.plot_height=400
# Add annotation
label1 = Label(x=6, y=1.2, text='No. of samples: '+str(msreal_sample))
label2 = Label(x=6, y=1.1, text='Critical Systems: '+str(msreal_unstable))
p3.add_layout(label1)
p3.add_layout(label2)
# Show and Export
p3.output_backend = "svg"
export_svgs(p3, filename="SISO_Robustness_ALL.svg")

#bk.show(p3)


Out[6]:
['SISO_Robustness_ALL.svg']

In [ ]:
# Plot next figure
p4 = bk.figure(plot_width = 800, plot_height = 400, x_range=(0,10), y_range=(0.8, 2.5), x_axis_label='Maximum Sensitivity Real System', y_axis_label='Maximum Sensitivity Identified System')

p4.scatter(order,x,  color='blue')
p4.line(order,x,line_dash='dashed',  color='blue')
p4.scatter(order,y,color='orange')
p4.line(order,y,line_dash='dashed',  color='orange')
bk.show(p4)

In [14]:
from bokeh.models import Band

p5 = bk.figure(plot_width = 800, plot_height = 300, x_axis_label='Model Order', y_axis_label='Normalized Time')

# Empty dicts for storage
ymean = []
ymax = []
ymin = []
order = []

# Data iteration
for i, color in zip(range(1,10), colors):
    x = Data[((Data['Order'] == i))]['Order']
    y = Data[((Data['Order'] == i))]['LM']/(Data[((Data['Order'] == i))]['TM']+Data[((Data['Order'] == i))]['LM'])
    order.append(i)
    ymean.append((np.mean(y)))
    ymax.append(np.max(y))
    ymin.append(np.min(y))
    p5.scatter(x,y, color = color, legend='Order '+str(i))

# Get the legend horizontal    
p5.legend.orientation='horizontal'

# Add the Band
band = Band(x=order, upper=ymax, lower = ymin, level='underlay',
            fill_alpha=1.0, line_width=1, line_color='black')
p5.add_layout(band)
#p5.line(order,ymean, line_dash='dashed', color='black')
# Show and Export
#p5.output_backend = "svg"
#export_svgs(p5, filename="SISO_NormalizedTime.svg")

bk.show(p5)


---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-14-ccc9aa714ead> in <module>()
     24 # Add the Band
     25 band = Band(x=order, upper=ymax, lower = ymin, level='underlay',
---> 26             fill_alpha=1.0, line_width=1, line_color='black')
     27 p5.add_layout(band)
     28 #p5.line(order,ymean, line_dash='dashed', color='black')

/home/alcapitan/anaconda3/lib/python3.5/site-packages/bokeh/model.py in __init__(self, **kwargs)
    225         self._id = kwargs.pop("id", make_id())
    226         self._document = None
--> 227         super(Model, self).__init__(**kwargs)
    228         default_theme.apply_to_model(self)
    229 

/home/alcapitan/anaconda3/lib/python3.5/site-packages/bokeh/core/has_props.py in __init__(self, **properties)
    244 
    245         for name, value in properties.items():
--> 246             setattr(self, name, value)
    247 
    248     def __setattr__(self, name, value):

/home/alcapitan/anaconda3/lib/python3.5/site-packages/bokeh/core/has_props.py in __setattr__(self, name, value)
    272 
    273         if name in props or name in deprecated:
--> 274             super(HasProps, self).__setattr__(name, value)
    275         else:
    276             matches, text = difflib.get_close_matches(name.lower(), props), "similar"

/home/alcapitan/anaconda3/lib/python3.5/site-packages/bokeh/core/property/descriptors.py in __set__(self, obj, value, setter)
    970         '''
    971         value = self._extract_units(obj, value)
--> 972         super(UnitsSpecPropertyDescriptor, self).__set__(obj, value, setter)
    973 
    974     def set_from_json(self, obj, json, models=None, setter=None):

/home/alcapitan/anaconda3/lib/python3.5/site-packages/bokeh/core/property/descriptors.py in __set__(self, obj, value, setter)
    493             raise RuntimeError("%s.%s is a readonly property" % (obj.__class__.__name__, self.name))
    494 
--> 495         self._internal_set(obj, value, setter)
    496 
    497     def __delete__(self, obj):

/home/alcapitan/anaconda3/lib/python3.5/site-packages/bokeh/core/property/descriptors.py in _internal_set(self, obj, value, setter)
    711 
    712         '''
--> 713         value = self.property.prepare_value(obj, self.name, value)
    714 
    715         old = self.__get__(obj, obj.__class__)

/home/alcapitan/anaconda3/lib/python3.5/site-packages/bokeh/core/properties.py in prepare_value(self, cls, name, value)
   1661         except TypeError:
   1662             pass
-> 1663         return super(DistanceSpec, self).prepare_value(cls, name, value)
   1664 
   1665 class ScreenDistanceSpec(NumberSpec):

/home/alcapitan/anaconda3/lib/python3.5/site-packages/bokeh/core/property/bases.py in prepare_value(self, obj_or_cls, name, value)
    288                     break
    289             else:
--> 290                 raise e
    291         else:
    292             value = self.transform(value)

/home/alcapitan/anaconda3/lib/python3.5/site-packages/bokeh/core/property/bases.py in prepare_value(self, obj_or_cls, name, value)
    281     def prepare_value(self, obj_or_cls, name, value):
    282         try:
--> 283             self.validate(value)
    284         except ValueError as e:
    285             for tp, converter in self.alternatives:

/home/alcapitan/anaconda3/lib/python3.5/site-packages/bokeh/core/properties.py in validate(self, value)
    674 
    675         if not (value is None or any(param.is_valid(value) for param in self.type_params)):
--> 676             raise ValueError("expected an element of either %s, got %r" % (nice_join(self.type_params), value))
    677 
    678     # TODO (bev) implement this

ValueError: expected an element of either String, Dict(Enum('field', 'value', 'transform', 'units'), Either(String, Instance(Transform), Float)) or Float, got [0.029811251098300129, 0.32366385328311664, 0.46213764937767282, 0.55504810442996722, 0.62907774174020659, 0.68913173039194264, 0.73365430931689746, 0.77168165369875397, 0.80101740372202523]

In [7]:
p2 = bk.figure(plot_width = 800, plot_height = 300)
for i, color in zip(range(1,10), colors):
    ideal = Data[((Data['Order'] == i))]['Ts_RSW']
    real = Data[((Data['Order'] == i))]['Ts_R']
    p2.scatter(real,ideal, color = color)
bk.show(p2)



In [47]:
import bokeh
p = BoxPlot(Data, values='vals', label='cyl',
 legend='bottom_right')


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-47-bb2beb9909c7> in <module>()
      1 import bokeh
----> 2 p = BoxPlot(Data, values='vals', label='cyl',
      3  legend='bottom_right')

NameError: name 'BoxPlot' is not defined

In [91]:
p1 = bk.figure(plot_width = 800, plot_height = 800, x_range=(0.8,2.0))
p2 = bk.figure(plot_width = 800, plot_height = 800, x_range=(0.8,2.0))

for i, color in zip(range(1,10), colors):
    # Load the Data
    ms_id = Data[((Data['Order'] == i))]['MS Ideal']
    ms_re = Data[((Data['Order'] == i))]['MS Real']
    
    hist1, edges1 = np.histogram(ms_id, density=True, bins=50)
    hist2, edges2 = np.histogram(ms_re, density=True, bins=50)
    
    p1.quad(top=hist1, bottom=0, left=edges1[:-1], right=edges1[1:],
        fill_color=color, line_color=color, legend='Order '+str(i))
    p2.quad(top=hist2, bottom=0, left=edges2[:-1], right=edges2[1:],
        fill_color=color, line_color=color, legend='Order '+str(i))
    
    
p1.legend.orientation='horizontal'
p2.legend.orientation='horizontal'
bk.show(p1)
bk.show(p2)



In [ ]: