配線の受容野・被覆率
ImageLayout
Section titled “ImageLayout”実体: griffith_logic.analysis.wiring_stats.ImageLayout(クラス)
class ImageLayout( channels: int = 3, rows: int = 32, cols: int = 32, thresholds: int = 3,)入力ビットの並び(しきい値 minor)。
平坦化順は idx = ((channel * rows + row) * cols + col) * thresholds + threshold
(datasets.vision.ThresholdTransform(interleave=True) と同じ順)。
本モジュールでは画素占有率の分母(1 画素あたりのしきい値本数)にだけ使う。
layer_stats
Section titled “layer_stats”実体: griffith_logic.analysis.wiring_stats.layer_stats(関数)
def layer_stats(indices: Sequence, in_dim0: int) -> list[dict]層順の添字テーブルに core.connections.connection_stats を掛ける。
層 i > 0 の入力次元は前層のゲート数(= indices[i-1].shape[1])とみなす。
n_inputs = 2 のときは (b - a) mod in_dim の種類数も返す。rot / stretched_rot は
対の差が一定なので 1 種類(= s_b - s_a)になり、設計どおりのシフト量が
入っているかの確認に使える。
引数
indices— 層順の(n_inputs, out_dim)添字テーブルの列in_dim0— 層 0 の入力次元
戻り値
層ごとの辞書のリスト。connection_stats のキー
(coverage / usage_hist / same_input / n_gates)に加えて
layer / in_dim / unreferenced / unreferenced_ratio /
raw_diff_unique / raw_diff_value を持つ。
例外
ValueError: 添字が 2 次元でない / 範囲外(connection_stats が送出)
class_receptive_field
Section titled “class_receptive_field”実体: griffith_logic.analysis.wiring_stats.class_receptive_field(関数)
def class_receptive_field( indices: Sequence, in_dim0: int, classes: int = 10, thresholds: int = CIFAR10_3T.thresholds,) -> dictクラス受容野: 1 クラスが読める入力ビットの割合。
最終層の幅を classes で割った group 個のゲート(GroupSum の連続ブロック割当で
クラス c に加算されるゲート)から配線を後ろ向きに辿り、到達する入力ビットの
割合を数える。層ごとに bool マスクを逆写像するだけなので、幅 8,000 × 6 層でも
1 秒未満で終わる。
層 0 の被覆率(layer_stats の coverage)は「全クラス合計で読む入力」なので、
100% でもクラスごとには一部しか読めていないことがある。設計則で問うのは本関数の
class_cov_mean / class_cov_min のほう。
引数
indices— 層順の(n_inputs, out_dim)添字テーブルの列in_dim0— 層 0 の入力次元classes— クラス数(最終層の幅がこれで割り切れること)thresholds— 1 画素あたりのしきい値本数(画素占有率の分母に使う)
戻り値
{'classes', 'group', 'class_cov_mean', 'class_cov_min', 'class_cov_max', 'class_cov'(クラスごとの割合), 'pixel_occ_min'}
例外
ValueError: 最終層の幅がクラス数で割り切れない / 添字が 2 次元でない
receptive_field_upper_bound
Section titled “receptive_field_upper_bound”実体: griffith_logic.analysis.wiring_stats.receptive_field_upper_bound(関数)
def receptive_field_upper_bound(width: int, in_dim: int, n_inputs: int = 2) -> float幅 width の層が読める入力の割合の上限(2 入力なら 2W / 入力次元)。
層 0 のゲートは 1 個あたり n_inputs 本しか入力を読まないので、幅 W の層 0 が
触れる入力は高々 n_inputs · W 種類しかない。後続の層はその集合を増やせないから、
クラス受容野も層 0 の被覆率も この値を超えられない(配線の種類によらない構造上限)。
設計への使い方: 目標のクラス受容野が 1.0 なら、幅は
width >= in_dim / n_inputs が必要になる(CIFAR-10 の 9,216 入力・2 入力ゲートなら
幅 4,608 以上)。それより狭い予算では、シフト量をどう設計してもこの上限で頭打ちになる。
引数
width— 層の出力ゲート数(層 0 の幅)in_dim— 層 0 の入力次元n_inputs— 1 ゲートあたりの入力数
戻り値
min(1.0, n_inputs · width / in_dim)
例外
ValueError: width / in_dim / n_inputs が正でない
wiring_summary
Section titled “wiring_summary”実体: griffith_logic.analysis.wiring_stats.wiring_summary(関数)
def wiring_summary( indices: Sequence, in_dim0: int, classes: int = 10, layout: ImageLayout = CIFAR10_3T,) -> dict1 ネット分の配線統計(層ごと + クラス受容野 + 受容野の構造上限)。
引数
indices— 層順の(n_inputs, out_dim)添字テーブルの列in_dim0— 層 0 の入力次元classes— クラス数layout— 入力ビットの並び(画素占有率のしきい値本数に使う)
戻り値
{'layers': layer_stats(...), 'class_rf': class_receptive_field(...), 'rf_upper_bound': receptive_field_upper_bound(...)}