/// <summary>
        /// This method creates PxFormula class object and set in it calculated nu vector and sigma matrix values.
        /// </summary>
        /// <param name="trainingSet">This is TrainingSet class object. Must contain training set with ONLY normal records.</param>
        /// <returns>PxFormula class object with setted nu vector and sigma matrix values.</returns>
        private static PxFormula CalcFormula(TrainingSet trainingSet)
        {
            var trainingSetCount = trainingSet.GetCountOfRecords();
            var size = trainingSet.GetAllRecords().First().Length;

            // calculate nu vector value
            var nu = new double[size];

            nu = trainingSet.GetAllRecords().Aggregate(nu, (current, featureVector) => current.Add(featureVector));
            nu = nu.Divide(trainingSetCount);

            // calculate sigme matrix
            var sigma = new double[size, size];

            sigma = trainingSet.GetAllRecords().Select(featureVector => featureVector.Subtract(nu)).Aggregate(sigma, (current, xNu) => current.Add(Matrix.ColumnVector(xNu).Multiply(Matrix.RowVector(xNu))));

            sigma = sigma.Divide(trainingSetCount);

            // return PxFormula class object with setted nu and sigma values
            return new PxFormula(nu, sigma);
        }
Exemple #2
0
        /// <summary>
        /// This method creates PxFormula class object and set in it calculated nu vector and sigma matrix values.
        /// </summary>
        /// <param name="trainingSet">This is TrainingSet class object. Must contain training set with ONLY normal records.</param>
        /// <returns>PxFormula class object with setted nu vector and sigma matrix values.</returns>
        private static PxFormula CalcFormula(TrainingSet trainingSet)
        {
            var trainingSetCount = trainingSet.GetCountOfRecords();
            var size             = trainingSet.GetAllRecords().First().Length;

            // calculate nu vector value
            var nu = new double[size];

            nu = trainingSet.GetAllRecords().Aggregate(nu, (current, featureVector) => current.Add(featureVector));
            nu = nu.Divide(trainingSetCount);

            // calculate sigme matrix
            var sigma = new double[size, size];

            sigma = trainingSet.GetAllRecords().Select(featureVector => featureVector.Subtract(nu)).Aggregate(sigma, (current, xNu) => current.Add(Matrix.ColumnVector(xNu).Multiply(Matrix.RowVector(xNu))));

            sigma = sigma.Divide(trainingSetCount);

            // return PxFormula class object with setted nu and sigma values
            return(new PxFormula(nu, sigma));
        }