so heute bin ich mal mit "Hausaufgaben" dran Ich soll den Score einer Gaussmixturverteilung mittels dieser Formel berechnen:
mit
Die Mixturverteilung besteht aus zwei Gausglocken mit den Eigenschaften:
1. Gauss:
Gewicht: 0.4
Mittelwertsvektor : [3, 4.5]
Kovarianzmatrix : [[3,0],
[0,3]]
2. Gauss:
Gewicht: 0.6
Mittelwertsvektor : [4, -1]
Kovarianzmatrix : [[2,0],
[0,2]]
und der Vektor [2,1.5] soll bewertet werden.
Hier mein Ansatz in python:
Code: Alles auswählen
from __future__ import division
import numpy
from numpy import linalg
import math
def gauss(m, sigma, x, n):
return 1/(math.sqrt((2*math.pi)**n*linalg.det(sigma)))*math.exp(-0.5*(x-m).transpose()*linalg.inv(sigma)*(x-m))
def calculate_gaussian_score():
weights = [0.4, 0.6]
ms = [numpy.array([[3,4.5]]), numpy.array([[4,-1]])]
sigmas = [numpy.diag([3,3]), numpy.diag([2,2])]
vector = numpy.array([[2, 1.5]])
return sum([weights[index]*gauss(ms[index].transpose(), numpy.matrix(sigmas[index]), vector.transpose(), len(weights)) for index in range(2)])
Grüße,
anogayales