Skip to content

Commit 7b6c140

Browse files
committed
fixing the C#api and the entrypoints list.
attempt to fix the reference to intrinsics
1 parent 6eef331 commit 7b6c140

File tree

6 files changed

+378
-12
lines changed

6 files changed

+378
-12
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace Microsoft.ML.Runtime.FactorizationMachine
1212
{
1313
internal unsafe static class FieldAwareFactorizationMachineInterface
1414
{
15-
internal const string NativePath = "FactorizationMachineNative.dll";
15+
internal const string NativePath = "FactorizationMachineNative";
1616
public const int CbAlign = 16;
1717

1818
private static bool Compat(AlignedArray a)

src/Microsoft.ML/CSharpApi.cs

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,18 @@ public void Add(Microsoft.ML.Trainers.FastTreeTweedieRegressor input, Microsoft.
478478
_jsonNodes.Add(Serialize("Trainers.FastTreeTweedieRegressor", input, output));
479479
}
480480

481+
public Microsoft.ML.Trainers.FieldAwareFactorizationMachineBinaryClassifier.Output Add(Microsoft.ML.Trainers.FieldAwareFactorizationMachineBinaryClassifier input)
482+
{
483+
var output = new Microsoft.ML.Trainers.FieldAwareFactorizationMachineBinaryClassifier.Output();
484+
Add(input, output);
485+
return output;
486+
}
487+
488+
public void Add(Microsoft.ML.Trainers.FieldAwareFactorizationMachineBinaryClassifier input, Microsoft.ML.Trainers.FieldAwareFactorizationMachineBinaryClassifier.Output output)
489+
{
490+
_jsonNodes.Add(Serialize("Trainers.FieldAwareFactorizationMachineBinaryClassifier", input, output));
491+
}
492+
481493
public Microsoft.ML.Trainers.GeneralizedAdditiveModelBinaryClassifier.Output Add(Microsoft.ML.Trainers.GeneralizedAdditiveModelBinaryClassifier input)
482494
{
483495
var output = new Microsoft.ML.Trainers.GeneralizedAdditiveModelBinaryClassifier.Output();
@@ -5987,6 +5999,130 @@ public FastTreeTweedieRegressorPipelineStep(Output output)
59875999
}
59886000
}
59896001

6002+
namespace Trainers
6003+
{
6004+
6005+
/// <summary>
6006+
/// Train a field-aware factorization machine for binary classification
6007+
/// </summary>
6008+
public sealed partial class FieldAwareFactorizationMachineBinaryClassifier : Microsoft.ML.Runtime.EntryPoints.CommonInputs.ITrainerInputWithLabel, Microsoft.ML.Runtime.EntryPoints.CommonInputs.ITrainerInput, Microsoft.ML.ILearningPipelineItem
6009+
{
6010+
6011+
6012+
/// <summary>
6013+
/// Initial learning rate
6014+
/// </summary>
6015+
[TlcModule.SweepableFloatParamAttribute("LearningRate", 0.001f, 1f, isLogScale:true)]
6016+
public float LearningRate { get; set; } = 0.1f;
6017+
6018+
/// <summary>
6019+
/// Number of training iterations
6020+
/// </summary>
6021+
[TlcModule.SweepableLongParamAttribute("Iters", 1, 100)]
6022+
public int Iters { get; set; } = 5;
6023+
6024+
/// <summary>
6025+
/// Latent space dimension
6026+
/// </summary>
6027+
[TlcModule.SweepableLongParamAttribute("LatentDim", 4, 100)]
6028+
public int LatentDim { get; set; } = 20;
6029+
6030+
/// <summary>
6031+
/// Regularization coefficient of linear weights
6032+
/// </summary>
6033+
[TlcModule.SweepableFloatParamAttribute("LambdaLinear", 1E-08f, 1f, isLogScale:true)]
6034+
public float LambdaLinear { get; set; } = 0.0001f;
6035+
6036+
/// <summary>
6037+
/// Regularization coefficient of latent weights
6038+
/// </summary>
6039+
[TlcModule.SweepableFloatParamAttribute("LambdaLatent", 1E-08f, 1f, isLogScale:true)]
6040+
public float LambdaLatent { get; set; } = 0.0001f;
6041+
6042+
/// <summary>
6043+
/// Whether to normalize the input vectors so that the concatenation of all fields' feature vectors is unit-length
6044+
/// </summary>
6045+
public bool Norm { get; set; } = true;
6046+
6047+
/// <summary>
6048+
/// Whether to shuffle for each training iteration
6049+
/// </summary>
6050+
public bool Shuffle { get; set; } = true;
6051+
6052+
/// <summary>
6053+
/// Report traning progress or not
6054+
/// </summary>
6055+
public bool Verbose { get; set; } = true;
6056+
6057+
/// <summary>
6058+
/// Radius of initial latent factors
6059+
/// </summary>
6060+
[TlcModule.SweepableFloatParamAttribute("Radius", 0.1f, 1f)]
6061+
public float Radius { get; set; } = 0.5f;
6062+
6063+
/// <summary>
6064+
/// Column to use for labels
6065+
/// </summary>
6066+
public string LabelColumn { get; set; } = "Label";
6067+
6068+
/// <summary>
6069+
/// The data to be used for training
6070+
/// </summary>
6071+
public Var<Microsoft.ML.Runtime.Data.IDataView> TrainingData { get; set; } = new Var<Microsoft.ML.Runtime.Data.IDataView>();
6072+
6073+
/// <summary>
6074+
/// Column to use for features
6075+
/// </summary>
6076+
public string FeatureColumn { get; set; } = "Features";
6077+
6078+
/// <summary>
6079+
/// Normalize option for the feature column
6080+
/// </summary>
6081+
public Microsoft.ML.Models.NormalizeOption NormalizeFeatures { get; set; } = Microsoft.ML.Models.NormalizeOption.Auto;
6082+
6083+
/// <summary>
6084+
/// Whether learner should cache input training data
6085+
/// </summary>
6086+
public Microsoft.ML.Models.CachingOptions Caching { get; set; } = Microsoft.ML.Models.CachingOptions.Auto;
6087+
6088+
6089+
public sealed class Output : Microsoft.ML.Runtime.EntryPoints.CommonOutputs.IBinaryClassificationOutput, Microsoft.ML.Runtime.EntryPoints.CommonOutputs.ITrainerOutput
6090+
{
6091+
/// <summary>
6092+
/// The trained model
6093+
/// </summary>
6094+
public Var<Microsoft.ML.Runtime.EntryPoints.IPredictorModel> PredictorModel { get; set; } = new Var<Microsoft.ML.Runtime.EntryPoints.IPredictorModel>();
6095+
6096+
}
6097+
public Var<IDataView> GetInputData() => TrainingData;
6098+
6099+
public ILearningPipelineStep ApplyStep(ILearningPipelineStep previousStep, Experiment experiment)
6100+
{
6101+
if (previousStep != null)
6102+
{
6103+
if (!(previousStep is ILearningPipelineDataStep dataStep))
6104+
{
6105+
throw new InvalidOperationException($"{ nameof(FieldAwareFactorizationMachineBinaryClassifier)} only supports an { nameof(ILearningPipelineDataStep)} as an input.");
6106+
}
6107+
6108+
TrainingData = dataStep.Data;
6109+
}
6110+
Output output = experiment.Add(this);
6111+
return new FieldAwareFactorizationMachineBinaryClassifierPipelineStep(output);
6112+
}
6113+
6114+
private class FieldAwareFactorizationMachineBinaryClassifierPipelineStep : ILearningPipelinePredictorStep
6115+
{
6116+
public FieldAwareFactorizationMachineBinaryClassifierPipelineStep(Output output)
6117+
{
6118+
Model = output.PredictorModel;
6119+
}
6120+
6121+
public Var<IPredictorModel> Model { get; }
6122+
}
6123+
}
6124+
}
6125+
59906126
namespace Trainers
59916127
{
59926128

src/Native/FactorizationMachineNative/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ set(SOURCES
77

88
if(WIN32)
99
else()
10-
set_property(SOURCE segment.cpp APPEND_STRING PROPERTY COMPILE_FLAGS " -msse4.1")
1110
list(APPEND SOURCES ${VERSION_FILE_PATH})
1211
endif()
1312

src/Native/FactorizationMachineNative/FactorizationMachineCore.cpp

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,11 @@
22
#include <cstring>
33
#include <limits>
44
#include <pmmintrin.h>
5+
#include "../Stdafx.h"
56

67
#define UNUSED(x) (void)(x)
78
#define DEBUG_ONLY(x) (void)(x)
89

9-
#ifdef COMPILER_GCC
10-
11-
#include "UnixSal.h"
12-
#define EXPORT_API(ret) extern "C" __attribute__((visibility("default"))) ret
13-
14-
#else
15-
#include <intrin.h>
16-
#define EXPORT_API(ret) extern "C" __declspec(dllexport) ret __stdcall
17-
#endif
18-
1910
EXPORT_API(void) CalculateIntermediateVariablesNative(int fieldCount, int latentDim, int count, _In_ int * fieldIndices, _In_ int * featureIndices, _In_ float * featureValues,
2011
_In_ float * linearWeights, _In_ float * latentWeights, _Inout_ float * latentSum, _Out_ float * response)
2112
{

test/BaselineOutput/Common/EntryPoints/core_ep-list.tsv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ Trainers.FastTreeBinaryClassifier Uses a logit-boost boosted tree learner to per
3636
Trainers.FastTreeRanker Trains gradient boosted decision trees to the LambdaRank quasi-gradient. Microsoft.ML.Runtime.FastTree.FastTree TrainRanking Microsoft.ML.Runtime.FastTree.FastTreeRankingTrainer+Arguments Microsoft.ML.Runtime.EntryPoints.CommonOutputs+RankingOutput
3737
Trainers.FastTreeRegressor Trains gradient boosted decision trees to fit target values using least-squares. Microsoft.ML.Runtime.FastTree.FastTree TrainRegression Microsoft.ML.Runtime.FastTree.FastTreeRegressionTrainer+Arguments Microsoft.ML.Runtime.EntryPoints.CommonOutputs+RegressionOutput
3838
Trainers.FastTreeTweedieRegressor Trains gradient boosted decision trees to fit target values using a Tweedie loss function. This learner is a generalization of Poisson, compound Poisson, and gamma regression. Microsoft.ML.Runtime.FastTree.FastTree TrainTweedieRegression Microsoft.ML.Runtime.FastTree.FastTreeTweedieTrainer+Arguments Microsoft.ML.Runtime.EntryPoints.CommonOutputs+RegressionOutput
39+
Trainers.FieldAwareFactorizationMachineBinaryClassifier Train a field-aware factorization machine for binary classification Microsoft.ML.Runtime.FactorizationMachine.FieldAwareFactorizationMachineTrainer TrainBinary Microsoft.ML.Runtime.FactorizationMachine.FieldAwareFactorizationMachineTrainer+Arguments Microsoft.ML.Runtime.EntryPoints.CommonOutputs+BinaryClassificationOutput
3940
Trainers.GeneralizedAdditiveModelBinaryClassifier Trains a gradient boosted stump per feature, on all features simultaneously, to fit target values using least-squares. It mantains no interactions between features. Microsoft.ML.Runtime.FastTree.Gam TrainBinary Microsoft.ML.Runtime.FastTree.BinaryClassificationGamTrainer+Arguments Microsoft.ML.Runtime.EntryPoints.CommonOutputs+BinaryClassificationOutput
4041
Trainers.GeneralizedAdditiveModelRegressor Trains a gradient boosted stump per feature, on all features simultaneously, to fit target values using least-squares. It mantains no interactions between features. Microsoft.ML.Runtime.FastTree.Gam TrainRegression Microsoft.ML.Runtime.FastTree.RegressionGamTrainer+Arguments Microsoft.ML.Runtime.EntryPoints.CommonOutputs+RegressionOutput
4142
Trainers.KMeansPlusPlusClusterer K-means is a popular clustering algorithm. With K-means, the data is clustered into a specified number of clusters in order to minimize the within-cluster sum of squares. K-means++ improves upon K-means by using a better method for choosing the initial cluster centers. Microsoft.ML.Runtime.KMeans.KMeansPlusPlusTrainer TrainKMeans Microsoft.ML.Runtime.KMeans.KMeansPlusPlusTrainer+Arguments Microsoft.ML.Runtime.EntryPoints.CommonOutputs+ClusteringOutput

0 commit comments

Comments
 (0)