SmartEngine  1.6.0
CommonNodes.h
1 // Copyright (C) Entropy Software LLC - All Rights Reserved
2 
3 #pragma once
4 
5 #include "ActivationTypes.h"
6 #include "Context.h"
7 #include "GraphNode.h"
8 
9 namespace SmartEngine
10 {
11 
12 #pragma pack(push, 4)
13 struct ConcatNodeCInfo : GraphNodeCInfo
17 {
21  IGraphNode* const* inputs = nullptr;
22 
26  int inputCount = 0;
27 };
28 
33 {
37  IGraphNode* input = nullptr;
38 
43 
47  int columnCount = -1;
48 };
49 
53 enum class ChoiceType : byte
54 {
60  Random,
61 
65  Max,
66 
67  Count
68 };
69 SMARTENGINE_ENUM_STRING(ChoiceType, "Random", "Max");
70 
75 {
80  IGraphNode* input = nullptr;
81 
85  ChoiceType type = ChoiceType::Random;
86 
90  int axis = 1;
91 };
92 
97 {
101  IGraphNode* input = nullptr;
102 
106  ActivationType type = ActivationType::None;
107 };
108 
113 {
117  IGraphNode* mean = nullptr;
118 
123  IGraphNode* variance = nullptr;
124 };
125 
130 {
134  IGraphNode* A = nullptr;
135 
139  IGraphNode* B = nullptr;
140 };
141 
146 {
150  IGraphNode* A = nullptr;
151 
155  IGraphNode* B = nullptr;
156 };
157 
162 {
166  IGraphNode* input = nullptr;
167 };
168 
173 {
178  IGraphNode* selector = nullptr;
179 
183  IGraphNode* const* inputs = nullptr;
184 
188  int inputCount = 0;
189 
193  ChoiceType selectionMethod = ChoiceType::Max;
194 };
195 #pragma pack(pop)
196 
201 SMARTENGINE_EXPORT ObjectPtr<IGraphNode> CreateConcatNode(const ConcatNodeCInfo& cinfo);
202 
208 
213 SMARTENGINE_EXPORT ObjectPtr<IGraphNode> CreateChoiceNode(const ChoiceNodeCInfo& cinfo);
214 
219 
224 SMARTENGINE_EXPORT ObjectPtr<IGraphNode> CreateNormalNode(const NormalNodeCInfo& cinfo);
225 
230 
235 
241 
251 
253 extern "C"
254 {
255  SMARTENGINE_EXPORT ObjPtr ConcatNode_CreateInstance(const ConcatNodeCInfo& cinfo);
256  SMARTENGINE_EXPORT ObjPtr ExtractNode_CreateInstance(const ExtractNodeCInfo& cinfo);
257  SMARTENGINE_EXPORT ObjPtr ChoiceNode_CreateInstance(const ChoiceNodeCInfo& cinfo);
258  SMARTENGINE_EXPORT ObjPtr ActivationNode_CreateInstance(const ActivationNodeCInfo& cinfo);
259  SMARTENGINE_EXPORT ObjPtr NormalNode_CreateInstance(const NormalNodeCInfo& cinfo);
260  SMARTENGINE_EXPORT ObjPtr MinimumNode_CreateInstance(const MinimumNodeCInfo& cinfo);
261  SMARTENGINE_EXPORT ObjPtr MaximumNode_CreateInstance(const MaximumNodeCInfo& cinfo);
262  SMARTENGINE_EXPORT ObjPtr StopGradientNode_CreateInstance(const StopGradientNodeCInfo& cinfo);
263  SMARTENGINE_EXPORT ObjPtr MultiplexerNode_CreateInstance(const MultiplexerNodeCInfo& cinfo);
264 }
266 
267 } // namespace SmartEngine
SmartEngine::IGraphNode
A logical node in the AI graph. Some nodes, like NeuralNetwork, are composed of other nodes (neuron l...
Definition: GraphNode.h:34
SmartEngine::CreateChoiceNode
SMARTENGINE_EXPORT ObjectPtr< IGraphNode > CreateChoiceNode(const ChoiceNodeCInfo &cinfo)
Returns a random choice (as an integer) from the input node's probability distribution on each call t...
SmartEngine::CreateActivationNode
SMARTENGINE_EXPORT ObjectPtr< IGraphNode > CreateActivationNode(const ActivationNodeCInfo &cinfo)
Applies an activation function to the input.
SmartEngine::ConcatNodeCInfo::inputs
IGraphNode *const * inputs
Array of node inputs
Definition: CommonNodes.h:21
SmartEngine::CreateExtractNode
SMARTENGINE_EXPORT ObjectPtr< IGraphNode > CreateExtractNode(const ExtractNodeCInfo &cinfo)
Extracts a subset of columns from the input node. The start index + column count must not exceed the ...
SmartEngine::StopGradientNodeCInfo
Data used to construct a stop gradient node instance
Definition: CommonNodes.h:162
SmartEngine::ExtractNodeCInfo::columnCount
int columnCount
The number of columns to extract
Definition: CommonNodes.h:47
SmartEngine::NormalNodeCInfo::mean
IGraphNode * mean
Input node that represents the mean of the distribution
Definition: CommonNodes.h:117
SmartEngine::ChoiceNodeCInfo::input
IGraphNode * input
Node to choose from. This should have no activation applied when using a random decision algorithm.
Definition: CommonNodes.h:80
SmartEngine::MinimumNodeCInfo::B
IGraphNode * B
'B' value to take minimum of
Definition: CommonNodes.h:139
SmartEngine::CreateConcatNode
SMARTENGINE_EXPORT ObjectPtr< IGraphNode > CreateConcatNode(const ConcatNodeCInfo &cinfo)
Merges two or more node streams into one. Each input stream must have the same number of rows....
SmartEngine::ChoiceType::Random
@ Random
Treat the output as a probability distribution and sample from that distribution on each evaulation....
SmartEngine::ActivationNodeCInfo
Data used to construct an activation node instance
Definition: CommonNodes.h:97
SmartEngine::ChoiceNodeCInfo::type
ChoiceType type
The decision algorithm to use.
Definition: CommonNodes.h:85
SmartEngine::ActivationNodeCInfo::input
IGraphNode * input
The node to apply an activation on
Definition: CommonNodes.h:101
SmartEngine::ChoiceType
ChoiceType
Defines the descision algorithm of the ChoiceNode
Definition: CommonNodes.h:54
SmartEngine::CreateStopGradientNode
SMARTENGINE_EXPORT ObjectPtr< IGraphNode > CreateStopGradientNode(const StopGradientNodeCInfo &cinfo)
Stops the gradient from flowing backwards from this point. Only meaningful when training with gradien...
SmartEngine::GraphNodeCInfo
Data used to construct an IGraphNode instance
Definition: GraphNode.h:17
SmartEngine::CreateMinimumNode
SMARTENGINE_EXPORT ObjectPtr< IGraphNode > CreateMinimumNode(const MinimumNodeCInfo &cinfo)
Takes the minimum of the inputs.
SmartEngine::CreateNormalNode
SMARTENGINE_EXPORT ObjectPtr< IGraphNode > CreateNormalNode(const NormalNodeCInfo &cinfo)
Returns a random value from the normal distribution given by the input nodes. NOTE: Input takes in th...
SmartEngine::MinimumNodeCInfo::A
IGraphNode * A
'A' value to take minimum of.
Definition: CommonNodes.h:134
SmartEngine::ChoiceNodeCInfo
Data used to construct a choice node instance
Definition: CommonNodes.h:75
SmartEngine::MaximumNodeCInfo::B
IGraphNode * B
'B' value to take maximum of
Definition: CommonNodes.h:155
SmartEngine::MultiplexerNodeCInfo::inputCount
int inputCount
The number of inputs to select between.
Definition: CommonNodes.h:188
SmartEngine::MultiplexerNodeCInfo::inputs
IGraphNode *const * inputs
The inputs we will be selecting between.
Definition: CommonNodes.h:183
SmartEngine::ObjectPtr
Smart pointer to an IObject. Automatic ref counting.
Definition: ObjectPtr.h:16
SmartEngine::MaximumNodeCInfo
Data used to construct a maximum node instance
Definition: CommonNodes.h:146
SmartEngine::MultiplexerNodeCInfo::selector
IGraphNode * selector
Decides which input to pass through. Should have a dimension equal to the number of inputs.
Definition: CommonNodes.h:178
SmartEngine
Definition: A2CTrainer.h:10
SmartEngine::ConcatNodeCInfo
Data used to construct a concat node instance
Definition: CommonNodes.h:17
SmartEngine::ExtractNodeCInfo::input
IGraphNode * input
The input we will extract output columns from
Definition: CommonNodes.h:37
SmartEngine::ChoiceNodeCInfo::axis
int axis
Axis to take choices from. 0 = row, 1 = column
Definition: CommonNodes.h:90
SmartEngine::ActivationNodeCInfo::type
ActivationType type
The type of activation function to apply
Definition: CommonNodes.h:106
SmartEngine::CreateMultiplexerNode
SMARTENGINE_EXPORT ObjectPtr< IGraphNode > CreateMultiplexerNode(const MultiplexerNodeCInfo &cinfo)
Uses the value from the selector to decide which of the inputs to pass through. The selected input wi...
SmartEngine::ActivationType
ActivationType
The activation function to apply to the output of the NeuronLayer
Definition: ActivationTypes.h:14
SmartEngine::MultiplexerNodeCInfo
Data used to construct a multiplexer node instance.
Definition: CommonNodes.h:173
SmartEngine::ExtractNodeCInfo::columnStartIndex
int columnStartIndex
The column start index to extract
Definition: CommonNodes.h:42
SmartEngine::MultiplexerNodeCInfo::selectionMethod
ChoiceType selectionMethod
Method used to determine which output to select
Definition: CommonNodes.h:193
SmartEngine::MinimumNodeCInfo
Data used to construct a minimum node instance
Definition: CommonNodes.h:130
SmartEngine::MaximumNodeCInfo::A
IGraphNode * A
'A' value to take maximum of.
Definition: CommonNodes.h:150
SmartEngine::CreateMaximumNode
SMARTENGINE_EXPORT ObjectPtr< IGraphNode > CreateMaximumNode(const MaximumNodeCInfo &cinfo)
Takes the maximum of the inputs.
SmartEngine::StopGradientNodeCInfo::input
IGraphNode * input
This input is passed through directly to the output of this node.
Definition: CommonNodes.h:166
SmartEngine::NormalNodeCInfo::variance
IGraphNode * variance
Input node that represents the log of the variance. This should have no activation applied.
Definition: CommonNodes.h:123
SmartEngine::NormalNodeCInfo
Data used to construct a normal node instance
Definition: CommonNodes.h:113
SmartEngine::ExtractNodeCInfo
Data used to construct an extract node instance
Definition: CommonNodes.h:33
SmartEngine::ConcatNodeCInfo::inputCount
int inputCount
Node input array count
Definition: CommonNodes.h:26