-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Splitting OLS to a separate package called AdditionalLearners #611
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
Changes from 4 commits
9b7eab3
fa3370c
ba40ba4
83a737f
61cdb66
188bd4b
c2b87e7
2efe7bc
ede5c72
c666ad7
eeba577
1255e01
dee8b65
dc34085
3588e9b
05909c6
0f91d17
7d3bbab
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk" DefaultTargets="Pack"> | ||
|
|
||
| <PropertyGroup> | ||
| <TargetFramework>netstandard2.0</TargetFramework> | ||
| <PackageDescription>ML.NET additional learners. They depend on other packages, like MlNetMklDeps. </PackageDescription> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="../Microsoft.ML/Microsoft.ML.nupkgproj" /> | ||
| <PackageReference Include="MlNetMklDeps" Version="$(MlNetMklDepsPackageVersion)" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| <Project DefaultTargets="Pack"> | ||
|
|
||
| <Import Project="Microsoft.ML.AdditionalLearners.nupkgproj" /> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
MklDependentLearners maybe? it just separation of standard/additional learner is unclear from the names #Closed
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. was thinking that we could use it for other learners, that we don;t want on the core package because of other dependencies. We could bundle them all in one package.. In reply to: 206356744 [](ancestors = 206356744)
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suggest we continue the discussion in the other comment (Learners.nupkgproj) and close this one In reply to: 206357569 [](ancestors = 206357569,206356744) |
||
|
|
||
| </Project> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <TargetFramework>netstandard2.0</TargetFramework> | ||
| <IncludeInPackage>Microsoft.ML.AdditionalLearners</IncludeInPackage> | ||
| <AllowUnsafeBlocks>true</AllowUnsafeBlocks> | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think |
||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\Microsoft.ML.Core\Microsoft.ML.Core.csproj" /> | ||
| <ProjectReference Include="..\Microsoft.ML.Data\Microsoft.ML.Data.csproj" /> | ||
| <ProjectReference Include="..\Microsoft.ML.StandardLearners\Microsoft.ML.StandardLearners.csproj" /> | ||
| <ProjectReference Include="..\Microsoft.ML\Microsoft.ML.csproj" /> | ||
| <PackageReference Include="MlNetMklDeps" Version="$(MlNetMklDepsPackageVersion)" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,14 +7,15 @@ | |
| using System; | ||
| using System.Collections.Generic; | ||
| using System.IO; | ||
| using Microsoft.ML.Runtime.Internal.Internallearn; | ||
| using Microsoft.ML.Runtime; | ||
| using Microsoft.ML.Runtime.AdditionalLearners; | ||
| using Microsoft.ML.Runtime.Internal.Internallearn; | ||
| using Microsoft.ML.Runtime.Internal.Utilities; | ||
| using Microsoft.ML.Runtime.CommandLine; | ||
| using Microsoft.ML.Runtime.Data; | ||
| using Microsoft.ML.Runtime.EntryPoints; | ||
| using Microsoft.ML.Runtime.Learners; | ||
| using Microsoft.ML.Runtime.Model; | ||
| using Microsoft.ML.Runtime.Internal.Utilities; | ||
| using Microsoft.ML.Runtime.Training; | ||
| using System.Runtime.InteropServices; | ||
|
|
||
|
|
@@ -30,7 +31,7 @@ | |
|
|
||
| [assembly: LoadableClass(typeof(void), typeof(OlsLinearRegressionTrainer), null, typeof(SignatureEntryPointModule), OlsLinearRegressionTrainer.LoadNameValue)] | ||
|
|
||
| namespace Microsoft.ML.Runtime.Learners | ||
| namespace Microsoft.ML.Runtime.AdditionalLearners | ||
| { | ||
| /// <include file='doc.xml' path='doc/members/member[@name="OLS"]/*' /> | ||
| public sealed class OlsLinearRegressionTrainer : TrainerBase<OlsLinearRegressionPredictor> | ||
|
|
@@ -220,7 +221,7 @@ private OlsLinearRegressionPredictor TrainCore(IChannel ch, FloatLabelCursor.Fac | |
| catch (DllNotFoundException) | ||
| { | ||
| // REVIEW: Is there no better way? | ||
| throw ch.ExceptNotSupp("The MKL library (Microsoft.ML.MklImports.dll) or one of its dependencies is missing."); | ||
| throw ch.ExceptNotSupp("The MKL library (Microsoft.ML.MklImports) or one of its dependencies is missing."); | ||
| } | ||
| // Solve for beta in (LL')beta = X'y: | ||
| Mkl.Pptrs(Mkl.Layout.RowMajor, Mkl.UpLo.Lo, m, 1, xtx, xty, 1); | ||
|
|
@@ -466,7 +467,7 @@ public static void Pptri(Layout layout, UpLo uplo, int n, Double[] ap) | |
| Desc = "Train an OLS regression model.", | ||
| UserName = UserNameValue, | ||
| ShortName = ShortName, | ||
| XmlInclude = new[] { @"<include file='../Microsoft.ML.StandardLearners/Standard/doc.xml' path='doc/members/member[@name=""OLS""]/*' />" })] | ||
| XmlInclude = new[] { @"<include file='../Microsoft.ML.AdditionalLearners/Standard/doc.xml' path='doc/members/member[@name=""OLS""]/*' />" })] | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this the right path?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The reference is relative to the CSharpApi.cs file, in Microsoft.ML. This line of xml comment will appear atop the OrdinaryLeastSqaresregressor in the C#api, and from there make its way in the XML. In reply to: 206638688 [](ancestors = 206638688) |
||
| public static CommonOutputs.RegressionOutput TrainRegression(IHostEnvironment env, Arguments input) | ||
| { | ||
| Contracts.CheckValue(env, nameof(env)); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <doc> | ||
| <members> | ||
|
|
||
| <member name="OLS"> | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we also remove the doc from |
||
| <summary> | ||
| Train an OLS regression model. | ||
| </summary> | ||
| <remarks> | ||
| <a href='https://en.wikipedia.org/wiki/Ordinary_least_squares'>Ordinary least squares (OLS)</a> is a parameterized regression method. | ||
| It assumes that the conditional mean of the dependent variable follows a linear function of the dependent variables. | ||
| The parameters of the regressor can be estimated by minimizing the squares of the difference between observed values and the predictions. | ||
| </remarks> | ||
| <example> | ||
| <code language="csharp"> | ||
| new OrdinaryLeastSquaresRegressor | ||
| { | ||
| L2Weight = 0.1, | ||
| PerParameterSignificance = false, | ||
| NormalizeFeatures = Microsoft.ML.Models.NormalizeOption.Yes | ||
| } | ||
| </code> | ||
| </example> | ||
| </member> | ||
|
|
||
| </members> | ||
| </doc> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,7 +28,6 @@ | |
|
|
||
| namespace Microsoft.ML.Runtime.Learners | ||
| { | ||
| using Mkl = Microsoft.ML.Runtime.Learners.OlsLinearRegressionTrainer.Mkl; | ||
|
|
||
| /// <include file='doc.xml' path='doc/members/member[@name="LBFGS"]/*' /> | ||
| /// <include file='doc.xml' path='docs/members/example[@name="LogisticRegressionBinaryClassifier"]/*' /> | ||
|
|
@@ -282,64 +281,7 @@ protected override void ComputeTrainingStatistics(IChannel ch, FloatLabelCursor. | |
| } | ||
| } | ||
|
|
||
| // Apply Cholesky Decomposition to find the inverse of the Hessian. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Hmm, it's too bad we have to completely drop good code.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe have a virtual 'UpdateStdErrors' method that does nothing here, and have a better version of LR in MKL-0dependent assembly that overrides this? In reply to: 206635936 [](ancestors = 206635936)
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| Double[] invHessian = null; | ||
| try | ||
| { | ||
| // First, find the Cholesky decomposition LL' of the Hessian. | ||
| Mkl.Pptrf(Mkl.Layout.RowMajor, Mkl.UpLo.Lo, numParams, hessian); | ||
| // Note that hessian is already modified at this point. It is no longer the original Hessian, | ||
| // but instead represents the Cholesky decomposition L. | ||
| // Also note that the following routine is supposed to consume the Cholesky decomposition L instead | ||
| // of the original information matrix. | ||
| Mkl.Pptri(Mkl.Layout.RowMajor, Mkl.UpLo.Lo, numParams, hessian); | ||
| // At this point, hessian should contain the inverse of the original Hessian matrix. | ||
| // Swap hessian with invHessian to avoid confusion in the following context. | ||
| Utils.Swap(ref hessian, ref invHessian); | ||
| Contracts.Assert(hessian == null); | ||
| } | ||
| catch (DllNotFoundException) | ||
| { | ||
| throw ch.ExceptNotSupp("The MKL library (Microsoft.ML.MklImports.dll) or one of its dependencies is missing."); | ||
| } | ||
|
|
||
| Float[] stdErrorValues = new Float[numParams]; | ||
| stdErrorValues[0] = (Float)Math.Sqrt(invHessian[0]); | ||
|
|
||
| for (int i = 1; i < numParams; i++) | ||
| { | ||
| // Initialize with inverse Hessian. | ||
| stdErrorValues[i] = (Single)invHessian[i * (i + 1) / 2 + i]; | ||
| } | ||
|
|
||
| if (L2Weight > 0) | ||
| { | ||
| // Iterate through all entries of inverse Hessian to make adjustment to variance. | ||
| // A discussion on ridge regularized LR coefficient covariance matrix can be found here: | ||
| // http://www.ncbi.nlm.nih.gov/pmc/articles/PMC3228544/ | ||
| // http://www.inf.unibz.it/dis/teaching/DWDM/project2010/LogisticRegression.pdf | ||
| int ioffset = 1; | ||
| for (int iRow = 1; iRow < numParams; iRow++) | ||
| { | ||
| for (int iCol = 0; iCol <= iRow; iCol++) | ||
| { | ||
| var entry = (Single)invHessian[ioffset]; | ||
| var adjustment = -L2Weight * entry * entry; | ||
| stdErrorValues[iRow] -= adjustment; | ||
| if (0 < iCol && iCol < iRow) | ||
| stdErrorValues[iCol] -= adjustment; | ||
| ioffset++; | ||
| } | ||
| } | ||
|
|
||
| Contracts.Assert(ioffset == invHessian.Length); | ||
| } | ||
|
|
||
| for (int i = 1; i < numParams; i++) | ||
| stdErrorValues[i] = (Float)Math.Sqrt(stdErrorValues[i]); | ||
|
|
||
| VBuffer<Float> stdErrors = new VBuffer<Float>(CurrentWeights.Length, numParams, stdErrorValues, weightIndices); | ||
| _stats = new LinearModelStatistics(Host, NumGoodRows, numParams, deviance, nullDeviance, ref stdErrors); | ||
| _stats = new LinearModelStatistics(Host, NumGoodRows, numParams, deviance, nullDeviance); | ||
| } | ||
|
|
||
| protected override void ProcessPriorDistribution(Float label, Float weight) | ||
|
|
@@ -382,7 +324,7 @@ protected override ParameterMixingCalibratedPredictor CreatePredictor() | |
| CurrentWeights.GetItemOrDefault(0, ref bias); | ||
| CurrentWeights.CopyTo(ref weights, 1, CurrentWeights.Length - 1); | ||
| return new ParameterMixingCalibratedPredictor(Host, | ||
| new LinearBinaryPredictor(Host, ref weights, bias, _stats), | ||
| new LinearBinaryPredictor(Host, ref weights, bias), | ||
| new PlattCalibrator(Host, -1, 0)); | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8839,7 +8839,7 @@ public OnlineGradientDescentRegressorPipelineStep(Output output) | |
| namespace Trainers | ||
| { | ||
|
|
||
| /// <include file='../Microsoft.ML.StandardLearners/Standard/doc.xml' path='doc/members/member[@name="OLS"]/*' /> | ||
| /// <include file='../Microsoft.ML.AdditionalLearners/Standard/doc.xml' path='doc/members/member[@name="OLS"]/*' /> | ||
| public sealed partial class OrdinaryLeastSquaresRegressor : Microsoft.ML.Runtime.EntryPoints.CommonInputs.ITrainerInputWithWeight, Microsoft.ML.Runtime.EntryPoints.CommonInputs.ITrainerInputWithLabel, Microsoft.ML.Runtime.EntryPoints.CommonInputs.ITrainerInput, Microsoft.ML.ILearningPipelineItem | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Hmmm this should not be here either. Nor should LightGBM since it lives in a diff package. Opening an issue about it. #Pending
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| { | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -888,7 +888,7 @@ public void RegressorOlsTest() | |
| /// <summary> | ||
| /// A test for ordinary least squares regression. | ||
| /// </summary> | ||
| [Fact(Skip = "Need CoreTLC specific baseline update")] | ||
| [Fact] | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we enable the test above this too? It is an
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| [TestCategory("Regressor")] | ||
| public void RegressorOlsTestOne() | ||
| { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
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.
The name "additional learners" is something we might want to reconsider, since in future as we publish more wrappers we will surely want descriptive names.
I think naming it
OrdinaryLeastSquaresis probably a fine choice since that's literally all it is? #PendingThere 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 was thinking that maybe we can have SymSGD here too, and other learners that need to drag dependencies?
@Ivanidzo4ka didn't like it either and suggested MklDepsLearners.
In reply to: 206582236 [](ancestors = 206582236)
Uh oh!
There was an error while loading. Please reload this page.
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.
MklDeps also doesn't feel good, but it's better. Can we have a name that conveys 'these learners use MKL's optimized linear algebra', without actually saying 'MKL' in the name?
I don't think this should be 'all learners with big dependencies', because it doesn't actually improve the experience too much (if you need one of these learners, you have to grab all). I'd much rather have 'learners depending on MKL' and 'learners depending on OtherHeaveDependency' separate
In reply to: 206584367 [](ancestors = 206584367,206582236)
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.
renaming it to HalLearners. If that doesn's sound good, please suggest a name :)
In reply to: 206634151 [](ancestors = 206634151,206584367,206582236)
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 like HAL learners.
In reply to: 206661889 [](ancestors = 206661889,206634151,206584367,206582236)