Exemplo n.º 1
0
        public void Statistics_Mode_Single_Value()
        {
            double[] na    = new double[] { 1 };
            double   value = Dispersion.Mode(na);

            Assert.AreEqual(1, value);
        }
Exemplo n.º 2
0
        double RunModelForSingleData(double[] data)
        {
            VerifyDataForRun(data);
            double[] values =
                new double[_allTrees.Length];
            int idx = 0;

            //Iterate through all trees
            foreach (ModelCART modelCart in _allTrees)
            {
                values[idx++] =
                    modelCart.RunModelForSingleData(data);
            }

            double finalValue = Dispersion.Mode(values);

            return(finalValue);
        }
Exemplo n.º 3
0
        public override double RunModelForSingleData(double[] data)
        {
            double value = 0;

            VerifyDataForRun(data);

            if (data.Length != _data.Length - 1)
            {
                throw new InvalidDataException();
            }

            KeyValuePair <int, double>[] allValues =
                new KeyValuePair <int, double> [_data[0].Length];

            //Compute distance per Row
            Parallel.For(0, _data[0].Length, new ParallelOptions {
                MaxDegreeOfParallelism = _maxParallelThreads
            }, row =>
            {
                double[] tArray = SupportFunctions.GetLinearArray(_data, row, _data.Length - 2);
                double distance = _distanceMeasure.getDistanceVector(tArray, data);
                allValues[row]  = new KeyValuePair <int, double>(row, distance);
            });

            List <KeyValuePair <int, double> > distList =
                SupportFunctions.GetSortedKeyValuePair(allValues);

            double[] targetValues = new double[_k];
            //Get lowest k distancesPerRow and their count
            //for (int ii= 0; ii < _k;ii++)
            Parallel.For(0, _k, new ParallelOptions {
                MaxDegreeOfParallelism = _maxParallelThreads
            }, ii =>
            {
                int row          = distList[ii].Key;
                targetValues[ii] = _data[_origTargetAttributeIndex][row];
            });

            //Get the mode
            value = Dispersion.Mode(targetValues);
            return(value);
        }
Exemplo n.º 4
0
        public void Statistics_Mode()
        {
            double value = Dispersion.Mode(ta);

            Assert.AreEqual(Double.NaN, value);
        }