コード例 #1
0
ファイル: AddBias.cs プロジェクト: ohisama/KelpNet
        protected NdArray ForwardCpu(NdArray x)
        {
            int[] inputShape  = x.Shape;
            int[] outputShape = this.Bias.Shape;

            List <int> shapeList = new List <int>();

            for (int i = 0; i < this.Axis; i++)
            {
                shapeList.Add(1);
            }

            shapeList.AddRange(outputShape);

            for (int i = 0; i < inputShape.Length - this.Axis - outputShape.Length; i++)
            {
                shapeList.Add(1);
            }

            int[] y1Shape = shapeList.ToArray();

            NdArray y1 = new Reshape(y1Shape).Forward(this.Bias)[0];
            NdArray y2 = new Broadcast(inputShape).Forward(y1)[0];

            return(x + y2);
        }
コード例 #2
0
ファイル: AddBias.cs プロジェクト: ziichuan/KelpNet
        public NdArray <T> AddBiasForward(NdArray <T> x)
        {
            int[] inputShape  = x.Shape;
            int[] outputShape = this.Bias.Shape;

            List <int> shapeList = new List <int>();

            for (int i = 0; i < this.Axis; i++)
            {
                shapeList.Add(1);
            }

            shapeList.AddRange(outputShape);

            for (int i = 0; i < inputShape.Length - this.Axis - outputShape.Length; i++)
            {
                shapeList.Add(1);
            }

            int[] y1Shape = shapeList.ToArray();

            NdArray <T> y1 = new Reshape <T>(y1Shape).Forward(this.Bias)[0];
            NdArray <T> y2 = new Broadcast <T>(inputShape).Forward(y1)[0];

            return(x + y2);
        }
コード例 #3
0
ファイル: MultiplyScale.cs プロジェクト: Satssuki/KelpNet
        protected NdArray ForwardCpu(NdArray x)
        {
            int[] inputShape  = x.Shape;
            int[] outputShape = this.Weight.Shape;

            List <int> shapeList = new List <int>();

            for (int i = 0; i < this.Axis; i++)
            {
                shapeList.Add(1);
            }

            shapeList.AddRange(outputShape);

            for (int i = 0; i < inputShape.Length - this.Axis - outputShape.Length; i++)
            {
                shapeList.Add(1);
            }

            int[] preShape = shapeList.ToArray();

            NdArray y1 = new Reshape(preShape).Forward(this.Weight)[0];
            NdArray y2 = new Broadcast(inputShape).Forward(y1)[0];

            if (BiasTerm)
            {
                NdArray b1 = new Reshape(preShape).Forward(this.Bias)[0];
                NdArray b2 = new Broadcast(inputShape).Forward(b1)[0];

                return(x * y2 + b2);
            }
            else
            {
                return(x * y2);
            }
        }
コード例 #4
0
        public NdArray <T> MultiplyScaleForward(NdArray <T> x)
        {
            int[] inputShape  = x.Shape;
            int[] outputShape = this.Weight.Shape;

            List <int> shapeList = new List <int>();

            for (int i = 0; i < this.Axis; i++)
            {
                shapeList.Add(1);
            }

            shapeList.AddRange(outputShape);

            for (int i = 0; i < inputShape.Length - this.Axis - outputShape.Length; i++)
            {
                shapeList.Add(1);
            }

            int[] preShape = shapeList.ToArray();

            NdArray <T> y1 = new Reshape <T>(preShape).Forward(this.Weight)[0];
            NdArray <T> y2 = new Broadcast <T>(inputShape).Forward(y1)[0];

            if (BiasTerm)
            {
                NdArray <T> b1 = new Reshape <T>(preShape).Forward(this.Bias)[0];
                NdArray <T> b2 = new Broadcast <T>(inputShape).Forward(b1)[0];

                return(x * y2 + b2);
            }
            else
            {
                return(x * y2);
            }
        }