Esempio n. 1
0
        private static string[] ColumnNames(bool withLabel, ModelValue prediction)
        {
            var columns = new List <string>();
            var data    = new ModelDataSet();

            for (int i = 0; i < data.Features(); i++)
            {
                columns.Add(data.Name(i));
            }

            if (withLabel)
            {
                switch (prediction)
                {
                case ModelValue.Action: columns.Add("Action"); break;

                case ModelValue.Angle: columns.Add("FaceAngle"); break;

                case ModelValue.XY: columns.Add("MoveAngle"); break;

                default: throw new Exception("Unknown value for prediction : " + prediction);
                }
            }

            return(columns.ToArray());
        }
Esempio n. 2
0
        public override float Predict(ModelDataSet input)
        {
            if (TrainedModel == null)
            {
                throw new Exception("Must initialize the model before calling");
            }

            lock (TrainedModel)
            {
                // cache for reuse
                if (PredictInput == null)
                {
                    PredictInput = new float[input.Features()];
                }
                for (int i = 0; i < PredictInput.Length; i++)
                {
                    PredictInput[i] = input.Feature(i);
                }

                using (var arr = InputArray.Create <float>(PredictInput))
                {
                    return(TrainedModel.Predict(arr));
                }
            }
        }