Exemplo n.º 1
0
		/// <summary> Sets up the priors for numeric class attributes from the 
		/// training class values that have been seen so far.
		/// </summary>
		protected internal virtual void  setNumericPriorsFromBuffer()
		{
			
			double numPrecision = 0.01; // Default value
			if (m_NumTrainClassVals > 1)
			{
				double[] temp = new double[m_NumTrainClassVals];
				Array.Copy(m_TrainClassVals, 0, temp, 0, m_NumTrainClassVals);
				int[] index = Utils.sort(temp);
				double lastVal = temp[index[0]];
				double deltaSum = 0;
				int distinct = 0;
				for (int i = 1; i < temp.Length; i++)
				{
					double current = temp[index[i]];
					if (current != lastVal)
					{
						deltaSum += current - lastVal;
						lastVal = current;
						distinct++;
					}
				}
				if (distinct > 0)
				{
					numPrecision = deltaSum / distinct;
				}
			}
			m_PriorErrorEstimator = new KernelEstimator(numPrecision);
			m_ErrorEstimator = new KernelEstimator(numPrecision);
			m_ClassPriors[0] = m_ClassPriorsSum = 0;
			for (int i = 0; i < m_NumTrainClassVals; i++)
			{
				m_ClassPriors[0] += m_TrainClassVals[i] * m_TrainClassWeights[i];
				m_ClassPriorsSum += m_TrainClassWeights[i];
				m_PriorErrorEstimator.addValue(m_TrainClassVals[i], m_TrainClassWeights[i]);
			}
		}