def run(self, file_name):
     self.load_data(file_name)
     for index in range(len(self.data_X)):
         self.data_X[index] = [1] + self.data_X[index]
     temp = Matrix.multiply(Matrix.transpose(self.data_X), self.data_X)
     temp = Matrix.multiply(Matrix.inverse(temp), Matrix.transpose(self.data_X))
     temp = Matrix.multiply(temp, self.data_Y)
     return temp
Beispiel #2
0
def gaussian(x,u,C):
    res=(1/sqrt(2*math.pi*abs(Matrix.determinant(C))))
    temp=Matrix.transpose(Matrix.minus(x, u))
    temp=Matrix.multiply(temp, Matrix.inverse(C))
    temp=Matrix.multiply(temp,Matrix.minus(x, u))
    try:
        res*=exp(-0.5*temp[0][0])
    except:
        print(temp[0][0])
        print(x)
        print(u)
        print(C)
    return res
 def test_inverse(self):
     A=[[1,1,2],[-1,2,0],[1,1,3]]
     expected_result=[[2.0, -0.3333333333333333, -1.3333333333333335], [1.0, 0.3333333333333333, -0.6666666666666666], [-1.0, 0.0, 1.0]]
     actual_result=Matrix.inverse(A)
     self.assertEqual(expected_result, actual_result)