MklComponentsCatalog.VectorWhiten 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
알려진 공변성 행렬이 있는 임의 변수의 벡터로 채워진 열을 공변이 ID 행렬인 새 변수 집합으로 가져옵니다. 즉, 서로 상호 관련이 없으며 각각 분산 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
미백 상수, 0으로 나누기 방지.
- 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;
}
}
}