MyCaffe  1.12.2.41
Deep learning software for Windows C# programmers.
FileMemoryCollection.cs
1using MyCaffe.basecode;
2using System;
3using System.Collections.Generic;
4using System.IO;
5using System.Linq;
6using System.Text;
7using System.Threading.Tasks;
8
10{
15 {
16 MemoryCollection m_mem;
17 int m_nSampleIdx = 0;
18 string m_strFile;
19 bool m_bPreLoaded = false;
20 bool m_bSaveOnCleanup = false;
21 double[] m_rgWts = null;
22 int[] m_rgIdx = null;
23
24
32 public FileMemoryCollection(int nMax, bool bPreLoad, bool bSaveOnCleanup, string strFile)
33 {
34 m_mem = new MemoryCollection(nMax);
35 m_strFile = strFile;
36 m_bPreLoaded = bPreLoad;
37 m_bSaveOnCleanup = bSaveOnCleanup;
38
39 if (bPreLoad)
40 m_mem.Load(m_strFile);
41 }
42
46 public void CleanUp()
47 {
48 if (m_bSaveOnCleanup)
49 m_mem.Save(m_strFile);
50 }
51
55 public int Count
56 {
57 get { return m_mem.Count; }
58 }
59
64 public void Add(MemoryItem mi)
65 {
66 if (!m_bPreLoaded)
67 m_mem.Add(mi);
68 }
69
77 public MemoryCollection GetSamples(CryptoRandom random, int nCount, double dfBeta)
78 {
79 if (m_rgWts == null || m_rgWts.Length != nCount)
80 {
81 m_rgWts = new double[nCount];
82 for (int i = 0; i < m_rgWts.Length; i++)
83 {
84 m_rgWts[i] = 1.0;
85 }
86 }
87
88 if (m_rgIdx == null || m_rgIdx.Length != nCount)
89 {
90 m_rgIdx = new int[nCount];
91 }
92
93 MemoryCollection mem = new MemoryCollection(nCount);
94
95 if (m_bPreLoaded)
96 {
97 for (int i = 0; i < nCount; i++)
98 {
99 mem.Add(m_mem[m_nSampleIdx]);
100 m_nSampleIdx++;
101
102 if (m_nSampleIdx == m_mem.Count)
103 m_nSampleIdx = 0;
104 }
105 }
106 else
107 {
108 mem = m_mem.GetRandomSamples(random, nCount);
109 }
110
111 mem.Indexes = m_rgIdx;
112 mem.Priorities = m_rgWts;
113
114 return mem;
115 }
116
121 public void Update(MemoryCollection rgSamples)
122 {
123 }
124 }
125}
The CryptoRandom is a random number generator that can use either the standard .Net Random objec or t...
Definition: CryptoRandom.cs:14
The FileMemoryCollection is used during debugging to load from and save to file.
void Update(MemoryCollection rgSamples)
Update - does nothing.
FileMemoryCollection(int nMax, bool bPreLoad, bool bSaveOnCleanup, string strFile)
The constructor.
void CleanUp()
Complete any final processing.
MemoryCollection GetSamples(CryptoRandom random, int nCount, double dfBeta)
Return a batch of items.
void Add(MemoryItem mi)
Add a new item to the collection.
int Count
Returns the number of items in the collection.
The memory collection stores a set of memory items.
void Load(string strFile)
Load all memory items from file.
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).
int Count
Returns the current count of items.
int[] Indexes
Get/set the indexes associated with the collection (if any).
void Save(string strFile)
Save the memory items to file.
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 IMemoryCollection interface is implemented by all memory collection types.
Definition: Interfaces.cs:37
The MyCaffe.basecode contains all generic types used throughout MyCaffe.
Definition: Annotation.cs:12
The MyCaffe namespace contains the main body of MyCaffe code that closesly tracks the C++ Caffe open-...
Definition: Annotation.cs:12