Пример #1
0
        /// <summary>
        /// 存储在内存中
        /// </summary>
        /// <returns></returns>
        public (byte[] actorBuffer, byte[] cirticBuffer, string innerTypeName, int actionsNum, int featuresNum, int[] actionKeys) PersistencMemory()
        {
            //actor and critic must be the same type
            string innerTypeName = _actorNet.GetType().Name;

            byte[] actorBuffer  = _actorNet.PersistenceMemory();
            byte[] cirticBuffer = _criticNet.PersistenceMemory();
            int[]  actionKeys   = Env.RandomSeedKeys;
            return(actorBuffer, cirticBuffer, innerTypeName, _actionsNumber, _featuresNumber, actionKeys);
        }
Пример #2
0
        public void Accept(ISupportNet sourceNet)
        {
            //convert to bytes
            byte[] bytes = sourceNet.PersistenceMemory();
            //read model and set parameters
            classifierOutput = Function.Load(bytes, device);
            inputVariable    = classifierOutput.Inputs.First(v => v.Name == "inputVariable");
            outputVariable   = Variable.InputVariable(classifierOutput.Output.Shape, DataType.Float, "labelVariable");
            var trainingLoss = CNTKLib.SquaredError(classifierOutput, outputVariable);
            var prediction   = CNTKLib.SquaredError(classifierOutput, outputVariable);
            TrainingParameterScheduleDouble learningRatePerSample = new TrainingParameterScheduleDouble(0.00178125, 1); //0.00178125
            TrainingParameterScheduleDouble momentumTimeConstant  = CNTKLib.MomentumAsTimeConstantSchedule(256);
            IList <Learner> parameterLearners = new List <Learner>()
            {
                Learner.MomentumSGDLearner(classifierOutput.Parameters(), learningRatePerSample, momentumTimeConstant, true)
            };

            trainer = Trainer.CreateTrainer(classifierOutput, trainingLoss, prediction, parameterLearners);
        }