DSL_nodeDef

<< Click to Display Table of Contents >>

Navigation:  Reference Manual > Node definitions >

DSL_nodeDef

Header file: nodedef.h

DSL_nodeDef is a base class in the node definition class hierarchy. Various (public) virtual DSL_nodeDef class methods called internally by DSL_network to manage its nodes are not listed in this section, because they should never be called by code that is not part of SMILE library.

Objects of classes derived from DSL_nodeDef are created and destroyed by their parent DSL_node. Never use delete on a node definition pointer.

Use DSL_node::Def method to obtain a pointer to node's definition.


template <class T> T* As();

template <class T> const T* As() const;

Statically cast this to specified type T. Note that there is no runtime type checking. DSL_node::Def()->As<T> is equivalent to DSL_node::Def<T>().


DSL_network* Network();
const DSL_network* Network() const;

Returns a pointer to node's network. The network does not change during the lifetime of the node definition object.


int Handle() const;

Returns a handle of node's definition. The handle does not change during the lifetime of the node definition object.


const DSL_intArray& GetParents() const;

const DSL_intArray& GetChildren() const;

Return a reference to parent/children array. These helper methods call DSL_network::GetParents/GetChildren.


virtual int GetType() const = 0;

Returns a numeric identifier of the definition type.


virtual const char* GetTypeName() const = 0;

Returns a definition type name.


virtual int AddOutcome(const char *outcomeId);

Adds node outcome with the specified identifier. Returns DSL_OKAY on success, or a negative error code on failure. The default implementation in DSL_nodeDef returns DSL_WRONG_NODE_TYPE to indicate that operation is not supported.

Overridden in DSL_discDef.


virtual int InsertOutcome(int outcomeIndex, const char *outcomeId);

Inserts node outcome with the specified identifier at the specified index. Returns DSL_OKAY on success, or a negative error code on failure. The default implementation in DSL_nodeDef returns DSL_WRONG_NODE_TYPE to indicate that operation is not supported.

Overridden in DSL_discDef.


virtual int RemoveOutcome(int outcomeIndex);

Removes node outcome at the specified index. Returns DSL_OKAY on success, or a negative error code on failure. The default implementation in DSL_nodeDef returns DSL_WRONG_NODE_TYPE to indicate that operation is not supported.

Overridden in DSL_discDef.


virtual int GetNumberOfOutcomes();

Returns the number of node outcomes or a negative error code if the node type does not have outcomes (e.g., it is not discrete). Note that equation nodes, even if they have discretization intervals, return a negative number from GetNumberOfOutcomes. Returns DSL_OKAY on success, or a negative error code on failure. The default implementation in DSL_nodeDef returns DSL_WRONG_NODE_TYPE to indicate that operation is not supported.

Overridden in DSL_discDef.


virtual int RenameOutcome(int outcomeIndex, const char *newId);

Changes node outcome identifier at the specified index. Returns DSL_OKAY on success, or a negative error code on failure. The default implementation in DSL_nodeDef returns DSL_WRONG_NODE_TYPE to indicate that operation is not supported.

Overridden in DSL_discDef.


virtual int RenameOutcomes(const DSL_idArray& newOutcomeIds);
virtual int RenameOutcomes(const std::vector<std::string>& newOutcomeIds);

Change all outcome identifiers. Returns DSL_OKAY on success, or a negative error code on failure. The default implementation in DSL_nodeDef returns DSL_WRONG_NODE_TYPE to indicate that operation is not supported.

Overridden in DSL_discDef.


virtual const DSL_idArray* GetOutcomeIds() const;

Returns a const pointer to an identifier array with all outcome identifiers. Returns NULL when the node does not have outcomes.

Overridden in DSL_discDef.


virtual int SetNumberOfOutcomes(int outcomeCount);

Sets the number of node outcomes. If the outcome count increases, new outcomes will have automatically generated identifiers. Returns DSL_OKAY on success, or a negative error code on failure. The default implementation in DSL_nodeDef returns DSL_WRONG_NODE_TYPE to indicate that operation is not supported.

Overridden in DSL_discDef.


virtual int SetNumberOfOutcomes(const DSL_idArray& outcomeIds);

Sets the number of node outcomes and renames them by using specified identifiers. Returns DSL_OKAY on success, or a negative error code on failure. The default implementation in DSL_nodeDef returns DSL_WRONG_NODE_TYPE to indicate that operation is not supported.

Overridden in DSL_discDef.


virtual int ChangeOrderOfOutcomes(const DSL_intArray& newOrder);

Reorders node outcomes. Returns DSL_OKAY on success, or a negative error code on failure. The default implementation in DSL_nodeDef returns DSL_WRONG_NODE_TYPE to indicate that operation is not supported.

Overridden in DSL_discDef.


virtual int ChangeOrderOfOutcomesWithAddAndRemove(

 const DSL_idArray& ids, const DSL_intArray& newOrder);

Reorders node outcomes and optionally adds/removes existing outcomes. The outcomes to add should be represented by -1 in newOrder. If the original outcome index is not present in newOrder, the outcome is removed. Returns DSL_OKAY on success, or a negative error code on failure. The default implementation in DSL_nodeDef returns DSL_WRONG_NODE_TYPE to indicate that operation is not supported.

Overridden in DSL_discDef.


virtual const DSL_Dmatrix* GetMatrix() const;

Returns a const pointer to a DSL_Dmatrix object with node's numeric parameters, or NULL when node does not have numeric parameters. For all chance and discrete deterministic nodes, the matrix is a CPT (even if the node is canonical or qualitative). The matrix returned by utility nodes contains utilities.

Overridden in DSL_discDef and DSL_lazyDef.


int GetDefinition(const DSL_Dmatrix** parameters) const;

Sets the numeric parameters of the node. While GetDefinition is not virtual, the method calls a protected virtual function defined in DSL_nodeDef and overridden in the derived classes. Returns DSL_OKAY on success, or a negative error code on failure.


int SetDefinition(const DSL_Dmatrix& parameters);

int SetDefinition(const DSL_doubleArray& parameters);

int SetDefinition(const std::vector<double>& parameters);
int SetDefinition(std::initializer_list<double> parameters);

Sets the numeric parameters of the node. While none of the SetDefinition overloads are virtual, the methods call a protected virtual function defined in DSL_nodeDef and overridden in the derived classes. Returns DSL_OKAY on success, or a negative error code on failure.


virtual int RawDefinition(DSL_Dmatrix** parameters);

Returns a pointer to a writable DSL_Dmatrix object with node's numeric parameters, or NULL if node does not have numeric parameters. Should be only used by performance-critical code to modify the definition of the node (parameter learning, for example). Returns DSL_OKAY on success, or a negative error code on failure. The default implementation in DSL_nodeDef returns DSL_WRONG_NODE_TYPE to indicate that operation is not supported.

Overridden in DSL_lazyDef.


const DSL_Dmatrix* GetTemporalDefinition(int order) const;

For a plate node in a DBN, returns a pointer to an array representing the temporal parameters of the node with the specified order, or NULL if node does not have temporal parameters of the specified order.


int SetTemporalDefinition(int order, const DSL_Dmatrix& temporal);

int SetTemporalDefinition(int order, const std::vector<double>& temporal);

int SetTemporalDefinition(int order, const DSL_doubleArray& temporal);

For a plate node in a DBN, sets the temporal parameters of the node for the specified temporal order. While none of the SetTemporalDefinition overloads are virtual, the methods delegate the parameter modification to a protected virtual function defined in DSL_nodeDef and overridden in the derived classes. Returns DSL_OKAY on success, or a negative error code on failure.


virtual int MakeUniform();

Uniformizes the definition parameters. Returns DSL_OKAY on success, or a negative error code on failure. The default implementation in DSL_nodeDef returns DSL_WRONG_NODE_TYPE to indicate that operation is not supported.

Overridden in DSL_cpt, DSL_truthTable, DSL_ciDef and DSL_utility.


virtual int MakeRandom(DSL_randGen& randGen);

Randomizes the definition parameters using the specified random generator. Returns DSL_OKAY on success, or a negative error code on failure. The default implementation in DSL_nodeDef returns DSL_WRONG_NODE_TYPE to indicate that operation is not supported.


const DSL_idArray* GetOutcomesNames() const;

int NodeTypeIs(int flags) const 

BACKWARD COMPATIBILITY ONLY. Available when SMILE_NO_V1_COMPATIBILITY is not defined.