選好関係と効用関数:完備性・推移性と効用表現
実行環境
Python 3.14.6、NumPy 2.5.4、SciPy 1.18.1、Matplotlib 3.11.2(Jupyter Notebook)。
本記事は2021年頃の記事をリライトし、上記の環境で計算したものである。
概要
選好を数値に置き換える前に、何を比較でき、比較が整合しているかを確認する。有限個の候補に対して完備性と推移性を検査し、同順位を含む効用表現をPythonで構成する。
書籍『意思決定の理論と実践』/第2章 選好と期待効用理論。数値例は説明用に設定したものであり、実測データではない。
計算の準備
コードは上から順に実行する。数値は表示時だけ有効数字3桁に整える。
実行環境の確認・ライブラリの読み込み・描画設定
import sys
from pathlib import Path
from pprint import pprint
import numpy as np
import scipy
import matplotlib
import matplotlib.pyplot as plt
from matplotlib.ticker import FuncFormatter, ScalarFormatter
from matplotlib_inline.backend_inline import set_matplotlib_formats
from IPython.display import Math, display
# 表示だけを丸め、計算には丸める前の値を使う。
def s3(value):
return format(float(value), "#.3g").rstrip(".")
np.set_printoptions(formatter={"float_kind": s3})
set_matplotlib_formats("svg")
plt.rcParams.update({
"figure.figsize": (7, 4),
"font.size": 11,
"axes.spines.top": False,
"axes.spines.right": False,
"axes.grid": True,
"grid.alpha": 0.200,
"svg.fonttype": "path",
})
OUT_DIR = Path("104_nb_files")
OUT_DIR.mkdir(exist_ok=True)
def save_fig(fig, name):
# 数値の目盛りだけを整形し、候補名などのラベルは保つ。
for ax in fig.axes:
for axis in (ax.xaxis, ax.yaxis):
if isinstance(axis.get_major_formatter(), ScalarFormatter):
axis.set_major_formatter(FuncFormatter(lambda x, pos: s3(x)))
# SVGをファイルとセル出力の両方に残す。
fig.tight_layout()
fig.savefig(OUT_DIR / f"{name}.svg", format="svg", bbox_inches="tight")
display(fig)
plt.close(fig)
assert sys.version_info[:3] == (3, 14, 6), "Python 3.14.6のカーネルを選択すること"
print("実行環境: wa-src(3.14.6)")
print("Python:", sys.version.split()[0])
print("NumPy:", np.__version__, "SciPy:", scipy.__version__)
print("Matplotlib:", matplotlib.__version__)
実行環境: wa-src(3.14.6)
Python: 3.14.6
NumPy: 2.5.4 SciPy: 1.18.1
Matplotlib: 3.11.2
1. 選好は大小関係を表す
$x\succeq y$は「$x$は$y$と同じか、それ以上に好ましい」という弱い選好を表す。厳密な選好と無差別は次のように定義する。
$$ \begin{aligned} x\succ y&\iff x\succeq y\ \text{かつ}\ \neg(y\succeq x),\\ x\sim y&\iff x\succeq y\ \text{かつ}\ y\succeq x. \end{aligned} $$
「比較できない」と「同じくらい好ましい」は異なる。前者は両方向とも判断が成立せず、後者は両方向とも成立する。
完備性は任意の$x,y$について$x\succeq y$または$y\succeq x$が成立すること、推移性は次を満たすことである。
$$ x\succeq y,\quad y\succeq z\quad\Longrightarrow\quad x\succeq z. $$
完備性では$x=y$も含めるので、反射性$x\succeq x$も得られる。この2条件を満たす選好は弱順序と呼ばれる。現実の回答で満たされない場合、回答の誤記、状況の変化、比較基準の違いなどを確認する必要がある。
2. 有限集合なら順位から効用を作れる
4つの候補について$A\succ B\sim C\succ D$とする。効用関数$u$は、次の同値関係を満たす数値表現である。
$$ x\succeq y\iff u(x)\geq u(y). $$
無差別な候補を同じ組にまとめ、下から$\{D\},\{B,C\},\{A\}$と並べる。各組に0、1、2を割り当てればよい。推移性によって組の間に循環が生じず、完備性によって組同士を比較できる。
したがって、有限集合では完備性と推移性から効用表現を構成できる。無限集合で同じことを無条件に主張することはできない。連続的な選択肢で連続効用を得たい場合は、選好の連続性などの追加条件を調べる。この区別は有限表の実装から一般論へ進む際に必要になる。
labels = ["A", "B", "C", "D"]
utility = np.array([2, 1, 1, 0])
relation = utility[:, None] >= utility[None, :]
def check_relation(r):
# r[i, j]は、iがjと同等以上であることを示す。
r = np.asarray(r, dtype=bool)
assert r.ndim == 2 and r.shape[0] == r.shape[1]
complete = bool(np.all(r | r.T))
# 整数の行列積で、i→j→kという2段階の関係を数える。
two_steps = (r.astype(int) @ r.astype(int)) > 0
transitive = bool(np.all(~two_steps | r))
return {"完備性": complete, "推移性": transitive}
pprint({"関係行列": relation.astype(int), "検査": check_relation(relation)})
assert all(check_relation(relation).values())
fig, ax = plt.subplots(figsize=(5, 4))
ax.imshow(relation, cmap="Blues", vmin=0, vmax=1)
ax.set(xticks=range(4), xticklabels=labels, yticks=range(4), yticklabels=labels,
xlabel="Compared candidate", ylabel="Candidate")
for i, j in np.ndindex(relation.shape):
ax.text(j, i, str(int(relation[i, j])), ha="center", va="center",
color="white" if relation[i, j] else "black")
save_fig(fig, "01_preference_relation")
# A≽B、B≽C、C≽Aという循環は、完備でも推移的ではない。
cycle = np.array([[1, 1, 0], [0, 1, 1], [1, 0, 1]], dtype=bool)
pprint({"循環する関係": check_relation(cycle)})
assert check_relation(cycle) == {"完備性": True, "推移性": False}
{'検査': {'完備性': True, '推移性': True},
'関係行列': array([[1, 1, 1, 1],
[0, 1, 1, 1],
[0, 1, 1, 1],
[0, 0, 0, 1]])}
{'循環する関係': {'完備性': True, '推移性': False}}
3. 効用の差に大きさの意味はない
確実な候補の順位だけを表す効用を序数的効用という。$f$が狭義単調増加なら、
$$ u(x)\geq u(y)\iff f(u(x))\geq f(u(y)) $$
なので、$v=f\circ u$も同じ選好を表す。本例の非負な効用値では$f(t)=t^2$がこの条件を満たす。AとBの差は、変換前は1、変換後は3になるが、順位は変わらない。「AはBの2倍うれしい」といった解釈はできない。
実装では同順位を保つ必要がある。単に配列の並び順へ異なる整数を付けると、BとCの無差別を壊してしまう。
$$ \displaystyle u(A)=2>u(B)=u(C)=1>u(D)=0 $$
# 自分より厳密に下にある無差別類の個数を数える。
levels = np.unique(utility)
constructed = np.array([np.count_nonzero(levels < u) for u in utility])
transformed = constructed ** 2
assert np.array_equal(constructed[:, None] >= constructed[None, :], relation)
assert np.array_equal(transformed[:, None] >= transformed[None, :], relation)
pprint({"構成した効用": constructed, "二乗した効用": transformed})
fig, ax = plt.subplots()
x = np.arange(4)
ax.bar(x - 0.180, constructed, width=0.350, label="u")
ax.bar(x + 0.180, transformed, width=0.350, label="u squared")
ax.set(xticks=x, xticklabels=labels, ylabel="Utility representation")
ax.legend()
save_fig(fig, "02_ordinal_transform")
{'二乗した効用': array([4, 1, 1, 0]), '構成した効用': array([2, 1, 1, 0])}
4. 序数的効用の平均には注意が必要である
確実な結果の順位が同じでも、変換後の効用を平均すると、くじの順位が変わる場合がある。結果の効用が0、1、2であるとする。くじPは確率$0.400$で2、残りで0を得る。くじQは確実に1を得る。
$$ \mathbb E[u(P)]=0.600\times0+0.400\times2=0.800<1=\mathbb E[u(Q)]. $$
二乗後は次のようになる。
$$ \mathbb E[u(P)^2]=0.600\times0+0.400\times4=1.60>1=\mathbb E[u(Q)^2]. $$
確実な結果の選好だけでは、不確実なくじの選好までは決まらない。期待効用理論では、くじ全体に対する選好に追加の公理を置く。効用の数字を付けて平均する操作には、そのための前提が必要なのである。
u = np.array([0, 1, 2])
p_lottery = np.array([0.600, 0, 0.400])
q_lottery = np.array([0, 1, 0])
pprint({"変換前(P,Q)": (np.vstack([p_lottery, q_lottery]) @ u),
"変換後(P,Q)": (np.vstack([p_lottery, q_lottery]) @ (u ** 2))})
assert p_lottery @ u < q_lottery @ u
assert p_lottery @ (u ** 2) > q_lottery @ (u ** 2)
{'変換前(P,Q)': array([0.800, 1.00]), '変換後(P,Q)': array([1.60, 1.00])}
結論
この記事では、有限集合の完備性・推移性を検査し、同順位を保つ効用表現を構成した。
序数的効用は順位を表すもので、値の差や比に固定した意味はない。くじを評価する期待効用は、確実な候補の順位表現と区別して扱う。
参考文献
Muhamet Yildiz, Theory of Choice, MIT OpenCourseWare 。有限集合での表現と、一般の選択集合で必要になる条件を参照した。