15
15
using Microsoft . ML . Model ;
16
16
using Microsoft . ML . Transforms ;
17
17
18
- [ assembly: LoadableClass ( RandomFourierFeaturizingTransformer . Summary , typeof ( IDataTransform ) , typeof ( RandomFourierFeaturizingTransformer ) , typeof ( RandomFourierFeaturizingTransformer . Options ) , typeof ( SignatureDataTransform ) ,
18
+ [ assembly: LoadableClass ( RandomFourierExpansionTransformer . Summary , typeof ( IDataTransform ) , typeof ( RandomFourierExpansionTransformer ) , typeof ( RandomFourierExpansionTransformer . Options ) , typeof ( SignatureDataTransform ) ,
19
19
"Random Fourier Features Transform" , "RffTransform" , "Rff" ) ]
20
20
21
- [ assembly: LoadableClass ( RandomFourierFeaturizingTransformer . Summary , typeof ( IDataTransform ) , typeof ( RandomFourierFeaturizingTransformer ) , null , typeof ( SignatureLoadDataTransform ) ,
22
- "Random Fourier Features Transform" , RandomFourierFeaturizingTransformer . LoaderSignature ) ]
21
+ [ assembly: LoadableClass ( RandomFourierExpansionTransformer . Summary , typeof ( IDataTransform ) , typeof ( RandomFourierExpansionTransformer ) , null , typeof ( SignatureLoadDataTransform ) ,
22
+ "Random Fourier Features Transform" , RandomFourierExpansionTransformer . LoaderSignature ) ]
23
23
24
- [ assembly: LoadableClass ( RandomFourierFeaturizingTransformer . Summary , typeof ( RandomFourierFeaturizingTransformer ) , null , typeof ( SignatureLoadModel ) ,
25
- "Random Fourier Features Transform" , RandomFourierFeaturizingTransformer . LoaderSignature ) ]
24
+ [ assembly: LoadableClass ( RandomFourierExpansionTransformer . Summary , typeof ( RandomFourierExpansionTransformer ) , null , typeof ( SignatureLoadModel ) ,
25
+ "Random Fourier Features Transform" , RandomFourierExpansionTransformer . LoaderSignature ) ]
26
26
27
- [ assembly: LoadableClass ( typeof ( IRowMapper ) , typeof ( RandomFourierFeaturizingTransformer ) , null , typeof ( SignatureLoadRowMapper ) ,
28
- "Random Fourier Features Transform" , RandomFourierFeaturizingTransformer . LoaderSignature ) ]
27
+ [ assembly: LoadableClass ( typeof ( IRowMapper ) , typeof ( RandomFourierExpansionTransformer ) , null , typeof ( SignatureLoadRowMapper ) ,
28
+ "Random Fourier Features Transform" , RandomFourierExpansionTransformer . LoaderSignature ) ]
29
29
30
30
namespace Microsoft . ML . Transforms
31
31
{
@@ -36,21 +36,21 @@ namespace Microsoft.ML.Transforms
36
36
/// This transformation is based on this paper by
37
37
/// <a href="http://pages.cs.wisc.edu/~brecht/papers/07.rah.rec.nips.pdf">Rahimi and Recht</a>.
38
38
/// </summary>
39
- public sealed class RandomFourierFeaturizingTransformer : OneToOneTransformerBase
39
+ public sealed class RandomFourierExpansionTransformer : OneToOneTransformerBase
40
40
{
41
41
internal sealed class Options
42
42
{
43
43
[ Argument ( ArgumentType . Multiple | ArgumentType . Required , HelpText = "New column definition(s) (optional form: name:src)" , Name = "Column" , ShortName = "col" , SortOrder = 1 ) ]
44
44
public Column [ ] Columns ;
45
45
46
46
[ Argument ( ArgumentType . AtMostOnce , HelpText = "The number of random Fourier features to create" , ShortName = "dim" ) ]
47
- public int NewDim = RandomFourierFeaturizingEstimator . Defaults . Dimension ;
47
+ public int NewDim = RandomFourierExpansionEstimator . Defaults . Dimension ;
48
48
49
49
[ Argument ( ArgumentType . Multiple , HelpText = "Which kernel to use?" , ShortName = "kernel" , SignatureType = typeof ( SignatureKernelBase ) ) ]
50
50
public IComponentFactory < KernelBase > MatrixGenerator = new GaussianKernel . Options ( ) ;
51
51
52
52
[ Argument ( ArgumentType . AtMostOnce , HelpText = "Create two features for every random Fourier frequency? (one for cos and one for sin)" ) ]
53
- public bool UseSin = RandomFourierFeaturizingEstimator . Defaults . UseCosAndSinBases ;
53
+ public bool UseSin = RandomFourierExpansionEstimator . Defaults . UseCosAndSinBases ;
54
54
55
55
[ Argument ( ArgumentType . LastOccurenceWins ,
56
56
HelpText = "The seed of the random number generator for generating the new features (if unspecified, " +
@@ -109,7 +109,7 @@ private sealed class TransformInfo
109
109
private readonly TauswortheHybrid _rand ;
110
110
private readonly TauswortheHybrid . State _state ;
111
111
112
- public TransformInfo ( IHost host , RandomFourierFeaturizingEstimator . ColumnOptions column , int d , float avgDist )
112
+ public TransformInfo ( IHost host , RandomFourierExpansionEstimator . ColumnOptions column , int d , float avgDist )
113
113
{
114
114
Contracts . AssertValue ( host ) ;
115
115
@@ -224,7 +224,7 @@ private static VersionInfo GetVersionInfo()
224
224
verReadableCur : 0x00010002 ,
225
225
verWeCanReadBack : 0x00010001 ,
226
226
loaderSignature : LoaderSignature ,
227
- loaderAssemblyName : typeof ( RandomFourierFeaturizingTransformer ) . Assembly . FullName ) ;
227
+ loaderAssemblyName : typeof ( RandomFourierExpansionTransformer ) . Assembly . FullName ) ;
228
228
}
229
229
230
230
private readonly TransformInfo [ ] _transformInfos ;
@@ -238,7 +238,7 @@ private static string TestColumnType(DataViewType type)
238
238
return "Expected vector of floats with known size" ;
239
239
}
240
240
241
- private static ( string outputColumnName , string inputColumnName ) [ ] GetColumnPairs ( RandomFourierFeaturizingEstimator . ColumnOptions [ ] columns )
241
+ private static ( string outputColumnName , string inputColumnName ) [ ] GetColumnPairs ( RandomFourierExpansionEstimator . ColumnOptions [ ] columns )
242
242
{
243
243
Contracts . CheckValue ( columns , nameof ( columns ) ) ;
244
244
return columns . Select ( x => ( x . Name , x . InputColumnName ) ) . ToArray ( ) ;
@@ -255,8 +255,8 @@ private protected override void CheckInputColumn(DataViewSchema inputSchema, int
255
255
new VectorType ( NumberDataViewType . Single , _transformInfos [ col ] . SrcDim ) . ToString ( ) , type . ToString ( ) ) ;
256
256
}
257
257
258
- internal RandomFourierFeaturizingTransformer ( IHostEnvironment env , IDataView input , RandomFourierFeaturizingEstimator . ColumnOptions [ ] columns )
259
- : base ( Contracts . CheckRef ( env , nameof ( env ) ) . Register ( nameof ( RandomFourierFeaturizingTransformer ) ) , GetColumnPairs ( columns ) )
258
+ internal RandomFourierExpansionTransformer ( IHostEnvironment env , IDataView input , RandomFourierExpansionEstimator . ColumnOptions [ ] columns )
259
+ : base ( Contracts . CheckRef ( env , nameof ( env ) ) . Register ( nameof ( RandomFourierExpansionTransformer ) ) , GetColumnPairs ( columns ) )
260
260
{
261
261
var avgDistances = GetAvgDistances ( columns , input ) ;
262
262
_transformInfos = new TransformInfo [ columns . Length ] ;
@@ -281,7 +281,7 @@ private static int RoundUp(int cflt, int cfltAlign)
281
281
return cblob * cfltAlign ;
282
282
}
283
283
284
- private float [ ] GetAvgDistances ( RandomFourierFeaturizingEstimator . ColumnOptions [ ] columns , IDataView input )
284
+ private float [ ] GetAvgDistances ( RandomFourierExpansionEstimator . ColumnOptions [ ] columns , IDataView input )
285
285
{
286
286
var avgDistances = new float [ columns . Length ] ;
287
287
const int reservoirSize = 5000 ;
@@ -395,7 +395,7 @@ private static IDataTransform Create(IHostEnvironment env, ModelLoadContext ctx,
395
395
private static IRowMapper Create ( IHostEnvironment env , ModelLoadContext ctx , DataViewSchema inputSchema )
396
396
=> Create ( env , ctx ) . MakeRowMapper ( inputSchema ) ;
397
397
398
- private RandomFourierFeaturizingTransformer ( IHost host , ModelLoadContext ctx )
398
+ private RandomFourierExpansionTransformer ( IHost host , ModelLoadContext ctx )
399
399
: base ( host , ctx )
400
400
{
401
401
// *** Binary format ***
@@ -420,14 +420,14 @@ private static IDataTransform Create(IHostEnvironment env, Options options, IDat
420
420
env . CheckValue ( input , nameof ( input ) ) ;
421
421
422
422
env . CheckValue ( options . Columns , nameof ( options . Columns ) ) ;
423
- var cols = new RandomFourierFeaturizingEstimator . ColumnOptions [ options . Columns . Length ] ;
423
+ var cols = new RandomFourierExpansionEstimator . ColumnOptions [ options . Columns . Length ] ;
424
424
using ( var ch = env . Start ( "ValidateArgs" ) )
425
425
{
426
426
427
427
for ( int i = 0 ; i < cols . Length ; i ++ )
428
428
{
429
429
var item = options . Columns [ i ] ;
430
- cols [ i ] = new RandomFourierFeaturizingEstimator . ColumnOptions (
430
+ cols [ i ] = new RandomFourierExpansionEstimator . ColumnOptions (
431
431
item . Name ,
432
432
item . NewDim ?? options . NewDim ,
433
433
item . UseSin ?? options . UseSin ,
@@ -436,14 +436,14 @@ private static IDataTransform Create(IHostEnvironment env, Options options, IDat
436
436
item . Seed ?? options . Seed ) ;
437
437
} ;
438
438
}
439
- return new RandomFourierFeaturizingTransformer ( env , input , cols ) . MakeDataTransform ( input ) ;
439
+ return new RandomFourierExpansionTransformer ( env , input , cols ) . MakeDataTransform ( input ) ;
440
440
}
441
441
442
442
// Factory method for SignatureLoadModel.
443
- private static RandomFourierFeaturizingTransformer Create ( IHostEnvironment env , ModelLoadContext ctx )
443
+ private static RandomFourierExpansionTransformer Create ( IHostEnvironment env , ModelLoadContext ctx )
444
444
{
445
445
Contracts . CheckValue ( env , nameof ( env ) ) ;
446
- var host = env . Register ( nameof ( RandomFourierFeaturizingTransformer ) ) ;
446
+ var host = env . Register ( nameof ( RandomFourierExpansionTransformer ) ) ;
447
447
448
448
host . CheckValue ( ctx , nameof ( ctx ) ) ;
449
449
ctx . CheckAtModel ( GetVersionInfo ( ) ) ;
@@ -452,7 +452,7 @@ private static RandomFourierFeaturizingTransformer Create(IHostEnvironment env,
452
452
int cbFloat = ctx . Reader . ReadInt32 ( ) ;
453
453
env . CheckDecode ( cbFloat == sizeof ( float ) ) ;
454
454
}
455
- return new RandomFourierFeaturizingTransformer ( host , ctx ) ;
455
+ return new RandomFourierExpansionTransformer ( host , ctx ) ;
456
456
}
457
457
458
458
private protected override void SaveModel ( ModelSaveContext ctx )
@@ -476,9 +476,9 @@ private sealed class Mapper : OneToOneMapperBase
476
476
private readonly DataViewType [ ] _srcTypes ;
477
477
private readonly int [ ] _srcCols ;
478
478
private readonly DataViewType [ ] _types ;
479
- private readonly RandomFourierFeaturizingTransformer _parent ;
479
+ private readonly RandomFourierExpansionTransformer _parent ;
480
480
481
- public Mapper ( RandomFourierFeaturizingTransformer parent , DataViewSchema inputSchema )
481
+ public Mapper ( RandomFourierExpansionTransformer parent , DataViewSchema inputSchema )
482
482
: base ( parent . Host . Register ( nameof ( Mapper ) ) , parent , inputSchema )
483
483
{
484
484
_parent = parent ;
@@ -606,7 +606,7 @@ private void TransformFeatures(in VBuffer<float> src, ref VBuffer<float> dst, Tr
606
606
/// <summary>
607
607
/// Maps vector columns to a low -dimensional feature space.
608
608
/// </summary>
609
- public sealed class RandomFourierFeaturizingEstimator : IEstimator < RandomFourierFeaturizingTransformer >
609
+ public sealed class RandomFourierExpansionEstimator : IEstimator < RandomFourierExpansionTransformer >
610
610
{
611
611
[ BestFriend ]
612
612
internal static class Defaults
@@ -679,22 +679,22 @@ public ColumnOptions(string name, int dimension, bool useCosAndSinBases, string
679
679
/// <param name="inputColumnName">Name of the column to transform. If set to <see langword="null"/>, the value of the <paramref name="outputColumnName"/> will be used as source.</param>
680
680
/// <param name="newDim">The number of random Fourier features to create.</param>
681
681
/// <param name="useSin">Create two features for every random Fourier frequency? (one for cos and one for sin).</param>
682
- internal RandomFourierFeaturizingEstimator ( IHostEnvironment env , string outputColumnName , string inputColumnName = null , int newDim = Defaults . Dimension , bool useSin = Defaults . UseCosAndSinBases )
682
+ internal RandomFourierExpansionEstimator ( IHostEnvironment env , string outputColumnName , string inputColumnName = null , int newDim = Defaults . Dimension , bool useSin = Defaults . UseCosAndSinBases )
683
683
: this ( env , new ColumnOptions ( outputColumnName , newDim , useSin , inputColumnName ?? outputColumnName ) )
684
684
{
685
685
}
686
686
687
- internal RandomFourierFeaturizingEstimator ( IHostEnvironment env , params ColumnOptions [ ] columns )
687
+ internal RandomFourierExpansionEstimator ( IHostEnvironment env , params ColumnOptions [ ] columns )
688
688
{
689
689
Contracts . CheckValue ( env , nameof ( env ) ) ;
690
- _host = env . Register ( nameof ( RandomFourierFeaturizingEstimator ) ) ;
690
+ _host = env . Register ( nameof ( RandomFourierExpansionEstimator ) ) ;
691
691
_columns = columns ;
692
692
}
693
693
694
694
/// <summary>
695
- /// Trains and returns a <see cref="RandomFourierFeaturizingTransformer "/>.
695
+ /// Trains and returns a <see cref="RandomFourierExpansionTransformer "/>.
696
696
/// </summary>
697
- public RandomFourierFeaturizingTransformer Fit ( IDataView input ) => new RandomFourierFeaturizingTransformer ( _host , input , _columns ) ;
697
+ public RandomFourierExpansionTransformer Fit ( IDataView input ) => new RandomFourierExpansionTransformer ( _host , input , _columns ) ;
698
698
699
699
/// <summary>
700
700
/// Returns the <see cref="SchemaShape"/> of the schema which will be produced by the transformer.
0 commit comments