Posts Tagged with "ISO 26262"

既に発行済みのブログであっても適宜修正・追加することがあります。
We may make changes and additions to blogs already published.

新方式によるPUDの導出 (2)

posted by sakurai on April 2, 2024 #767

論文に掲載したPUDのグラフ(前項に掲載)を描画するプログラムを貼付します。コメントを含めほとんど全てをChatGPTが作成しました。

import numpy as np
import matplotlib.pyplot as plt
from functools import lru_cache

plt.rcParams['font.family'] = 'serif'
plt.rcParams['mathtext.rm'] = 'Times New Roman'
plt.rcParams['mathtext.fontset'] = 'cm'

# パラメータ設定
lambdaVal = 0.1  # 故障率
tau = 2  # 点検期間
K = 0.5  # 修復率
epsilon = 0.00001  # 不連続点の直前を示すために使用する小さい値

def R(t):
    """信頼度関数"""
    return np.exp(-lambdaVal * t)

def F(t):
    """故障関数"""
    return 1 - R(t)

def f(t):
    """密度関数"""
    return lambdaVal * R(t)

@lru_cache(maxsize=None)
def Q_n(t, n):
    """Q_nの再帰関数。結果をキャッシュする。"""
    if n == 0:
        return F(t)
    else:
        tau_n = n * tau
        tau_n_minus_1 = (n - 1) * tau
        return 

@lru_cache(maxsize=None)
def q_n(t, n):
    """q_nの再帰関数。結果をキャッシュする。"""
    if n == 0:
        return f(t)
    else:
        tau_n = n * tau
        tau_n_minus_1 = (n - 1) * tau
        return 

def q_approx(t):
    """tにおけるq(t)の近似値を計算する関数"""
    u = t % tau
    return (1 - K) * f(t) + K * f(u)

# グラフ描画
fontsize_axes_label = 24 * 1.8
fontsize_ticks = 16 * 1.8
fontsize_legend = 24 * 1.8

plt.figure(figsize=(18, 11))
#軸(spines)の線幅を太くする
ax=plt.gca()#現在の軸を取得
spine_width=2#軸の線幅
for spine in ax.spines.values():
    spine.set_linewidth(spine_width)

# 凡例用のダミープロット
plt.plot([], [], '-', label=f'$q_{{\\text{{exact}},n}}(t)$ for $\\lambda = {lambdaVal}$', color='black')
plt.plot([], [], '--', label=f'$q_{{\\text{{approx}}}}(t)$ for $\\lambda = {lambdaVal}$', color='black')

# 不連続性を示すために各区間を個別にプロット
for i in range(10):
    start = i * tau
    end = (i + 1) * tau -epsilon # epsilonを削除
    t_range_segment = np.linspace(start, end, 500)  # endの計算からepsilonを除去
    q_exact_segment_values = [q_n(t, i) for t in t_range_segment]
    q_approx_segment_values = [q_approx(t) for t in t_range_segment]

    # グラフ描画
    plt.plot(t_range_segment, q_exact_segment_values, 'k-', lw=2.5)
    plt.plot(t_range_segment, q_approx_segment_values, 'k--', lw=2.5)
    plt.plot(end, q_n(end, i), 'o', mfc='white', mec='black', mew=2, markersize=8)  # q_nの終点
    plt.plot(end, q_approx(end), 'o', mfc='white', mec='black', mew=2, markersize=8)  # q_approxの終点
    if (i > 0):
        # 不連続点で白丸を追加
        plt.plot(start, q_n(start, i), 'o', mfc='white', mec='black', mew=2, markersize=8)  # 区間の開始点
        plt.plot(start, q_approx(start), 'o', mfc='white', mec='black', mew=2, markersize=8)  # q_approxの開始点

plt.xlabel('Time (t)', fontsize=fontsize_axes_label)
plt.ylabel('$q(t)$', fontsize=fontsize_axes_label)
plt.xticks(np.arange(0, 11*tau, tau), fontsize=fontsize_ticks)
plt.yticks(fontsize=fontsize_ticks)
legend = plt.legend(fontsize=fontsize_legend)
for handle in legend.legendHandles:
    handle.set_linewidth(2.5)  # ここで線の太さを指定
plt.grid(True, color='gray', linestyle='-', linewidth=1.4)
plt.xlim(0,10*tau)
plt.subplots_adjust(left=0.15, bottom=0.14) 
plt.show()

なお、本稿はRAMS 2025に投稿予定のため一部を秘匿しています。


左矢前のブログ 次のブログ右矢


ページ: