Skip to content
Snippets Groups Projects
Select Git revision
  • 7fc865a4caec1a2ced41918449e34596f50f8c43
  • master default protected
  • android-7.1.2_r28_klist
  • pie-cts-release
  • pie-vts-release
  • pie-cts-dev
  • oreo-mr1-iot-release
  • sdk-release
  • oreo-m6-s4-release
  • oreo-m4-s12-release
  • pie-release
  • pie-r2-release
  • pie-r2-s1-release
  • oreo-vts-release
  • oreo-cts-release
  • oreo-dev
  • oreo-mr1-dev
  • pie-gsi
  • pie-platform-release
  • pie-dev
  • oreo-cts-dev
  • android-o-mr1-iot-release-1.0.4
  • android-9.0.0_r8
  • android-9.0.0_r7
  • android-9.0.0_r6
  • android-9.0.0_r5
  • android-8.1.0_r46
  • android-8.1.0_r45
  • android-n-iot-release-smart-display-r2
  • android-vts-8.1_r5
  • android-cts-8.1_r8
  • android-cts-8.0_r12
  • android-cts-7.1_r20
  • android-cts-7.0_r24
  • android-o-mr1-iot-release-1.0.3
  • android-cts-9.0_r1
  • android-8.1.0_r43
  • android-8.1.0_r42
  • android-n-iot-release-smart-display
  • android-p-preview-5
  • android-9.0.0_r3
41 results

initial_sid_contexts

Blame
  • measurements.py 4.89 KiB
    ## This file is part of the simulative evaluation for the qronos observer abstractions.
    ## Copyright (C) 2022-2023  Tim Rheinfels  <tim.rheinfels@fau.de>
    ## See https://gitlab.cs.fau.de/qronos-state-abstractions/simulation
    ##
    ## Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
    ##
    ## 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
    ##
    ## 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
    ##
    ## 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
    ##
    ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    
    ###
    ###  @file  visualization/measurements.py
    ###
    ###  @brief  Provides the visualization of @cite ECRTS23-Rheinfels figure 3
    ###
    ###  @author  Tim Rheinfels  <tim.rheinfels@fau.de>
    ###
    
    import itertools
    import matplotlib.pyplot as plot
    import numpy as np
    
    from simulation.closed_loop import ClosedLoopSimulation
    from visualization.color import scale_lightness
    
    ###
    ###  @brief  Visualizes the results from multiple @ref closed_loop.ClosedLoopSimulation instances with respect to their individual state abstractions
    ###
    ###  @param  ax           The matplotlib.Axes object to render to
    ###  @param  experiments  List of @ref closed_loop.ClosedLoopSimulation instances
    ###  @param  names        Names associated with the @p experiments
    ###  @param  which_run    Index of the run to visualize (defaults to 0)
    ###
    def visualize_measurements(ax, experiments, names, which_run=0):
        assert(len(experiments) == len(names))
        assert(len(experiments) > 0)
    
        colors = (
            scale_lightness('C0', 0.5),
            scale_lightness('C0', 0.75),
            scale_lightness('C0', 1.0),
        )
        linestyles=(
            'dashdot',
            'dashed',
            'solid',
        )
    
        timesteps = None
        for i in range(len(experiments)):
            experiment = experiments[i]
            name = names[i]
    
            assert(isinstance(experiment, ClosedLoopSimulation))
    
            run = experiment.get_run(which_run)
    
            # Get data from experiment
            state_abstraction = experiment.state_abstraction_simulation.abstraction
            assert(np.isclose(state_abstraction.v_max, 1.0))
    
            # Extract signals, match lengths, and convert to numpy arrays
            t = np.array(run['sigma']['time_data'])
            if timesteps is not None:
                assert(t.size == timesteps)
            timesteps = t.size
    
            v = np.array(run['v']['signal_data'][:timesteps])
            v_sys = np.concatenate(run['v_sys']['signal_data'][:timesteps])
    
            # === Plot common data ===
            if i == 0:
    
                # Plot specification
                ax.plot((0, timesteps-1), (1, 1), color='C1', linewidth=2, label=r'Safety Specification: $v_{max}$')
    
                # Plot area where dropouts occur
                k_start = max(experiment.switching_sequence_simulation.T_start, 0)
                k_end = min(experiment.switching_sequence_simulation.T_end, timesteps-1)
                ax.axvspan(k_start, k_end, color='darkgray', alpha=0.4, label=r'Scenario: 50% Dropout in $\sigma_k$')
    
            # === Plot abstraction data ===
            # Plot abstraction
            ax.plot(t, v, color=colors[i], linestyle=linestyles[i], linewidth=2, label=name)
    
            if i == len(experiments) - 1:
                # Plot system safety output scaled to be comparable with the abstraction
                ax.plot(t, state_abstraction.v_max * v_sys, color='k', linestyle=':', linewidth=2, label=r'Specification Output: $v_{max} \cdot ||s_k||_S$')
    
    
        # Some styling
        ax.set_xlabel('Time Step $k$')
        ax.set_ylabel('Abstraction Domain')
        ax.set_ylim([-0.05, 1.05])
        ax.grid()
    
        legend = ax.legend(loc='center right', ncol=1, bbox_to_anchor=(0.95, 0.5))
    
        for text in legend.get_texts():
            if not text.get_text().startswith(r'\Large '):
                continue
    
            text.set(
                text = text.get_text()[7:],
                size = 'medium',
                weight = 32,
            )