示例#1
0
        public static double Variance <F>(this Vector <F> vec) where F : IRealHilbertField <F>, new()
        {
            var mean   = vec.Mean();
            var zeroed = new Vector <F>(vec.Select(f => f.IsZero() ? f : f.Subtract(mean)));

            return(zeroed.Aggregate(new F(), (a, f) => a.Add(f.Square())).Divide(vec.Count(f => !f.IsZero())).AbsSqrt().RealPart());
        }
示例#2
0
        public VectorAggregateFunc(params IntegrableFunction <S, T>[] comps)
        {
            this.comps = comps;
            Fst        = Vector <T> .Aggregate <S>(comps.Map(x => x.F));

            FIst = Vector <T> .Aggregate <S>(comps.Map(x => x.FI));
        }
示例#3
0
        public static void Main()
        {
            Particle p = new Particle(t => t, t => t);

            p.ChangeTrajectory(Vector <double> .Aggregate <double>(t => 2 * t, t => t), 2);
            for (double d = 0; d < 5; d += 0.1)
            {
                p.Time = d;
                Console.WriteLine(p.CurrentPosition);
            }
            Console.ReadKey();
        }
示例#4
0
        public override string ToString()
        {
            var result = "\t" + Vector.Aggregate((p, n) => p + "\t" + n) + "\n";

            for (var i = 0; i < Matrix.Count; i++)
            {
                result += Vector[i] + "\t";
                result += Matrix[i].Aggregate((p, n) => p + "\t" + n);
                result += "\n";
            }

            return(result);
        }
示例#5
0
        /// <summary>Compute probability according to multivariate Gaussian.</summary>
        /// <param name="x">Vector in question.</param>
        /// <param name="mu">Mean.</param>
        /// <param name="sigma">diag(covariance)</param>
        /// <returns>Probability.</returns>
        private double Normal(Vector x, Vector mu, Vector sigma)
        {
            // 1 / (2pi)^(2/D) where D = length of sigma
            var one_over_2pi = 1 / System.Math.Pow(2 * System.Math.PI, 2 / sigma.Length);

            // 1 / sqrt(det(sigma)) where det(sigma) is the product of the diagonals

            var one_over_det_sigma = System.Math.Sqrt(sigma.Aggregate(1d, (a, i) => a *= i));

            // -.5 (x-mu).T sigma^-1 (x-mu) I have taken some liberties ;)
            var exp = -0.5d * ((x - mu) * sigma.Each(d => 1 / d, true)).Dot(x - mu);

            // e^(exp)
            var e_exp = System.Math.Pow(System.Math.E, exp);

            var result = one_over_2pi * one_over_det_sigma * e_exp;

            return(result);
        }
示例#6
0
        public void WriteMatrix()
        {
            Console.WriteLine("\t" + Vector.Aggregate((p, n) => p + "\t" + n));
            for (var i = 0; i < Matrix.Count; i++)
            {
                Console.Write(Vector[i] + "\t");
                for (var j = 0; j < Matrix[i].Count; j++)
                {
                    var val = Changed.Find(coord => coord.I == i && coord.J == j);
                    if (val != null)
                    {
                        Console.ForegroundColor = ConsoleColor.Yellow;
                    }

                    Console.Write(Matrix[i][j] + "\t");
                    Console.ForegroundColor = ConsoleColor.White;
                }

                Console.WriteLine();
            }

            Changed.Clear();
        }
示例#7
0
 public string VectorToString()
 {
     return("{ " + Vector.Aggregate((p, n) => p + " " + n) + " }");
 }
示例#8
0
 public Particle(params Func <double, double>[] components)
     : this(null, Vector <double> .Aggregate <double>(components))
 {
 }
 public static Vector<float> FindCentroid(Vector<float>[] set)
 {
     return set.Aggregate((v1, v2) => v1 + v2) / set.Length;
 }