5using System.Collections.Generic;
9using System.Runtime.InteropServices;
10using System.Security.Cryptography;
13using System.Threading.Tasks;
34 EventWaitHandle m_evtInitializing =
null;
35 EventWaitHandle m_evtInitialized =
null;
36 EventWaitHandle m_evtAbortInitialization =
null;
37 bool m_bEnabled =
false;
38 static object m_syncObject =
new object();
46 Dictionary<int, TemporalSet> m_rgTemporalSets =
new Dictionary<int, TemporalSet>();
57 InitializeComponent();
68 InitializeComponent();
76 public void CleanUp(
int nDsId = 0,
bool bForce =
false)
83 m_rgTemporalSets.Clear();
120 foreach (KeyValuePair<int, TemporalSet> kv
in m_rgTemporalSets)
148 int nStepsPerBlock = nHistoricalSteps + nFutureSteps;
150 if (!nTotalSteps.HasValue || nTotalSteps.Value < nStepsPerBlock)
151 m_log.
FAIL(
"Stream: " + sd.
Name +
" - The number of historical and future steps must be less than the number of steps in the temporal data stream. The steps per block = " + nStepsPerBlock.ToString() +
" and the total steps = " + nTotalSteps.ToString() +
" items.");
153 int nRowBlocks = nTotalSteps.Value - nStepsPerBlock;
262 return new Tuple<DB_LABEL_SELECTION_METHOD, DB_ITEM_SELECTION_METHOD>(valueSelectionMethod, itemSelectionMethod);
281 return new Tuple<DB_LABEL_SELECTION_METHOD, DB_ITEM_SELECTION_METHOD>(itemSelectionMethod, valueSelectionMethod);
290 return new Tuple<DB_LABEL_SELECTION_METHOD, DB_ITEM_SELECTION_METHOD>(m_itemSelectionMethod, m_valueSelectionMethod);
428 m_evtAbortInitialization =
new AutoResetEvent(
false);
435 ds = m_rgDataSets.
Add(dsd, m_log);
442 throw new Exception(
"You must first call SetInitializationProperties with the properties to use for initialization.");
444 bool bNormalizeData = prop.GetPropertyAsBool(
"NormalizedData",
true);
445 int nHistSteps = prop.GetPropertyAsInt(
"HistoricalSteps", 0);
446 int nFutureSteps = prop.GetPropertyAsInt(
"FutureSteps", 0);
447 int nChunks = prop.GetPropertyAsInt(
"Chunks", 1024);
450 throw new Exception(
"The historical steps are missing from the properties, please add the 'HistoricalSteps' property with a value > 0.");
451 if (nFutureSteps == 0)
452 throw new Exception(
"The future steps are missing from the properties, please add the 'FutureSteps' property with a value > 0.");
454 if (nHistSteps < 0 || nFutureSteps < 0)
455 throw new Exception(
"The historical and future steps must be > 0.");
535 if (m_rgTemporalSets.ContainsKey(nSrcId))
537 ts = m_rgTemporalSets[nSrcId];
542 m_rgTemporalSets.Add(nSrcId, ts);
563 DB_LABEL_SELECTION_METHOD itemSelection = (itemSelectionOverride.HasValue) ? itemSelectionOverride.Value : m_itemSelectionMethod;
564 DB_ITEM_SELECTION_METHOD valueSelection = (valueSelectionOverride.HasValue) ? valueSelectionOverride.Value : m_valueSelectionMethod;
566 return ts.
GetData(nQueryIdx, ref nItemIdx, ref nValueIdx, itemSelection, valueSelection, 1, bEnableDebug, strDebugPath);
587 m_itemSelectionMethod = item.Value;
589 m_valueSelectionMethod = value.Value;
595 #region Not Implemented
596 public int FindItemIndex(
int nSrcId, DateTime dt,
string strDescription)
598 throw new NotImplementedException();
601 public SimpleDatum GetItem(
int nItemID, params
int[] rgSrcId)
603 throw new NotImplementedException();
606 public int GetItemCount(
int nSrcId,
string strFilterVal =
null,
int? nBoostVal =
null,
bool bBoostValIsExact =
false)
608 TemporalSet ts = getTemporalSet(nSrcId);
609 return ts.GetCount();
614 throw new NotImplementedException();
617 public List<SimpleDatum> GetItems(
int nSrcId,
int[] rgIdx,
string strFilterVal =
null,
int? nBoostVal =
null,
bool bBoostValIsExact =
false)
619 throw new NotImplementedException();
622 public List<SimpleDatum> GetItemsFromIndex(
int nSrcId,
int nStartIdx,
int nQueryCount =
int.MaxValue,
string strFilterVal =
null,
int? nBoostVal =
null,
bool bBoostValIsExact =
false,
bool bAttemptDirectLoad =
false)
624 throw new NotImplementedException();
627 public List<SimpleDatum> GetItemsFromTime(
int nSrcId, DateTime dtStart,
int nQueryCount =
int.MaxValue,
string strFilterVal =
null,
int? nBoostVal =
null,
bool bBoostValIsExact =
false)
629 throw new NotImplementedException();
632 public bool GetLoadItemDataCriteria()
634 throw new NotImplementedException();
637 public bool GetLoadItemDebugData()
639 throw new NotImplementedException();
652 public SimpleDatum QueryItemMeanFromDataset(
int nDatasetId)
The ConnectInfo class specifies the server, database and username/password used to connect to a datab...
The CryptoRandom is a random number generator that can use either the standard .Net Random objec or t...
The Log class provides general output in text form.
void FAIL(string str)
Causes a failure which throws an exception with the desciptive text.
The ProjectEx class manages a project containing the solver description, model description,...
bool EnableRandomSelection
Returns whether or not random image selection is enabled. When enabled, images are randomly selected ...
bool EnableLabelBalancing
Returns whether or not label balancing is enabled. When enabled, first the label set is randomly sele...
Specifies a key-value pair of properties.
The SettingsCaffe defines the settings used by the MyCaffe CaffeControl.
bool EnableRandomInputSelection
Get/set random image selection. When enabled, images are randomly selected from the entire set,...
double DbAutoRefreshScheduledReplacementPercent
Get/set the automatic refresh scheduled update replacement percentage used on refresh (default = 0....
int DbLoadLimit
Get/set the image database load limit.
DB_LOAD_METHOD DbLoadMethod
Get/set the image database loading method.
int DbAutoRefreshScheduledUpdateInMs
Get/set the automatic refresh scheduled udpate period (default = 10000, only applies when ImageDbLoad...
bool EnableLabelBalancing
Get/set label balancing. When enabled, first the label set is randomly selected and then the image is...
The SimpleDatum class holds a data input within host memory.
The SimpleTemporalDatumCollection manages a collection of SimpleTemporalDatum objects.
int ID
Get/set the database ID of the item.
string Name
Get/set the name of the item.
The DatasetDescriptor class describes a dataset which contains both a training data source and testin...
SourceDescriptor TrainingSource
Get/set the training data source.
SourceDescriptor TestingSource
Get/set the testing data source.
The SourceDescriptor class contains all information describing a data source.
TemporalDescriptor TemporalDescriptor
Get/set the temporal descriptor (if any).
List< ValueItemDescriptor > ValueItemDescriptors
Returns the value item descriptor.
int GetDatasetID(string strName, ConnectInfo ci=null)
Returns a datasets ID given its name.
The DatabaseManagement class is used to create the image database.
void CreateTemporalTables()
Create the temporal tables.
Exception CreateDatabase(bool bUpdateDatabase=false)
The CreateDatabae creates a new instance of the database in Microsoft SQL.
The EntitiesConnection class defines how to connect to the database via Entity Frameworks.
static ConnectInfo GlobalDatabaseConnectInfo
Get/set the global database connection info.
The DataSet class loads the training and testing data.
DatasetDescriptor Dataset
Return the dataset descriptor.
double GetLoadPercent(out double dfTraining, out double dfTesting)
Return the load percentage for the dataset.
bool Load(DB_LOAD_METHOD loadMethod, int nLoadLimit, double dfReplacementPct, int nRefreshUpdateMs, bool bNormalizedData, int nHistoricalSteps, int nFutureSteps, int nChunks, EventWaitHandle evtCancel)
Load the training and testing data.
The DatasetLoader is used to load descriptors from the database.
DatasetDescriptor LoadDatasetFromDb(string strDs)
Load a dataset with the specified name from the database.
The DatabaseTemporal is used to manage all temporal specific database objects.
The DatasetCollection manages a set of datasets.
TemporalSet FindTemporalSetBySourceID(int nSrcID)
Find the temporal set associated with the source ID.
SourceDescriptor FindSourceByID(int nSrcID)
Find the source descriptor associated with the source ID.
void CleanUp(int nDsID)
Release all resources used by the dataset with the specified ID.
DataSet Find(int nDatasetID)
Find and return the dataset associated with the dataset ID.
DataSet Add(DatasetDescriptor dsd, Log log)
Add a new dataset to the collection if it does not already exist.
SourceDescriptor FindSourceByName(string strSrc)
Find the source descriptor associated with the source Name.
int GetDatasetID(string strDs)
Returns the dataset ID associated with the dataset name.
[Temporal Database] The MyCaffeTemporalDatabase provides an enhanced in-memory temporal database used...
double GetDatasetLoadedPercentByName(string strDataset, out double dfTraining, out double dfTesting)
Return the load percentage for a dataset.
bool LoadDatasetByName1(string strDs, string strEvtCancel=null)
Load the dataset specified by the dataset name.
static Tuple< DB_LABEL_SELECTION_METHOD, DB_ITEM_SELECTION_METHOD > GetSelectionMethod(SettingsCaffe s)
Returns the item/value selection methods based on the SettingsCaffe settings.
bool InitializeWithDs1(SettingsCaffe s, DatasetDescriptor ds1, string strEvtCancel=null, PropertySet prop=null)
Initialize the database with the specified dataset descriptor.
bool UnloadDatasetById(int nDsId)
Unload the dataset specified by the dataset ID.
DatasetDescriptor GetDatasetById(int nDsId)
Return the dataset descriptor of the dataset with the specified ID.
SourceDescriptor GetSourceByName(string strSrc)
Get the source given its name.
void SetSelectionMethod(DB_LABEL_SELECTION_METHOD? item, DB_ITEM_SELECTION_METHOD? value)
Sets the label and image selection methods.
SourceDescriptor GetSourceById(int nSrcId)
Get the source given its ID.
static void CreateDatabaseTables(ConnectInfo ci, bool bTemporalOnly)
Create the database tables used by the MyCaffeTemporalDatabase.
void CleanUp(int nDsId=0, bool bForce=false)
Cleanup all resources used by the dataset specified (or all when no dataset is specified).
Tuple< DB_LABEL_SELECTION_METHOD, DB_ITEM_SELECTION_METHOD > GetSelectionMethod()
Returns the item and value selection method used.
string GetDatasetName(int nDsId)
Returns the dataset name given its ID.
void SetInitializationProperties(PropertySet prop)
Set the initialization properties to use when initializing a dataset.
int GetSourceID(string strSrc)
Get the source ID given its name.
static Tuple< DB_LABEL_SELECTION_METHOD, DB_ITEM_SELECTION_METHOD > GetSelectionMethod(ProjectEx p)
Returns the item/value selection methods based on the ProjectEx settings.
MyCaffeTemporalDatabase(IContainer container)
The constructor.
void SetConnection(ConnectInfo ci)
Set the database connection to use.
bool InitializeWithDsName1(SettingsCaffe s, string strDs, string strEvtCancel=null, PropertySet prop=null)
Initialize the database with the specified dataset name.
int GetDatasetID(string strDs)
Return the dataset ID of the dataset with the specified dataset name.
SimpleTemporalDatumCollection QueryTemporalItem(int nQueryIdx, int nSrcId, ref int? nItemIdx, ref int? nValueIdx, DB_LABEL_SELECTION_METHOD? itemSelectionOverride=null, DB_ITEM_SELECTION_METHOD? valueSelectionOverride=null, bool bEnableDebug=false, string strDebugPath=null)
Returns a block of static, observed and known data from the database where one block is a set of (his...
bool ReloadDataset(int nDsId)
Reload the dataset with the specified dataset ID.
MyCaffeTemporalDatabase(Log log, PropertySet prop)
The constructor.
int GetTotalSize(int nDsId, Phase phase, int nHistoricalSteps, int nFutureSteps)
Returns the total number of blocks in the database where one block is a set of (historical and future...
void Reset()
Reset the database indexes.
DB_VERSION GetVersion()
Returns the version of the database (e.g., TEMPORAL).
bool LoadDatasetByID1(int nDsId, string strEvtCancel=null)
Load the dataset specified by the dataset ID.
bool UnloadDatasetByName(string strDataset)
Unload the dataset specified by the dataset name.
bool InitializeWithDsId1(SettingsCaffe s, int nDataSetID, string strEvtCancel=null, int nPadW=0, int nPadH=0, PropertySet prop=null)
Initialize the database with the specified dataset ID.
DatasetDescriptor GetDatasetByName(string strDs)
Return the dataset descriptor of the dataset with the specified dataset name.
double GetDatasetLoadedPercentById(int nDatasetID, out double dfTraining, out double dfTesting)
Return the load percentage for dataset ID.
string GetSourceName(int nSrcId)
Get the source name given its ID.
The TemporalSet manages a set of temporal data for a given data source.
SimpleTemporalDatumCollection GetData(int nQueryIdx, ref int? nItemIdx, ref int? nValueIdx, DB_LABEL_SELECTION_METHOD itemSelectionMethod, DB_ITEM_SELECTION_METHOD valueSelectionMethod, int nValueStepOffset=1, bool bEnableDebug=false, string strDebugPath=null)
Get a data set consisting of the static, historical, and future data for a selected item where the st...
void CleanUp()
Release all resources used by the temporal set and shut down all internal threads.
The Component class is a standard Microsoft.NET class that implements the IComponent interface and is...
Teh IXTemporalDatabaseBase interface defines the general interface to the in-memory temporal database...
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.
DB_ITEM_SELECTION_METHOD
Defines the item (e.g., image or temporal item) selection method.
DB_LOAD_METHOD
Defines how to laod the items into the in-memory database.
Phase
Defines the Phase under which to run a Net.
DB_VERSION
Defines the image database version to use.
DB_LABEL_SELECTION_METHOD
Defines the label selection method.
The MyCaffe.db.image namespace contains all image database related classes.
The MyCaffe.db.temporal namespace contains all classes used to create the MyCaffeTemporalDatabase in-...
The MyCaffe namespace contains the main body of MyCaffe code that closesly tracks the C++ Caffe open-...