-
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 all 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 making use of hardware acceleration. They depend on the MlNetMklDeps NuGet package.</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.HalLearners.nupkgproj" /> | ||
|
||
</Project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netstandard2.0</TargetFramework> | ||
<IncludeInPackage>Microsoft.ML.HalLearners</IncludeInPackage> | ||
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't wait to train my HAL9000! https://pbs.twimg.com/profile_images/1788506913/HAL-MC2_400x400.png #Resolved 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. |
||
</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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<doc> | ||
<members> | ||
|
||
<member name="OLS"> | ||
<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. | ||
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. 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) 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. 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 |
---|---|---|
|
@@ -888,7 +888,7 @@ public void RegressorOlsTest() | |
/// <summary> | ||
/// A test for ordinary least squares regression. | ||
/// </summary> | ||
[Fact(Skip = "Need CoreTLC specific baseline update")] | ||
[Fact] | ||
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 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() | ||
{ | ||
|
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.
Obviously doesn’t need to be changed on this PR, but this doesn’t handle OS X and Linux, right? It only works for Windows.
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.
we'd have to do it for all those dlls.