-
Notifications
You must be signed in to change notification settings - Fork 330
Add Param and methods to Spark.ML #586
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
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
f9a4929
adding Param
e41c535
format comment
52b87be
removing isValid and making Params methods properties
8b17e69
Merge branch 'master' into ml/params
GoEddie 3d2064f
reverting formatting change
794ce7c
reverting formatting change
ea6c856
reverting formatting change
fbe85cc
feedback from review
10badc7
Apply suggestions from code review
GoEddie 7c53230
last parens missing
37d2619
over 100 char comment and missing )
efd5e3d
fixes from review
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
src/csharp/Microsoft.Spark.E2ETest/IpcTests/ML/Param/ParamTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| // See the LICENSE file in the project root for more information. | ||
|
|
||
| using Microsoft.Spark.ML.Feature.Param; | ||
GoEddie marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| using Microsoft.Spark.Sql; | ||
| using Xunit; | ||
|
|
||
| namespace Microsoft.Spark.E2ETest.IpcTests.ML.ParamTests | ||
| { | ||
| [Collection("Spark E2E Tests")] | ||
| public class ParamTests | ||
| { | ||
| private readonly SparkSession _spark; | ||
|
|
||
| public ParamTests(SparkFixture fixture) | ||
| { | ||
| _spark = fixture.Spark; | ||
| } | ||
|
|
||
| [Fact] | ||
| public void Test() | ||
| { | ||
| const string expectedParent = "parent"; | ||
| const string expectedName = "name"; | ||
| const string expectedDoc = "doc"; | ||
|
|
||
| var param = new Param(expectedParent, expectedName, expectedDoc); | ||
|
|
||
| Assert.Equal(expectedParent, param.Parent); | ||
| Assert.Equal(expectedDoc, param.Doc); | ||
| Assert.Equal(expectedName, param.Name); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| // See the LICENSE file in the project root for more information. | ||
|
|
||
| using System; | ||
| using Microsoft.Spark.Interop; | ||
| using Microsoft.Spark.Interop.Ipc; | ||
|
|
||
| namespace Microsoft.Spark.ML.Feature.Param | ||
| { | ||
| /// <summary> | ||
| /// A <see cref="Param"/> with self-contained documentation and optionally default value. | ||
| /// | ||
| /// A <see cref="Param"/> references an individual parameter that includes documentation, the | ||
| /// name of the parameter and optionally a default value. Params can either be set using the | ||
| /// generic <see cref="Param"/> methods or by using explicit methods. For example | ||
| /// <see cref="Bucketizer"/> has <c>SetHandleInvalid</c> or you can call | ||
| /// <c>GetParam("handleInvalid")</c>and then <see cref="Bucketizer"/>. Set using the | ||
| /// <see cref="Param"/> and the value you want to use. | ||
| /// </summary> | ||
| public class Param : IJvmObjectReferenceProvider | ||
| { | ||
| private static readonly string s_ParamClassName = | ||
| "org.apache.spark.ml.param.Param"; | ||
|
|
||
| private readonly JvmObjectReference _jvmObject; | ||
|
|
||
| /// <summary> | ||
| /// Creates a new instance of a <see cref="Param"/> which will be attached to the parent | ||
| /// specified. The most likely use case for a <see cref="Param"/> is being read from a | ||
| /// parent object such as <see cref="Bucketizer"/> rather than independently | ||
| /// <param name="parent">The parent object to assign the <see cref="Param"/> to</param> | ||
| /// <param name="name">The name of this <see cref="Param"/></param> | ||
| /// <param name="doc">The documentation for this <see cref="Param"/></param> | ||
| /// </summary> | ||
| public Param(Identifiable parent, string name, string doc) | ||
GoEddie marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| : this(SparkEnvironment.JvmBridge.CallConstructor( | ||
| s_ParamClassName, parent.Uid(), name, doc)) | ||
| { | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Creates a new instance of a <see cref="Param"/> which will be attached to the parent | ||
| /// with the UID specified. The most likely use case for a <see cref="Param"/> is being | ||
| /// read from a parent object such as <see cref="Bucketizer"/> rather than independently | ||
| /// <param name="parent"> | ||
| /// The UID of the parent object to assign the <see cref="Param"/> to | ||
| /// </param> | ||
| /// <param name="name">The name of this <see cref="Param"/></param> | ||
| /// <param name="doc">The documentation for this <see cref="Param"/></param> | ||
| /// </summary> | ||
| public Param(string parent, string name, string doc) | ||
GoEddie marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| : this(SparkEnvironment.JvmBridge.CallConstructor(s_ParamClassName, parent, name, doc)) | ||
| { | ||
| } | ||
|
|
||
| internal Param(JvmObjectReference jvmObject) | ||
| { | ||
| _jvmObject = jvmObject; | ||
| } | ||
|
|
||
| JvmObjectReference IJvmObjectReferenceProvider.Reference => _jvmObject; | ||
|
|
||
| /// <summary> | ||
| /// The description of what the <see cref="Param"/> does and how it works including any | ||
| /// defaults and the current value | ||
| /// </summary> | ||
| /// <returns>A description of how the <see cref="Param"/> works</returns> | ||
| public string Doc => (string)_jvmObject.Invoke("doc"); | ||
|
|
||
| /// <summary> | ||
| /// The name of the <see cref="Param"/> | ||
| /// </summary> | ||
| /// <returns>The name of the <see cref="Param"/></returns> | ||
| public string Name => (string)_jvmObject.Invoke("name"); | ||
|
|
||
| /// <summary> | ||
| /// The object that contains the <see cref="Param"/> | ||
| /// </summary> | ||
| /// <returns>The UID of the parent oject that this <see cref="Param"/> belongs to</returns> | ||
| public string Parent => (string)_jvmObject.Invoke("parent"); | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.