org.encog.ml.prg
Class EncogProgramContext
- java.lang.Object
-
- org.encog.ml.prg.EncogProgramContext
-
- All Implemented Interfaces:
- java.io.Serializable
public class EncogProgramContext extends java.lang.Object implements java.io.SerializableEvery EncogProgram must belong to a context. When programs are in a population, they must all share a common context. The context defines attributes that are common to all programs. The following information is stored in a context. The number formatting used. Namely, what type of radix point should strings be parsed/rendered to. The functions, or opcodes, that are available to the program. This defines the set of functions and operators that a program might use. For an Encog Program all operators are treated as functions internally. A operator is essentially a shortcut notation for common functions. The defined variables. These variables are constant for the run of the program, but typically change for each run. They are essentially the variables that make up an algebraic expression. Finally, the return value mapping for the programs.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor and Description EncogProgramContext()Construct the context with an English number format and an empty function factory.EncogProgramContext(CSVFormat format)Construct a context with the specified number format and an empty function factory.EncogProgramContext(CSVFormat theFormat, FunctionFactory theFunctions)Construct the context with the specified format and function factory.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description voidclearDefinedVariables()Clear the defined variables.ProgramNodecloneBranch(EncogProgram targetProgram, ProgramNode sourceBranch)Clone a branch of the program from the specified node.EncogProgramcloneProgram(EncogProgram sourceProgram)Clone an entire program, keep the same context.EncogProgramcreateProgram(java.lang.String expression)Create a new program, using this context.voiddefineVariable(java.lang.String theName)Define the specified variable as floating point.voiddefineVariable(java.lang.String theName, ValueType theVariableType)Define the specified variable as the specified type.voiddefineVariable(java.lang.String theName, ValueType theVariableType, int theEnumType, int theEnumValueCount)Define a variable.voiddefineVariable(VariableMapping mapping)Define a variable, based on a mapping.java.util.List<VariableMapping>findVariablesByTypes(java.util.List<ValueType> desiredTypes)Find all of the variables of the specified types.java.util.List<VariableMapping>getDefinedVariables()intgetEnumCount(int enumType)Get the enum ordinal count for the specified enumeration type.CSVFormatgetFormat()FunctionFactorygetFunctions()intgetMaxEnumType()Get the max enum type for all defined variables.VariableMappinggetResult()booleanhasEnum()voidloadAllFunctions()Load all known functions as opcodes.voidsetResult(VariableMapping result)
-
-
-
Constructor Detail
-
EncogProgramContext
public EncogProgramContext()
Construct the context with an English number format and an empty function factory.
-
EncogProgramContext
public EncogProgramContext(CSVFormat format)
Construct a context with the specified number format and an empty function factory.- Parameters:
format- The format.
-
EncogProgramContext
public EncogProgramContext(CSVFormat theFormat, FunctionFactory theFunctions)
Construct the context with the specified format and function factory.- Parameters:
theFormat- The format.theFunctions- The function factory.
-
-
Method Detail
-
clearDefinedVariables
public void clearDefinedVariables()
Clear the defined variables.
-
cloneBranch
public ProgramNode cloneBranch(EncogProgram targetProgram, ProgramNode sourceBranch)
Clone a branch of the program from the specified node.- Parameters:
targetProgram- The program that this branch will be "grafted" into.sourceBranch- The branch to clone, from the source program.- Returns:
- The cloned branch.
-
cloneProgram
public EncogProgram cloneProgram(EncogProgram sourceProgram)
Clone an entire program, keep the same context.- Parameters:
sourceProgram- The source program.- Returns:
- The cloned program.
-
createProgram
public EncogProgram createProgram(java.lang.String expression)
Create a new program, using this context.- Parameters:
expression- The common expression to compile.- Returns:
- The resulting program.
-
defineVariable
public void defineVariable(java.lang.String theName)
Define the specified variable as floating point.- Parameters:
theName- The variable name to define.
-
defineVariable
public void defineVariable(java.lang.String theName, ValueType theVariableType)Define the specified variable as the specified type. Don't use this for enums.- Parameters:
theName- The name of the variable.theVariableType- The variable type.
-
defineVariable
public void defineVariable(java.lang.String theName, ValueType theVariableType, int theEnumType, int theEnumValueCount)Define a variable.- Parameters:
theName- The name of the variable.theVariableType- The type of variable.theEnumType- The enum type, not used if not an enum type.theEnumValueCount- The number of values for the enum, not used if not an enum type.
-
defineVariable
public void defineVariable(VariableMapping mapping)
Define a variable, based on a mapping.- Parameters:
mapping- The variable mapping.
-
findVariablesByTypes
public java.util.List<VariableMapping> findVariablesByTypes(java.util.List<ValueType> desiredTypes)
Find all of the variables of the specified types.- Parameters:
desiredTypes- The types to look for.- Returns:
- The variables that matched the specified types.
-
getDefinedVariables
public java.util.List<VariableMapping> getDefinedVariables()
- Returns:
- The defined variables.
-
getEnumCount
public int getEnumCount(int enumType)
Get the enum ordinal count for the specified enumeration type.- Parameters:
enumType- The enumeration type.- Returns:
- The ordinal count for the specified enumeration type.
-
getFormat
public CSVFormat getFormat()
- Returns:
- The number formatting used. Namely, what type of radix point should strings be parsed/rendered to.
-
getFunctions
public FunctionFactory getFunctions()
- Returns:
- The functions, or opcodes, that are available to the program. This defines the set of functions and operators that a program might use. For an Encog Program all operators are treated as functions internally. A operator is essentially a shortcut notation for common functions.
-
getMaxEnumType
public int getMaxEnumType()
Get the max enum type for all defined variables.- Returns:
- The max enumeration type.
-
getResult
public VariableMapping getResult()
- Returns:
- the result
-
hasEnum
public boolean hasEnum()
- Returns:
- True, if enums are defined.
-
loadAllFunctions
public void loadAllFunctions()
Load all known functions as opcodes.
-
setResult
public void setResult(VariableMapping result)
- Parameters:
result- the result to set
-
-
DMelt 3.0 © DataMelt by jWork.ORG