Ejemplo n.º 1
0
        public Func <IList <Tin>, double[][]> CreatePreprocessorFunction(PreprocessorCoefficients coefficients)
        {
            var means  = coefficients.Means;
            var sigmas = coefficients.Sigmas;

            return((sequence) =>
            {
                if (sequence.Count == 0)
                {
                    return new double[0][];
                }

                double[][] result = new double[sequence.Count][];
                for (int i = 0; i < sequence.Count; i++)
                {
                    result[i] = Datapoint.AsDblArrayFrom <Tin>(sequence[i]);
                }

                double[][] zscores = Accord.Statistics.Tools.ZScores(result, means, sigmas);

                return Accord.Math.Elementwise.Add(zscores, 10);
            });
        }
Ejemplo n.º 2
0
        public double[][] Preprocess(double[][] extracted, PreprocessorCoefficients?coefficients = null)
        {
            // If not using the (more advanced) precalculated full-dataset averages & sigmas, calculate them locally here.
            if (coefficients == null)
            {
                //var dims = Datapoint.From<Tsource>(default(Tsource)).Dimensions;
                var      dims = Dimensions;
                double[] currentAxisValues = new double[extracted.Length]; // Just to save on allocations a tiny bit by reusing it within a single axis.
                double[] means             = new double[dims];
                double[] sigmas            = new double[dims];

                for (int j = 0; j < dims; j++)
                {
                    for (int i = 0; i < extracted.Length; i++)
                    {
                        currentAxisValues[i] = extracted[i][j];
                    }
                    means[j]  = currentAxisValues.Average();
                    sigmas[j] = Accord.Statistics.Measures.StandardDeviation(currentAxisValues);
                }

                // Use our standard crosslinking function to lock values which should share a normalization constant into the same scale as each other.
                if (doCrosslink)
                {
                    sigmas = CrosslinkAxes.Apply <Tin>(sigmas);             // Locks values in the same space - like X and Y axes - to the same window size.
                }
                coefficients = new PreprocessorCoefficients()
                {
                    Means = means, Sigmas = sigmas
                };
            }

            // Calculate the z-scores, then make them positive by the simple expedient of adding ten to them.  (Yes, yes, but ten-sigma? Gotta mean an error anyway.)
            double[][] zscores = Accord.Statistics.Tools.ZScores(extracted, coefficients.Value.Means, coefficients.Value.Sigmas);
            return(Accord.Math.Elementwise.Add(zscores, 10));
        }