/// <summary> /// Sets to uniform /// </summary> public void SetToUniform() { IncludePrior = false; InducingDist.SetToUniform(); pointFunc = null; ClearCachedValues(); }
public static VectorGaussian AAverageConditional(double innerProduct, Vector B, VectorGaussian result) { // a'*b == ip, therefore: // E[a]'*b == ip // b'*var(a)*b == 0 // inv(var(a)) = Inf*bb' // E[a] = ip*b/(b'b) result.SetToUniform(); bool nonzero(double x) => x != 0; int nonZeroCount = B.CountAll(nonzero); if (nonZeroCount == 0) { return(result); } else if (nonZeroCount == 1) { int index = B.FindFirstIndex(nonzero); result.Precision[index, index] = double.PositiveInfinity; result.MeanTimesPrecision[index] = innerProduct / B[index]; return(result); } else { throw new NotImplementedException(LowRankNotSupportedMessage); } }
public static VectorGaussian AAverageConditional([SkipIfUniform] VectorGaussian product, Gaussian b, VectorGaussian result) { if (!b.IsPointMass) { throw new ArgumentException("b is not a point mass", nameof(b)); } double bPoint = b.Point; if (bPoint == 0) { result.SetToUniform(); } else if (double.IsPositiveInfinity(bPoint)) { result.Point = result.Point; result.Point.SetAllElementsTo(0.0); } else if (product.IsPointMass) { result.Point = result.Point; result.Point.SetToProduct(product.Point, 1.0 / bPoint); } else { // mean = xMean/b // variance = xVariance/b^2 // precision = xPrecision*b^2 // meanTimesPrecision = xMeanTimesPrecision*b result.MeanTimesPrecision.SetToProduct(product.MeanTimesPrecision, bPoint); result.Precision.SetToProduct(product.Precision, bPoint * bPoint); } return(result); }
/// <summary> /// Predictive coariance at a given list of points /// </summary> /// <param name="XList">List of inputs</param> /// <returns>Predictive covariance</returns> public PositiveDefiniteMatrix Covariance(IList <Vector> XList) { if (IsUniform()) { VectorGaussian temp = new VectorGaussian(XList.Count); temp.SetToUniform(); return(temp.GetVariance()); } else { PositiveDefiniteMatrix kXX = FixedParameters.Prior.Covariance(XList); Matrix kXB = FixedParameters.KernelOf_X_B(XList); kXX.SetToDifference(kXX, kXB * Beta * kXB.Transpose()); return(kXX); } }
/// <summary> /// Mean at a given list of points /// </summary> /// <param name="XList">List of inputs</param> /// <returns>Predictive mean vector</returns> public Vector Mean(IList <Vector> XList) { if (IsUniform()) { VectorGaussian temp = new VectorGaussian(XList.Count); temp.SetToUniform(); return(temp.GetMean()); } else { int numPoints = XList.Count; Vector result = Vector.Zero(numPoints); for (int i = 0; i < numPoints; i++) { result[i] = Mean(XList[i]); } return(result); } }
/// <summary> /// EP message to 'x'. /// </summary> /// <param name="y">Incoming message from 'y'.</param> /// <param name="func">Incoming message from 'func'.</param> /// <param name="x">Constant value for 'x'.</param> /// <param name="result">Modified to contain the outgoing message.</param> /// <returns><paramref name="result"/></returns> /// <remarks><para> /// The outgoing message is the integral of the factor times incoming messages, over all arguments except 'x'. /// The formula is <c>int f(x,x) q(x) dx</c> where <c>x = (y,func)</c>. /// </para></remarks> public static VectorGaussian XAverageConditional(Gaussian y, SparseGP func, Vector x, VectorGaussian result) { // Doesn't matter what message we return as we are only supporting a point x result.SetToUniform(); return(result); }
/// <summary> /// EP message to 'x'. /// </summary> /// <param name="y">Incoming message from 'y'.</param> /// <param name="func">Incoming message from 'func'.</param> /// <param name="x">Constant value for 'x'.</param> /// <param name="result">Modified to contain the outgoing message.</param> /// <returns><paramref name="result"/></returns> /// <remarks><para> /// The outgoing message is the integral of the factor times incoming messages, over all arguments except 'x'. /// The formula is <c>int f(x,x) q(x) dx</c> where <c>x = (y,func)</c>. /// </para></remarks> public static VectorGaussian XAverageConditional(Gaussian y, SparseGP func, Vector x, VectorGaussian result) { // Doesn't matter what message we return as we are only supporting a point x result.SetToUniform(); return result; }