<jupyter_start><jupyter_text>Example of analyzing a NN in isolation  Load libraries and set random seed<jupyter_code>import numpy as np
import nn_partition.analyzers as analyzers
import sys
sys.path.append("../")
from nn_partition.models.models import model_xiang_2020_robot_arm as robot_arm
np.random.seed(seed=0)<jupyter_output><empty_output><jupyter_text>Load NN controller<jupyter_code>activation = "tanh" # "relu" "sigmoid"
torch_model, model_info = robot_arm(
    activation=activation
)
print(torch_model)<jupyter_output><empty_output><jupyter_text>Define NN input set<jupyter_code>input_range = np.array(
    [  # (num_inputs, 2)
        [np.pi / 3, 2 * np.pi / 3],  # x0min, x0max
        [np.pi / 3, 2 * np.pi / 3],  # x1min, x1max
    ]
)<jupyter_output><empty_output><jupyter_text>Define partitioner hyperparameters<jupyter_code>partitioner_hyperparams = {
    "num_simulations": 1e5,
    "type": "GreedySimGuided",
    "termination_condition_type": "time_budget",
    "termination_condition_value": 2, # seconds
    "interior_condition": "convex_hull",
    "make_animation": False,
    "show_animation": False,
    "show_input": True,
    "show_output": True,
}<jupyter_output><empty_output><jupyter_text>Define propagator hyperparameters<jupyter_code>propagator_hyperparams = {
    "type": "CROWN_LIRPA",
    "input_shape": input_range.shape[:-1],
}<jupyter_output><empty_output><jupyter_text>Initialize analyzer, partitioner, propagator<jupyter_code>analyzer = analyzers.Analyzer(torch_model)
analyzer.partitioner = partitioner_hyperparams
analyzer.propagator = propagator_hyperparams
print(analyzer)<jupyter_output><empty_output><jupyter_text>Compute the output set<jupyter_code>output_range, analyzer_info = analyzer.get_output_range(input_range)
print(output_range)
# analyzer_info contains more details, including the convex hull of the partitioned output, if applicable<jupyter_output><empty_output><jupyter_text>Generate a visualization of the input/output mapping<jupyter_code>labels = {"input": [None, None], "output": [None, None]}
aspects = {"input": "auto", "output": "auto"}

analyzer.visualize(
    input_range,
    output_range,
    show=True,
    show_samples=True,
    show_legend=False,
    show_input=True,
    show_output=True,
    title=None,
    labels=labels,
    aspects=aspects,
    **analyzer_info
)<jupyter_output><empty_output><jupyter_text>Estimate the output set error<jupyter_code>error = analyzer.get_error(input_range, output_range, **analyzer_info)
print("Error: {:.4f}".format(error))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11626999609832228, 'fraction_numerical': 0.008193523214982443, 'mean_word_length': 6.585798816568047, 'pattern_counts': {'":': 15, '<': 37, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '518710', 'license': 'MIT', 'n_tokens_mistral': 934, 'n_tokens_neox': 891, 'n_words': 158, 'path': 'jupyter_notebooks/partitioner_example.ipynb', 'repo_name': 'StanfordASL/nn_robustness_analysis', 'size': '2563'}