共用方式為


MklComponentsCatalog.VectorWhiten 方法

定義

將資料行填入具有已知共變數矩陣的隨機變數向量,併入一組新的變數,其中共變數是識別矩陣,這表示它們不相關,而且每個變數都有變異數 1。

public static Microsoft.ML.Transforms.VectorWhiteningEstimator VectorWhiten (this Microsoft.ML.TransformsCatalog catalog, string outputColumnName, string inputColumnName = default, Microsoft.ML.Transforms.WhiteningKind kind = Microsoft.ML.Transforms.WhiteningKind.ZeroPhaseComponentAnalysis, float epsilon = 1E-05, int maximumNumberOfRows = 100000, int rank = 0);
static member VectorWhiten : Microsoft.ML.TransformsCatalog * string * string * Microsoft.ML.Transforms.WhiteningKind * single * int * int -> Microsoft.ML.Transforms.VectorWhiteningEstimator
<Extension()>
Public Function VectorWhiten (catalog As TransformsCatalog, outputColumnName As String, Optional inputColumnName As String = Nothing, Optional kind As WhiteningKind = Microsoft.ML.Transforms.WhiteningKind.ZeroPhaseComponentAnalysis, Optional epsilon As Single = 1E-05, Optional maximumNumberOfRows As Integer = 100000, Optional rank As Integer = 0) As VectorWhiteningEstimator

參數

catalog
TransformsCatalog

轉換的目錄。

outputColumnName
String

轉換所產生的 inputColumnName 資料行名稱。

inputColumnName
String

要轉換的資料行名稱。 如果設定為 null ,則會將 的值 outputColumnName 當做來源使用。

kind
WhiteningKind

PCA/ZCA) (白化種類。

epsilon
Single

白化常數,可防止除以零。

maximumNumberOfRows
Int32

用來定型轉換的資料列數目上限。

rank
Int32

如果是 PCA 白化,表示要保留的元件數目。

傳回

範例

using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.ML;
using Microsoft.ML.Data;

namespace Samples.Dynamic
{
    public sealed class VectorWhiten
    {

        /// This example requires installation of additional nuget package 
        /// <a href="https://www.nuget.org/packages/Microsoft.ML.Mkl.Components/">Microsoft.ML.Mkl.Components</a>.
        public static void Example()
        {
            // Create a new ML context, for ML.NET operations. It can be used for
            // exception tracking and logging, as well as the source of randomness.
            var ml = new MLContext();

            // Get a small dataset as an IEnumerable and convert it to an IDataView.
            var data = GetVectorOfNumbersData();
            var trainData = ml.Data.LoadFromEnumerable(data);

            // Preview of the data.
            //
            // Features
            // 0   1   2   3   4   5   6   7   8   9
            // 1   2   3   4   5   6   7   8   9   0  
            // 2   3   4   5   6   7   8   9   0   1
            // 3   4   5   6   7   8   9   0   1   2
            // 4   5   6   7   8   9   0   1   2   3
            // 5   6   7   8   9   0   1   2   3   4
            // 6   7   8   9   0   1   2   3   4   5

            // A small printing utility.
            Action<string, IEnumerable<VBuffer<float>>> printHelper = (colName,
                column) =>
            {
                Console.WriteLine($"{colName} column obtained " +
                    $"post-transformation.");

                foreach (var row in column)
                    Console.WriteLine(string.Join(" ", row.DenseValues().Select(x =>
                        x.ToString("f3"))) + " ");
            };

            // A pipeline to project Features column into white noise vector.
            var whiteningPipeline = ml.Transforms.VectorWhiten(nameof(
                SampleVectorOfNumbersData.Features), kind: Microsoft.ML.Transforms
                .WhiteningKind.ZeroPhaseComponentAnalysis);

            // The transformed (projected) data.
            var transformedData = whiteningPipeline.Fit(trainData).Transform(
                trainData);

            // Getting the data of the newly created column, so we can preview it.
            var whitening = transformedData.GetColumn<VBuffer<float>>(
                transformedData.Schema[nameof(SampleVectorOfNumbersData.Features)]);

            printHelper(nameof(SampleVectorOfNumbersData.Features), whitening);

            // Features column obtained post-transformation.
            //
            //-0.394 -0.318 -0.243 -0.168  0.209  0.358  0.433  0.589  0.873  2.047
            //-0.034  0.030  0.094  0.159  0.298  0.427  0.492  0.760  1.855 -1.197
            // 0.099  0.161  0.223  0.286  0.412  0.603  0.665  1.797 -1.265 -0.172
            // 0.211  0.277  0.344  0.410  0.606  1.267  1.333 -1.340 -0.205  0.065
            // 0.454  0.523  0.593  0.664  1.886 -0.757 -0.687 -0.022  0.176  0.310
            // 0.863  0.938  1.016  1.093 -1.326 -0.096 -0.019  0.189  0.330  0.483
        }

        private class SampleVectorOfNumbersData
        {
            [VectorType(10)]
            public float[] Features { get; set; }
        }

        /// <summary>
        /// Returns a few rows of the infertility dataset.
        /// </summary>
        private static IEnumerable<SampleVectorOfNumbersData>
            GetVectorOfNumbersData()
        {
            var data = new List<SampleVectorOfNumbersData>();
            data.Add(new SampleVectorOfNumbersData
            {
                Features = new float[10] { 0,
                1, 2, 3, 4, 5, 6, 7, 8, 9 }
            });

            data.Add(new SampleVectorOfNumbersData
            {
                Features = new float[10] { 1,
                2, 3, 4, 5, 6, 7, 8, 9, 0 }
            });

            data.Add(new SampleVectorOfNumbersData
            {
                Features = new float[10] { 2, 3, 4, 5, 6, 7, 8, 9, 0, 1 }
            });
            data.Add(new SampleVectorOfNumbersData
            {
                Features = new float[10] { 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, }
            });
            data.Add(new SampleVectorOfNumbersData
            {
                Features = new float[10] { 5, 6, 7, 8, 9, 0, 1, 2, 3, 4 }
            });
            data.Add(new SampleVectorOfNumbersData
            {
                Features = new float[10] { 6, 7, 8, 9, 0, 1, 2, 3, 4, 5 }
            });
            return data;
        }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.ML;
using Microsoft.ML.Data;

namespace Samples.Dynamic
{
    public sealed class VectorWhitenWithOptions
    {
        /// This example requires installation of additional nuget package
        /// <a href="https://www.nuget.org/packages/Microsoft.ML.Mkl.Components/">Microsoft.ML.Mkl.Components</a>.
        public static void Example()
        {
            // Create a new ML context, for ML.NET operations. It can be used for
            // exception tracking and logging, as well as the source of randomness.
            var ml = new MLContext();

            // Get a small dataset as an IEnumerable and convert it to an IDataView.
            var data = GetVectorOfNumbersData();
            var trainData = ml.Data.LoadFromEnumerable(data);

            // Preview of the data.
            //
            // Features
            // 0   1   2   3   4   5   6   7   8   9
            // 1   2   3   4   5   6   7   8   9   0  
            // 2   3   4   5   6   7   8   9   0   1
            // 3   4   5   6   7   8   9   0   1   2
            // 4   5   6   7   8   9   0   1   2   3
            // 5   6   7   8   9   0   1   2   3   4
            // 6   7   8   9   0   1   2   3   4   5

            // A small printing utility.
            Action<string, IEnumerable<VBuffer<float>>> printHelper = (colName,
                column) =>
            {
                Console.WriteLine($"{colName} column obtained" +
                    $"post-transformation.");

                foreach (var row in column)
                    Console.WriteLine(string.Join(" ", row.DenseValues().Select(x =>
                        x.ToString("f3"))) + " ");
            };


            // A pipeline to project Features column into white noise vector.
            var whiteningPipeline = ml.Transforms.VectorWhiten(nameof(
                SampleVectorOfNumbersData.Features), kind: Microsoft.ML.Transforms
                .WhiteningKind.PrincipalComponentAnalysis, rank: 4);

            // The transformed (projected) data.
            var transformedData = whiteningPipeline.Fit(trainData).Transform(
                trainData);

            // Getting the data of the newly created column, so we can preview it.
            var whitening = transformedData.GetColumn<VBuffer<float>>(
                transformedData.Schema[nameof(SampleVectorOfNumbersData.Features)]);

            printHelper(nameof(SampleVectorOfNumbersData.Features), whitening);

            // Features column obtained post-transformation.
            // -0.979  0.867  1.449  1.236
            // -1.030  1.012  0.426 -0.902
            // -1.047  0.677 -0.946 -1.060
            // -1.029  0.019 -1.502  1.108
            // -0.972 -1.338 -0.028  0.614
            // -0.938 -1.405  0.752 -0.967
        }

        private class SampleVectorOfNumbersData
        {
            [VectorType(10)]
            public float[] Features { get; set; }
        }

        /// <summary>
        /// Returns a few rows of the infertility dataset.
        /// </summary>
        private static IEnumerable<SampleVectorOfNumbersData>
            GetVectorOfNumbersData()
        {
            var data = new List<SampleVectorOfNumbersData>();
            data.Add(new SampleVectorOfNumbersData
            {
                Features = new float[10] { 0,
                1, 2, 3, 4, 5, 6, 7, 8, 9 }
            });

            data.Add(new SampleVectorOfNumbersData
            {
                Features = new float[10] { 1,
                2, 3, 4, 5, 6, 7, 8, 9, 0 }
            });

            data.Add(new SampleVectorOfNumbersData
            {
                Features = new float[10] { 2, 3, 4, 5, 6, 7, 8, 9, 0, 1 }
            });
            data.Add(new SampleVectorOfNumbersData
            {
                Features = new float[10] { 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, }
            });
            data.Add(new SampleVectorOfNumbersData
            {
                Features = new float[10] { 5, 6, 7, 8, 9, 0, 1, 2, 3, 4 }
            });
            data.Add(new SampleVectorOfNumbersData
            {
                Features = new float[10] { 6, 7, 8, 9, 0, 1, 2, 3, 4, 5 }
            });
            return data;
        }
    }
}

適用於