104 lines
3.0 KiB
C#
104 lines
3.0 KiB
C#
// This file was auto-generated by ML.NET Model Builder.
|
|
using Microsoft.ML;
|
|
using Microsoft.ML.Data;
|
|
using System;
|
|
using System.Linq;
|
|
using System.IO;
|
|
using System.Collections.Generic;
|
|
namespace EvenPerfectBitScanner
|
|
{
|
|
public partial class MLModel1
|
|
{
|
|
/// <summary>
|
|
/// model input class for MLModel1.
|
|
/// </summary>
|
|
#region model input class
|
|
public class ModelInput
|
|
{
|
|
[LoadColumn(0)]
|
|
[ColumnName(@"p")]
|
|
public float P { get; set; }
|
|
|
|
[LoadColumn(1)]
|
|
[ColumnName(@"divisor")]
|
|
public float Divisor { get; set; }
|
|
|
|
[LoadColumn(2)]
|
|
[ColumnName(@"lastDigit")]
|
|
public float LastDigit { get; set; }
|
|
|
|
[LoadColumn(3)]
|
|
[ColumnName(@"k")]
|
|
public float K { get; set; }
|
|
|
|
[LoadColumn(4)]
|
|
[ColumnName(@"lastMersenneDigit")]
|
|
public float LastMersenneDigit { get; set; }
|
|
|
|
[LoadColumn(5)]
|
|
[ColumnName(@"isNextKHigher")]
|
|
public float IsNextKHigher { get; set; }
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
/// <summary>
|
|
/// model output class for MLModel1.
|
|
/// </summary>
|
|
#region model output class
|
|
public class ModelOutput
|
|
{
|
|
[ColumnName(@"p")]
|
|
public float P { get; set; }
|
|
|
|
[ColumnName(@"divisor")]
|
|
public float Divisor { get; set; }
|
|
|
|
[ColumnName(@"lastDigit")]
|
|
public float LastDigit { get; set; }
|
|
|
|
[ColumnName(@"k")]
|
|
public float K { get; set; }
|
|
|
|
[ColumnName(@"lastMersenneDigit")]
|
|
public float LastMersenneDigit { get; set; }
|
|
|
|
[ColumnName(@"isNextKHigher")]
|
|
public float IsNextKHigher { get; set; }
|
|
|
|
[ColumnName(@"Features")]
|
|
public float[] Features { get; set; }
|
|
|
|
[ColumnName(@"Score")]
|
|
public float Score { get; set; }
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
private static string MLNetModelPath = Path.GetFullPath("MLModel1.mlnet");
|
|
|
|
public static readonly Lazy<PredictionEngine<ModelInput, ModelOutput>> PredictEngine = new Lazy<PredictionEngine<ModelInput, ModelOutput>>(() => CreatePredictEngine(), true);
|
|
|
|
|
|
private static PredictionEngine<ModelInput, ModelOutput> CreatePredictEngine()
|
|
{
|
|
var mlContext = new MLContext();
|
|
ITransformer mlModel = mlContext.Model.Load(MLNetModelPath, out var _);
|
|
return mlContext.Model.CreatePredictionEngine<ModelInput, ModelOutput>(mlModel);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Use this method to predict on <see cref="ModelInput"/>.
|
|
/// </summary>
|
|
/// <param name="input">model input.</param>
|
|
/// <returns><seealso cref=" ModelOutput"/></returns>
|
|
public static ModelOutput Predict(ModelInput input)
|
|
{
|
|
var predEngine = PredictEngine.Value;
|
|
return predEngine.Predict(input);
|
|
}
|
|
}
|
|
}
|