Esempio n. 1
0
        public AnfisService(List <DataItem> dataItems, double trainChunk, double minValue, double maxValue, int foldNum) : this()
        {
            if (dataItems.Count == 0)
            {
                throw new Exception("Data items must not be empty");
            }
            if (trainChunk <= 0 || trainChunk >= 1)
            {
                throw  new Exception("Train chunk value must be between 0 and 1");
            }
            if (foldNum <= 1)
            {
                throw new Exception("Number of folds must be greater than 1");
            }

            TrainSet.AddRange(dataItems.GetRange(0, (int)(trainChunk * dataItems.Count)));
            TestSet.AddRange(dataItems.GetRange(
                                 (int)(trainChunk * dataItems.Count), dataItems.Count - (int)(trainChunk * dataItems.Count)));

            TriangularInfoFolds = new TriangularInfo[foldNum];
            var step = (maxValue - minValue) / (foldNum - 1);

            for (int i = 0; i < foldNum; i++)
            {
                TriangularInfoFolds[i] = new TriangularInfo()
                {
                    A = minValue - step + i * step,
                    M = minValue + i * step
                };
            }
        }