public EmployeeController(ECPDbContext context, IPredictionService predictionService, IOptions <PredictionOptions> predictionOptions) { _context = context; _predictionService = predictionService; _predictionOptions = predictionOptions.Value; modelName = _predictionOptions.ModelName; thresHold = _predictionOptions.Threshold; }
private PredictDictionary GetPredictionDictionary(float[] outputValues, PredictorPredictContext ctx, PredictionOptions options) { using (HeavyProfiler.LogNoStackTrace("GetPredictionDictionary")) { return(new PredictDictionary(ctx.Predictor, options, null) { MainQueryValues = ctx.MainOutputCodifications.SelectDictionary(col => col, (col, list) => Encodings.GetOrThrow(col.Encoding).DecodeValue(list.First().Column, list, outputValues, options)), SubQueries = ctx.Predictor.SubQueries.ToDictionary(sq => sq, sq => new PredictSubQueryDictionary(sq) { SubQueryGroups = ctx.SubQueryOutputCodifications.TryGetC(sq)?.Groups.ToDictionary( kvp => kvp.Key, kvp => kvp.Value .Where(a => a.Key.Usage == PredictorSubQueryColumnUsage.Output) .ToDictionary(a => a.Key, a => Encodings.GetOrThrow(a.Key.Encoding).DecodeValue(a.Value.FirstEx().Column, a.Value, outputValues, options)), ObjectArrayComparer.Instance ) ?? new Dictionary <object?[], Dictionary <PredictorSubQueryColumnEmbedded, object?> >(ObjectArrayComparer.Instance), }) }); } }
public object?DecodeValue(PredictorColumnBase column, List <PredictorCodification> codifications, float[] outputValues, PredictionOptions options) { var c = codifications.SingleEx(); return(ReflectionTools.ChangeType(outputValues[c.Index], column.Token.Type)); }
public object?DecodeValue(PredictorColumnBase column, List <PredictorCodification> codifications, float[] outputValues, PredictionOptions options) { var bestCodifications = codifications .Where(c => outputValues[c.Index] > MinDecodedWordValue) .OrderByDescending(a => outputValues[a.Index]) .Take(MaxDecodedWords) .ToList(); return(bestCodifications.ToString(a => a.IsValue !.ToString(), ", ")); }
public object?DecodeValue(PredictorColumnBase column, List <PredictorCodification> codifications, float[] outputValues, PredictionOptions options) { PredictorCodification cod = codifications.SingleEx(); float value = outputValues[cod.Index]; return(DecodeSingleValue(value, cod)); }
public object?DecodeValue(PredictorColumnBase column, List <PredictorCodification> codifications, float[] outputValues, PredictionOptions options) { var cods = options?.FilteredCodifications ?? codifications; if (options?.AlternativeCount == null) { var max = float.MinValue; PredictorCodification?best = null; foreach (var c in cods) { if (max < outputValues[c.Index]) { best = c; max = outputValues[c.Index]; } } return(best?.IsValue); } else { //Softmax var sum = cods.Sum(cod => Math.Exp(outputValues[cod.Index])); return(cods.OrderByDescending(c => outputValues[c.Index]).Take(options.AlternativeCount.Value).Select(c => new AlternativePrediction( probability: (float)(Math.Exp(outputValues[c.Index]) / sum), value: c.IsValue )).ToList()); } }