3using System.Collections.Generic;
6using System.Threading.Tasks;
16 double m_fMaxPriority = 1.0f;
17 int m_nItCapacity = 1;
32 while (m_nItCapacity < nMax)
53 get {
return m_mem.
Count; }
65 int nVal = (int)Math.Pow(m_fMaxPriority, m_fAlpha);
70 private int[] getSamplesProportional(
CryptoRandom random,
int nCount)
72 int[] rgIdx =
new int[nCount];
74 for (
int i = 0; i < nCount; i++)
77 double dfSum1 = m_ItSum.
sum(0, m_mem.
Count - 1);
78 double dfMass = dfRand * dfSum1;
95 int[] rgIdx = getSamplesProportional(random, nCount);
96 double[] rgfWeights =
new double[nCount];
97 double fSum = m_ItSum.
sum();
98 double fMin = m_ItMin.
min();
99 double fPMin = fMin / fSum;
100 double fMaxWeight = (float)Math.Pow(fPMin * m_mem.
Count, -dfBeta);
103 for (
int i = 0; i < rgIdx.Length; i++)
106 double fItSum = m_ItSum[nIdx];
107 double fPSample = fItSum / fSum;
108 double fWeight = Math.Pow(fPSample * m_mem.
Count, -dfBeta);
109 rgfWeights[i] = fWeight / fMaxWeight;
111 mem.
Add(m_mem[nIdx]);
129 int[] rgIdx = rgSamples.
Indexes;
130 double[] rgfPriorities = rgSamples.
Priorities;
132 if (rgIdx.Length != rgfPriorities.Length)
133 throw new Exception(
"The index and priority arrays must have the same length.");
135 for (
int i = 0; i < rgIdx.Length; i++)
138 double fPriority = rgfPriorities[i];
141 throw new Exception(
"The priority at index '" + i.ToString() +
"' is zero!");
143 if (nIdx < 0 || nIdx >= m_mem.
Count)
144 throw new Exception(
"The index at index '" + i.ToString() +
"' is out of range!");
146 double fNewPriority = Math.Pow(fPriority, m_fAlpha);
147 m_ItSum[nIdx] = fNewPriority;
148 m_ItMin[nIdx] = fNewPriority;
149 m_fMaxPriority = Math.Max(m_fMaxPriority, fPriority);
The CryptoRandom is a random number generator that can use either the standard .Net Random objec or t...
double NextDouble()
Returns a random double within the range .
The memory collection stores a set of memory items.
double[] Priorities
Get/set the priorities associated with the collection (if any).
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).
virtual void Add(MemoryItem item)
Adds a new memory item to the array of items and if at capacity, removes an item.
The MemoryItem stores the information about a given cycle.
The MinSegmentTree performs a reduction over the array and returns the minimum value.
double min(int nStart=0, int? nEnd=null)
Returns the minimum element in the array.
The PrioritizedMemoryCollection provides a sampling based on prioritizations.
PrioritizedMemoryCollection(int nMax, float fAlpha)
The constructor.
void Add(MemoryItem m)
Add a new item to the collection.
MemoryCollection GetSamples(CryptoRandom random, int nCount, double dfBeta)
Return a batch of items.
void Update(MemoryCollection rgSamples)
Update the priorities of sampled transitions.
void CleanUp()
Complete any final processing.
int Count
Returns the number of items in the collection.
The SumSegmentTree provides a sum reduction of the items within the array.
int find_prefixsum_idx(double fPrefixSum)
Finds the highest indes 'i' in the array such that sum(arr[0] + arr[1] + ... + arr[i-1]) less than or...
double sum(int nStart=0, int? nEnd=null)
Returns arr[start] + ... + arr[end]
The IMemoryCollection interface is implemented by all memory collection types.
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-...