Beispiel #1
0
        /// <summary>
        /// MLPの学習と更新
        /// </summary>
        /// <param name="inputs">入力ベクトルの浮動小数点の行列で,1行で1ベクトル.</param>
        /// <param name="outputs">対応する出力ベクトルの浮動小数点の行列で,1行で1ベクトル.</param>
        /// <param name="sampleWeights">(RPROPのみ)各サンプルの重みを指定する浮動小数点のベクトル.オプション. 学習において,幾つかのサンプルは他のものより重要な場合がある. 例えば検出率と誤検出率間の適切なバランスを探すために,あるクラスの重みを増加させたい場合など.</param>
        /// <param name="sampleIdx">用いるサンプルを表す整数のベクトル(すなわち_inputsと_outputsの行).</param>
        /// <param name="param">学習パラメータ</param>
        /// <param name="flags">学習アルゴリズムを制御する様々なパラメータ</param>
        /// <returns>ネットワークの重みを計算/調整した繰り返し回数.</returns>
#else
        /// <summary>
        /// Trains/updates MLP
        /// </summary>
        /// <param name="inputs">A floating-point matrix of input vectors, one vector per row. </param>
        /// <param name="outputs">A floating-point matrix of the corresponding output vectors, one vector per row. </param>
        /// <param name="sampleWeights">(RPROP only) The optional floating-point vector of weights for each sample. Some samples may be more important than others for training, e.g. user may want to gain the weight of certain classes to find the right balance between hit-rate and false-alarm rate etc. </param>
        /// <param name="sampleIdx">The optional integer vector indicating the samples (i.e. rows of _inputs and _outputs) that are taken into account. </param>
        /// <param name="param">The training params.</param>
        /// <param name="flags">The various parameters to control the training algorithm.</param>
        /// <returns>the number of done iterations.</returns>
#endif
        public virtual int Train(Mat inputs, Mat outputs, Mat sampleWeights,
                                 Mat sampleIdx = null,
                                 CvANN_MLP_TrainParams param = null,
                                 MLPTrainingFlag flags       = MLPTrainingFlag.Zero)
        {
            if (inputs == null)
            {
                throw new ArgumentNullException("inputs");
            }
            if (outputs == null)
            {
                throw new ArgumentNullException("outputs");
            }
            inputs.ThrowIfDisposed();
            outputs.ThrowIfDisposed();

            if (param == null)
            {
                param = new CvANN_MLP_TrainParams();
            }

            return(NativeMethods.ml_CvANN_MLP_train_CvMat(
                       ptr,
                       inputs.CvPtr,
                       outputs.CvPtr,
                       Cv2.ToPtr(sampleWeights),
                       Cv2.ToPtr(sampleIdx),
                       param.NativeStruct,
                       (int)flags
                       ));
        }
Beispiel #2
0
        /// <summary>
        /// MLPの学習と更新
        /// </summary>
        /// <param name="inputs">入力ベクトルの浮動小数点の行列で,1行で1ベクトル.</param>
		/// <param name="outputs">対応する出力ベクトルの浮動小数点の行列で,1行で1ベクトル.</param>
        /// <param name="sampleWeights">(RPROPのみ)各サンプルの重みを指定する浮動小数点のベクトル.オプション. 学習において,幾つかのサンプルは他のものより重要な場合がある. 例えば検出率と誤検出率間の適切なバランスを探すために,あるクラスの重みを増加させたい場合など.</param>
        /// <param name="sampleIdx">用いるサンプルを表す整数のベクトル(すなわち_inputsと_outputsの行).</param>
        /// <param name="param">学習パラメータ</param>
		/// <param name="flags">学習アルゴリズムを制御する様々なパラメータ</param>
		/// <returns>ネットワークの重みを計算/調整した繰り返し回数.</returns>
#else
        /// <summary>
        /// Trains/updates MLP
        /// </summary>
        /// <param name="inputs">A floating-point matrix of input vectors, one vector per row. </param>
        /// <param name="outputs">A floating-point matrix of the corresponding output vectors, one vector per row. </param>
        /// <param name="sampleWeights">(RPROP only) The optional floating-point vector of weights for each sample. Some samples may be more important than others for training, e.g. user may want to gain the weight of certain classes to find the right balance between hit-rate and false-alarm rate etc. </param>
        /// <param name="sampleIdx">The optional integer vector indicating the samples (i.e. rows of _inputs and _outputs) that are taken into account. </param>
        /// <param name="param">The training params.</param>
        /// <param name="flags">The various parameters to control the training algorithm.</param>
        /// <returns>the number of done iterations.</returns>
#endif
        public virtual int Train(Mat inputs, Mat outputs, Mat sampleWeights,
            Mat sampleIdx = null,
            CvANN_MLP_TrainParams param = null,
            MLPTrainingFlag flags = MLPTrainingFlag.Zero)
        {
            if (inputs == null)
                throw new ArgumentNullException("inputs");
            if (outputs == null)
                throw new ArgumentNullException("outputs");
            inputs.ThrowIfDisposed();
            outputs.ThrowIfDisposed();

            if (param == null)
                param = new CvANN_MLP_TrainParams();

            return NativeMethods.ml_CvANN_MLP_train_CvMat(
                ptr,
                inputs.CvPtr,
                outputs.CvPtr,
                Cv2.ToPtr(sampleWeights),
                Cv2.ToPtr(sampleIdx),
                param.NativeStruct,
                (int)flags
            );
        }