public final class TexelOptimizer extends NadamSGD<String,Float> implements AutoCloseable
costCalculationBatchSize, epochs, epsilon, EPSILON, FIRST_MOMENT_DECAY_RATE, firstMomentDecayRate, h, H, indicesToIgnore, L1_REGULARIZATION_COEFF, l1RegularizationCoeff, L2_REGULARIZATION_COEFF, l2RegularizationCoeff, LEARNING_ANNEALING_RATE, LEARNING_RATE, learningAnnealingRate, learningRate, logger, maxValues, minValues, parameters, SECOND_MOMENT_DECAY_RATE, secondMomentDecayRate, trainingBatchSize
Constructor and Description |
---|
TexelOptimizer(TunableEngine[] engines,
long trainingBatchSize,
int epochs,
Double h,
Double baseLearningRate,
Double learningAnnealingRate,
Double l1RegularizationCoeff,
Double l2RegularizationCoeff,
String epdFilePath,
String gameResultOpCode,
Long costCalculationBatchSize,
Double k,
Double testDataProportion,
Logger logger)
Constructs and returns a new instance according to the specified parameters.
|
Modifier and Type | Method and Description |
---|---|
void |
close() |
protected double |
computeCost(double[] parameters,
List<Map.Entry<String,Float>> dataSample)
Calculates the costs associated with the given parameter set for the specified data sample.
|
protected double[] |
computeGradient(double[] parameters,
List<Map.Entry<String,Float>> dataSample)
Calculates the derivative of the cost function with respect to the parameters.
|
protected List<Map.Entry<String,Float>> |
getTestData(long batchSize)
Extracts a sample from the test data set and loads it into a list of key-value pairs where the key is the data and the value is the
ground truth.
|
protected List<Map.Entry<String,Float>> |
getTrainingData(long batchSize)
Extracts a sample from the training data set and loads it into a list of key-value pairs where the key is the data and the value is the
ground truth.
|
protected void |
resetTestDataReader()
Resets the test data reader enanbling the resampling of already sampled data points.
|
protected void |
resetTrainingDataReader()
Resets the training data reader enanbling the resampling of already sampled data points.
|
optimize, verifyGradient
public TexelOptimizer(TunableEngine[] engines, long trainingBatchSize, int epochs, Double h, Double baseLearningRate, Double learningAnnealingRate, Double l1RegularizationCoeff, Double l2RegularizationCoeff, String epdFilePath, String gameResultOpCode, Long costCalculationBatchSize, Double k, Double testDataProportion, Logger logger) throws Exception, IllegalArgumentException
engines
- An array of TunableEngine
instances (of which the parameters' gray code
string should have the same length). For each non-null element in the array, a new thread will be utilized for the optimization. E.g.
if engines is an array of four non-null elements, the fitness function will be distributed and executed parallel on four threads. If
the array or its first element are null or the method init
hasn't been
called on the first element, a NullPointerException
is thrown.trainingBatchSize
- The number of positions to include in one mini-batch. The higher this number is, the slower but more stable
the convergence will be.epochs
- The maximum number of iterations. If it is 0, the loop is endless.h
- The step size to use for the numerical differentiation of the cost function. If it is null, it defaults to 1 (if the
parameters are integers as they usually are in chess engines, a value of less than 1 or any non-integer value whatsoever would make no
sense).baseLearningRate
- The base step size for the gradient descent. If it is null, it defaults to 1.learningAnnealingRate
- The factor by which the learning rate is multiplied after every epoch. If it is null, it defaults to 0.9.l1RegularizationCoeff
- The coefficient to use for L1 parameter regularization, by default 0.001.l2RegularizationCoeff
- The coefficient to use for L2 parameter regularization, by default 0.0001.epdFilePath
- The path to the file containing the FEN list of positions to evaluate. If it doesn't exist an IOException
is thrown.gameResultOpCode
- The EPD operation code of the result of the game the position occurred in.costCalculationBatchSize
- The number of samples in the batches used for calculating the total training and test costs. If it is
null, it defaults to 4 million.k
- A scaling constant for the sigmoid function used calculate the average error.testDataProportion
- The proportion of the entire data set that should be used as test data. It has to be greater than or equal
to 0 and less than 1. If it is null, it defaults to DEF_TEST_DATA_PROPORTION
.logger
- A logger to log the status of the optimization. It cannot be null.Exception
- If the engines cannot be initialised.IllegalArgumentException
- If the logger is null, or the batch size is not greater than 0, or the data set is too small.protected void resetTrainingDataReader()
NadamSGD
resetTrainingDataReader
in class NadamSGD<String,Float>
protected void resetTestDataReader()
NadamSGD
resetTestDataReader
in class NadamSGD<String,Float>
protected List<Map.Entry<String,Float>> getTrainingData(long batchSize)
NadamSGD
NadamSGD.resetTrainingDataReader()
method is called. If there
is no more training data left, an empty list should be returned. The list should never be null.getTrainingData
in class NadamSGD<String,Float>
batchSize
- The maximum number of entries the returned list is to have. It is never less than 1.protected List<Map.Entry<String,Float>> getTestData(long batchSize)
NadamSGD
NadamSGD.resetTestDataReader()
method is called. If there
is no more test data left, an empty list should be returned. The list should never be null.getTestData
in class NadamSGD<String,Float>
batchSize
- The maximum number of entries the returned list is to have. It is never less than 1.protected double computeCost(double[] parameters, List<Map.Entry<String,Float>> dataSample)
NadamSGD
computeCost
in class NadamSGD<String,Float>
parameters
- An array of parameters.dataSample
- A list of the training data mapped to the correct labels on which the cost function is to be calculated.protected double[] computeGradient(double[] parameters, List<Map.Entry<String,Float>> dataSample)
NadamSGD
computeGradient
in class NadamSGD<String,Float>
parameters
- An array of parameters.dataSample
- A list of the training data mapped to the correct labels on which the cost function is to be calculated.public void close()
close
in interface AutoCloseable
Copyright © 2020. All rights reserved.