L2 norm for Variable<vector>
-
Friday, December 09, 2011 9:42 AM
Hi All,
I am new to infer.net and need some help.
I wrote and tried the following code :
Variable<double> A = Variable.GaussianFromMeanVariance(0,9)
Variable<double> B = Variable.GaussianFromMeanVariance(10,16)
Variable<double> d = Variable.GaussianFromMeanVariance(10,0.01)Variable.constrainTrue((d-(B-A)) < 0.01);
Variable.constrainTrue((d-(B-A)) > -0.01);InferenceEngine e = new InferenceEngine();
console.writeline(e.infer(A)+" "+e.infer(B)+" "+e.infer(d));
This worked satisfactorily for me.
However, I am having trouble moving to 2 dimensions using Multivariate Gaussian's with vector gaussians while
creating a constraint based on the L2 Norm. Here is the code I tried.double[] mean1 = {0,0};
double [,] covariance1 = new double[,] { {9,0} , {0,9}};
PositiveDefiniteMatrix matrix1 = new PositiveDefiniteMatrix(covariance1);
Variable<Vector> A = Variable.VectorGaussianFromMeanAndVariance(Vector.FromArray(mean1), matrix1);double[] mean2 = { 10, 10 };
double[,] covariance2 = new double[,] { { 16, 0 }, { 0, 16 } };
PositiveDefiniteMatrix matrix2 = new PositiveDefiniteMatrix(covariance2);
Variable<Vector> B = Variable.VectorGaussianFromMeanAndVariance(Vector.FromArray(mean2), matrix2);Variable<double> d = Variable.GaussianFromMeanAndVariance(10, 0.01);
%I want d^2 - L2Norm(B-A) < 0.01 and d^2 - L2Norm(B-A) > -0.01Variable.ConstrainTrue((d*d - (Variable<Vector>.innerProduct(B-A,B-A))) < 0.01);
Variable.constrainTrue((d*d -(Variable<Vector>.innerProduct(B-A,B-A))) > -0.01);InferenceEngine e = new InferenceEngine();
console.writeline(e.infer(A)+" "+e.infer(B)+" "+e.infer(d));
We get the following error.No operator factor registered for 'Minus' with argument type MicrosoftResearch.Infer.Maths.Vector.What should I do?
All Replies
-
Friday, December 09, 2011 10:10 AMInfer.NET does not yet support vector subtraction, and it also does not support L2Norm. Even if you got around the subtraction issue, InnerProduct would not allow you to multiply a random vector with itself, or even multiply a random scalar with itself. This is a known limitation. To get around it, you would have to implement your own factor for L2Norm (or more specific to your problem, ConstrainL2NormBetween). However, this is non-trivial, which is why we haven't done it yet.
-
Friday, December 09, 2011 11:45 AM
Hi Minka,
Thanks for the reply. On a related note, how do we use Gaussian Mixtures instead of Gaussians?
For example is there a way we can do the following?
Variable<double> A = Variable.GaussianMixture(double[] weights,double[] means, double[] variances)
Variable<double> B = Variable.GaussianMixture(double[] weights,double[] means, double[] variances)
Variable<double> d = Variable.GaussianMixture(double[] weights,double[] means, double[] variances)
Variable.constrainTrue((d-(B-A)) < 0.01);
Variable.constrainTrue((d-(B-A)) > -0.01);InferenceEngine e = new InferenceEngine();
console.writeline(e.infer(A)+" "+e.infer(B)+" "+e.infer(d));
We have already the Gaussian Mixture example http://research.microsoft.com/en-us/um/cambridge/projects/infernet/docs/Mixture%20of%20Gaussians%20tutorial.aspx .
But it was not clear how we could use this? -
Friday, December 09, 2011 11:53 AMIn the Gaussian Mixture example, 'data' is distributed according to a Gaussian mixture. It happens to be observed in that example, but this isn't essential. To make this easier, you can write a function GaussianMixture(double[] weights,double[] means, double[] variances) that constructs a variable with the same definition as 'data' in the example, and then call this 3 times. In your case, 'data' would be a Variable<double> instead of a VariableArray<Vector>.