10
10
using Microsoft . ML . Runtime ;
11
11
using Microsoft . ML . Runtime . CommandLine ;
12
12
using Microsoft . ML . Runtime . Data ;
13
+ using Microsoft . ML . Runtime . EntryPoints ;
13
14
using Microsoft . ML . Runtime . Internal . CpuMath ;
14
15
using Microsoft . ML . Runtime . Internal . Utilities ;
15
16
using Microsoft . ML . Runtime . Model ;
@@ -39,11 +40,12 @@ public sealed class Arguments
39
40
[ Argument ( ArgumentType . AtMostOnce , HelpText = "The number of random Fourier features to create" , ShortName = "dim" ) ]
40
41
public int NewDim = Defaults . NewDim ;
41
42
42
- [ Argument ( ArgumentType . Multiple , HelpText = "which kernel to use?" , ShortName = "kernel" ) ]
43
- public SubComponent < IFourierDistributionSampler , SignatureFourierDistributionSampler > MatrixGenerator =
44
- new SubComponent < IFourierDistributionSampler , SignatureFourierDistributionSampler > ( GaussianFourierSampler . LoadName ) ;
43
+ [ Argument ( ArgumentType . Multiple , HelpText = "Which kernel to use?" , ShortName = "kernel" , SignatureType = typeof ( SignatureFourierDistributionSampler ) ) ]
44
+ public IComponentFactory < Float , IFourierDistributionSampler > MatrixGenerator =
45
+ ComponentFactoryUtils . CreateFromFunction < Float , IFourierDistributionSampler > (
46
+ ( env , avgDist ) => new GaussianFourierSampler ( env , new GaussianFourierSampler . Arguments ( ) , avgDist ) ) ;
45
47
46
- [ Argument ( ArgumentType . AtMostOnce , HelpText = "create two features for every random Fourier frequency? (one for cos and one for sin)" ) ]
48
+ [ Argument ( ArgumentType . AtMostOnce , HelpText = "Create two features for every random Fourier frequency? (one for cos and one for sin)" ) ]
47
49
public bool UseSin = Defaults . UseSin ;
48
50
49
51
[ Argument ( ArgumentType . LastOccurenceWins ,
@@ -57,8 +59,8 @@ public sealed class Column : OneToOneColumn
57
59
[ Argument ( ArgumentType . AtMostOnce , HelpText = "The number of random Fourier features to create" , ShortName = "dim" ) ]
58
60
public int ? NewDim ;
59
61
60
- [ Argument ( ArgumentType . Multiple , HelpText = "which kernel to use?" , ShortName = "kernel" ) ]
61
- public SubComponent < IFourierDistributionSampler , SignatureFourierDistributionSampler > MatrixGenerator ;
62
+ [ Argument ( ArgumentType . Multiple , HelpText = "which kernel to use?" , ShortName = "kernel" , SignatureType = typeof ( SignatureFourierDistributionSampler ) ) ]
63
+ public IComponentFactory < Float , IFourierDistributionSampler > MatrixGenerator ;
62
64
63
65
[ Argument ( ArgumentType . AtMostOnce , HelpText = "create two features for every random Fourier frequency? (one for cos and one for sin)" ) ]
64
66
public bool ? UseSin ;
@@ -81,7 +83,7 @@ public static Column Parse(string str)
81
83
public bool TryUnparse ( StringBuilder sb )
82
84
{
83
85
Contracts . AssertValue ( sb ) ;
84
- if ( NewDim != null || MatrixGenerator . IsGood ( ) || UseSin != null || Seed != null )
86
+ if ( NewDim != null || MatrixGenerator != null || UseSin != null || Seed != null )
85
87
return false ;
86
88
return TryUnparseCore ( sb ) ;
87
89
}
@@ -115,10 +117,10 @@ public TransformInfo(IHost host, Column item, Arguments args, int d, Float avgDi
115
117
_rand = seed . HasValue ? RandomUtils . Create ( seed ) : RandomUtils . Create ( host . Rand ) ;
116
118
_state = _rand . GetState ( ) ;
117
119
118
- var sub = item . MatrixGenerator ;
119
- if ( ! sub . IsGood ( ) )
120
- sub = args . MatrixGenerator ;
121
- _matrixGenerator = sub . CreateInstance ( host , avgDist ) ;
120
+ var generator = item . MatrixGenerator ;
121
+ if ( generator == null )
122
+ generator = args . MatrixGenerator ;
123
+ _matrixGenerator = generator . CreateComponent ( host , avgDist ) ;
122
124
123
125
int roundedUpD = RoundUp ( NewDim , CfltAlign ) ;
124
126
int roundedUpNumFeatures = RoundUp ( SrcDim , CfltAlign ) ;
@@ -417,12 +419,13 @@ private static Float[] Train(IHost host, ColInfo[] infos, Arguments args, IDataV
417
419
else
418
420
{
419
421
Float [ ] distances ;
420
-
421
422
var sub = args . Column [ iinfo ] . MatrixGenerator ;
422
- if ( ! sub . IsGood ( ) )
423
+ if ( sub == null )
423
424
sub = args . MatrixGenerator ;
424
- var info = ComponentCatalog . GetLoadableClassInfo ( sub ) ;
425
- bool gaussian = info != null && info . Type == typeof ( GaussianFourierSampler ) ;
425
+ // create a dummy generator in order to get its type.
426
+ // REVIEW this should be refactored. See https://github.com/dotnet/machinelearning/issues/699
427
+ var matrixGenerator = sub . CreateComponent ( host , 1 ) ;
428
+ bool gaussian = matrixGenerator is GaussianFourierSampler ;
426
429
427
430
// If the number of pairs is at most the maximum reservoir size / 2, go over all the pairs.
428
431
if ( resLength < reservoirSize )
0 commit comments