More keywords

This commit is contained in:
2015-11-10 14:31:47 +01:00
parent 9525d2995d
commit ed361930fa
4 changed files with 82 additions and 99 deletions

View File

@@ -5,16 +5,16 @@ from matplotlib.transforms import Bbox
def create_data():
m = 0.75
n= -40
x = np.arange(5.,115., 2.5)
x = np.arange(10.,110., 2.5)
y = m * x + n;
noise = np.random.randn(len(x))*15
rng = np.random.RandomState(37281)
noise = rng.randn(len(x))*15
y += noise
return x, y, m, n
def plot_data(x, y):
plt.scatter(x, y, marker='o', color='dodgerblue', s=40)
ax = plt.gca()
def plot_data(ax, x, y):
ax.scatter(x, y, marker='o', color='b', s=40)
ax.spines["right"].set_visible(False)
ax.spines["top"].set_visible(False)
ax.yaxis.set_ticks_position('left')
@@ -27,21 +27,13 @@ def plot_data(x, y):
ax.set_ylim(-80, 80)
ax.set_xticks(np.arange(0,121, 40))
ax.set_yticks(np.arange(-80,81, 40))
fig = plt.gcf()
fig.set_facecolor("white")
fig.set_size_inches(3., 3.)
plt.tight_layout()
fig.savefig("lin_regress.pdf")
plt.close()
def plot_data_slopes(x, y, m, n):
plt.scatter(x, y, marker='o', color='dodgerblue', s=40)
for i in np.linspace(m/4, m*1.5, 5):
plt.plot(x, i*x+n, color="r", lw=2)
plt.xlim([-2.5, 102.5])
ax = plt.gca()
def plot_data_slopes(ax, x, y, m, n):
ax.scatter(x, y, marker='o', color='b', s=40)
xx = np.asarray([2, 118])
for i in np.linspace(0.3*m, 2.0*m, 5):
ax.plot(xx, i*xx+n, color="r", lw=2)
ax.spines["right"].set_visible(False)
ax.spines["top"].set_visible(False)
ax.yaxis.set_ticks_position('left')
@@ -49,26 +41,18 @@ def plot_data_slopes(x, y, m, n):
ax.tick_params(direction="out", width=1.25)
ax.tick_params(direction="out", width=1.25)
ax.set_xlabel('Input x')
ax.set_ylabel('Output y')
#ax.set_ylabel('Output y')
ax.set_xlim(0, 120)
ax.set_ylim(-80, 80)
ax.set_xticks(np.arange(0,121, 40))
ax.set_yticks(np.arange(-80,81, 40))
fig = plt.gcf()
fig.set_facecolor("white")
fig.set_size_inches(3., 3.)
plt.tight_layout()
fig.savefig("lin_regress_slope.pdf")
plt.close()
def plot_data_intercepts(x, y, m, n):
plt.scatter(x, y, marker='o', color='dodgerblue', s=40)
for i in np.linspace(n-n/2, n+n/2, 5):
plt.plot(x, m * x + i, color="r", lw=2)
plt.xlim([-2.5, 102.5])
ax = plt.gca()
def plot_data_intercepts(ax, x, y, m, n):
ax.scatter(x, y, marker='o', color='b', s=40)
xx = np.asarray([2, 118])
for i in np.linspace(n-1*n, n+1*n, 5):
ax.plot(xx, m*xx + i, color="r", lw=2)
ax.spines["right"].set_visible(False)
ax.spines["top"].set_visible(False)
ax.yaxis.set_ticks_position('left')
@@ -76,22 +60,25 @@ def plot_data_intercepts(x, y, m, n):
ax.tick_params(direction="out", width=1.25)
ax.tick_params(direction="out", width=1.25)
ax.set_xlabel('Input x')
ax.set_ylabel('Output y')
#ax.set_ylabel('Output y')
ax.set_xlim(0, 120)
ax.set_ylim(-80, 80)
ax.set_xticks(np.arange(0,121, 40))
ax.set_yticks(np.arange(-80,81, 40))
fig = plt.gcf()
fig.set_facecolor("white")
fig.set_size_inches(3., 3.)
plt.tight_layout()
fig.savefig("lin_regress_intercept.pdf")
plt.close()
if __name__ == "__main__":
x, y, m, n = create_data()
plt.xkcd()
plot_data(x,y)
plot_data_slopes(x,y,m,n)
plot_data_intercepts(x,y,m,n)
fig = plt.figure()
ax = fig.add_subplot(1, 3, 1)
plot_data(ax, x, y)
ax = fig.add_subplot(1, 3, 2)
plot_data_slopes(ax, x, y, m, n)
ax = fig.add_subplot(1, 3, 3)
plot_data_intercepts(ax, x, y, m, n)
fig.set_facecolor("white")
fig.set_size_inches(7., 2.6)
fig.tight_layout()
fig.savefig("lin_regress.pdf")
plt.close()

View File

@@ -10,9 +10,7 @@ ein Optimierungsproblem, der besser als Kurvenfit bekannt ist
(\enterm{curve fitting}).
\begin{figure}[tp]
\includegraphics[width=0.33\columnwidth]{lin_regress}\hfill
\includegraphics[width=0.33\columnwidth]{lin_regress_slope}\hfill
\includegraphics[width=0.33\columnwidth]{lin_regress_intercept}
\includegraphics[width=1\textwidth]{lin_regress}\hfill
\titlecaption{.}{F\"ur eine Reihe von Eingangswerten $x$,
z.B. Stimulusintensit\"aten, wurden die Antworten $y$ eines
Systems gemessen (links). Der postulierte lineare Zusammenhang hat
@@ -32,14 +30,15 @@ beiden Parameter Steigung $m$ und $y$-Achsenabschnitt $n$ und es wird
die Kombination von $m$ und $n$ gesucht, die die Systemantwort am
besten vorhersagt.
In folgenden Kapitel werden wir anhand dieses Beispiels zeigen,
welchen Methoden hinter einem Kurvenfit stecken, wie also die optimale
Kombination aus Steigung und $y$-Achsenabschnitt gefunden werden kann.
In folgenden Kapitel werden wir anhand dieses Beispiels zeigen, welche
Methoden hinter einem Kurvenfit stecken, wie also numerisch die
optimale Kombination aus Steigung und $y$-Achsenabschnitt gefunden
werden kann.
\section{Methode der kleinsten quadratischen Abweichung}
Um die optimale Parameterkombination zu finden muss zun\"achst ein
Um die optimale Parameterkombination zu finden, muss zun\"achst ein
Ma{\ss} f\"ur den Unterschied zwischen den tats\"achlich gemessenen
und den unter Verwendung eines Parametersatzes vorhergesagten Werten
definiert werden. Eine der am h\"aufigsten verwendeten