Skip to content

Hide delegates, model parameters constructors and other small things #2701

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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Microsoft.ML.Core/Data/InPredicate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@

namespace Microsoft.ML.Data
{
public delegate bool InPredicate<T>(in T value);
[BestFriend]
internal delegate bool InPredicate<T>(in T value);
}
22 changes: 0 additions & 22 deletions src/Microsoft.ML.Data/DataLoadSave/TransformWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,26 +168,4 @@ public SchemaShape GetOutputSchema(SchemaShape inputSchema)
return SchemaShape.Create(transformer.GetOutputSchema(fakeSchema));
}
}

/// <summary>
/// Estimator for untrained wrapped transformers.
/// </summary>
public abstract class TrivialWrapperEstimator : TrivialEstimator<TransformWrapper>
Copy link
Member

@abgoswam abgoswam Feb 23, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TrivialWrapperEstimator [](start = 26, length = 23)

where did this go ? #Resolved

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah i see. no usages in code :)


In reply to: 259595477 [](ancestors = 259595477)

Copy link
Contributor Author

@Ivanidzo4ka Ivanidzo4ka Feb 24, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To Valhalla!

{
protected TrivialWrapperEstimator(IHost host, TransformWrapper transformer)
: base(host, transformer)
{
}

/// <summary>
/// Returns the <see cref="SchemaShape"/> of the schema which will be produced by the transformer.
/// Used for schema propagation and verification in a pipeline.
/// </summary>
public override SchemaShape GetOutputSchema(SchemaShape inputSchema)
{
Host.CheckValue(inputSchema, nameof(inputSchema));
var fakeSchema = FakeSchemaFactory.Create(inputSchema);
return SchemaShape.Create(Transformer.GetOutputSchema(fakeSchema));
}
}
}
9 changes: 4 additions & 5 deletions src/Microsoft.ML.Data/Dirty/ILoss.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

using System;
using Microsoft.ML.EntryPoints;
using Float = System.Single;

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

public interface IScalarOutputLoss : ILossFunction<Float, Float>
public interface IScalarOutputLoss : ILossFunction<float, float>
{
/// <summary>
/// Derivative of the loss function with respect to output
/// </summary>
Float Derivative(Float output, Float label);
float Derivative(float output, float label);
}

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

/// <summary>
/// Delegate signature for standardized regression loss functions.
/// </summary>
public delegate void SignatureRegressionLoss();
internal delegate void SignatureRegressionLoss();
}
21 changes: 0 additions & 21 deletions src/Microsoft.ML.Data/Transforms/ValueToKeyMappingEstimator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,25 +159,4 @@ public enum KeyValueOrder : byte
/// </summary>
Value = ValueToKeyMappingEstimator.SortOrder.Value
}

/// <summary>
/// Information on the result of fitting a to-key transform.
/// </summary>
/// <typeparam name="T">The type of the values.</typeparam>
public sealed class ToKeyFitResult<T>
{
/// <summary>
/// For user defined delegates that accept instances of the containing type.
/// </summary>
/// <param name="result"></param>
public delegate void OnFit(ToKeyFitResult<T> result);

// At the moment this is empty. Once PR #863 clears, we can change this class to hold the output
// key-values metadata.

[BestFriend]
internal ToKeyFitResult(ValueToKeyMappingTransformer.TermMap map)
{
}
}
}
2 changes: 1 addition & 1 deletion src/Microsoft.ML.FastTree/GamClassification.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public sealed class BinaryClassificationGamModelParameters : GamModelParametersB
/// <param name="featureToInputMap">A map from the feature shape functions (as described by the binUpperBounds and BinEffects)
/// 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
/// a shape function.</param>
public BinaryClassificationGamModelParameters(IHostEnvironment env,
internal BinaryClassificationGamModelParameters(IHostEnvironment env,
double[][] binUpperBounds, double[][] binEffects, double intercept, int inputLength, int[] featureToInputMap)
: base(env, LoaderSignature, binUpperBounds, binEffects, intercept, inputLength, featureToInputMap) { }

Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.ML.FastTree/GamRegression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public sealed class RegressionGamModelParameters : GamModelParametersBase
/// <param name="featureToInputMap">A map from the feature shape functions (as described by the binUpperBounds and BinEffects)
/// 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
/// a shape function.</param>
public RegressionGamModelParameters(IHostEnvironment env,
internal RegressionGamModelParameters(IHostEnvironment env,
double[][] binUpperBounds, double[][] binEffects, double intercept, int inputLength = -1, int[] featureToInputMap = null)
: base(env, LoaderSignature, binUpperBounds, binEffects, intercept, inputLength, featureToInputMap) { }

Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.ML.PCA/PcaTrainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ private static VersionInfo GetVersionInfo()
/// <param name="rank">The rank of the PCA approximation of the covariance matrix. This is the number of eigenvectors in the model.</param>
/// <param name="eigenVectors">Array of eigenvectors.</param>
/// <param name="mean">The mean vector of the training data.</param>
public PcaModelParameters(IHostEnvironment env, int rank, float[][] eigenVectors, in VBuffer<float> mean)
internal PcaModelParameters(IHostEnvironment env, int rank, float[][] eigenVectors, in VBuffer<float> mean)
: base(env, RegistrationName)
{
_dimension = eigenVectors[0].Length;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ private static VersionInfo GetVersionInfo()
/// 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
/// https://github.com/wschin/fast-ffm/blob/master/fast-ffm.pdf, starts at latentWeights[j * fieldCount * latentDim + f * latentDim].
/// 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>
public FieldAwareFactorizationMachineModelParameters(IHostEnvironment env, bool norm, int fieldCount, int featureCount, int latentDim,
internal FieldAwareFactorizationMachineModelParameters(IHostEnvironment env, bool norm, int fieldCount, int featureCount, int latentDim,
float[] linearWeights, float[] latentWeights) : base(env, LoaderSignature)
{
Host.Assert(fieldCount > 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public IEnumerator<float> GetEnumerator()
/// <param name="weights">The weights for the linear model. The i-th element of weights is the coefficient
/// of the i-th feature. Note that this will take ownership of the <see cref="VBuffer{T}"/>.</param>
/// <param name="bias">The bias added to every output score.</param>
public LinearModelParameters(IHostEnvironment env, string name, in VBuffer<float> weights, float bias)
internal LinearModelParameters(IHostEnvironment env, string name, in VBuffer<float> weights, float bias)
: base(env, name)
{
Host.CheckParam(FloatUtils.IsFinite(weights.GetValues()), nameof(weights), "Cannot initialize linear predictor with non-finite weights");
Expand Down Expand Up @@ -436,7 +436,7 @@ private static VersionInfo GetVersionInfo()
/// of the i-th feature. Note that this will take ownership of the <see cref="VBuffer{T}"/>.</param>
/// <param name="bias">The bias added to every output score.</param>
/// <param name="stats"></param>
public LinearBinaryModelParameters(IHostEnvironment env, in VBuffer<float> weights, float bias, LinearModelStatistics stats = null)
internal LinearBinaryModelParameters(IHostEnvironment env, in VBuffer<float> weights, float bias, LinearModelStatistics stats = null)
: base(env, RegistrationName, in weights, bias)
{
Contracts.AssertValueOrNull(stats);
Expand Down Expand Up @@ -604,7 +604,7 @@ private static VersionInfo GetVersionInfo()
/// <param name="weights">The weights for the linear model. The i-th element of weights is the coefficient
/// of the i-th feature. Note that this will take ownership of the <see cref="VBuffer{T}"/>.</param>
/// <param name="bias">The bias added to every output score.</param>
public LinearRegressionModelParameters(IHostEnvironment env, in VBuffer<float> weights, float bias)
internal LinearRegressionModelParameters(IHostEnvironment env, in VBuffer<float> weights, float bias)
: base(env, RegistrationName, in weights, bias)
{
}
Expand Down Expand Up @@ -687,7 +687,7 @@ private static VersionInfo GetVersionInfo()
/// <param name="weights">The weights for the linear model. The i-th element of weights is the coefficient
/// of the i-th feature. Note that this will take ownership of the <see cref="VBuffer{T}"/>.</param>
/// <param name="bias">The bias added to every output score.</param>
public PoissonRegressionModelParameters(IHostEnvironment env, in VBuffer<float> weights, float bias)
internal PoissonRegressionModelParameters(IHostEnvironment env, in VBuffer<float> weights, float bias)
: base(env, RegistrationName, in weights, bias)
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ internal MulticlassLogisticRegressionModelParameters(IHostEnvironment env, in VB
/// <param name="numFeatures">The length of the feature vector.</param>
/// <param name="labelNames">The optional label names. If specified not null, it should have the same length as <paramref name="numClasses"/>.</param>
/// <param name="stats">The model statistics.</param>
public MulticlassLogisticRegressionModelParameters(IHostEnvironment env, VBuffer<float>[] weights, float[] bias, int numClasses, int numFeatures, string[] labelNames, LinearModelStatistics stats = null)
internal MulticlassLogisticRegressionModelParameters(IHostEnvironment env, VBuffer<float>[] weights, float[] bias, int numClasses, int numFeatures, string[] labelNames, LinearModelStatistics stats = null)
: base(env, RegistrationName)
{
Contracts.CheckValue(weights, nameof(weights));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ public void GetFeatureHistogram(ref int[][] featureHistogram, out int labelCount
/// <param name="labelHistogram">The histogram of labels.</param>
/// <param name="featureHistogram">The feature histogram.</param>
/// <param name="featureCount">The number of features.</param>
public MultiClassNaiveBayesModelParameters(IHostEnvironment env, int[] labelHistogram, int[][] featureHistogram, int featureCount)
internal MultiClassNaiveBayesModelParameters(IHostEnvironment env, int[] labelHistogram, int[][] featureHistogram, int featureCount)
: base(env, LoaderSignature)
{
Host.AssertValue(labelHistogram);
Expand Down
1 change: 1 addition & 0 deletions src/Microsoft.ML.StaticPipe/CategoricalStaticExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Microsoft.ML.StaticPipe.Runtime;
using Microsoft.ML.Transforms.Categorical;
using Microsoft.ML.Transforms.Conversions;
using static Microsoft.ML.StaticPipe.TermStaticExtensions;

namespace Microsoft.ML.StaticPipe
{
Expand Down
22 changes: 20 additions & 2 deletions src/Microsoft.ML.StaticPipe/TermStaticExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,33 @@
// See the LICENSE file in the project root for more information.

using System;
using Microsoft.ML;
using Microsoft.ML.StaticPipe;
using Microsoft.ML.Transforms.Conversions;

namespace Microsoft.ML.StaticPipe
{
public static partial class TermStaticExtensions
{
// Do not edit this file directly. Rather, it is generated out of TermStaticExtensions.tt.
/// <summary>
/// Information on the result of fitting a to-key transform.
/// </summary>
/// <typeparam name="T">The type of the values.</typeparam>
public sealed class ToKeyFitResult<T>
{
/// <summary>
/// For user defined delegates that accept instances of the containing type.
/// </summary>
/// <param name="result"></param>
public delegate void OnFit(ToKeyFitResult<T> result);

// At the moment this is empty. Once PR #863 clears, we can change this class to hold the output
// key-values metadata.

[BestFriend]
internal ToKeyFitResult(ValueToKeyMappingTransformer.TermMap map)
{
}
}

#region For string inputs.
/// <summary>
Expand Down
22 changes: 20 additions & 2 deletions src/Microsoft.ML.StaticPipe/TermStaticExtensions.tt
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,33 @@
// See the LICENSE file in the project root for more information.

using System;
using Microsoft.ML;
using Microsoft.ML.StaticPipe;
using Microsoft.ML.Transforms.Conversions;

namespace Microsoft.ML.StaticPipe
{
public static partial class TermStaticExtensions
{
// Do not edit this file directly. Rather, it is generated out of TermStaticExtensions.tt.
/// <summary>
/// Information on the result of fitting a to-key transform.
/// </summary>
/// <typeparam name="T">The type of the values.</typeparam>
public sealed class ToKeyFitResult<T>
{
/// <summary>
/// For user defined delegates that accept instances of the containing type.
/// </summary>
/// <param name="result"></param>
public delegate void OnFit(ToKeyFitResult<T> result);

// At the moment this is empty. Once PR #863 clears, we can change this class to hold the output
// key-values metadata.

[BestFriend]
internal ToKeyFitResult(ValueToKeyMappingTransformer.TermMap map)
{
}
}
<#
// Let's skip the time-based types for now.
foreach (string typeName in new string[] { "string", "float", "double", "sbyte", "short", "int", "long", "byte", "ushort", "uint", "ulong", "bool" }) {
Expand Down