Пример #1
0
        protected void Initialize <TKey>(Dictionary <TKey, float[]> modelDictionary)
        {
            if (modelDictionary == null || modelDictionary.Count == 0)
            {
                throw (new ArgumentNullException("modelDictionary"));
            }

            TotalClassCount = modelDictionary.First().Value.Length;
            VectorLength    = modelDictionary.Count;

            VectorsSquareLength = new double[TotalClassCount];
            var values = modelDictionary.Values;

            Parallel.For(0, TotalClassCount,
                         classIndex => VectorsSquareLength[classIndex] = VectorsArithmetic.VectorSquareLength(values, classIndex)
                         );
        }
Пример #2
0
        unsafe private void InitializeNative(Dictionary <IntPtr, IntPtr> modelDictionary)
        {
            if (modelDictionary == null || modelDictionary.Count == 0)
            {
                throw (new ArgumentNullException("modelDictionary"));
            }

            var weightClassesPtr = modelDictionary.First().Value;

            TotalClassCount = *((byte *)weightClassesPtr);
            VectorLength    = modelDictionary.Count;

            _ModelRow = new float[TotalClassCount];

            VectorsSquareLength = new double[TotalClassCount];
            var values = _DictionaryNative.Values;

            Parallel.For(0, TotalClassCount,
                         classIndex => VectorsSquareLength[classIndex] = VectorsArithmetic.VectorSquareLength(values, classIndex)
                         );
        }