org.encog.ml.prg.extension
Class FunctionFactory

java.lang.Object
  extended by org.encog.ml.prg.extension.FunctionFactory
All Implemented Interfaces:
Serializable

public class FunctionFactory
extends Object
implements Serializable

A function factory maps the opcodes contained in the EncogOpcodeRegistry into an EncogProgram. You rarely want to train with every available opcode. For example, if you are only looking to produce an equation, you should not make use of the if-statement and logical operators.

See Also:
Serialized Form

Constructor Summary
FunctionFactory()
          Default constructor.
 
Method Summary
 void addExtension(ProgramExtensionTemplate ext)
          Add an opcode to the function factory.
 void addExtension(String name, int args)
          Add an opcode to the function factory from the opcode registry.
 ProgramNode factorProgramNode(ProgramExtensionTemplate temp, EncogProgram program, ProgramNode[] args)
          Factor a new program node, based in a template object.
 ProgramNode factorProgramNode(String name, EncogProgram program, ProgramNode[] args)
          Factor a new program node, based on an opcode name and arguments.
 ProgramExtensionTemplate findFunction(String name)
          Find a function with the specified name.
 List<ProgramExtensionTemplate> findOpcodes(List<ValueType> types, EncogProgramContext context, boolean includeTerminal, boolean includeFunction)
          Find all opcodes that match the search criteria.
 ProgramExtensionTemplate findOperator(char ch1, char ch2)
          This method is used when parsing an expression.
 ProgramExtensionTemplate getOpCode(int theOpCode)
          Get the specified opcode.
 List<ProgramExtensionTemplate> getOpCodes()
           
 Map<String,ProgramExtensionTemplate> getTemplateMap()
           
 boolean isDefined(String name, int l)
          Determine if an opcode is in the function factory.
 int size()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FunctionFactory

public FunctionFactory()
Default constructor.

Method Detail

addExtension

public void addExtension(ProgramExtensionTemplate ext)
Add an opcode to the function factory. The opcode must exist in the opcode registry.

Parameters:
ext - The opcode to add.

addExtension

public void addExtension(String name,
                         int args)
Add an opcode to the function factory from the opcode registry.

Parameters:
name - The name of the opcode.
args - The number of arguments.

factorProgramNode

public ProgramNode factorProgramNode(ProgramExtensionTemplate temp,
                                     EncogProgram program,
                                     ProgramNode[] args)
Factor a new program node, based in a template object.

Parameters:
temp - The opcode.
program - The program.
args - The arguments for this node.
Returns:
The newly created ProgramNode.

factorProgramNode

public ProgramNode factorProgramNode(String name,
                                     EncogProgram program,
                                     ProgramNode[] args)
Factor a new program node, based on an opcode name and arguments.

Parameters:
name - The name of the opcode.
program - The program to factor for.
args - The arguements.
Returns:
The newly created ProgramNode.

findFunction

public ProgramExtensionTemplate findFunction(String name)
Find a function with the specified name.

Parameters:
name - The name of the function.
Returns:
The function opcode.

findOpcodes

public List<ProgramExtensionTemplate> findOpcodes(List<ValueType> types,
                                                  EncogProgramContext context,
                                                  boolean includeTerminal,
                                                  boolean includeFunction)
Find all opcodes that match the search criteria.

Parameters:
types - The return types to consider.
context - The program context.
includeTerminal - True, to include the terminals.
includeFunction - True, to include the functions.
Returns:
The opcodes found.

findOperator

public ProgramExtensionTemplate findOperator(char ch1,
                                             char ch2)
This method is used when parsing an expression. Consider x>=2. The parser first sees the > symbol. But it must also consider the =. So we first look for a 2-char operator, in this case there is one.

Parameters:
ch1 - The first character of the potential operator.
ch2 - The second character of the potential operator. Zero if none.
Returns:
The expression template for the operator found.

getOpCode

public ProgramExtensionTemplate getOpCode(int theOpCode)
Get the specified opcode.

Parameters:
theOpCode - The opcode index.
Returns:
The opcode.

getOpCodes

public List<ProgramExtensionTemplate> getOpCodes()
Returns:
The opcode list.

getTemplateMap

public Map<String,ProgramExtensionTemplate> getTemplateMap()
Returns:
the templateMap

isDefined

public boolean isDefined(String name,
                         int l)
Determine if an opcode is in the function factory.

Parameters:
name - The name of the opcode.
l - The argument count for the opcode.
Returns:
True if the opcode exists.

size

public int size()
Returns:
The number of opcodes.


Copyright © 2014. All Rights Reserved.