Skip to content

Commit 622543c

Browse files
author
Ivan Matantsev
committed
Hide delegates, model parameters classes, move onFit to staticPIpe, get rid of trivial transformWrapper
1 parent ec418e4 commit 622543c

File tree

14 files changed

+57
-63
lines changed

14 files changed

+57
-63
lines changed

src/Microsoft.ML.Core/Data/InPredicate.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@
44

55
namespace Microsoft.ML.Data
66
{
7-
public delegate bool InPredicate<T>(in T value);
7+
[BestFriend]
8+
internal delegate bool InPredicate<T>(in T value);
89
}

src/Microsoft.ML.Data/DataLoadSave/TransformWrapper.cs

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -168,26 +168,4 @@ public SchemaShape GetOutputSchema(SchemaShape inputSchema)
168168
return SchemaShape.Create(transformer.GetOutputSchema(fakeSchema));
169169
}
170170
}
171-
172-
/// <summary>
173-
/// Estimator for untrained wrapped transformers.
174-
/// </summary>
175-
public abstract class TrivialWrapperEstimator : TrivialEstimator<TransformWrapper>
176-
{
177-
protected TrivialWrapperEstimator(IHost host, TransformWrapper transformer)
178-
: base(host, transformer)
179-
{
180-
}
181-
182-
/// <summary>
183-
/// Returns the <see cref="SchemaShape"/> of the schema which will be produced by the transformer.
184-
/// Used for schema propagation and verification in a pipeline.
185-
/// </summary>
186-
public override SchemaShape GetOutputSchema(SchemaShape inputSchema)
187-
{
188-
Host.CheckValue(inputSchema, nameof(inputSchema));
189-
var fakeSchema = FakeSchemaFactory.Create(inputSchema);
190-
return SchemaShape.Create(Transformer.GetOutputSchema(fakeSchema));
191-
}
192-
}
193171
}

src/Microsoft.ML.Data/Dirty/ILoss.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
using System;
66
using Microsoft.ML.EntryPoints;
7-
using Float = System.Single;
87

98
namespace Microsoft.ML
109
{
@@ -17,12 +16,12 @@ public interface ILossFunction<in TOutput, in TLabel>
1716
Double Loss(TOutput output, TLabel label);
1817
}
1918

20-
public interface IScalarOutputLoss : ILossFunction<Float, Float>
19+
public interface IScalarOutputLoss : ILossFunction<float, float>
2120
{
2221
/// <summary>
2322
/// Derivative of the loss function with respect to output
2423
/// </summary>
25-
Float Derivative(Float output, Float label);
24+
float Derivative(float output, float label);
2625
}
2726

2827
[TlcModule.ComponentKind("RegressionLossFunction")]
@@ -46,10 +45,10 @@ public interface IClassificationLoss : IScalarOutputLoss
4645
/// <summary>
4746
/// Delegate signature for standardized classification loss functions.
4847
/// </summary>
49-
public delegate void SignatureClassificationLoss();
48+
internal delegate void SignatureClassificationLoss();
5049

5150
/// <summary>
5251
/// Delegate signature for standardized regression loss functions.
5352
/// </summary>
54-
public delegate void SignatureRegressionLoss();
53+
internal delegate void SignatureRegressionLoss();
5554
}

src/Microsoft.ML.Data/Transforms/ValueToKeyMappingEstimator.cs

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -159,25 +159,4 @@ public enum KeyValueOrder : byte
159159
/// </summary>
160160
Value = ValueToKeyMappingEstimator.SortOrder.Value
161161
}
162-
163-
/// <summary>
164-
/// Information on the result of fitting a to-key transform.
165-
/// </summary>
166-
/// <typeparam name="T">The type of the values.</typeparam>
167-
public sealed class ToKeyFitResult<T>
168-
{
169-
/// <summary>
170-
/// For user defined delegates that accept instances of the containing type.
171-
/// </summary>
172-
/// <param name="result"></param>
173-
public delegate void OnFit(ToKeyFitResult<T> result);
174-
175-
// At the moment this is empty. Once PR #863 clears, we can change this class to hold the output
176-
// key-values metadata.
177-
178-
[BestFriend]
179-
internal ToKeyFitResult(ValueToKeyMappingTransformer.TermMap map)
180-
{
181-
}
182-
}
183162
}

src/Microsoft.ML.FastTree/GamClassification.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ public sealed class BinaryClassificationGamModelParameters : GamModelParametersB
180180
/// <param name="featureToInputMap">A map from the feature shape functions (as described by the binUpperBounds and BinEffects)
181181
/// to the input feature. Used when the number of input features is different than the number of shape functions. Use default if all features have
182182
/// a shape function.</param>
183-
public BinaryClassificationGamModelParameters(IHostEnvironment env,
183+
internal BinaryClassificationGamModelParameters(IHostEnvironment env,
184184
double[][] binUpperBounds, double[][] binEffects, double intercept, int inputLength, int[] featureToInputMap)
185185
: base(env, LoaderSignature, binUpperBounds, binEffects, intercept, inputLength, featureToInputMap) { }
186186

src/Microsoft.ML.FastTree/GamRegression.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public sealed class RegressionGamModelParameters : GamModelParametersBase
126126
/// <param name="featureToInputMap">A map from the feature shape functions (as described by the binUpperBounds and BinEffects)
127127
/// to the input feature. Used when the number of input features is different than the number of shape functions. Use default if all features have
128128
/// a shape function.</param>
129-
public RegressionGamModelParameters(IHostEnvironment env,
129+
internal RegressionGamModelParameters(IHostEnvironment env,
130130
double[][] binUpperBounds, double[][] binEffects, double intercept, int inputLength = -1, int[] featureToInputMap = null)
131131
: base(env, LoaderSignature, binUpperBounds, binEffects, intercept, inputLength, featureToInputMap) { }
132132

src/Microsoft.ML.PCA/PcaTrainer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ private static VersionInfo GetVersionInfo()
411411
/// <param name="rank">The rank of the PCA approximation of the covariance matrix. This is the number of eigenvectors in the model.</param>
412412
/// <param name="eigenVectors">Array of eigenvectors.</param>
413413
/// <param name="mean">The mean vector of the training data.</param>
414-
public PcaModelParameters(IHostEnvironment env, int rank, float[][] eigenVectors, in VBuffer<float> mean)
414+
internal PcaModelParameters(IHostEnvironment env, int rank, float[][] eigenVectors, in VBuffer<float> mean)
415415
: base(env, RegistrationName)
416416
{
417417
_dimension = eigenVectors[0].Length;

src/Microsoft.ML.StandardLearners/FactorizationMachine/FieldAwareFactorizationMachineModelParameters.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ private static VersionInfo GetVersionInfo()
5757
/// and each latent vector contains <see cref="LatentDim"/> values. In the f-th field, the j-th feature's latent vector, `v_{j, f}` in the doc
5858
/// https://github.com/wschin/fast-ffm/blob/master/fast-ffm.pdf, starts at latentWeights[j * fieldCount * latentDim + f * latentDim].
5959
/// The k-th element in v_{j, f} is latentWeights[j * fieldCount * latentDim + f * latentDim + k]. The size of the array must be featureCount x fieldCount x latentDim.</param>
60-
public FieldAwareFactorizationMachineModelParameters(IHostEnvironment env, bool norm, int fieldCount, int featureCount, int latentDim,
60+
internal FieldAwareFactorizationMachineModelParameters(IHostEnvironment env, bool norm, int fieldCount, int featureCount, int latentDim,
6161
float[] linearWeights, float[] latentWeights) : base(env, LoaderSignature)
6262
{
6363
Host.Assert(fieldCount > 0);

src/Microsoft.ML.StandardLearners/Standard/LinearModelParameters.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public IEnumerator<float> GetEnumerator()
115115
/// <param name="weights">The weights for the linear model. The i-th element of weights is the coefficient
116116
/// of the i-th feature. Note that this will take ownership of the <see cref="VBuffer{T}"/>.</param>
117117
/// <param name="bias">The bias added to every output score.</param>
118-
public LinearModelParameters(IHostEnvironment env, string name, in VBuffer<float> weights, float bias)
118+
internal LinearModelParameters(IHostEnvironment env, string name, in VBuffer<float> weights, float bias)
119119
: base(env, name)
120120
{
121121
Host.CheckParam(FloatUtils.IsFinite(weights.GetValues()), nameof(weights), "Cannot initialize linear predictor with non-finite weights");
@@ -436,7 +436,7 @@ private static VersionInfo GetVersionInfo()
436436
/// of the i-th feature. Note that this will take ownership of the <see cref="VBuffer{T}"/>.</param>
437437
/// <param name="bias">The bias added to every output score.</param>
438438
/// <param name="stats"></param>
439-
public LinearBinaryModelParameters(IHostEnvironment env, in VBuffer<float> weights, float bias, LinearModelStatistics stats = null)
439+
internal LinearBinaryModelParameters(IHostEnvironment env, in VBuffer<float> weights, float bias, LinearModelStatistics stats = null)
440440
: base(env, RegistrationName, in weights, bias)
441441
{
442442
Contracts.AssertValueOrNull(stats);
@@ -604,7 +604,7 @@ private static VersionInfo GetVersionInfo()
604604
/// <param name="weights">The weights for the linear model. The i-th element of weights is the coefficient
605605
/// of the i-th feature. Note that this will take ownership of the <see cref="VBuffer{T}"/>.</param>
606606
/// <param name="bias">The bias added to every output score.</param>
607-
public LinearRegressionModelParameters(IHostEnvironment env, in VBuffer<float> weights, float bias)
607+
internal LinearRegressionModelParameters(IHostEnvironment env, in VBuffer<float> weights, float bias)
608608
: base(env, RegistrationName, in weights, bias)
609609
{
610610
}
@@ -687,7 +687,7 @@ private static VersionInfo GetVersionInfo()
687687
/// <param name="weights">The weights for the linear model. The i-th element of weights is the coefficient
688688
/// of the i-th feature. Note that this will take ownership of the <see cref="VBuffer{T}"/>.</param>
689689
/// <param name="bias">The bias added to every output score.</param>
690-
public PoissonRegressionModelParameters(IHostEnvironment env, in VBuffer<float> weights, float bias)
690+
internal PoissonRegressionModelParameters(IHostEnvironment env, in VBuffer<float> weights, float bias)
691691
: base(env, RegistrationName, in weights, bias)
692692
{
693693
}

src/Microsoft.ML.StandardLearners/Standard/LogisticRegression/MulticlassLogisticRegression.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ internal MulticlassLogisticRegressionModelParameters(IHostEnvironment env, in VB
434434
/// <param name="numFeatures">The length of the feature vector.</param>
435435
/// <param name="labelNames">The optional label names. If specified not null, it should have the same length as <paramref name="numClasses"/>.</param>
436436
/// <param name="stats">The model statistics.</param>
437-
public MulticlassLogisticRegressionModelParameters(IHostEnvironment env, VBuffer<float>[] weights, float[] bias, int numClasses, int numFeatures, string[] labelNames, LinearModelStatistics stats = null)
437+
internal MulticlassLogisticRegressionModelParameters(IHostEnvironment env, VBuffer<float>[] weights, float[] bias, int numClasses, int numFeatures, string[] labelNames, LinearModelStatistics stats = null)
438438
: base(env, RegistrationName)
439439
{
440440
Contracts.CheckValue(weights, nameof(weights));

0 commit comments

Comments
 (0)