Beispiel #1
0
        private void ValidateParameters()
        {
            if (EmissionMatrix == null || TransitionMatrix == null || SequenceOfObservations == null ||
                StateSpace == null || ObservationSpace == null)
            {
                throw new ArgumentException("Parameters cannot be null");
            }

            if (ObservationSpace.Length != EmissionMatrix.GetLength(1) || ObservationSpace.Length == 0)
            {
                throw new ArgumentException("N should be greater than 0 and consistent");
            }

#if _USE_ARRAYS_INSTEAD_OF_MATRIX_HASHTABLE
            if (StateSpace.Length != TransitionMatrix.GetLength(0) || TransitionMatrix.GetLength(0) != TransitionMatrix.GetLength(1) || TransitionMatrix.GetLength(1) != EmissionMatrix.GetLength(0) || EmissionMatrix.GetLength(0) != InitialProbabilitiesOfStates.Length || StateSpace.Length == 0)
            {
                throw new ArgumentException("K should be greater than 0 and consistent");
            }
#else
            if (StateSpace.Length != TransitionMatrix.GetLength(0) ||
                TransitionMatrix.GetLength(0) != TransitionMatrix.GetLength(1) ||
                TransitionMatrix.GetLength(1) != EmissionMatrix.GetLength(0) ||
                EmissionMatrix.GetLength(0) != InitialProbabilitiesOfStates.Count || StateSpace.Length == 0)
            {
                throw new ArgumentException("K should be greater than 0 and consistent");
            }
#endif
            if (SequenceOfObservations.Length == 0)
            {
                throw new ArgumentException("T should be greater than 0 and consistent");
            }

            if (
                StateSpace.Select(state => ObservationSpace.Sum(observation => EmissionMatrix[state, observation]))
                .Any(sum => sum <= 0.99 || sum >= 1.01))
            {
                throw new ArgumentException("EmissionMatrix has not normalized probabilities"); //Exception("Emi");
            }

            if (
                StateSpace.Select(state1 => StateSpace.Sum(state2 => TransitionMatrix[state1, state2]))
                .Any(sum => sum <= 0.99 || sum >= 1.01))
            {
                throw new ArgumentException("TransitionMatrix has not normalized probabilities"); //Exception("Emi");
            }
        }