Search in sources :

Example 1 with IterativeStopException

use of com.simiacryptus.mindseye.lang.IterativeStopException in project MindsEye by SimiaCryptus.

the class LayerRateDiagnosticTrainer method measure.

/**
 * Measure point sample.
 *
 * @return the point sample
 */
public PointSample measure() {
    PointSample currentPoint;
    int retries = 0;
    do {
        if (!subject.reseed(System.nanoTime()) && retries > 0)
            throw new IterativeStopException();
        if (10 < retries++)
            throw new IterativeStopException();
        currentPoint = subject.measure(monitor);
    } while (!Double.isFinite(currentPoint.sum));
    assert Double.isFinite(currentPoint.sum);
    return currentPoint;
}
Also used : IterativeStopException(com.simiacryptus.mindseye.lang.IterativeStopException) PointSample(com.simiacryptus.mindseye.lang.PointSample)

Example 2 with IterativeStopException

use of com.simiacryptus.mindseye.lang.IterativeStopException in project MindsEye by SimiaCryptus.

the class ValidatingTrainer method reset.

@Nonnull
private ValidatingTrainer reset(@Nonnull final TrainingPhase phase, final long seed) {
    if (!phase.trainingSubject.reseed(seed))
        throw new IterativeStopException();
    phase.orientation.reset();
    phase.trainingSubject.reseed(seed);
    if (phase.trainingSubject.getLayer() instanceof DAGNetwork) {
        ((DAGNetwork) phase.trainingSubject.getLayer()).visitLayers(layer -> {
            if (layer instanceof StochasticComponent)
                ((StochasticComponent) layer).shuffle(StochasticComponent.random.get().nextLong());
        });
    }
    return this;
}
Also used : StochasticComponent(com.simiacryptus.mindseye.layers.java.StochasticComponent) IterativeStopException(com.simiacryptus.mindseye.lang.IterativeStopException) DAGNetwork(com.simiacryptus.mindseye.network.DAGNetwork) Nonnull(javax.annotation.Nonnull)

Example 3 with IterativeStopException

use of com.simiacryptus.mindseye.lang.IterativeStopException in project MindsEye by SimiaCryptus.

the class ValidatingTrainer method measure.

private PointSample measure(@Nonnull final TrainingPhase phase) {
    int retries = 0;
    do {
        if (10 < retries++)
            throw new IterativeStopException();
        final PointSample currentPoint = phase.trainingSubject.measure(monitor);
        if (Double.isFinite(currentPoint.getMean()))
            return currentPoint;
        phase.orientation.reset();
    } while (true);
}
Also used : IterativeStopException(com.simiacryptus.mindseye.lang.IterativeStopException) PointSample(com.simiacryptus.mindseye.lang.PointSample)

Example 4 with IterativeStopException

use of com.simiacryptus.mindseye.lang.IterativeStopException in project MindsEye by SimiaCryptus.

the class IterativeTrainer method measure.

/**
 * Measure point sample.
 *
 * @param reset the reset
 * @return the point sample
 */
@Nullable
public PointSample measure(boolean reset) {
    @Nullable PointSample currentPoint = null;
    int retries = 0;
    do {
        if (reset) {
            orientation.reset();
            if (subject.getLayer() instanceof DAGNetwork) {
                ((DAGNetwork) subject.getLayer()).visitLayers(layer -> {
                    if (layer instanceof StochasticComponent)
                        ((StochasticComponent) layer).shuffle(StochasticComponent.random.get().nextLong());
                });
            }
            if (!subject.reseed(System.nanoTime())) {
                if (retries > 0)
                    throw new IterativeStopException("Failed to reset training subject");
            } else {
                monitor.log(String.format("Reset training subject"));
            }
        }
        if (null != currentPoint) {
            currentPoint.freeRef();
        }
        currentPoint = subject.measure(monitor);
    } while (!Double.isFinite(currentPoint.getMean()) && 10 < retries++);
    if (!Double.isFinite(currentPoint.getMean())) {
        currentPoint.freeRef();
        throw new IterativeStopException();
    }
    return currentPoint;
}
Also used : StochasticComponent(com.simiacryptus.mindseye.layers.java.StochasticComponent) IterativeStopException(com.simiacryptus.mindseye.lang.IterativeStopException) PointSample(com.simiacryptus.mindseye.lang.PointSample) DAGNetwork(com.simiacryptus.mindseye.network.DAGNetwork) Nullable(javax.annotation.Nullable) Nullable(javax.annotation.Nullable)

Example 5 with IterativeStopException

use of com.simiacryptus.mindseye.lang.IterativeStopException in project MindsEye by SimiaCryptus.

the class RoundRobinTrainer method measure.

/**
 * Measure point sample.
 *
 * @return the point sample
 */
public PointSample measure() {
    PointSample currentPoint;
    int retries = 0;
    do {
        if (!subject.reseed(System.nanoTime()) && retries > 0)
            throw new IterativeStopException();
        if (10 < retries++)
            throw new IterativeStopException();
        currentPoint = subject.measure(monitor);
    } while (!Double.isFinite(currentPoint.sum));
    assert Double.isFinite(currentPoint.sum);
    return currentPoint;
}
Also used : IterativeStopException(com.simiacryptus.mindseye.lang.IterativeStopException) PointSample(com.simiacryptus.mindseye.lang.PointSample)

Aggregations

IterativeStopException (com.simiacryptus.mindseye.lang.IterativeStopException)5 PointSample (com.simiacryptus.mindseye.lang.PointSample)4 StochasticComponent (com.simiacryptus.mindseye.layers.java.StochasticComponent)2 DAGNetwork (com.simiacryptus.mindseye.network.DAGNetwork)2 Nonnull (javax.annotation.Nonnull)1 Nullable (javax.annotation.Nullable)1