MklComponentsCatalog.VectorWhiten Metode
Definisi
Penting
Beberapa informasi terkait produk prarilis yang dapat diubah secara signifikan sebelum dirilis. Microsoft tidak memberikan jaminan, tersirat maupun tersurat, sehubungan dengan informasi yang diberikan di sini.
Mengambil kolom yang diisi dengan vektor variabel acak dengan matriks kovarian yang diketahui ke dalam satu set variabel baru yang kovariansnya adalah matriks identitas, yang berarti bahwa variabel tersebut tidak terkait dan masing-masing memiliki variansi 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
Parameter
- catalog
- TransformsCatalog
Katalog transformasi.
- outputColumnName
- String
Nama kolom yang dihasilkan dari transformasi inputColumnName
.
- inputColumnName
- String
Nama kolom yang akan diubah. Jika diatur ke null
, nilai outputColumnName
akan digunakan sebagai sumber.
- kind
- WhiteningKind
Jenis whitening (PCA/ZCA).
- epsilon
- Single
Memisahkan konstanta, mencegah pembagian dengan nol.
- maximumNumberOfRows
- Int32
Jumlah baris maksimum yang digunakan untuk melatih transformasi.
- rank
- Int32
Dalam kasus pemutihan PCA, menunjukkan jumlah komponen yang akan dipertahankan.
Mengembalikan
Contoh
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;
}
}
}