-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Remove the IFourierDistributionSampler interface #2698
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove the IFourierDistributionSampler interface #2698
Conversation
|
||
public interface IFourierDistributionSampler : ICanSaveModel | ||
public abstract class RngGeneratorBase |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general, .NET APIs prefer to write out the names. Rng
. Also I assume the g
in Rng
is "generator", so it is a little redundant.
X DO NOT use abbreviations or contractions as part of identifier names.
For example, use GetWindow rather than GetWin.
Can we add some public XML doc to this new pubilc class?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it would be good to tie this with Fourier
as well? Since this is in the Microsoft.ML.Transforms
namespace, having a RngGeneratorBase
class seems a bit broad, especially one that doesn't have any public members on it.
In reply to: 259486033 [](ancestors = 259486033)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I was going to mention that I'm not happy with these class names... I wrote an explanation about these classes in a separate comment, I'll also add some XML comments and post another iteration for this PR.
In reply to: 259486033 [](ancestors = 259486033)
float Next(Random rand); | ||
internal abstract float Dist(in VBuffer<float> first, in VBuffer<float> second); | ||
|
||
internal abstract RandomNumberGeneratorBase GetRandomNumberGenerator(float avgDist); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the difference between RngGeneratorBase
and RandomNumberGeneratorBase
?
The problem with |
[assembly: LoadableClass(typeof(LaplacianFourierSampler), null, typeof(SignatureLoadModel), | ||
"Laplacian Fourier Sampler Executor", "LaplacianSamplerExecutor", LaplacianFourierSampler.LoaderSignature)] | ||
[assembly: LoadableClass(typeof(LaplacianRngGenerator.RandomNumberGenerator), null, typeof(SignatureLoadModel), | ||
"Laplacian Fourier Sampler Executor", "LaplacianSamplerExecutor", LaplacianRngGenerator.RandomNumberGenerator.LoaderSignature)] | ||
|
||
// REVIEW: Roll all of this in with the RffTransform. | ||
namespace Microsoft.ML.Transforms |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would remove this comment, and change namespace to Microsoft.ML.Transforms.Projections
to be align with RFF #Closed
{ | ||
float Next(Random rand); | ||
internal abstract float Dist(in VBuffer<float> first, in VBuffer<float> second); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dist [](start = 32, length = 4)
I know it's internal, but since we touching this, can we call it Distance? #Closed
Codecov Report
@@ Coverage Diff @@
## master #2698 +/- ##
==========================================
+ Coverage 71.58% 71.67% +0.08%
==========================================
Files 805 808 +3
Lines 142025 142288 +263
Branches 16130 16136 +6
==========================================
+ Hits 101674 101981 +307
+ Misses 35910 35869 -41
+ Partials 4441 4438 -3
|
|
||
public interface IFourierDistributionSampler : ICanSaveModel | ||
public abstract class RngGeneratorBase |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RngGeneratorBase [](start = 26, length = 16)
I would call it DistributionBase
, or KernelBase
.
Matrix Generator
The RFF transform produces data whose inner product approximates a kernel-dot-product in the original data space. This transform can approximate two kernels: the Gaussian kernel and the Laplacian kernel. Each of these kernels has one user defined numeric parameter (gamma for the Gaussian kernel and A for the Laplacian kernel), that can be specified by clicking on the wrench button next to the kernel name.``` #Closed
} | ||
|
||
[TlcModule.ComponentKind("FourierDistributionSampler")] | ||
internal interface IFourierDistributionSamplerFactory : IComponentFactory<float, IFourierDistributionSampler> | ||
internal abstract class RandomNumberGeneratorBase |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
internal abstract class RandomNumberGeneratorBase [](start = 4, length = 49)
any reason why it's not interface? #Closed
public RandomNumberGenerator(float gamma, float avgDist) | ||
: base() | ||
{ | ||
_gamma = gamma / avgDist; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
avgDist [](start = 33, length = 7)
would be nice to have Assert for non zero value. #Closed
{ | ||
public sealed class Options : IFourierDistributionSamplerFactory | ||
public sealed class Options : IComponentFactory<RngGeneratorBase> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Options [](start = 28, length = 7)
does it still need to be public? #Closed
|
||
public RandomNumberGenerator(float a, float avgDist) | ||
{ | ||
_a = a / avgDist; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
avgDist [](start = 25, length = 7)
assert for non zero value. #Closed
/// </summary> | ||
[BestFriend] | ||
internal delegate void SignatureFourierDistributionSampler(float avgDist); | ||
internal delegate void SignatureRngGenerator(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we rename this for the new name? - SignatureKernelBase
? #Resolved
distances[count++] = gaussian ? VectorUtils.L2DistSquared(in res[i], in res[j]) | ||
: VectorUtils.L1Distance(in res[i], in res[j]); | ||
} | ||
distances[count++] = columns[iinfo].Generator.Distance(in res[i], in res[j]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You may want to factor out columns[iinfo].Generator
into a new variable (here and below). That way we aren't indexing into the array over and over inside these nested for loops. #Resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks really good, @yaeldekel. I just had a few clean up items.
} | ||
|
||
internal const string LoadName = "GaussianRandom"; | ||
|
||
private readonly float _gamma; | ||
|
||
public GaussianFourierSampler(IHostEnvironment env, Options options, float avgDist) | ||
public GaussianKernel(float gamma = 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GaussianKernel [](start = 15, length = 14)
would be nice to have comment.
Also MathUtils.Sqrt(2 * _gamma)
Since I doubt average distance can be negative and _gamma in random generator is this gamma / avgDistance, we need to specify what gamma is non-negative number. and assert it. #Resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
private readonly float _a; | ||
|
||
public LaplacianFourierSampler(IHostEnvironment env, Options options, float avgDist) | ||
public LaplacianKernel(float a = 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would be nice to have comment. #Resolved
} | ||
|
||
public sealed class GaussianFourierSampler : IFourierDistributionSampler | ||
public sealed class GaussianKernel : KernelBase |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GaussianKernel [](start = 24, length = 14)
would be nice to have comment. #Resolved
} | ||
} | ||
|
||
public sealed class LaplacianFourierSampler : IFourierDistributionSampler | ||
public sealed class LaplacianKernel : KernelBase |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LaplacianKernel [](start = 24, length = 15)
would be nice to have comment #Resolved
Fixes #2659,
fixes #699.