Пример #1
0
        public unsafe double[,] PredictForMatsMulti(PredictType predictType, float[][] data, int numIteration = -1)
        {
            if (predictType == PredictType.LeafIndex)
            {
                throw new NotImplementedException("TODO: PredictType.LeafIndex");
            }

            var outResult = new double[data.Length, NumClasses];

            if (data.Length > 0)
            {
                long outLen = outResult.GetLength(0) * outResult.GetLength(1);
                var  hdl    = GCHandle.Alloc(outResult, GCHandleType.Pinned);
                try
                {
                    PInvokeException.Check(PInvoke.BoosterPredictForMats(Handle
                                                                         , data
                                                                         , /*nCol*/ data[0].Length
                                                                         , (PInvoke.CApiPredictType)predictType
                                                                         , (numIteration == -1) ? BestIteration : numIteration
                                                                         , ""
                                                                         , outLen
                                                                         , (double *)hdl.AddrOfPinnedObject().ToPointer()
                                                                         ), nameof(PInvoke.BoosterPredictForMats));
                }
                finally
                {
                    if (hdl.IsAllocated)
                    {
                        hdl.Free();
                    }
                }
            }
            return(outResult);
        }
Пример #2
0
        public unsafe double[] PredictForMats(PredictType predictType, float[][] data, int numIteration = -1)
        {
            if (predictType == PredictType.LeafIndex)
            {
                throw new NotImplementedException("TODO: PredictType.LeafIndex");
            }
            if (NumClasses != 1)
            {
                throw new Exception("Call PredictForMatsMulti when NumClasses > 1");
            }

            var outResult = new double[data.Length];

            if (data.Length > 0)
            {
                fixed(double *ptr = outResult)
                PInvokeException.Check(PInvoke.BoosterPredictForMats(Handle
                                                                     , data
                                                                     , /*nCol*/ data[0].Length
                                                                     , (PInvoke.CApiPredictType)predictType
                                                                     , (numIteration == -1) ? BestIteration : numIteration
                                                                     , ""
                                                                     , outResult.Length
                                                                     , ptr
                                                                     ), nameof(PInvoke.BoosterPredictForMats));
            }
            return(outResult);
        }
Пример #3
0
 // Calculate the number of predictions for a dataset with a given number of rows and iterations.
 public long CalcNumPredict(int numRow, PredictType predType, int numIteration)
 {
     long outLen = 0L;
     PInvokeException.Check(PInvoke.BoosterCalcNumPredict(Handle, numRow, (PInvoke.CApiPredictType)predType, 0, numIteration, ref outLen),
                           nameof(PInvoke.BoosterCalcNumPredict));
     return outLen;
 }
Пример #4
0
        public unsafe double [] PredictForMat(PredictType predictType, float [] data, int numIteration = -1)
        {
            if (predictType == PredictType.LeafIndex)
            {
                throw new NotImplementedException("TODO: PredictType.LeafIndex");
            }

            long outLen = NumClasses; // TODO

            double[] outResult = new double[outLen];

            fixed(double *ptr = outResult)
            PInvokeException.Check(PInvoke.BoosterPredictForMat(Handle
                                                                , data
                                                                , /*nRow*/ 1
                                                                , /*nCol*/ data.Length
                                                                , /*isRowMajor*/ true
                                                                , (PInvoke.CApiPredictType)predictType
                                                                , (numIteration == -1) ? BestIteration : numIteration
                                                                , ""
                                                                , ref outLen
                                                                , ptr
                                                                ), nameof(PInvoke.BoosterPredictForMat));

            return(outResult);
        }
Пример #5
0
        private List <string> PredictVals(int position, PredictType predictType, int maxPosition = 10)
        {
            var valArr = new List <string>();

            //var longPosition = position;
            //var huPosition = maxPosition - position + 1;

            //if (predictType == PredictType.Fix)
            //{
            //    if (_predictedDataRate[longPosition] > _predictedDataRate[huPosition])
            //    {
            //        valArr.Add(longVal);
            //        valArr.Add(huVal);
            //    }
            //    else
            //    {
            //        valArr.Add(huVal);
            //        valArr.Add(longVal);
            //    }
            //}
            //else
            //{
            //    if (_predictedDataRate[longPosition] > _predictedDataRate[huPosition])
            //    {
            //        valArr.Add(huVal);
            //        valArr.Add(longVal);
            //    }
            //    else
            //    {
            //        valArr.Add(longVal);
            //        valArr.Add(huVal);
            //    }
            //}
            valArr = longhuVal.OrderBy(p => new Random().Next()).ToList();

            return(valArr);
        }