示例#1
0
        public static DVectorNormal ToJointGaussian(params IKEPDist[] msgs)
        {
            // Stack all messages to form a big Gaussian distribution
            Vector[]      means = msgs.Select(dist => dist.GetMeanVector()).ToArray();
            Matrix[]      covs  = msgs.Select(dist => dist.GetCovarianceMatrix()).ToArray();
            Vector        M     = MatrixUtils.ConcatAll(means);
            Matrix        V     = MatrixUtils.BlkDiag(covs);
            DVectorNormal joint = new DVectorNormal(M, V);

            return(joint);
        }
示例#2
0
        public override double[] GenFeatures(params IKEPDist[] msgs)
        {
            DVectorNormal joint = ToJointGaussian(msgs);

            InitMap(joint);
            Vector innerFeature = eprodMap.MapToVector(joint);
            Vector FWout        = innerFeature * Wout;

            double[] fea   = new double[this.numFeatures];
            double   scale = Math.Sqrt(2.0 / numFeatures);

            for (int i = 0; i < fea.Length; i++)
            {
                fea[i] = Math.Cos(FWout[i] + Bout[i]) * scale;
            }
            return(fea);
        }
示例#3
0
        public void InitMap(DVectorNormal joint)
        {
            // dynamically initialize the random feature map
            if (Wout == null)
            {
                Debug.Assert(Bout == null);
                int totalDim = joint.GetDimension();
                if (totalDim != flattenEmbedWidth2s.Length)
                {
                    throw new SystemException("Expect total dim. of the joint to be = length of params.");
                }

                eprodMap = new RFGEProdMap(flattenEmbedWidth2s, innerNumFeatures);
                Wout     = MatrixUtils.Randn(innerNumFeatures, numFeatures) * (1.0 / Math.Sqrt(outer_width2));
                double[] Bvec = MatrixUtils.UniformVector(0, 2.0 * Math.PI, numFeatures);
                Bout = Vector.FromArray(Bvec);
                //			VectorGaussian.SampleFromMeanAndVariance();
            }
        }