コード例 #1
0
        public override void Build()
        {
            // init fields

            m_InputDepth  = Net.InputDepth;
            m_InputHeight = Net.InputHeight;
            m_InputWidth  = Net.InputWidth;
            m_OutputDepth = Net[Net.LayerCount - 1].OutputDepth;

            m_Gradient = new double[Net.LayerCount][];
            m_Values   = new double[Net.LayerCount][][, ];
            m_Errors   = new double[Net.LayerCount][][, ];
            for (int l = 0; l < Net.LayerCount; l++)
            {
                var layer = Net[l];

                m_Gradient[l] = new double[layer.ParamCount];
                m_Values[l]   = new double[layer.OutputDepth][, ];
                m_Errors[l]   = new double[layer.OutputDepth][, ];
                for (int p = 0; p < layer.OutputDepth; p++)
                {
                    m_Values[l][p] = new double[layer.OutputHeight, layer.OutputWidth];
                    m_Errors[l][p] = new double[layer.OutputHeight, layer.OutputWidth];
                }
            }

            // init optimizer
            if (m_Optimizer == null)
            {
                m_Optimizer = Registry.Optimizer.SGD;
            }

            // init scheduler
            if (m_LearningRateScheduler == null)
            {
                m_LearningRateScheduler = Registry.LearningRateScheduler.Constant(m_LearningRate);
            }

            // init batch context
            if (m_UseBatchParallelization)
            {
                m_BatchContext = new BatchContext(this, m_MaxBatchThreadCount);
            }
        }
コード例 #2
0
ファイル: BackpropAlgorithm.cs プロジェクト: itadapter/ML
        public override void Build()
        {
            // init fields

            m_EpochLength = TrainingSample.Count;
            m_InputDepth  = Net.InputDepth;
            m_InputHeight = Net.InputHeight;
            m_InputWidth  = Net.InputWidth;
            m_OutputDepth = Net[Net.LayerCount - 1].OutputDepth;

            m_Gradient = new double[Net.LayerCount][];
            m_Values   = new double[Net.LayerCount][][, ];
            m_Errors   = new double[Net.LayerCount][][, ];
            for (int l = 0; l < Net.LayerCount; l++)
            {
                var layer = Net[l];

                m_Gradient[l] = new double[layer.ParamCount];
                m_Values[l]   = new double[layer.OutputDepth][, ];
                m_Errors[l]   = new double[layer.OutputDepth][, ];
                for (int p = 0; p < layer.OutputDepth; p++)
                {
                    m_Values[l][p] = new double[layer.OutputHeight, layer.OutputWidth];
                    m_Errors[l][p] = new double[layer.OutputHeight, layer.OutputWidth];
                }
            }

            // init expected outputs

            m_ExpectedOutputs = new Dictionary <Class, double[]>();
            var count = Classes.Count;

            if (count != OutputDepth)
            {
                throw new MLException("Number of classes must be equal to dimension of output vector");
            }

            for (int i = 0; i < count; i++)
            {
                var cls = Classes.FirstOrDefault(p => (int)p.Value.Value == i).Value;
                if (cls == null)
                {
                    throw new MLException(string.Format("There is no class with value {0}. It is neccessary to have full set of classes with values from 0 to {1}", i, count));
                }

                var output = new double[count];
                output[i] = 1.0D;
                m_ExpectedOutputs[cls] = output;
            }

            // init optimizer
            if (m_Optimizer == null)
            {
                m_Optimizer = Registry.Optimizer.SGD;
            }

            // init scheduler
            if (m_LearningRateScheduler == null)
            {
                m_LearningRateScheduler = Registry.LearningRateScheduler.Constant(m_LearningRate);
            }

            // init batch context
            if (m_UseBatchParallelization)
            {
                m_BatchContext = new BatchContext(this, m_MaxBatchThreadCount);
            }
        }