Class DJLRegressor
- java.lang.Object
-
- adams.core.logging.LoggingObject
-
- adams.core.logging.CustomLoggingLevelObject
-
- adams.core.option.AbstractOptionHandler
-
- weka.core.AbstractSimpleOptionHandler
-
- weka.classifiers.simple.AbstractSimpleClassifier
-
- weka.classifiers.meta.DJLRegressor
-
- All Implemented Interfaces:
adams.core.Destroyable,adams.core.GlobalInfoSupporter,adams.core.logging.LoggingLevelHandler,adams.core.logging.LoggingSupporter,adams.core.option.OptionHandler,adams.core.SizeOfHandler,adams.flow.core.FlowContextHandler,Serializable,AutoCloseable,weka.classifiers.Classifier,weka.classifiers.ScriptedClassifier,weka.core.CapabilitiesHandler,weka.core.OptionHandler,weka.core.Randomizable
public class DJLRegressor extends weka.classifiers.simple.AbstractSimpleClassifier implements weka.classifiers.ScriptedClassifier, AutoCloseable, weka.core.Randomizable
Uses Deep Java Library for building a regression model.- Author:
- fracpete (fracpete at waikato dot ac dot nz)
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected InstancesDatasetm_Datasetthe DJL dataset.protected Stringm_DatasetConfigthe dataset config.protected adams.flow.core.Actorm_FlowContextthe flow context.protected weka.core.Instancesm_Headerthe header.protected IDGeneratorm_IDthe model ID/prefix generator.protected intm_MiniBatchSizethe batchsize.protected ai.djl.Modelm_Modelthe model.protected static Map<String,ai.djl.Model>m_Modelsfor keeping track of models.protected NetworkGeneratorm_Networkthe network generator to use.protected intm_NumEpochsthe number of epochs to train.protected OutputDirGeneratorm_OutputDirthe output dir generator.protected ai.djl.inference.Predictor<ai.djl.basicdataset.tabular.ListFeatures,Float>m_Predictorthe predictor to use.protected intm_Seedthe seed to use.protected booleanm_SupportParallelExecutionwhether to support parallel execution.protected intm_TrainPercentagethe percentage for the network's training set.protected ai.djl.translate.Translator<ai.djl.basicdataset.tabular.ListFeatures,Float>m_Translatorthe feature translator to use.
-
Constructor Summary
Constructors Constructor Description DJLRegressor()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidbuildClassifier(weka.core.Instances data)Generates a classifier.doubleclassifyInstance(weka.core.Instance instance)Classifies the given test instance.voidclose()Closes this resource, relinquishing any underlying resources.voiddefineOptions()Adds options to the internal list of options.weka.core.CapabilitiesgetCapabilities()Returns the Capabilities of this classifier.adams.flow.core.ActorgetFlowContext()Returns the flow context.IDGeneratorgetID()Gets the ID/prefix generator for saving the model.intgetMiniBatchSize()Gets the batch size to use.NetworkGeneratorgetNetwork()Gets the network generator to use.intgetNumEpochs()Gets the number of epochs to train for.OutputDirGeneratorgetOutputDir()Gets the output directory generator to use.intgetSeed()Gets the seed for the random number generationsbooleangetSupportParallelExecution()Returns whether to support parallel execution by appending a unique ID to the model ID.intgetTrainPercentage()Gets the percentage to use for the internal training set.StringglobalInfo()Returns a string describing the object.StringIDTipText()Returns the tip text for this property.voidinitPrediction(adams.flow.core.Actor context)Prepares the classifier for predictions.static voidmain(String[] args)Runs the classifier from the command-line with the specified options.StringminiBatchSizeTipText()Returns the tip text for this property.StringnetworkTipText()Returns the tip text for this property.StringnumEpochsTipText()Returns the tip text for this property.StringoutputDirTipText()Returns the tip text for this property.StringseedTipText()Returns the tip text for this property.voidsetFlowContext(adams.flow.core.Actor value)Sets the flow context.voidsetID(IDGenerator value)Sets the ID/prefix generator for saving the model.voidsetMiniBatchSize(int value)Sets the batch size to use.voidsetNetwork(NetworkGenerator value)Sets the network generator to use.voidsetNumEpochs(int value)Sets the number of epochs to train for.voidsetOutputDir(OutputDirGenerator value)Sets the output directory generator to use.voidsetSeed(int value)Set the seed for random number generation.voidsetSupportParallelExecution(boolean value)Sets whether to support parallel execution by appending a unique ID to the model ID.voidsetTrainPercentage(int value)Sets the percentage to use for the internal training set.StringsupportParallelExecutionTipText()Returns the tip text for this property.StringtoString()Returns a short description of the setup.StringtrainPercentageTipText()Returns the tip text for this property.-
Methods inherited from class weka.classifiers.simple.AbstractSimpleClassifier
distributionForInstance, runClassifier
-
Methods inherited from class weka.core.AbstractSimpleOptionHandler
getOptions, listOptions, setOptions
-
Methods inherited from class adams.core.option.AbstractOptionHandler
cleanUpOptions, destroy, finishInit, getDefaultLoggingLevel, getOptionManager, initialize, loggingLevelTipText, newOptionManager, reset, setLoggingLevel, toCommandLine
-
Methods inherited from class adams.core.logging.LoggingObject
configureLogger, getLogger, getLoggingLevel, initializeLogging, isLoggingEnabled, sizeOf
-
-
-
-
Field Detail
-
m_Seed
protected int m_Seed
the seed to use.
-
m_Network
protected NetworkGenerator m_Network
the network generator to use.
-
m_TrainPercentage
protected int m_TrainPercentage
the percentage for the network's training set.
-
m_MiniBatchSize
protected int m_MiniBatchSize
the batchsize.
-
m_NumEpochs
protected int m_NumEpochs
the number of epochs to train.
-
m_ID
protected IDGenerator m_ID
the model ID/prefix generator.
-
m_OutputDir
protected OutputDirGenerator m_OutputDir
the output dir generator.
-
m_SupportParallelExecution
protected boolean m_SupportParallelExecution
whether to support parallel execution.
-
m_FlowContext
protected transient adams.flow.core.Actor m_FlowContext
the flow context.
-
m_Header
protected weka.core.Instances m_Header
the header.
-
m_Dataset
protected transient InstancesDataset m_Dataset
the DJL dataset.
-
m_Translator
protected transient ai.djl.translate.Translator<ai.djl.basicdataset.tabular.ListFeatures,Float> m_Translator
the feature translator to use.
-
m_Model
protected transient ai.djl.Model m_Model
the model.
-
m_Predictor
protected transient ai.djl.inference.Predictor<ai.djl.basicdataset.tabular.ListFeatures,Float> m_Predictor
the predictor to use.
-
m_DatasetConfig
protected String m_DatasetConfig
the dataset config.
-
-
Method Detail
-
globalInfo
public String globalInfo()
Returns a string describing the object.- Specified by:
globalInfoin interfaceadams.core.GlobalInfoSupporter- Specified by:
globalInfoin classadams.core.option.AbstractOptionHandler- Returns:
- a description suitable for displaying in the gui
-
defineOptions
public void defineOptions()
Adds options to the internal list of options.- Specified by:
defineOptionsin interfaceadams.core.option.OptionHandler- Overrides:
defineOptionsin classadams.core.option.AbstractOptionHandler
-
setSeed
public void setSeed(int value)
Set the seed for random number generation.- Specified by:
setSeedin interfaceweka.core.Randomizable- Parameters:
value- the seed
-
getSeed
public int getSeed()
Gets the seed for the random number generations- Specified by:
getSeedin interfaceweka.core.Randomizable- Returns:
- the seed for the random number generation
-
seedTipText
public String seedTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the explorer/experimenter gui
-
setNetwork
public void setNetwork(NetworkGenerator value)
Sets the network generator to use.- Parameters:
value- the generator
-
getNetwork
public NetworkGenerator getNetwork()
Gets the network generator to use.- Returns:
- the generator
-
networkTipText
public String networkTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the explorer/experimenter gui
-
setTrainPercentage
public void setTrainPercentage(int value)
Sets the percentage to use for the internal training set.- Parameters:
value- the percentage
-
getTrainPercentage
public int getTrainPercentage()
Gets the percentage to use for the internal training set.- Returns:
- the percentage
-
trainPercentageTipText
public String trainPercentageTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the explorer/experimenter gui
-
setMiniBatchSize
public void setMiniBatchSize(int value)
Sets the batch size to use.- Parameters:
value- the batch size
-
getMiniBatchSize
public int getMiniBatchSize()
Gets the batch size to use.- Returns:
- the batch size
-
miniBatchSizeTipText
public String miniBatchSizeTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the explorer/experimenter gui
-
setNumEpochs
public void setNumEpochs(int value)
Sets the number of epochs to train for.- Parameters:
value- the epochs
-
getNumEpochs
public int getNumEpochs()
Gets the number of epochs to train for.- Returns:
- the epochs
-
numEpochsTipText
public String numEpochsTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the explorer/experimenter gui
-
setID
public void setID(IDGenerator value)
Sets the ID/prefix generator for saving the model.- Parameters:
value- the ID/prefix
-
getID
public IDGenerator getID()
Gets the ID/prefix generator for saving the model.- Returns:
- the ID/prefix
-
IDTipText
public String IDTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the explorer/experimenter gui
-
setOutputDir
public void setOutputDir(OutputDirGenerator value)
Sets the output directory generator to use.- Parameters:
value- the generator
-
getOutputDir
public OutputDirGenerator getOutputDir()
Gets the output directory generator to use.- Returns:
- the generator
-
outputDirTipText
public String outputDirTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the explorer/experimenter gui
-
setSupportParallelExecution
public void setSupportParallelExecution(boolean value)
Sets whether to support parallel execution by appending a unique ID to the model ID.- Parameters:
value- true if to support
-
getSupportParallelExecution
public boolean getSupportParallelExecution()
Returns whether to support parallel execution by appending a unique ID to the model ID.- Returns:
- true if supported
-
supportParallelExecutionTipText
public String supportParallelExecutionTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the explorer/experimenter gui
-
setFlowContext
public void setFlowContext(adams.flow.core.Actor value)
Sets the flow context.- Specified by:
setFlowContextin interfaceadams.flow.core.FlowContextHandler- Parameters:
value- the context
-
getFlowContext
public adams.flow.core.Actor getFlowContext()
Returns the flow context.- Specified by:
getFlowContextin interfaceadams.flow.core.FlowContextHandler- Returns:
- the context, null if not available
-
getCapabilities
public weka.core.Capabilities getCapabilities()
Returns the Capabilities of this classifier. Maximally permissive capabilities are allowed by default. Derived classifiers should override this method and first disable all capabilities and then enable just those capabilities that make sense for the scheme.- Specified by:
getCapabilitiesin interfaceweka.core.CapabilitiesHandler- Specified by:
getCapabilitiesin interfaceweka.classifiers.Classifier- Overrides:
getCapabilitiesin classweka.classifiers.simple.AbstractSimpleClassifier- Returns:
- the capabilities of this object
- See Also:
Capabilities
-
buildClassifier
public void buildClassifier(weka.core.Instances data) throws ExceptionGenerates a classifier. Must initialize all fields of the classifier that are not being set via options (ie. multiple calls of buildClassifier must always lead to the same result). Must not change the dataset in any way.- Specified by:
buildClassifierin interfaceweka.classifiers.Classifier- Parameters:
data- set of instances serving as training data- Throws:
Exception- if the classifier has not been generated successfully
-
initPrediction
public void initPrediction(adams.flow.core.Actor context)
Prepares the classifier for predictions.- Specified by:
initPredictionin interfaceweka.classifiers.ScriptedClassifier- Parameters:
context- the context to use
-
classifyInstance
public double classifyInstance(weka.core.Instance instance) throws ExceptionClassifies the given test instance. The instance has to belong to a dataset when it's being classified. Note that a classifier MUST implement either this or distributionForInstance().- Specified by:
classifyInstancein interfaceweka.classifiers.Classifier- Overrides:
classifyInstancein classweka.classifiers.simple.AbstractSimpleClassifier- Parameters:
instance- the instance to be classified- Returns:
- the predicted most likely class for the instance or Utils.missingValue() if no prediction is made
- Throws:
Exception- if an error occurred during the prediction
-
toString
public String toString()
Returns a short description of the setup.- Overrides:
toStringin classadams.core.option.AbstractOptionHandler- Returns:
- the description
-
main
public static void main(String[] args) throws Exception
Runs the classifier from the command-line with the specified options.- Parameters:
args- the options for the classifier- Throws:
Exception- if execution fails
-
close
public void close() throws ExceptionCloses this resource, relinquishing any underlying resources. This method is invoked automatically on objects managed by thetry-with-resources statement.While this interface method is declared to throw
Exception, implementers are strongly encouraged to declare concrete implementations of theclosemethod to throw more specific exceptions, or to throw no exception at all if the close operation cannot fail.Cases where the close operation may fail require careful attention by implementers. It is strongly advised to relinquish the underlying resources and to internally mark the resource as closed, prior to throwing the exception. The
closemethod is unlikely to be invoked more than once and so this ensures that the resources are released in a timely manner. Furthermore it reduces problems that could arise when the resource wraps, or is wrapped, by another resource.Implementers of this interface are also strongly advised to not have the
closemethod throwInterruptedException.This exception interacts with a thread's interrupted status, and runtime misbehavior is likely to occur if an
InterruptedExceptionis suppressed.More generally, if it would cause problems for an exception to be suppressed, the
AutoCloseable.closemethod should not throw it.Note that unlike the
closemethod ofCloseable, thisclosemethod is not required to be idempotent. In other words, calling thisclosemethod more than once may have some visible side effect, unlikeCloseable.closewhich is required to have no effect if called more than once.However, implementers of this interface are strongly encouraged to make their
closemethods idempotent.- Specified by:
closein interfaceAutoCloseable- Throws:
Exception- if this resource cannot be closed
-
-