/** * ISchedule: a general purpose interface for getting values according to some schedule. * Used for implementing learning rate, dropout and momentum schedules - and in principle, any univariate (double) * value that deponds on the current iteration and epochs numbers.<br> * <br> * Note: ISchedule objects should not have mutable state - i.e., they should be safe to share between multiple * locations/layers. * * @author Alex Black */ @JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.PROPERTY, property = "@class") public interface ISchedule extends Serializable, Cloneable { /** * @param iteration Current iteration number. Starts at 0 * @param epoch Current epoch number. Starts at 0 * @return Value at the current iteration/epoch for this schedule */ double valueAt(int iteration, int epoch); ISchedule clone(); }
@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.PROPERTY, property = "@class", defaultImpl = LegacyILossFunctionDeserializerHelper.class) public interface ILossFunction extends Serializable {
@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.PROPERTY, property = "@class", defaultImpl = LegacyIActivationDeserializerHelper.class) @JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY, getterVisibility = JsonAutoDetect.Visibility.NONE,
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY, getterVisibility = JsonAutoDetect.Visibility.NONE, setterVisibility = JsonAutoDetect.Visibility.NONE) @JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.PROPERTY, property = "@class") public interface IUpdater extends Serializable, Cloneable {
/** * Idea: We can't store all results in memory in general (might have thousands of candidates with millions of * parameters each) * So instead: return a reference to the saved result. Idea is that the result may be saved to disk or a database, * and we can easily load it back into memory (if/when required) using the getResult() method */ @JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.PROPERTY, property = "@class") public interface ResultReference { OptimizationResult getResult() throws IOException; }
/** * Idea: We can't store all results in memory in general (might have thousands of candidates with millions of * parameters each) * So instead: return a reference to the saved result. Idea is that the result may be saved to disk or a database, * and we can easily load it back into memory (if/when required) using the getResult() method */ @JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.PROPERTY, property = "@class") public interface ResultReference { OptimizationResult getResult() throws IOException; Object getResultModel() throws IOException; }
/** * An abstract distribution. * */ @JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.PROPERTY, property = "type", defaultImpl = LegacyDistributionHelper.class) public abstract class Distribution implements Serializable, Cloneable { private static final long serialVersionUID = 5401741214954998498L; @Override public Distribution clone() { try { return (Distribution) super.clone(); } catch (CloneNotSupportedException e) { throw new RuntimeException(e); } } }
@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.PROPERTY, property = "@class") public interface IOptimizationRunner {
@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.PROPERTY, property = "@class") public interface IOptimizationRunner {
/** * Custom step function for line search. */ @JsonTypeInfo(use = Id.NAME, include = As.WRAPPER_OBJECT) @JsonSubTypes(value = {@JsonSubTypes.Type(value = DefaultStepFunction.class, name = "default"), @JsonSubTypes.Type(value = GradientStepFunction.class, name = "gradient"), @JsonSubTypes.Type(value = NegativeDefaultStepFunction.class, name = "negativeDefault"), @JsonSubTypes.Type(value = NegativeGradientStepFunction.class, name = "negativeGradient"),}) public class StepFunction implements Serializable, Cloneable { private static final long serialVersionUID = -1884835867123371330L; @Override public StepFunction clone() { try { StepFunction clone = (StepFunction) super.clone(); return clone; } catch (CloneNotSupportedException e) { throw new RuntimeException(e); } } }
/** * Global termination condition for conducting hyperparameter optimization. * Termination conditions are used to determine if/when the optimization should stop. */ @JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.PROPERTY, property = "@class") @JsonInclude(JsonInclude.Include.NON_NULL) public interface TerminationCondition { /** * Initialize the termination condition (such as starting timers, etc). */ void initialize(IOptimizationRunner optimizationRunner); /** * Determine whether optimization should be terminated * * @param optimizationRunner Optimization runner * @return true if learning should be terminated, false otherwise */ boolean terminate(IOptimizationRunner optimizationRunner); }
/** * Global termination condition for conducting hyperparameter optimization. * Termination conditions are used to determine if/when the optimization should stop. */ @JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.PROPERTY, property = "@class") @JsonInclude(JsonInclude.Include.NON_NULL) public interface TerminationCondition { /** * Initialize the termination condition (such as starting timers, etc). */ void initialize(IOptimizationRunner optimizationRunner); /** * Determine whether optimization should be terminated * * @param optimizationRunner Optimization runner * @return true if learning should be terminated, false otherwise */ boolean terminate(IOptimizationRunner optimizationRunner); }
/** * DataProvider interface abstracts out the providing of data */ @JsonInclude(JsonInclude.Include.NON_NULL) @JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.PROPERTY, property = "@class") public interface DataProvider extends Serializable { /** * Get training data given some parameters for the data. * Data parameters map is used to specify things like batch * size data preprocessing * * @param dataParameters Parameters for data. May be null or empty for default data * @return training data */ Object trainData(Map<String, Object> dataParameters); /** * Get training data given some parameters for the data. Data parameters map is used to specify things like batch * size data preprocessing * * @param dataParameters Parameters for data. May be null or empty for default data * @return training data */ Object testData(Map<String, Object> dataParameters); Class<?> getDataType(); }
/** * DataProvider interface abstracts out the providing of data */ @JsonInclude(JsonInclude.Include.NON_NULL) @JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.PROPERTY, property = "@class") public interface DataProvider extends Serializable { /** * Get training data given some parameters for the data. * Data parameters map is used to specify things like batch * size data preprocessing * * @param dataParameters Parameters for data. May be null or empty for default data * @return training data */ Object trainData(Map<String, Object> dataParameters); /** * Get training data given some parameters for the data. Data parameters map is used to specify things like batch * size data preprocessing * * @param dataParameters Parameters for data. May be null or empty for default data * @return training data */ Object testData(Map<String, Object> dataParameters); Class<?> getDataType(); }
@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.PROPERTY, property = "@class") public interface ResultSaver {
@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.PROPERTY, property = "@class") public interface ResultSaver {
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.WRAPPER_OBJECT) @JsonSubTypes(value = {@JsonSubTypes.Type(value = ChartHistogram.class, name = "ChartHistogram"), @JsonSubTypes.Type(value = ChartHorizontalBar.class, name = "ChartHorizontalBar"),
/** ScoreCalculator interface is used to calculate a score for a neural network. * For example, the loss function, test set accuracy, F1, or some other (possibly custom) metric. * @param <T> Type of model. For example, {@link org.deeplearning4j.nn.multilayer.MultiLayerNetwork} or {@link org.deeplearning4j.nn.graph.ComputationGraph} */ @JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.PROPERTY, property = "@class") @JsonInclude(JsonInclude.Include.NON_NULL) @JsonSubTypes(value = { @JsonSubTypes.Type(value = DataSetLossCalculator.class, name = "BestScoreEpochTerminationCondition"), @JsonSubTypes.Type(value = DataSetLossCalculatorCG.class, name = "MaxEpochsTerminationCondition"), }) public interface ScoreCalculator<T extends Model> extends Serializable { /** Calculate the score for the given MultiLayerNetwork */ double calculateScore(T network); }
/** Interface for saving MultiLayerNetworks learned during early stopping, and retrieving them again later * @param <T> Type of model to save. For example, {@link org.deeplearning4j.nn.multilayer.MultiLayerNetwork} or {@link org.deeplearning4j.nn.graph.ComputationGraph} * @author Alex Black */ @JsonInclude(JsonInclude.Include.NON_NULL) @JsonSubTypes(value = {@JsonSubTypes.Type(value = InMemoryModelSaver.class, name = "InMemoryModelSaver"), @JsonSubTypes.Type(value = LocalFileGraphSaver.class, name = "LocalFileGraphSaver"), @JsonSubTypes.Type(value = LocalFileModelSaver.class, name = "LocalFileModelSaver"), }) @JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.PROPERTY, property = "@class") public interface EarlyStoppingModelSaver<T extends Model> extends Serializable { /** Save the best model (so far) learned during early stopping training */ void saveBestModel(T net, double score) throws IOException; /** Save the latest (most recent) model learned during early stopping */ void saveLatestModel(T net, double score) throws IOException; /** Retrieve the best model that was previously saved */ T getBestModel() throws IOException; /** Retrieve the most recent model that was previously saved */ T getLatestModel() throws IOException; }
/** Interface for termination conditions to be evaluated once per epoch (i.e., once per pass of the full data set), * based on a score and epoch number */ @JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.PROPERTY, property = "@class") @JsonInclude(JsonInclude.Include.NON_NULL) @JsonSubTypes(value = { @JsonSubTypes.Type(value = BestScoreEpochTerminationCondition.class, name = "BestScoreEpochTerminationCondition"), @JsonSubTypes.Type(value = MaxEpochsTerminationCondition.class, name = "MaxEpochsTerminationCondition"), @JsonSubTypes.Type(value = MaxScoreIterationTerminationCondition.class, name = "MaxScoreIterationTerminationCondition"), }) public interface EpochTerminationCondition extends Serializable { /** Initialize the epoch termination condition (often a no-op)*/ void initialize(); /**Should the early stopping training terminate at this epoch, based on the calculated score and the epoch number? * Returns true if training should terminated, or false otherwise * @param epochNum Number of the last completed epoch (starting at 0) * @param score Score calculate for this epoch * @return Whether training should be terminated at this epoch */ boolean terminate(int epochNum, double score); }