MyCaffe  1.12.2.41
Deep learning software for Windows C# programmers.
CurveGym.cs
1using MyCaffe.basecode;
3using System;
4using System.Collections.Generic;
5using System.Diagnostics;
6using System.Drawing;
7using System.Drawing.Drawing2D;
8using System.Linq;
9using System.Text;
10using System.Threading;
11using System.Threading.Tasks;
12
13namespace MyCaffe.gym
14{
18 public class CurveGym : IXMyCaffeGym, IDisposable
19 {
20 string m_strName = "Curve";
21 Dictionary<string, int> m_rgActionSpace;
22 Bitmap m_bmp = null;
23 int m_nSteps = 0;
24 int m_nMaxSteps = int.MaxValue;
25 ColorMapper m_clrMap = null;
26 DATA_TYPE m_dt = DATA_TYPE.VALUES;
27 GeomGraph m_geomGraph;
28 GeomPolyLine m_geomTargetLine;
29 List<GeomPolyLine> m_rgGeomPredictedLines = new List<GeomPolyLine>();
30 CURVE_TYPE m_curveType = CURVE_TYPE.SIN;
31 float m_fXScale = 512;
32 float m_fYScale = 150;
33 float m_fX = 0;
34 float m_fInc = (float)(Math.PI * 2.0f / 360.0f);
35 float m_fMax = (float)(Math.PI * 2.0f);
36 List<DataPoint> m_rgPrevPoints = new List<DataPoint>();
37 Dictionary<Color, Brush> m_rgBrushes = new Dictionary<Color, Brush>();
38 Dictionary<Color, Brush> m_rgBrushesEmphasize = new Dictionary<Color, Brush>();
39 int m_nMaxPlots = 500;
40 float m_fLastY = 0;
41 bool m_bRenderImage = true;
42 List<string> m_rgstrLabels = null;
43 List<bool> m_rgEmphasize = null;
44 List<Color> m_rgPallete = new List<Color>();
45 List<Color> m_rgPalleteEmphasize = new List<Color>() { Color.Orange, Color.Green, Color.Red, Color.HotPink, Color.Tomato, Color.Lavender, Color.DarkOrange };
46 int m_nAlphaNormal = 64;
47
48 Random m_random = new Random();
49 CurveState m_state = new CurveState();
50 Log m_log;
51
55 public enum ACTION
56 {
60 MOVEUP,
64 MOVEDN
65 }
66
70 public enum CURVE_TYPE
71 {
75 SIN,
79 COS,
83 RANDOM
84 }
85
89 public CurveGym()
90 {
91 m_rgActionSpace = new Dictionary<string, int>();
92 m_rgActionSpace.Add("MoveUp", 0);
93 m_rgActionSpace.Add("MoveDn", 1);
94
95 foreach (Color clr in m_rgPalleteEmphasize)
96 {
97 Color clrLite = Color.FromArgb(m_nAlphaNormal, clr);
98 m_rgPallete.Add(clrLite);
99
100 m_rgBrushes.Add(clr, new SolidBrush(clrLite));
101 m_rgBrushesEmphasize.Add(clr, new SolidBrush(clr));
102 }
103 }
104
108 public void Dispose()
109 {
110 foreach (KeyValuePair<Color, Brush> kv in m_rgBrushes)
111 {
112 kv.Value.Dispose();
113 }
114
115 foreach (KeyValuePair<Color, Brush> kv in m_rgBrushesEmphasize)
116 {
117 kv.Value.Dispose();
118 }
119 }
120
131 public void Initialize(Log log, PropertySet properties)
132 {
133 m_log = log;
134 m_nMaxSteps = 0;
135
136 int nCurveType = properties.GetPropertyAsInt("CurveType", -1);
137 if (nCurveType != -1)
138 m_curveType = (CURVE_TYPE)nCurveType;
139
140 Reset(false);
141 }
142
143
149 public IXMyCaffeGym Clone(PropertySet properties = null)
150 {
151 CurveGym gym = new CurveGym();
152
153 if (properties != null)
154 gym.Initialize(m_log, properties);
155
156 return gym;
157 }
158
163 {
164 get { return false; }
165 }
166
171 {
172 get { return m_dt; }
173 }
174
179 {
180 get { return new DATA_TYPE[] { DATA_TYPE.VALUES, DATA_TYPE.BLOB }; }
181 }
182
186 public string Name
187 {
188 get { return m_strName; }
189 }
190
194 public int UiDelay
195 {
196 get { return 1; }
197 }
198
202 public double TestingPercent
203 {
204 get { return -1; }
205 }
206
211 public Dictionary<string, int> GetActionSpace()
212 {
213 return m_rgActionSpace;
214 }
215
216 private void processAction(ACTION? a, double? dfOverride = null)
217 {
218 }
219
223 public void Close()
224 {
225 }
226
235 public Tuple<Bitmap, SimpleDatum> Render(bool bShowUi, int nWidth, int nHeight, bool bGetAction)
236 {
237 List<double> rgData = new List<double>();
238
239 rgData.Add(m_state.X);
240 rgData.Add(m_state.Y);
241 rgData.Add(m_nSteps);
242
243 if (m_state.PredictedYValues.Count > 0)
244 rgData.AddRange(m_state.PredictedYValues);
245 else
246 rgData.Add(0);
247
248 m_rgstrLabels = m_state.PredictedYNames;
249 m_rgEmphasize = m_state.PredictedYEmphasize;
250
251 return Render(bShowUi, nWidth, nHeight, rgData.ToArray(), bGetAction);
252 }
253
263 public Tuple<Bitmap, SimpleDatum> Render(bool bShowUi, int nWidth, int nHeight, double[] rgData, bool bGetAction)
264 {
265 double dfX = rgData[0];
266 double dfY = rgData[1];
267 int nSteps = (int)rgData[2];
268 int nPredictedIdx = 3;
269
270 m_nSteps = nSteps;
271 m_nMaxSteps = Math.Max(nSteps, m_nMaxSteps);
272
273 SimpleDatum sdAction = null;
274 Bitmap bmp = null;
275
276 if (m_bRenderImage)
277 {
278 bmp = new Bitmap(nWidth, nHeight);
279 using (Graphics g = Graphics.FromImage(bmp))
280 {
281 Rectangle rc = new Rectangle(0, 0, bmp.Width, bmp.Height);
282 g.FillRectangle(Brushes.White, rc);
283
284 float fScreenWidth = g.VisibleClipBounds.Width;
285 float fScreenHeight = g.VisibleClipBounds.Height;
286 float fWorldWidth = (float)m_fXScale;
287 float fWorldHeight = (float)m_fYScale * 2;
288 float fScale = fScreenHeight / fWorldHeight;
289
290 float fL = 0;
291 float fR = fWorldWidth;
292 float fT = fWorldHeight / 2;
293 float fB = -fWorldHeight / 2;
294
295 if (m_geomGraph == null)
296 {
297 m_geomGraph = new GeomGraph(fL, fR, fT, fB, Color.Azure, Color.SteelBlue);
298 m_geomGraph.SetLocation(0, fScale * (fWorldHeight / 2));
299 }
300 if (m_geomTargetLine == null)
301 {
302 m_geomTargetLine = new GeomPolyLine(fL, fR, fT, fB, Color.Blue, Color.Blue, m_nMaxPlots);
303 m_geomTargetLine.Polygon.Clear();
304 m_geomTargetLine.SetLocation(0, fScale * (fWorldHeight / 2));
305 }
306 m_geomTargetLine.Polygon.Add(new PointF((float)dfX, (float)(dfY * m_fYScale)));
307
308 if (m_rgGeomPredictedLines.Count == 0)
309 {
310 bool bEmphasize = (m_rgEmphasize == null || m_rgEmphasize.Count == 0) || (m_rgEmphasize.Count > 0 && m_rgEmphasize[0]);
311 List<Color> rgClr = (bEmphasize) ? m_rgPalleteEmphasize : m_rgPallete;
312 GeomPolyLine geomPredictLine = new GeomPolyLine(fL, fR, fT, fB, rgClr[0], rgClr[0], m_nMaxPlots);
313 geomPredictLine.Polygon.Clear();
314 geomPredictLine.SetLocation(0, fScale * (fWorldHeight / 2));
315 m_rgGeomPredictedLines.Add(geomPredictLine);
316 }
317
318 if (m_rgstrLabels != null && m_rgstrLabels.Count > 0)
319 {
320 if (m_rgEmphasize[0])
321 {
322 List<Color> rgClr = ((m_rgEmphasize == null || m_rgEmphasize.Count == 0) || (m_rgEmphasize.Count > 0 && m_rgEmphasize[0])) ? m_rgPalleteEmphasize : m_rgPallete;
323 m_rgGeomPredictedLines[0].SetColors(rgClr[0], rgClr[0]);
324 }
325
326 int nIdx = 1;
327 while (m_rgGeomPredictedLines.Count < m_rgstrLabels.Count && nIdx < m_rgPallete.Count)
328 {
329 bool bEmphasize = (m_rgEmphasize == null || m_rgEmphasize.Count == 0) || (m_rgEmphasize.Count > 0 && m_rgEmphasize[nIdx]);
330 List<Color> rgClr = (bEmphasize) ? m_rgPalleteEmphasize : m_rgPallete;
331 GeomPolyLine geomPredictLine = new GeomPolyLine(fL, fR, fT, fB, rgClr[nIdx], rgClr[nIdx], m_nMaxPlots);
332 geomPredictLine.Polygon.Clear();
333 geomPredictLine.SetLocation(0, fScale * (fWorldHeight / 2));
334 m_rgGeomPredictedLines.Add(geomPredictLine);
335 nIdx++;
336 }
337 }
338
339 for (int i=0; i < m_rgGeomPredictedLines.Count; i++)
340 {
341 double dfPredicted = 0;
342 if (i+nPredictedIdx < rgData.Length)
343 dfPredicted = rgData[nPredictedIdx + i];
344
345 m_rgGeomPredictedLines[i].Polygon.Add(new PointF((float)dfX, (float)(dfPredicted * m_fYScale)));
346 }
347
348 GeomView view = new GeomView();
349
350 view.RenderText(g, "X = " + dfX.ToString("N02"), 10, 24);
351 view.RenderText(g, "Y = " + dfY.ToString("N02"), 10, 36);
352 int nY = 48;
353
354 if (m_rgstrLabels != null && m_rgstrLabels.Count > 0)
355 {
356 for (int i = 0; i < m_rgGeomPredictedLines.Count && i < m_rgstrLabels.Count; i++)
357 {
358 bool bEmphasize = (m_rgEmphasize == null || m_rgEmphasize.Count == 0) || (m_rgEmphasize.Count > 0 && m_rgEmphasize[i]);
359 Dictionary<Color, Brush> rgClr = (bEmphasize) ? m_rgBrushesEmphasize : m_rgBrushes;
360 view.RenderText(g, "Predicted Y (" + m_rgstrLabels[i] + ") = " + rgData[nPredictedIdx + i].ToString("N02"), 10, nY, rgClr[m_rgPalleteEmphasize[i]]);
361 nY += 12;
362 }
363 }
364 else
365 {
366 bool bEmphasize = (m_rgEmphasize == null || m_rgEmphasize.Count == 0) || (m_rgEmphasize.Count > 0 && m_rgEmphasize[0]);
367 Dictionary<Color, Brush> rgClr = (bEmphasize) ? m_rgBrushesEmphasize : m_rgBrushes;
368 view.RenderText(g, "Predicted Y = " + rgData[nPredictedIdx].ToString("N02"), 10, nY, rgClr[m_rgPalleteEmphasize[0]]);
369 nY += 12;
370 }
371
372 view.RenderText(g, "Curve Type = " + m_curveType.ToString(), 10, nY);
373 view.RenderSteps(g, m_nSteps, m_nMaxSteps);
374
375 // Render the objects.
376 view.AddObject(m_geomGraph);
377 view.AddObject(m_geomTargetLine);
378
379 for (int i = 0; i < m_rgGeomPredictedLines.Count; i++)
380 {
381 view.AddObject(m_rgGeomPredictedLines[i]);
382 }
383
384 view.Render(g);
385
386 if (bGetAction)
387 sdAction = getActionData((float)dfX, (float)dfY, (float)fWorldWidth, (float)fWorldHeight, bmp);
388
389 m_bmp = bmp;
390 }
391 }
392
393 return new Tuple<Bitmap, SimpleDatum>(bmp, sdAction);
394 }
395
396 private SimpleDatum getActionData(float fX, float fY, float fWid, float fHt, Bitmap bmpSrc)
397 {
398 double dfX = (fWid * 0.85);
399 double dfY = (bmpSrc.Height - fY) - (fHt * 0.75);
400
401 RectangleF rc = new RectangleF((float)dfX, (float)dfY, fWid, fHt);
402 Bitmap bmp = new Bitmap((int)fWid, (int)fHt);
403
404 using (Graphics g = Graphics.FromImage(bmp))
405 {
406 RectangleF rc1 = new RectangleF(0, 0, (float)fWid, (float)fHt);
407 g.FillRectangle(Brushes.Black, rc1);
408 g.DrawImage(bmpSrc, rc1, rc, GraphicsUnit.Pixel);
409 }
410
411 return ImageData.GetImageDataD(bmp, 3, false, -1);
412 }
413
420 public Tuple<State, double, bool> Reset(bool bGetLabel, PropertySet props = null)
421 {
422 double dfX = 0;
423 double dfY = 0;
424 double dfPredictedY = 0;
425
426 m_bRenderImage = true;
427 m_rgPrevPoints.Clear();
428 m_nSteps = 0;
429
430 m_fLastY = 0;
431 m_state = new CurveState(dfX, dfY, new List<double>() { dfPredictedY });
432
433 if (props != null)
434 {
435 bool bTraining = props.GetPropertyAsBool("Training", false);
436 if (bTraining)
437 m_bRenderImage = false;
438
439 m_fLastY = (float)props.GetPropertyAsDouble("TrainingStart", 0);
440 }
441
442 return new Tuple<State, double, bool>(m_state.Clone(), 1, false);
443 }
444
445 private double randomUniform(double dfMin, double dfMax)
446 {
447 double dfRange = dfMax - dfMin;
448 return dfMin + (m_random.NextDouble() * dfRange);
449 }
450
451 private double calculateTarget(double dfX)
452 {
453 switch (m_curveType)
454 {
455 case CURVE_TYPE.SIN:
456 return Math.Sin(dfX);
457
458 case CURVE_TYPE.COS:
459 return Math.Cos(dfX);
460
461 case CURVE_TYPE.RANDOM:
462 float fCurve = m_fLastY + (float)(m_random.NextDouble() - 0.5) * (float)(m_random.NextDouble() * 0.20f);
463 if (fCurve > 1.0f)
464 fCurve = 1.0f;
465 if (fCurve < -1.0f)
466 fCurve = -1.0f;
467 m_fLastY = fCurve;
468 return fCurve;
469
470 default:
471 throw new Exception(Name + " does not support the curve type '" + m_curveType.ToString() + "'.");
472 }
473 }
474
482 public Tuple<State, double, bool> Step(int nAction, bool bGetLabel, PropertySet propExtra = null)
483 {
484 CurveState state = new CurveState(m_state);
485 double dfReward = 0;
486 List<double> rgOverrides = new List<double>();
487 List<string> rgOverrideNames = new List<string>();
488 List<bool> rgOverrideEmphasize = new List<bool>();
489 double? dfOverride = null;
490
491 m_bRenderImage = true;
492
493 if (propExtra != null)
494 {
495 bool bTraining = propExtra.GetPropertyAsBool("Training", false);
496 if (bTraining)
497 m_bRenderImage = false;
498
499 double dfCount = propExtra.GetPropertyAsDouble("override_predictions", 0);
500 if (dfCount > 0)
501 {
502 for (int i = 0; i < (int)dfCount; i++)
503 {
504 double dfVal = propExtra.GetPropertyAsDouble("override_prediction" + i.ToString(), double.MaxValue);
505 if (dfVal != double.MaxValue)
506 rgOverrides.Add(dfVal);
507
508 string strName = propExtra.GetProperty("override_prediction" + i.ToString() + "_name");
509 if (!string.IsNullOrEmpty(strName))
510 rgOverrideNames.Add(strName);
511
512 string strVal = propExtra.GetProperty("override_prediction" + i.ToString() + "_emphasize");
513 bool bEmphasize;
514 if (bool.TryParse(strVal, out bEmphasize))
515 rgOverrideEmphasize.Add(bEmphasize);
516 }
517 }
518 else
519 {
520 double dfVal = propExtra.GetPropertyAsDouble("override_prediction", double.MaxValue);
521 if (dfVal != double.MaxValue)
522 rgOverrides.Add(dfVal);
523 }
524
525 if (rgOverrides.Count > 0)
526 dfOverride = rgOverrides[0];
527 }
528
529 processAction((ACTION)nAction, dfOverride);
530
531 double dfX = state.X;
532 double dfY = state.Y;
533 double dfPredictedY = ((dfOverride.HasValue) ? dfOverride.Value : state.PredictedY);
534
535 m_fX += m_fInc;
536 if (m_fX > m_fMax)
537 m_fX = 0;
538
539 dfY = calculateTarget(m_fX);
540 dfX += 1;
541
542 float[] rgInput = new float[] { m_fX };
543 float[] rgMask = new float[] { 1 };
544 float fTarget = (float)dfY;
545 float fTime = (float)(dfX / m_nMaxPlots);
546
547 DataPoint pt = new DataPoint(rgInput, rgMask, fTarget, rgOverrides, rgOverrideNames, rgOverrideEmphasize, fTime);
548 m_rgPrevPoints.Add(pt);
549
550 if (m_rgPrevPoints.Count > m_nMaxPlots)
551 m_rgPrevPoints.RemoveAt(0);
552
553 CurveState stateOut = m_state;
554 m_state = new CurveState(dfX, dfY, rgOverrides, rgOverrideNames, rgOverrideEmphasize, m_rgPrevPoints);
555
556 dfReward = 1.0 - Math.Abs(dfPredictedY - dfY);
557 if (dfReward < -1)
558 dfReward = -1;
559
560 m_nSteps++;
561 m_nMaxSteps = Math.Max(m_nMaxSteps, m_nSteps);
562
563 stateOut.Steps = m_nSteps;
564 return new Tuple<State, double, bool>(stateOut.Clone(), dfReward, false);
565 }
566
574 {
575 int nH = 1;
576 int nW = 1;
577 int nC = 1;
578
579 if (dt == DATA_TYPE.DEFAULT)
580 dt = DATA_TYPE.VALUES;
581
582 if (dt == DATA_TYPE.BLOB)
583 {
584 nH = 156;
585 nW = 156;
586 nC = 3;
587 }
588
589 SourceDescriptor srcTrain = new SourceDescriptor((int)GYM_DS_ID.CURVE, Name + ".training", nW, nH, nC, false, false);
590 SourceDescriptor srcTest = new SourceDescriptor((int)GYM_SRC_TEST_ID.CURVE, Name + ".testing", nW, nH, nC, false, false);
591 DatasetDescriptor ds = new DatasetDescriptor((int)GYM_SRC_TRAIN_ID.CURVE, Name, null, null, srcTrain, srcTest, "CurveGym", "Curve Gym", null, GYM_TYPE.DYNAMIC);
592
593 m_dt = dt;
594
595 return ds;
596 }
597 }
598
599 class GeomGraph : GeomPolygon
600 {
601 public GeomGraph(float fL, float fR, float fT, float fB, Color clrFill, Color clrBorder)
602 : base(fL, fR, fT, fB, clrFill, clrBorder)
603 {
604 }
605
606 public override void Render(Graphics g)
607 {
608 base.Render(g);
609 }
610 }
611
612 class CurveState : State
613 {
614 double m_dfX = 0;
615 double m_dfY = 0;
616 List<double> m_rgdfPredictedY = null;
617 List<string> m_rgstrPredictedY = null;
618 List<bool> m_rgbPredictedY = null;
619 int m_nSteps = 0;
620
621 public const double MAX_X = 2.4;
622 public const double MAX_Y = 2.4;
623
624 public CurveState(double dfX = 0, double dfY = 0, List<double> rgdfPredictedY = null, List<string> rgstrPredictedY = null, List<bool> rgbPredictedY = null, List<DataPoint> rgPoints = null)
625 {
626 m_dfX = dfX;
627 m_dfY = dfY;
628 m_rgdfPredictedY = rgdfPredictedY;
629 m_rgstrPredictedY = rgstrPredictedY;
630 m_rgbPredictedY = rgbPredictedY;
631
632 if (rgPoints != null)
633 m_rgPrevPoints = rgPoints;
634 }
635
636 public CurveState(CurveState s)
637 {
638 m_dfX = s.m_dfX;
639 m_dfY = s.m_dfY;
640 m_rgdfPredictedY = Utility.Clone<double>(s.m_rgdfPredictedY);
641 m_rgstrPredictedY = Utility.Clone<string>(s.m_rgstrPredictedY);
642 m_rgbPredictedY = Utility.Clone<bool>(s.m_rgbPredictedY);
643 m_nSteps = s.m_nSteps;
644 m_rgPrevPoints = new List<DataPoint>();
645
646 if (s.m_rgPrevPoints != null)
647 m_rgPrevPoints.AddRange(s.m_rgPrevPoints);
648 }
649
650 public int Steps
651 {
652 get { return m_nSteps; }
653 set { m_nSteps = value; }
654 }
655
656 public double X
657 {
658 get { return m_dfX; }
659 set { m_dfX = value; }
660 }
661
662 public double Y
663 {
664 get { return m_dfY; }
665 set { m_dfY = value; }
666 }
667
668 public double PredictedY
669 {
670 get
671 {
672 if (m_rgdfPredictedY == null || m_rgdfPredictedY.Count == 0)
673 return 0;
674
675 return m_rgdfPredictedY[0];
676 }
677 }
678
679 public List<double> PredictedYValues
680 {
681 get { return m_rgdfPredictedY; }
682 set { m_rgdfPredictedY = value; }
683 }
684
685 public List<string> PredictedYNames
686 {
687 get { return m_rgstrPredictedY; }
688 set { m_rgstrPredictedY = value; }
689 }
690
691 public List<bool> PredictedYEmphasize
692 {
693 get { return m_rgbPredictedY; }
694 set { m_rgbPredictedY = value; }
695 }
696
697 public override State Clone()
698 {
699 return new CurveState(this);
700 }
701
702 public override SimpleDatum GetData(bool bNormalize, out int nDataLen)
703 {
704 nDataLen = 4;
705 Valuemap data = new Valuemap(1, 4, 1);
706
707 double dfPredictedY = 0;
708
709 if (m_rgdfPredictedY != null && m_rgdfPredictedY.Count > 0)
710 dfPredictedY = m_rgdfPredictedY[0];
711
712 data.SetPixel(0, 0, getValue(m_dfX, -MAX_X, MAX_X, bNormalize));
713 data.SetPixel(0, 1, getValue(m_dfY, -MAX_Y, MAX_Y, bNormalize));
714 data.SetPixel(0, 2, getValue(dfPredictedY, -MAX_Y, MAX_Y, bNormalize));
715 data.SetPixel(0, 3, m_nSteps);
716
717 return new SimpleDatum(data);
718 }
719
720 private double getValue(double dfVal, double dfMin, double dfMax, bool bNormalize)
721 {
722 if (!bNormalize)
723 return dfVal;
724
725 return (dfVal - dfMin) / (dfMax - dfMin);
726 }
727 }
728}
The ColorMapper maps a value within a number range, to a Color within a color scheme.
Definition: ColorMapper.cs:14
The ImageData class is a helper class used to convert between Datum, other raw data,...
Definition: ImageData.cs:14
static Datum GetImageDataD(Bitmap bmp, int nChannels, bool bDataIsReal, int nLabel, bool bUseLockBitmap=true, int[] rgFocusMap=null)
The GetImageDataD function converts a Bitmap into a Datum using the double type for real data.
Definition: ImageData.cs:44
The Log class provides general output in text form.
Definition: Log.cs:13
Specifies a key-value pair of properties.
Definition: PropertySet.cs:16
int GetPropertyAsInt(string strName, int nDefault=0)
Returns a property as an integer value.
Definition: PropertySet.cs:287
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 Realmap operates similar to a bitmap but is actually just an array of doubles.
Definition: Valuemap.cs:15
void SetPixel(int nX, int nY, double clr)
Set a given pixel to a given color.
Definition: Valuemap.cs:65
The DatasetDescriptor class describes a dataset which contains both a training data source and testin...
The SourceDescriptor class contains all information describing a data source.
The Curve Gym provides a simulation of continuous curve such as Sin or Cos.
Definition: CurveGym.cs:19
DATA_TYPE[] SupportedDataType
Returns the data types supported by this gym.
Definition: CurveGym.cs:179
double TestingPercent
Returns the testinng percent of -1, which then uses the default of 0.2.
Definition: CurveGym.cs:203
void Close()
Shutdown and close the gym.
Definition: CurveGym.cs:223
bool RequiresDisplayImage
Returns false indicating that this Gym does not require a display image.
Definition: CurveGym.cs:163
Tuple< State, double, bool > Reset(bool bGetLabel, PropertySet props=null)
Reset the state of the gym.
Definition: CurveGym.cs:420
CurveGym()
The constructor.
Definition: CurveGym.cs:89
IXMyCaffeGym Clone(PropertySet properties=null)
Create a new copy of the gym.
Definition: CurveGym.cs:149
DatasetDescriptor GetDataset(DATA_TYPE dt, Log log=null)
Returns the dataset descriptor of the dynamic dataset produced by the Gym.
Definition: CurveGym.cs:573
string Name
Returns the gym's name.
Definition: CurveGym.cs:187
DATA_TYPE SelectedDataType
Returns the selected data type.
Definition: CurveGym.cs:171
CURVE_TYPE
Defines the curve types.
Definition: CurveGym.cs:71
int UiDelay
Returns the delay to use (if any) when the user-display is visible.
Definition: CurveGym.cs:195
void Dispose()
Release all resources used.
Definition: CurveGym.cs:108
void Initialize(Log log, PropertySet properties)
Initialize the gym with the specified properties.
Definition: CurveGym.cs:131
Tuple< Bitmap, SimpleDatum > Render(bool bShowUi, int nWidth, int nHeight, bool bGetAction)
Render the gym's current state on a bitmap and SimpleDatum.
Definition: CurveGym.cs:235
Tuple< Bitmap, SimpleDatum > Render(bool bShowUi, int nWidth, int nHeight, double[] rgData, bool bGetAction)
Render the gyms specified data.
Definition: CurveGym.cs:263
ACTION
Defines the actions to perform.
Definition: CurveGym.cs:56
Tuple< State, double, bool > Step(int nAction, bool bGetLabel, PropertySet propExtra=null)
Step the gym one step in its simulation.
Definition: CurveGym.cs:482
Dictionary< string, int > GetActionSpace()
Returns the action space as a dictionary of name,actionid pairs.
Definition: CurveGym.cs:211
The DataPoint contains the data used when training.
Definition: Interfaces.cs:236
virtual void SetLocation(float fX, float fY)
Sets the object location.
Definition: Geometry.cs:198
List< PointF > Polygon
Returns the bounds as a Polygon.
Definition: Geometry.cs:216
The GeomPolyLine object is used to render an spline.
Definition: Geometry.cs:420
The GeomView manages and renders a collection of Geometric objects.
Definition: Geometry.cs:476
void Render(Graphics g)
Renders the view.
Definition: Geometry.cs:570
void AddObject(GeomObj obj)
Add a new geometric object to the view.
Definition: Geometry.cs:490
void RenderText(Graphics g, string str, float fX, float fY, Brush br=null)
Render text at a location.
Definition: Geometry.cs:503
void RenderSteps(Graphics g, int nSteps, int nMax)
Renders the Gym step information.
Definition: Geometry.cs:519
State()
The constructor.
Definition: Interfaces.cs:346
The IXMyCaffeGym interface is used to interact with each Gym.
Definition: Interfaces.cs:99
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
@ RANDOM
Randomly select the images, ignore the input index.
GYM_TYPE
Defines the gym type (if any).
Definition: Interfaces.cs:116
DATA_TYPE
Defines the gym data type.
Definition: Interfaces.cs:135
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
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