Commit c74cc6a7 authored by li213's avatar li213
Browse files

splitting the plotting and verification functions, further change dependencies

parent 638f61a9
from scipy.integrate import odeint
import numpy as np
import matplotlib.pyplot as plt
# import matplotlib.pyplot as plt
# Source: https://ths.rwth-aachen.de/research/projects/hypro/lotka-volterra/
......
from Car_Dynamic_Single import *
import matplotlib.pyplot as plt
# import matplotlib.pyplot as plt
def TC_Simulate(Modes,initialCondition,time_bound):
Modes = Modes.split(';')
......
from scipy.integrate import odeint
import numpy as np
import matplotlib.pyplot as plt
# import matplotlib.pyplot as plt
# Source: https://ths.rwth-aachen.de/research/projects/hypro/rod-reactor/
......
from scipy.integrate import odeint
import numpy as np
import matplotlib.pyplot as plt
# import matplotlib.pyplot as plt
# Source: https://ths.rwth-aachen.de/research/projects/hypro/roessler-attractor/
......
from scipy.integrate import odeint
import numpy as np
import matplotlib.pyplot as plt
# import matplotlib.pyplot as plt
# Source: https://ths.rwth-aachen.de/research/projects/hypro/spiking-neurons/
......
from scipy.integrate import odeint
import numpy as np
import matplotlib.pyplot as plt
# import matplotlib.pyplot as plt
# Source: https://ths.rwth-aachen.de/research/projects/hypro/spring-pendulum/
......
from scipy.integrate import odeint
import numpy as np
import matplotlib.pyplot as plt
# # import matplotlib.pyplot as plt
# Source: https://ths.rwth-aachen.de/research/projects/hypro/steam-governor/
......
from scipy.integrate import odeint
import numpy as np
import matplotlib.pyplot as plt
# # import matplotlib.pyplot as plt
# Source: https://ths.rwth-aachen.de/research/projects/hypro/two-tank/
......
from scipy.integrate import odeint
import numpy as np
import matplotlib.pyplot as plt
# # import matplotlib.pyplot as plt
# Source: https://ths.rwth-aachen.de/research/projects/hypro/van-der-pol-oscillator/
......
from scipy.integrate import odeint
import numpy as np
import matplotlib.pyplot as plt
# # import matplotlib.pyplot as plt
# Source: https://ths.rwth-aachen.de/research/projects/hypro/van-der-pol-oscillator/
......
pycairo
# pycairo
# pygraphviz
# glpk
networkx
python-igraph
matplotlib
# matplotlib
numpy
scipy
sympy==1.6.2
......
......@@ -48,9 +48,9 @@ def build_graph(vertex, edge, guards, resets):
g.es['guards'] = guards
g.es['resets'] = resets
if PLOTGRAPH:
graph = igraph.plot(g, GRAPHOUTPUT, margin=40)
graph.save()
# if PLOTGRAPH:
# graph = igraph.plot(g, GRAPHOUTPUT, margin=40)
# graph.save()
return g
......
"""
This file contains graph class for DryVR
"""
import matplotlib.pyplot as plt
# import matplotlib.pyplot as plt
import networkx as nx
......@@ -33,18 +33,18 @@ class Graph:
for e in edges:
self.edgeList.append((vertex[e[0]], vertex[e[1]]))
# Initialize the plot
self.fig = plt.figure()
self.ax = self.fig.add_subplot(111)
# self.fig = plt.figure()
# self.ax = self.fig.add_subplot(111)
# Initialize the graph
self.G = nx.DiGraph()
self.G.add_edges_from(self.edgeList)
self.pos = nx.spring_layout(self.G)
self.colors = ['green'] * len(self.G.nodes())
self.fig.suptitle('', fontsize=10)
# self.fig.suptitle('', fontsize=10)
# Draw the graph when initialize
self.draw()
plt.show()
# self.draw()
# plt.show()
def draw(self):
"""
......
......@@ -2,13 +2,10 @@
This file contains core bloating algorithm for dryvr
"""
import pdb
from typing import List, Tuple
import numpy as np
import scipy as sp
import scipy.spatial
import matplotlib.pyplot as plt
from matplotlib.patches import Rectangle
_TRUE_MIN_CONST = -10
_EPSILON = 1.0e-100
......@@ -117,26 +114,12 @@ def all_sensitivities_calc(training_traces: np.ndarray, initial_radii: np.ndarra
cur_dim_ind - 1]) / initial_distances)
return y_points
def plot_rtsegment_and_traces(rtsegment: np.ndarray, traces: np.ndarray):
for dim_ind in range(1, traces.shape[2]):
fig, ax = plt.subplots(1)
facecolor = 'r'
for trace_ind in range(traces.shape[0]):
ax.plot(traces[trace_ind, :, 0], traces[trace_ind, :, dim_ind])
for hrect_ind in range(rtsegment.shape[0]):
ax.add_patch(Rectangle((rtsegment[hrect_ind, 0, 0], rtsegment[hrect_ind, 0, dim_ind]), rtsegment[hrect_ind, 1, 0]-rtsegment[hrect_ind, 0, 0],
rtsegment[hrect_ind, 1, dim_ind] - rtsegment[hrect_ind, 0, dim_ind], alpha=0.1, facecolor='r'))
ax.set_title(f'dim #{dim_ind}')
fig.canvas.draw()
plt.show()
if __name__=="__main__":
with open("test.npy", "rb") as f:
training_traces = np.load(f)
initial_radii = np.array([1.96620653e-06, 2.99999995e+00, 3.07000514e-07, 8.84958773e-13, 1.05625786e-16, 3.72500000e+00, 0.00000000e+00, 0.00000000e+00])
result = get_reachtube_segment(training_traces, initial_radii, method='PWGlobal')
print(training_traces.dtype)
plot_rtsegment_and_traces(result, training_traces[np.array((0, 6))])
# plot_rtsegment_and_traces(result, training_traces[np.array((0, 6))])
......@@ -2,8 +2,6 @@ from __future__ import division, print_function
import math
import matplotlib.pyplot as plt
def read_data(traces):
""" Read in all the traces """
......@@ -287,36 +285,6 @@ def generate_bloat_tube(traces, time_intervals, discrepancies, Initial_Delta, en
return bloat_tube
def plot_traces(traces, dim, bloat_tube):
""" Plot the traces """
# Iterate over all individual traces
for i in range(0, len(traces)):
trace = traces[i]
# Obtain desired dimension
time = []
data = []
for j in range(0, len(trace)):
# for j in xrange(0,2):
time.append(trace[j][0])
data.append(trace[j][dim])
# Plot data
if i == 0:
plt.plot(time, data, 'b')
else:
plt.plot(time, data, 'r')
time = [row[0] for row in bloat_tube]
value = [row[dim] for row in bloat_tube]
time_bloat = [time[i] for i in range(0, len(value), 2)]
lower_bound = [value[i] for i in range(0, len(value), 2)]
upper_bound = [value[i + 1] for i in range(0, len(value), 2)]
plt.plot(time_bloat, lower_bound, 'g')
plt.plot(time_bloat, upper_bound, 'g')
# Print out the intervals and discrepancies
def print_int_disc(discrepancies, time_intervals):
for nd in range(0, len(discrepancies)):
......@@ -326,7 +294,6 @@ def print_int_disc(discrepancies, time_intervals):
str(discrepancies[nd][p]))
print('')
def PW_Bloat_to_tube(Initial_Delta, plot_flag, plot_dim, traces, K_value):
# Read data in
# if Mode == 'Const':
......@@ -367,8 +334,8 @@ def PW_Bloat_to_tube(Initial_Delta, plot_flag, plot_dim, traces, K_value):
reach_tube = generate_bloat_tube(traces, time_intervals, discrepancies, Initial_Delta, end_time, trace_len,
dimensions_nt, delta_time, K_value)
if plot_flag:
plot_traces(traces, plot_dim, reach_tube)
plt.show()
# if plot_flag:
# plot_traces(traces, plot_dim, reach_tube)
# plt.show()
return reach_tube
import numpy as np
from matplotlib import pyplot as plt
from matplotlib.patches import Rectangle
def plot_rtsegment_and_traces(rtsegment: np.ndarray, traces: np.ndarray):
for dim_ind in range(1, traces.shape[2]):
fig, ax = plt.subplots(1)
facecolor = 'r'
for trace_ind in range(traces.shape[0]):
ax.plot(traces[trace_ind, :, 0], traces[trace_ind, :, dim_ind])
for hrect_ind in range(rtsegment.shape[0]):
ax.add_patch(Rectangle((rtsegment[hrect_ind, 0, 0], rtsegment[hrect_ind, 0, dim_ind]), rtsegment[hrect_ind, 1, 0]-rtsegment[hrect_ind, 0, 0],
rtsegment[hrect_ind, 1, dim_ind] - rtsegment[hrect_ind, 0, dim_ind], alpha=0.1, facecolor='r'))
ax.set_title(f'dim #{dim_ind}')
fig.canvas.draw()
plt.show()
def plot_traces(traces, dim, bloat_tube):
""" Plot the traces """
# Iterate over all individual traces
for i in range(0, len(traces)):
trace = traces[i]
# Obtain desired dimension
time = []
data = []
for j in range(0, len(trace)):
# for j in xrange(0,2):
time.append(trace[j][0])
data.append(trace[j][dim])
# Plot data
if i == 0:
plt.plot(time, data, 'b')
else:
plt.plot(time, data, 'r')
time = [row[0] for row in bloat_tube]
value = [row[dim] for row in bloat_tube]
time_bloat = [time[i] for i in range(0, len(value), 2)]
lower_bound = [value[i] for i in range(0, len(value), 2)]
upper_bound = [value[i + 1] for i in range(0, len(value), 2)]
plt.plot(time_bloat, lower_bound, 'g')
plt.plot(time_bloat, upper_bound, 'g')
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment