28#ifndef __CTX_CORTEX_TRAINER_H__
29#define __CTX_CORTEX_TRAINER_H__
36class ctxBackpropStatistics;
244 gzBool prepareInternal(gzBool& runtimeMayChange);
250 ctxOptimizerPtr m_optimizer;
251 gzArray<gzUInt32> m_randomIndices;
252 gzArray<gzUInt32> m_batchSamples;
254 gzUInt32 m_validations;
255 gzUInt32 m_batchSize;
256 gzUInt32 m_subsetLength;
257 gzUInt32 m_nextBatchOffset;
258 gzUInt32 m_batchOffset;
259 gzUInt32 m_iteration;
264 ctxBackpropStatistics* m_statistics;
317 gzBool fail(
const gzString& error);
318 gzBool initializePopulation();
319 gzBool evaluatePreparedCandidate(gzFloat& errorSum);
320 gzBool rebasePopulation();
322 gzUInt32 nextRandom();
323 gzFloat nextRandomFloat();
324 gzFloat nextRandomNormal(gzFloat mean, gzFloat standardDeviation);
325 gzVoid randomParameters(gzBool add);
326 gzVoid mutateParameters(gzBool add);
327 gzVoid mutateBreeding();
329 gzVoid installBestParameters();
330 gzVoid randomizeSamples();
331 gzVoid initializeRandomPhase();
334 gzRefList<ctxCortexParameters> m_population;
335 gzRefList<ctxCortexParameters> m_elites;
336 gzArray<gzUInt32> m_randomIndices;
337 ctxCortexParametersPtr m_originalParameters;
341 gzUInt32 m_batchSize;
342 gzUInt32 m_totalBatchSize;
344 gzUInt32 m_subsetLength;
347 gzUInt32 m_generation;
348 gzUInt32 m_candidate;
349 gzUInt32 m_fitnessBatch;
350 gzUInt32 m_currentRandomCount;
351 gzUInt32 m_eliteCount;
353 gzUInt32 m_randomState;
354 gzFloat m_standardDeviation;
355 gzFloat m_candidateError;
357 gzFloat m_targetError;
358 gzBool m_candidateAvailable;
366 public gzObjectSender,
367 public gzObjectReceiver
373 CTX_EXPORT ctxCortexTrainer(
const gzString &save_url=GZ_EMPTY_STRING,
const gzString & channel_url=
"udp::45666",
const gzString& channel_name=
"ctx");
ctxAdam(gzFloat rate=1.0f, gzFloat beta1=CTX_GRADIENT_MY_DEFAULT, gzFloat beta2=CTX_GRADIENT_PHI_DEFAULT, gzFloat lambda=CTX_GRADIENT_LAMBDA_DEFAULT)
gzUInt32 getBatchSize() const
gzUInt32 getIteration() const
gzBool saveCheckpoint(const gzString &url) const
gzBool isComplete() const
ctxBackpropTrainer(const ctxBackpropTrainingOptions &options=ctxBackpropTrainingOptions())
gzUInt32 getSampleIndex(gzUInt32 page) const
gzUInt32 getValidations() const
gzBool prepareNextBatch()
Prepare the next selected batch, without a parameter update.
gzBool setDropConnect(gzFloat probability)
Set the training DropConnect probability for subsequent batches.
ctxTrainerProgramProfile getProgramProfile() const
gzBool isPrepared() const
gzBool loadCheckpoint(const gzString &url)
gzBool trainStep()
Prepare and train the next bounded unit; Backprop consumes one batch.
gzFloat getDropConnect() const
virtual ~ctxBackpropTrainer()
gzBool beginIndexedEpoch(gzUInt32 epoch, const ctxIndex &sampleOrder)
Install a prebuilt training-prefix order at an epoch boundary.
gzUInt32 getSamples() const
gzBool setOptimizer(ctxOptimizer *optimizer, ctxOptimizerStatePolicy statePolicy=CTX_OPTIMIZER_STATE_RESET)
gzBool trainPreparedBatch()
Train one prepared batch and commit its batch/epoch progress.
gzBool beginEpoch(gzUInt32 epoch)
gzUInt32 getSubsetLength() const
gzBool beginEpoch(gzUInt32 epoch, const gzArray< gzFloat > &sampleWeights, gzUInt32 seed=0)
Explicit weighted epoch over the prepared training prefix, excluding validations.
ctxOptimizer * getOptimizer() const
gzUInt32 getBatchOffset() const
gzUInt32 getCapabilities() const
ctxGradientType gradientType
ctxCostErrorMethod errorMethod
ctxBackpropTrainingOptions()
gzBool updateCandidates(ctxCortexParameters *parameters, gzUInt32 iteration, gzUInt32 period, gzUInt32 epoch, gzUInt32 method, gzFloat expectedMinDiff, gzBool external, gzBool *updatedPopulation=NULL)
ctxCortexTrainer(const gzString &save_url=GZ_EMPTY_STRING, const gzString &channel_url="udp::45666", const gzString &channel_name="ctx")
gzUInt32 m_candidateCount
gzBool train(const ctxGeneticTrainingOptions &options)
Train a complete fixed-topology Genetic session and retain its final population, elite archive and fi...
gzFloat calcAccumError(ctxContext *context, gzUInt32 *index, gzUInt32 accumulations, gzUInt32 batch_size, gzUInt32 subset_len)
virtual gzVoid onObject(gzObject *object)
gzVoid resetTrainerError()
gzMutex m_populationListLocker
gzString getTrainerError()
gzBool train(const ctxBackpropTrainingOptions &options)
Train a complete Backprop session with explicit typed configuration.
gzRefList< ctxCortexParameters > m_populationList
gzRefList< ctxCortexParameters > m_populationEliteList
gzBool completeCandidate()
gzBool isPrepared() const
gzFloat getBestError() const
gzBool nextFitnessBatch()
gzBool stepFitnessBatch()
ctxTrainerProgramProfile getProgramProfile() const
gzUInt32 getCandidate() const
gzUInt32 getCapabilities() const
ctxGeneticTrainer(const ctxGeneticTrainingOptions &options=ctxGeneticTrainingOptions())
friend class ctxCortexTrainer
gzBool isComplete() const
gzBool loadCheckpoint(const gzString &url)
gzUInt32 getFitnessBatch() const
gzUInt32 getPopulationSize() const
gzBool saveCheckpoint(const gzString &url) const
gzUInt32 getGeneration() const
gzBool trainStep()
Advance one bounded state-machine unit of genetic training.
gzBool completeGeneration()
gzUInt32 getFitnessBatchCount() const
ctxGeneticTrainingOptions()
gzUInt32 expectedElitesPerBatch
gzUInt32 estimatedNeurons
ctxCostErrorMethod errorMethod
ctxLevenbergMarquardtSolver(ctxDefSolverFunction function=NULL)
virtual gzBool validate(gzString &error) const
ctxGradientType m_gradientType
gzFloat getLambda() const
ctxOptimizer(ctxGradientType gradientType=CTX_GRADIENT_TYPE_DEFAULT, gzFloat rate=1.0f, gzFloat lambda=CTX_GRADIENT_LAMBDA_DEFAULT, gzFloat my=CTX_GRADIENT_MY_DEFAULT, gzFloat phi=CTX_GRADIENT_PHI_DEFAULT)
ctxGradientType getGradientType() const
virtual gzBool loadCheckpoint(const gzString &url)=0
gzString getError() const
virtual gzBool prepare()=0
virtual ctxTrainerProgramProfile getProgramProfile() const =0
virtual gzBool saveCheckpoint(const gzString &url) const =0
virtual gzUInt32 getCapabilities() const =0
virtual gzBool isComplete() const =0
virtual gzBool isPrepared() const =0
virtual gzBool trainStep()=0
Advance one bounded unit of the installed learning strategy.
virtual gzBool install(ctxCortex *cortex)
Bind this session to one cortex.
ctxCortex * getCortex() const
CONST_FLOAT CTX_GRADIENT_PHI_DEFAULT
CONST_FLOAT CTX_GRADIENT_MY_DEFAULT
CONST_FLOAT CTX_GRADIENT_LAMBDA_DEFAULT
@ CTX_GRADIENT_TYPE_DEFAULT
@ CTX_TRAINER_PROGRAM_BACKPROP
@ CTX_TRAINER_PROGRAM_EVALUATE
@ CTX_TRAINER_CAPABILITY_CHECKPOINTS
@ CTX_TRAINER_CAPABILITY_GRADIENTS
@ CTX_TRAINER_CAPABILITY_DISTRIBUTED
@ CTX_TRAINER_CAPABILITY_POPULATION
@ CTX_TRAINER_CAPABILITY_REWARDS
@ CTX_TRAINER_CAPABILITY_SEQUENCES
@ CTX_TRAINER_CAPABILITY_BATCHES
@ CTX_OPTIMIZER_STATE_CONTINUE
@ CTX_OPTIMIZER_STATE_RESET
LevenbergMarquardt base class for Newton Rapson on steroids.