Ja du hast mein Problem richtig verstanden. ich hätte gerne eine Gerade U die die beiden repräsentativen Punkte verbindet und dann noch mal die Vereinigung L aus zwei Geraden, wobei jeweils eine Gerade einen repräsentativen Punkt mit dem Idealpunkt verbindet. Da wir drei Punkte haben, erhalten wir also Wenn wir U und L zusammen betrachten ein Dreieck.
Und wie du auch richtig erkannt hast möchte ich dann die Distanz entsprechend berechnen und zwar kannst du dir es besser vorstellen wir, wenn du hier schaust http://de.wikipedia.org/wiki/Hausdorff-Abstand. Ich verstehe allerdings nicht ganz, wie ich für die Geraden ein Gleichungssystem aufstellen soll. Oder kann ich eine Funktion definieren wie sie in Mathe beschrieben wir durch f(x)=m*x + b wobei m die Steigung ist und b der y-Achsenabschnitt? An so eine vorgehensweise habe ich noch nicht gedacht, aber wenn das gehen würde, würde ich es auf die Art versuchen.
Wenn du mir sagst wie ich Bilder hier hochladen kann, dann kann ich genau eine Zeichnung davon schicken. Ich habe die Algorithmen die ich programmieren möchte schon mit Beispielen per Hand gerechnet und in Latex geschrieben. Allerdings weis ich nicht, wie ich die zugehörigen Bilder, die einiges verdeutlichen würden hier hochladen kann.
Hausdorffdistanz
Normalerweise lädt man Bilder auf Imagehoster (imagebanana, ...) hoch (oder andere Alternativen, die Direktlinks erlauben wie zum Beispiel Dropbox) und stellt hier besagte Direktlinks ein.zwiety hat geschrieben:Wenn du mir sagst wie ich Bilder hier hochladen kann, dann kann ich genau eine Zeichnung davon schicken.
@zwiety: Wenn Du etwas ohne den Rechner ausrechnen kannst, dann kannst Du das natürlich genau so *mit* dem Rechner ausrechnen. Du musst Dir halt überlegen welche Eingabegrössen Du hast, und was Du daraus ausrechnen möchtest. Bei meinem Beispiel mit dem Punkt auf einer Geraden mit dem kleinsten Abstand zu einem anderen gegebenen Punkt, geht das zum Beispiel wie hier beschrieben: https://en.wikipedia.org/wiki/Distance_ ... _to_a_line
Ich hab bis jetzt das folgendes programmiert
Ist das der richtige Ansatz?
Code: Alles auswählen
import math
from itertools import izip
import numpy as np
def erfrage_koordinate():
return np.array(
[float(raw_input('{0}. Koordinate: '.format(i + 1))) for i in xrange(2)]
)
def lex_opt_standort(index, gewichte, standorte):
a = sum(
(g[index] * s for g, s in izip(gewichte, standorte)),
np.zeros(2)
)
return a / sum(gewicht[index] for gewicht in gewichte)
def f_i(x, index, gewichte, standorte):
return sum(
# g[index] * ((s[0] - x[0])**2) + g[index] * ((s[1] - x[1])**2)
# ⇒ (factoring)
# g[index] * ((s[0] - x[0])**2 + (s[1] - x[1])**2)
# ⇒ (using `numpy`)
(g[index] * (s - x)**2).sum() for g, s in izip(gewichte, standorte)
)
def f(x, gewichte, standorte):
return [f_i(x, i, gewichte, standorte) for i in xrange(2)]
def idealpunkt(xs,gewichte,standorte):
return [f_i(xs[i],i,gewichte,standorte) for i in xrange(2)]
def U(xs, index1, index2, gewichte, standorte):
r = np.array([f_i(xs[index1], i, gewichte, standorte) for i in xrange(2)])
a = np.array([f_i(xs[index2], i, gewichte, standorte) - f_i(xs[index1], i, gewichte, standorte) for i in xrange(2)])
return r, a
def L(xs, index1, index2, gewichte, standorte, t1, t2):
r = np.array(idealpunkt(xs, gewichte, standorte))
a = np.array([abs(f_i(xs[index1], i, gewichte, standorte) - idealpunkt(xs, gewichte, standorte)[i]) for i in xrange(2)])
b = np.array([abs(f_i(xs[index2], i, gewichte, standorte) - idealpunkt(xs, gewichte, standorte)[i]) for i in xrange(2)])
l = r + t1 * a + t2 * b
return l
def H(L, U):
return max(h(L, U), h(U, L))
def distanz(p, U, xs, gewichte, standorte):
r = np.array([U(xs, 0, 1, gewichte, standorte)[0][i] - p[i] for i in xrange(2)])
a = np.array([U(xs, 0, 1, gewichte, standorte)[1][i] for i in xrange(2)])
kreuzprod = a[0] * r[1] - a[1] * r[0]
norm_laenge = math.sqrt(a[0]**2 + a[1]**2)
print kreuzprod / norm_laenge
def main():
anzahl_standorte = int(raw_input('Anzahl der existierenden Standorte: '))
standorte = [erfrage_koordinate() for _ in xrange(anzahl_standorte)]
print 'Die Menge der existierenden Standorte ist: ', standorte
gewichte = [erfrage_koordinate() for _ in xrange(anzahl_standorte)]
print 'Die Menge der Gewichte ist: ', gewichte
genauigkeit=float(raw_input('Gewuenschte Genauigkeit: '))
xs = [lex_opt_standort(i, gewichte, standorte) for i in xrange(2)]
repraesentatives_system = [f(x, gewichte, standorte) for x in xs]
print repraesentatives_system
idealpunkt(xs, gewichte, standorte)
p = idealpunkt(xs, gewichte, standorte)
print distanz(p, U, xs, gewichte, standorte)
if __name__ == '__main__':
main()
Also ich hab jetzt mal angefangen die Distanz zu programmieren. kann mir vielleicht jemand sagen ob das so richtig ist oder wie ich das besser machen kann, weil ich die h(L, U,....) und h(U, L, ....) benötige aber das so leider nicht geht.
Code: Alles auswählen
import math
from itertools import izip
import numpy as np
def erfrage_koordinate():
return np.array(
[float(raw_input('{0}. Koordinate: '.format(i + 1))) for i in xrange(2)]
)
def lex_opt_standort(index, gewichte, standorte):
a = sum(
(g[index] * s for g, s in izip(gewichte, standorte)),
np.zeros(2)
)
return a / sum(gewicht[index] for gewicht in gewichte)
def f_i(x, index, gewichte, standorte):
return sum(
# g[index] * ((s[0] - x[0])**2) + g[index] * ((s[1] - x[1])**2)
# ⇒ (factoring)
# g[index] * ((s[0] - x[0])**2 + (s[1] - x[1])**2)
# ⇒ (using `numpy`)
(g[index] * (s - x)**2).sum() for g, s in izip(gewichte, standorte)
)
def f(x, gewichte, standorte):
return [f_i(x, i, gewichte, standorte) for i in xrange(2)]
def idealpunkt(xs,gewichte,standorte):
return [f_i(xs[i],i,gewichte,standorte) for i in xrange(2)]
def U(xs, index1, index2, gewichte, standorte, t):
a = np.array([f_i(xs[index1], i, gewichte, standorte) for i in xrange(2)])
r = np.array([f_i(xs[index2], i, gewichte, standorte) - f_i(xs[index1], i, gewichte, standorte) for i in xrange(2)])
return a + t * r
def U1(xs, index1, index2, gewichte, standorte):
a = np.array([f_i(xs[index1], i, gewichte, standorte) for i in xrange(2)])
r = np.array([f_i(xs[index2], i, gewichte, standorte) - f_i(xs[index1], i, gewichte, standorte) for i in xrange(2)])
return a, r
def L(xs, index1,index2, gewichte, standorte, t):
a = np.array(idealpunkt(xs, gewichte, standorte))
r = np.array([abs(f_i(xs[index1], i, gewichte, standorte) - idealpunkt(xs, gewichte, standorte)[i]) for i in xrange(2)])
return a + t * r
def L1(xs, index1, index2, gewichte, standorte):
a = np.array(idealpunkt(xs, gewichte, standorte))
r = np.array([abs(f_i(xs[index1], i, gewichte, standorte) - idealpunkt(xs, gewichte, standorte)[i]) for i in xrange(2)])
return a, r
def H(L, U1, xs, index1, index2, gewichte, standorte):
return max(
h(L, U1, xs, index1, index2, gewichte, standorte)
)
def h1(L, U1, xs, index1, index2, gewichte, standorte):
return max(
distanz(L(xs, index,index2, gewichte, standorte, t), xs, index1, index2, gewichte, standorte, U1)
for t in np.linspace(0, 1, num=500) for index in xrange(2)
)
def h2(U, L1, xs, index1, index2, gewichte, standorte):
return max(
distanz(U(xs, index1, index2, gewichte, standorte, t), xs, index1, index2, gewichte, standorte, L1)
for t in np.linspace(0, 1, num=500) for index in xrange(2)
)
def distanz(p, xs, index1, index2, gewichte, standorte, U1):
s1 = sum(
U1(xs, index1, index2, gewichte, standorte)[1] * ( p - U1(xs, index1, index2, gewichte, standorte)[0])
)
s2 = sum(
U1(xs, index1, index2, gewichte, standorte)[1]**2
)
t = s1 / s2
q = U(xs, index1, index2, gewichte, standorte, t)
return math.sqrt((p[0] - q[0])**2 + (p[1]- q[1])**2)
def main():
anzahl_standorte = int(raw_input('Anzahl der existierenden Standorte: '))
standorte = [erfrage_koordinate() for _ in xrange(anzahl_standorte)]
print 'Die Menge der existierenden Standorte ist: ', standorte
gewichte = [erfrage_koordinate() for _ in xrange(anzahl_standorte)]
print 'Die Menge der Gewichte ist: ', gewichte
genauigkeit=float(raw_input('Gewuenschte Genauigkeit: '))
xs = [lex_opt_standort(i, gewichte, standorte) for i in xrange(2)]
repraesentatives_system = [f(x, gewichte, standorte) for x in xs]
print repraesentatives_system
idealpunkt(xs, gewichte, standorte)
print h1(L, U1, xs, 0, 1, gewichte, standorte)
if __name__ == '__main__':
main()