internal virtual SimpleTensor RandomBinaryTensor()
        {
            double       range  = 1.0 / (4.0 * numHid);
            SimpleTensor tensor = SimpleTensor.Random(numHid * 2, numHid * 2, numHid, -range, range, rand);

            return(tensor.Scale(op.trainOptions.scalingForInit));
        }
        private static double ScaleAndRegularizeTensor(TwoDimensionalMap <string, string, SimpleTensor> derivatives, TwoDimensionalMap <string, string, SimpleTensor> currentMatrices, double scale, double regCost)
        {
            double cost = 0.0;

            // the regularization cost
            foreach (TwoDimensionalMap.Entry <string, string, SimpleTensor> entry in currentMatrices)
            {
                SimpleTensor D = derivatives.Get(entry.GetFirstKey(), entry.GetSecondKey());
                D = D.Scale(scale).Plus(entry.GetValue().Scale(regCost));
                derivatives.Put(entry.GetFirstKey(), entry.GetSecondKey(), D);
                cost += entry.GetValue().ElementMult(entry.GetValue()).ElementSum() * regCost / 2.0;
            }
            return(cost);
        }