3using System.Collections.Generic;
7using System.Threading.Tasks;
18 double[] m_rgfPriorities =
null;
42 get {
return m_rgIdx; }
43 set { m_rgIdx = value; }
51 get {
return m_rgfPriorities; }
52 set { m_rgfPriorities = value; }
68 get {
return m_nCount; }
110 while (col.
Count < nCount)
125 return m_rgItems.Select(p => p.NextState).ToList();
134 return m_rgItems.Select(p => p.NextData).ToList();
144 return m_rgItems.Select(p => p.NextState.Clip).ToList();
155 return m_rgItems.Select(p => p.CurrentData).ToList();
165 return m_rgItems.Select(p => p.CurrentState.Clip).ToList();
177 float[] rg =
new float[
m_rgItems.Length * nActionCount];
179 for (
int i = 0; i <
m_rgItems.Length; i++)
183 for (
int j = 0; j < nActionCount; j++)
185 rg[(i * nActionCount) + j] = (j == nAction) ? 1 : 0;
198 float[] rgDoneInv =
new float[
m_rgItems.Length];
200 for (
int i = 0; i <
m_rgItems.Length; i++)
217 return m_rgItems.Select(p => (
float)p.Reward).ToArray();
224 public void Save(
string strFile)
226 if (File.Exists(strFile))
227 File.Delete(strFile);
229 using (StreamWriter sw =
new StreamWriter(strFile))
231 for (
int i = 0; i <
Count; i++)
235 sw.WriteLine(strLine);
244 public void Load(
string strFile)
249 List<MemoryItem> rg =
new List<MemoryItem>();
251 using (StreamReader sr =
new StreamReader(strFile))
253 string strLine = sr.ReadLine();
255 while (strLine !=
null)
257 string[] rgstr = strLine.Split(
',');
260 List<double> rgdfData =
new List<double>();
267 int nAction =
int.Parse(rgstr[nIdx]); nIdx++;
269 bool bTerminated = (
int.Parse(rgstr[nIdx]) == 1) ?
true :
false; nIdx++;
271 rgdfData =
new List<double>();
278 rg.Add(
new MemoryItem(
null, sdCurrent, nAction,
null, sdNext, dfReward, bTerminated, 0, 0));
279 strLine = sr.ReadLine();
319 m_state0 = currentState;
320 m_state1 = nextState;
324 m_bTerminated = bTerminated;
325 m_dfReward = dfReward;
326 m_nIteration = nIteration;
327 m_nEpisode = nEpisode;
335 get {
return m_bTerminated; }
343 get {
return m_dfReward; }
344 set { m_dfReward = value; }
352 get {
return m_state0; }
360 get {
return m_state1; }
384 get {
return m_nAction; }
392 get {
return m_nIteration; }
400 get {
return m_nEpisode; }
409 return "episode = " + m_nEpisode.ToString() +
" action = " + m_nAction.ToString() +
" reward = " + m_dfReward.ToString(
"N2");
412 private string tostring(
float[] rg)
416 for (
int i = 0; i < rg.Length; i++)
418 str += rg[i].ToString(
"N5");
422 str = str.TrimEnd(
',');
The BaseParameter class is the base class for all other parameter classes.
static double ParseDouble(string strVal)
Parse double values using the US culture if the decimal separator = '.', then using the native cultur...
The CryptoRandom is a random number generator that can use either the standard .Net Random objec or t...
int Next(int nMinVal, int nMaxVal, bool bMaxInclusive=true)
Returns a random int within the range
The SimpleDatum class holds a data input within host memory.
string ToArrayAsString(int nMaxItems)
Returns a string containing the items of the SimpleDatum.
The StateBase is the base class for the state of each observation - this is defined by actual trainer...
The memory collection stores a set of memory items.
int m_nNextIdx
Specifies the next available index in the rolling list.
float[] GetInvertedDoneAsOneHotVector()
Returns the inverted done (1 - done) values as a one-hot vector.
void Load(string strFile)
Load all memory items from file.
List< SimpleDatum > GetNextStateClip()
Returns the list of clip items associated with the next state.
MemoryCollection GetRandomSamples(CryptoRandom random, int nCount)
Retrieves a random sample of items from the list.
double[] Priorities
Get/set the priorities associated with the collection (if any).
List< StateBase > GetNextState()
Returns the list of Next State items.
int Count
Returns the current count of items.
int NextIndex
Returns the next index.
int[] Indexes
Get/set the indexes associated with the collection (if any).
void Save(string strFile)
Save the memory items to file.
MemoryCollection(int nMax)
The constructor.
List< SimpleDatum > GetCurrentStateData()
Returns the list of data items associated with the current state.
float[] GetActionsAsOneHotVector(int nActionCount)
Returns the action items as a set of one-hot vectors.
List< SimpleDatum > GetCurrentStateClip()
Returns the list of clip items associated with the current state.
virtual void Add(MemoryItem item)
Adds a new memory item to the array of items and if at capacity, removes an item.
MemoryItem[] m_rgItems
Specifies the memory item list.
float[] GetRewards()
Returns the rewards as a vector.
List< SimpleDatum > GetNextStateData()
Returns the list of data items associated with the next state.
The MemoryItem stores the information about a given cycle.
override string ToString()
Returns a string representation of the state transition.
StateBase CurrentState
Returns the current state.
int Iteration
Returns the iteration of the state transition.
MemoryItem(StateBase currentState, SimpleDatum currentData, int nAction, StateBase nextState, SimpleDatum nextData, double dfReward, bool bTerminated, int nIteration, int nEpisode)
The constructor.
double Reward
Returns the reward of the state transition.
bool IsTerminated
Returns the termination status of the next state.
int Episode
Returns the episode of the state transition.
int Action
Returns the action.
StateBase NextState
Returns the next state.
SimpleDatum NextData
Returns the data associated with the next state.
SimpleDatum CurrentData
Returns the data associated with the current state.
The MyCaffe.basecode contains all generic types used throughout MyCaffe.
The MyCaffe namespace contains the main body of MyCaffe code that closesly tracks the C++ Caffe open-...