MyCaffe  1.12.2.41
Deep learning software for Windows C# programmers.
Interfaces.cs
1using MyCaffe.basecode;
3using System;
4using System.Collections.Generic;
5using System.Drawing;
6using System.IO;
7using System.Linq;
8using System.Runtime.Serialization;
9using System.Text;
10using System.Threading.Tasks;
11
12namespace MyCaffe.gym
13{
17 public enum GYM_DS_ID
18 {
22 CARTPOLE = 99990001,
26 ATARI = 99990002,
30 CURVE = 99990003,
34 DATAGENERAL = 99991001,
38 MODEL = 99991002
39 }
40
44 public enum GYM_SRC_TRAIN_ID
45 {
49 CARTPOLE = 99995001,
53 ATARI = 99995002,
57 CURVE = 99995003,
61 DATAGENERAL = 99996001,
65 MODEL = 99996002
66 }
67
71 public enum GYM_SRC_TEST_ID
72 {
76 CARTPOLE = 99997001,
80 ATARI = 99997002,
84 CURVE = 99997003,
88 DATAGENERAL = 99998001,
92 MODEL = 99998002
93 }
94
98 public interface IXMyCaffeGym
99 {
105 void Initialize(Log log, PropertySet properties);
109 void Close();
115 IXMyCaffeGym Clone(PropertySet properties = null);
119 string Name { get; }
126 Tuple<State, double, bool> Reset(bool bGetLabel = false, PropertySet props = null);
134 Tuple<State, double, bool> Step(int nAction, bool bGetLabel = false, PropertySet extraProp = null);
143 Tuple<Bitmap, SimpleDatum> Render(bool bShowUi, int nWidth, int nHeight, bool bGetAction);
153 Tuple<Bitmap, SimpleDatum> Render(bool bShowUi, int nWidth, int nHeight, double[] rgData, bool bGetAction);
158 Dictionary<string, int> GetActionSpace();
169 int UiDelay { get; }
185 double TestingPercent { get; }
186 }
187
192 {
201 byte[] ConvertOutput(Stage stage, int nN, float[] rg, out string type);
205 Phase ActivePhase { get; set; }
206 }
207
212 {
217 Tuple<double, double> GetDataRange();
221 bool UseFixedVocabulary { get; }
225 int VocabularySize { get; }
229 bool UsePreLoadData { get; }
230 }
231
235 public class DataPoint
236 {
237 float[] m_rgfInputs;
238 float[] m_rgfMask;
239 float m_fTarget;
240 float m_fTime;
241 List<double> m_rgdfPredicted = null;
242 List<string> m_rgstrPredicted = null;
243 List<bool> m_rgbEmphasize = null;
244
255 public DataPoint(float[] rgfInputs, float[] rgfMask, float fTarget, List<double> rgdfPredicted, List<string> rgstrPredicted, List<bool> rgbEmphasize, float fTime)
256 {
257 m_rgfInputs = rgfInputs;
258 m_rgfMask = rgfMask;
259 m_fTarget = fTarget;
260 m_fTime = fTime;
261
262 m_rgdfPredicted = rgdfPredicted;
263 m_rgstrPredicted = rgstrPredicted;
264 m_rgbEmphasize = rgbEmphasize;
265 }
266
270 public float[] Inputs
271 {
272 get { return m_rgfInputs; }
273 }
274
278 public float[] Mask
279 {
280 get { return m_rgfMask; }
281 }
282
286 public float Target
287 {
288 get { return m_fTarget; }
289 }
290
294 public List<double> Predicted
295 {
296 get { return m_rgdfPredicted; }
297 }
298
302 public List<string> PredictedLabels
303 {
304 get { return m_rgstrPredicted; }
305 }
306
310 public List<bool> PredictedEmphasize
311 {
312 get { return m_rgbEmphasize; }
313 }
314
318 public float Time
319 {
320 get { return m_fTime; }
321 }
322
328 {
329 return new DataPoint(m_rgfInputs, m_rgfMask, m_fTarget, Utility.Clone<double>(m_rgdfPredicted), Utility.Clone<string>(m_rgstrPredicted), Utility.Clone<bool>(m_rgbEmphasize), m_fTime);
330 }
331 }
332
336 public abstract class State
337 {
341 protected List<DataPoint> m_rgPrevPoints = new List<DataPoint>();
342
346 public State()
347 {
348 }
353 public abstract State Clone();
360 public abstract SimpleDatum GetData(bool bNormalize, out int nDataLen);
364 public virtual bool HasClip { get { return false; } }
369 public virtual SimpleDatum GetClip() { throw new NotImplementedException(); }
373 public virtual bool HasLabel { get { return false; } }
378 public virtual SimpleDatum GetLabel() { throw new NotImplementedException(); }
379
383 public List<DataPoint> History
384 {
385 get { return m_rgPrevPoints; }
386 }
387 }
388}
The Log class provides general output in text form.
Definition: Log.cs:13
Specifies a key-value pair of properties.
Definition: PropertySet.cs:16
The SimpleDatum class holds a data input within host memory.
Definition: SimpleDatum.cs:161
The Utility class provides general utility funtions.
Definition: Utility.cs:35
The DatasetDescriptor class describes a dataset which contains both a training data source and testin...
The DataPoint contains the data used when training.
Definition: Interfaces.cs:236
List< bool > PredictedEmphasize
Returns the predicted labels to emphasize.
Definition: Interfaces.cs:311
float Target
Returns the target value.
Definition: Interfaces.cs:287
float Time
Returns the time for the data point.
Definition: Interfaces.cs:319
DataPoint Clone()
Copies the data point to a new data point.
Definition: Interfaces.cs:327
float[] Inputs
Returns the inputs.
Definition: Interfaces.cs:271
DataPoint(float[] rgfInputs, float[] rgfMask, float fTarget, List< double > rgdfPredicted, List< string > rgstrPredicted, List< bool > rgbEmphasize, float fTime)
The constructor.
Definition: Interfaces.cs:255
float[] Mask
Returns the mask where a value of 1 indicates that the input at that same location is valid.
Definition: Interfaces.cs:279
List< double > Predicted
Returns the predicted values.
Definition: Interfaces.cs:295
List< string > PredictedLabels
Returns the predicted labels.
Definition: Interfaces.cs:303
The State class defines an abstract base class for the state information and gym data.
Definition: Interfaces.cs:337
abstract State Clone()
Copies the state to another new state.
virtual SimpleDatum GetLabel()
Get the label data (used with recurrent models such as LSTM with dynamic data).
Definition: Interfaces.cs:378
virtual bool HasLabel
Returns 'true' if this state supports label data.
Definition: Interfaces.cs:373
virtual SimpleDatum GetClip()
Get the clip data (used with recurrent models such as LSTM).
Definition: Interfaces.cs:369
virtual bool HasClip
Returns 'true' if this State supports clip data.
Definition: Interfaces.cs:364
List< DataPoint > History
Returns the history of the previous points if provided by the gym.
Definition: Interfaces.cs:384
List< DataPoint > m_rgPrevPoints
Contains the history of the previous target points.
Definition: Interfaces.cs:341
State()
The constructor.
Definition: Interfaces.cs:346
abstract SimpleDatum GetData(bool bNormalize, out int nDataLen)
Get the data.
The IXMyCaffeGym interface is used to interact with each Gym.
Definition: Interfaces.cs:192
byte[] ConvertOutput(Stage stage, int nN, float[] rg, out string type)
Converts the output values into the native type used by the Gym during queries.
Phase ActivePhase
Specifies the active phase under which to get the data reset and next.
Definition: Interfaces.cs:205
The IXMyCaffeGym interface is used to interact with each Gym.
Definition: Interfaces.cs:99
DatasetDescriptor GetDataset(DATA_TYPE dt, Log log=null)
Returns the dataset of the gym.
string Name
Returns the name of the gym.
Definition: Interfaces.cs:119
Tuple< Bitmap, SimpleDatum > Render(bool bShowUi, int nWidth, int nHeight, bool bGetAction)
Render the gym on a bitmap.
Tuple< State, double, bool > Step(int nAction, bool bGetLabel=false, PropertySet extraProp=null)
Run an action on the gym.
DATA_TYPE[] SupportedDataType
Returns an array of data types supported by the gym.
Definition: Interfaces.cs:177
int UiDelay
Returns the user-interface delay to use (if any).
Definition: Interfaces.cs:169
Tuple< State, double, bool > Reset(bool bGetLabel=false, PropertySet props=null)
Resets the state of they gym.
double TestingPercent
Returns the percentage of the data to use for testing, or -1 which then uses the default of 0....
Definition: Interfaces.cs:185
DATA_TYPE SelectedDataType
Returns the selected data-type.
Definition: Interfaces.cs:173
Dictionary< string, int > GetActionSpace()
Returns a dictionary containing the action space where each entry contains the action name and action...
void Initialize(Log log, PropertySet properties)
Initialize the gym using the properties in the PropertySet.
Tuple< Bitmap, SimpleDatum > Render(bool bShowUi, int nWidth, int nHeight, double[] rgData, bool bGetAction)
Render the gym on a bitmap.
void Close()
Close a previously initialized gym.
IXMyCaffeGym Clone(PropertySet properties=null)
Copy a gym creating a new one.
bool RequiresDisplayImage
Returns whether or not the gym requires the display image.
Definition: Interfaces.cs:181
The IXMyCaffeGymRange interface is used to query the data range for the vocabulary.
Definition: Interfaces.cs:212
bool UseFixedVocabulary
Returns true to use the fixed bucket collection based on the GetDataRange values, otherwise the bucke...
Definition: Interfaces.cs:221
Tuple< double, double > GetDataRange()
Returns the data range of the gym which is used to build the vocabulary.
int VocabularySize
Returns the vocabulary size to use (e.g. the number of buckets).
Definition: Interfaces.cs:225
bool UsePreLoadData
Specifies whether or not to use the pre-load data.
Definition: Interfaces.cs:229
The descriptors namespace contains all descriptor used to describe various items stored within the da...
The MyCaffe.basecode contains all generic types used throughout MyCaffe.
Definition: Annotation.cs:12
Phase
Defines the Phase under which to run a Net.
Definition: Interfaces.cs:61
DATA_TYPE
Defines the gym data type.
Definition: Interfaces.cs:135
Stage
Specifies the stage underwhich to run a custom trainer.
Definition: Interfaces.cs:88
The MyCaffe.gym namespace contains all classes related to the Gym's supported by MyCaffe.
GYM_SRC_TRAIN_ID
Defines the Standard GYM Training Data Source ID's.
Definition: Interfaces.cs:45
GYM_DS_ID
Defines the Standard GYM Dataset ID's.
Definition: Interfaces.cs:18
@ CURVE
Specifies the Curve GYM Dataset ID.
@ DATAGENERAL
Specifies the Standard DATAGENERAL GYM Dataset ID.
@ MODEL
Specifies the Standard MODEL GYM Dataset ID.
@ ATARI
Specifies the Standard ATARI GYM Dataset ID.
@ CARTPOLE
Specifies the Standard CARTPOLE GYM Dataset ID.
GYM_SRC_TEST_ID
Defines the Standard GYM Testing Data Source ID's.
Definition: Interfaces.cs:72
The MyCaffe namespace contains the main body of MyCaffe code that closesly tracks the C++ Caffe open-...
Definition: Annotation.cs:12