/// <summary> /// Run a set of iterations and return the resuts. /// </summary> /// <param name="nIterations">Specifies the number of iterations to run.</param> /// <param name="type">Returns the data type contained in the byte stream.</param> /// <returns>The results of the run containing the action are returned as a byte stream.</returns> public byte[] Run(int nIterations, out string type) { IxTrainerCallbackRNN icallback = m_icallback as IxTrainerCallbackRNN; if (icallback == null) throw new Exception("The Run method requires an IxTrainerCallbackRNN interface to convert the results into the native format!"); StateBase s = getData(Phase.RUN, -1); int nIteration = 0; List<float> rgResults = new List<float>(); while (!m_brain.Cancel.WaitOne(0) && (nIterations == -1 || nIteration < nIterations)) { // Preprocess the observation. SimpleDatum x = m_brain.Preprocess(s, m_bUseRawInput); // Forward the policy network and sample an action. float[] rgfAprob; int action = m_brain.act(x, s.Clip, out rgfAprob); rgResults.Add(s.Data.TimeStamp.ToFileTime()); rgResults.Add((float)s.Data.GetDataAtF(0)); rgResults.Add(action); // Take the next step using the action StateBase s_ = getData(Phase.RUN, action); nIteration++; } ConvertOutputArgs args = new ConvertOutputArgs(nIterations, rgResults.ToArray()); icallback.OnConvertOutput(args); type = args.RawType; return args.RawOutput; }
protected override bool convertOutput(ConvertOutputArgs e) { IXMyCaffeGymData igym = m_igym as IXMyCaffeGymData; if (igym == null) { throw new Exception("Output data conversion requires a gym that implements the IXMyCaffeGymData interface."); } string type; byte[] rgOutput = igym.ConvertOutput(e.Output, out type); e.SetRawOutput(rgOutput, type); return(true); }
/// <summary> /// The Run method provides the main 'actor' that runs data through the trained network. /// </summary> /// <param name="nN">specifies the number of samples to run.</param> /// <param name="type">Returns the data type contained in the byte stream.</param> /// <returns>The results of the run are returned in the native format used by the CustomQuery.</returns> public byte[] Run(int nN, out string type) { float[] rgResults = m_brain.Run(nN); ConvertOutputArgs args = new ConvertOutputArgs(nN, rgResults); IxTrainerCallbackRNN icallback = m_icallback as IxTrainerCallbackRNN; if (icallback == null) { throw new Exception("The Run method requires an IxTrainerCallbackRNN interface to convert the results into the native format!"); } icallback.OnConvertOutput(args); type = args.RawType; return(args.RawOutput); }