示例#1
0
        protected virtual void Allocate()
        {
            InputLayer.Dimension(null);
            InputLayer.AllocateMemory();

            int maxLayerLength = 0;
            int maxWeightCount = 0;

            for (int i = 0; i < Layers.Count; i++)
            {
                if (i == 0)
                {
                    Layers[i].Dimension(InputLayer);
                }
                else
                {
                    Layers[i].Dimension(Layers[i - 1]);
                }
                Layers[i].AllocateMemory();

                // Because CuRand need multiple of 8, we need to align it. Float size is 4, so we need a multiple of 2.
                if (WeightsMemoryBlock.Count % 2 != 0)
                {
                    WeightsMemoryBlock.Count += 1;
                }

                StoredOutputBlock.Count += Layers[i].Output.Nb;
                maxLayerLength           = Math.Max(maxLayerLength, Layers[i].Output.Count);
            }

            RBMObserver.Count  = InputLayer.Output.Count;
            RBMObserver2.Count = Layers[Layers.Count - 1].Output.Count;

            RBMBiasMomentum1.Count = maxLayerLength;
            RBMBiasMomentum2.Count = maxLayerLength;
            RBMRandom.Count        = maxLayerLength;

            for (int i = 0; i < Layers.Count - 1; i++)
            {
                Layers[i].NextLayer = Layers[i + 1];
                maxWeightCount      = Math.Max(maxWeightCount, Layers[i].Output.Count * Layers[i + 1].Output.Count);
            }
            maxWeightCount = Math.Max(maxWeightCount, InputLayer.Output.Count * Layers[0].Output.Count);
            RBMPositiveMemoryBlock.Count = maxWeightCount;
            RBMWeightMomentum.Count      = maxWeightCount;
            //RBMPositiveMemoryBlock.Count = 1;
        }