示例#1
0
        /// <summary>
        /// Gets the event trainer.
        /// </summary>
        /// <param name="parameters">The machine learnable parameters.</param>
        /// <param name="reportMap">The report map.</param>
        /// <param name="monitor">A evaluation monitor that can be used to listen the messages during the training or it can cancel the training operation.
        /// This argument can be a <c>null</c> value.</param>
        /// <returns>The <see cref="IEventTrainer" /> trainer object.</returns>
        /// <exception cref="System.InvalidOperationException">
        /// Unable to retrieve the trainer from the training parameters.
        /// or
        /// The constructor of the trainer must have a standard constructor.
        /// </exception>
        public static IEventTrainer GetEventTrainer(TrainingParameters parameters, Dictionary <string, string> reportMap, Monitor monitor)
        {
            var algorithm = parameters.Get(Parameters.Algorithm);

            if (algorithm == null)
            {
                AbstractEventTrainer trainer = new GIS(monitor);
                trainer.Init(parameters, reportMap);
                return(trainer);
            }

            var trainerType = GetTrainerType(parameters);

            if (trainerType.HasValue && trainerType.Value == TrainerType.EventModelTrainer)
            {
                var type = GetTrainer(algorithm);

                if (type == null)
                {
                    throw new InvalidOperationException("Unable to retrieve the trainer from the training parameters.");
                }

                var ctor = type.GetConstructor(new [] { typeof(Monitor) });
                if (ctor == null)
                {
                    throw new InvalidOperationException("The constructor of the trainer must have a standard constructor.");
                }

                var trainer = (IEventTrainer)ctor.Invoke(new object[] { monitor });
                trainer.Init(parameters, reportMap);
                return(trainer);
            }

            return(null);
        }
示例#2
0
        /// <summary>
        /// Gets the event trainer.
        /// </summary>
        /// <param name="parameters">The machine learnable parameters.</param>
        /// <param name="reportMap">The report map.</param>
        /// <param name="monitor">
        /// A evaluation monitor that can be used to listen the messages during the training or it can cancel the training operation.
        /// This argument can be a <c>null</c> value.
        /// </param>
        /// <returns>The <see cref="IEventTrainer"/> trainer object.</returns>
        public static IEventTrainer GetEventTrainer(TrainingParameters parameters, Dictionary <string, string> reportMap, Monitor monitor)
        {
            var algorithm = parameters.Get(Parameters.Algorithm);

            if (algorithm == null)
            {
                AbstractEventTrainer trainer = new GIS(monitor);
                trainer.Init(parameters, reportMap);
                return(trainer);
            }

            var trainerType = GetTrainerType(parameters);

            if (trainerType.HasValue && trainerType.Value == TrainerType.EventModelTrainer)
            {
                var type = GetTrainer(algorithm);

                var trainer = (IEventTrainer)Activator.CreateInstance(type, monitor);
                trainer.Init(parameters, reportMap);
                return(trainer);
            }

            return(null);
        }