// This is the main DLL file. #include "stdafx.h" #include #include "HeuristicLab.Eigen.h" #include "Eigen/Dense" #include "Eigen/Core" using namespace Eigen; using namespace std; namespace HeuristicLabEigen { void MyEigen::Solve(double a[], double x[], double alpha[], double invL[], double sqrSigmaNoise, int n, double* negLogLikelihood, int* computationInfo) { MatrixXd A = Map>(a, n, n); LLT chol = A.llt(); *computationInfo = chol.info(); if(chol.info() != Success) return; VectorXd res = chol.solve(Map(x, n)) / sqrSigmaNoise; for(int i=0;i(x, n).dot(res) + chol.matrixU().toDenseMatrix().diagonal<0>().array().log().sum() + (n / 2.0) * log(2.0 * M_PI * sqrSigmaNoise); MatrixXd invLRes = chol.solve(MatrixXd::Identity(n,n)) / sqrSigmaNoise - res * res.transpose(); for(int i=0;i Math.Log(chol[i * i])).Sum(); //// solve for alpha //ILArray ym = ILMath.array(y.Zip(m, (a, b) => a - b).ToArray()); //MatrixProperties lowerTriProps = MatrixProperties.LowerTriangular; //MatrixProperties upperTriProps = MatrixProperties.UpperTriangular; //ILArray alpha; //try { // ILArray t1 = ILMath.linsolve(chol.T, ym, ref lowerTriProps); // alpha = ILMath.linsolve(chol, t1, ref upperTriProps) / sqrSigmaNoise; //} //catch (Exception e) { // throw new ArgumentException("covariance matrix is not positive definite", e); //} //if (alpha == null || alpha.IsEmpty) throw new ArgumentException(); //this.alpha = new double[alpha.Length]; //alpha.ExportValues(ref this.alpha); //negativeLogLikelihood = 0.5 * (double)ILMath.multiply(ym.T, alpha) + diagSum + (n / 2.0) * Math.Log(2.0 * Math.PI * sqrSigmaNoise); //// derivatives //int nAllowedVariables = x.GetLength(1); //ILArray lCopy; //try { // ILArray t2 = ILMath.linsolve(chol.T, ILMath.eye(n, n), ref lowerTriProps); // lCopy = ILMath.linsolve(chol, t2, ref upperTriProps) / sqrSigmaNoise - ILMath.multiply(alpha, alpha.T); //} //catch (Exception e) { // throw new ArgumentException("covariance matrix is not positive definite", e); //} //double noiseGradient = sqrSigmaNoise * ILMath.sumall(ILMath.diag(lCopy)).GetValue(0, 0); //double[] meanGradients = new double[meanFunction.GetNumberOfParameters(nAllowedVariables)]; //for (int k = 0; k < meanGradients.Length; k++) { // ILArray meanGrad = // ILMath.array( // Enumerable.Range(0, alpha.Length) // .Select(r => mean.Gradient(x, r, k)) // .ToArray()); // meanGradients[k] = -(double)ILMath.multiply(meanGrad.T, alpha); //} }