שבוע 7 — ניתוח וממצאים
המטבע הסטנדרטי של האימפריה הרומית, 211 לפנה”ס – המאה ה-3 לספירה.
האם ניתן להבחין בין מטבעות הדריאנוס (117–138 לספירה)
ובין מטבעות אנטונינוס פיוס (138–161 לספירה)
מצורת הדיוקן בלבד?
נתוני האוסף: 35 מטבעות (20 הדריאנוס + 15 אנטונינוס)
import numpy as np
import morphops
from sklearn.decomposition import PCA
import matplotlib.pyplot as plt
from bidi.algorithm import get_display
rtl = get_display
# 1. טעינת נתונים (TPS עם מספרים אירופאיים)
def read_tps(path):
coords, block = [], []
for line in open(path):
line = line.strip().replace(',', '.')
if line.startswith('LM='):
if block: coords.append(block)
block = []
elif line and not line.startswith(('ID=','IMAGE=','SCALE=')):
x, y = map(float, line.split())
block.append([x, y])
if block: coords.append(block)
return np.array(coords)
had = read_tps("data/coins/DEN_Hadrian/Hadrian.TPS")
ant = read_tps("data/coins/DEN_AntoniusPius/AntoniusPius.TPS")
all_coins = np.vstack([had, ant])
labels = ['הדריאנוס']*len(had) + ['אנטונינוס פיוס']*len(ant)
# 2. GPA — מחזיר מילון
result = morphops.gpa(all_coins)
aligned = result['aligned']
# 3. PCA
X = aligned.reshape(len(aligned), -1)
pca = PCA(n_components=10)
scores = pca.fit_transform(X)
var = pca.explained_variance_ratio_ * 100fig, ax = plt.subplots(figsize=(9, 7))
colors = {'הדריאנוס': '#e07b39', 'אנטונינוס פיוס': '#4a90c4'}
for label, c in colors.items():
mask = [l == label for l in labels]
ax.scatter(scores[mask, 0], scores[mask, 1],
c=c, label=rtl(label), s=80, alpha=0.8,
edgecolors='white', lw=0.5)
ax.set_xlabel(rtl(f"PC1 — {var[0]:.1f}% שונות"))
ax.set_ylabel(rtl(f"PC2 — {var[1]:.1f}% שונות"))
ax.set_title(rtl("מרחב הצורות: הדריאנוס לעומת אנטונינוס פיוס"))
ax.legend(fontsize=12)
plt.tight_layout()
plt.savefig("coins_pca.png", dpi=150)
plt.show()PCA — הדריאנוס לעומת אנטונינוס פיוס (n=35)
הפרדה ברורה בין שני הקיסרים — הצורה לבדה מנבאת את הקיסר.
from sklearn.discriminant_analysis import LinearDiscriminantAnalysis
from sklearn.model_selection import cross_val_score
# LDA: האם הצורה מנבאת את הקיסר?
y = [0]*len(had) + [1]*len(ant) # 0=הדריאנוס, 1=אנטונינוס
lda = LinearDiscriminantAnalysis()
scores_cv = cross_val_score(lda, X, y, cv=5)
print(f"דיוק סיווג (cross-validation): {scores_cv.mean()*100:.1f}%")
print(f"(50% = מקרי, 100% = הפרדה מושלמת)")פרשנות: האם AI + LDA יכולים לזהות קיסר רומאי ממטבע לא מסומן?
מטבעות = ציוני דרך (landmarks).
כלי חרס, גרזנים = קווי מתאר (outlines).
צורה בזמן — שי גורדין, אוניברסיטת אריאל