Search in sources :

Example 1 with LongToIntFunction

use of java.util.function.LongToIntFunction in project MindsEye by SimiaCryptus.

the class TestUtil method shuffle.

/**
 * Shuffle int stream.
 *
 * @param stream the stream
 * @return the int stream
 */
public static IntStream shuffle(@Nonnull IntStream stream) {
    // http://primes.utm.edu/lists/small/10000.txt
    long coprimeA = 41387;
    long coprimeB = 9967;
    long ringSize = coprimeA * coprimeB - 1;
    @Nonnull IntToLongFunction fn = x -> (x * coprimeA * coprimeA) % ringSize;
    @Nonnull LongToIntFunction inv = x -> (int) ((x * coprimeB * coprimeB) % ringSize);
    @Nonnull IntUnaryOperator conditions = x -> {
        assert x < ringSize;
        assert x >= 0;
        return x;
    };
    return stream.map(conditions).mapToLong(fn).sorted().mapToInt(inv);
}
Also used : Arrays(java.util.Arrays) ScheduledFuture(java.util.concurrent.ScheduledFuture) DoubleStatistics(com.simiacryptus.util.data.DoubleStatistics) IntUnaryOperator(java.util.function.IntUnaryOperator) BiFunction(java.util.function.BiFunction) LoggerFactory(org.slf4j.LoggerFactory) DoubleSummaryStatistics(java.util.DoubleSummaryStatistics) TrainingMonitor(com.simiacryptus.mindseye.opt.TrainingMonitor) Map(java.util.Map) ImageIO(javax.imageio.ImageIO) Layer(com.simiacryptus.mindseye.lang.Layer) URI(java.net.URI) Graph(guru.nidi.graphviz.model.Graph) LongToIntFunction(java.util.function.LongToIntFunction) StochasticComponent(com.simiacryptus.mindseye.layers.java.StochasticComponent) BufferedImage(java.awt.image.BufferedImage) UUID(java.util.UUID) ComponentEvent(java.awt.event.ComponentEvent) WindowAdapter(java.awt.event.WindowAdapter) DAGNode(com.simiacryptus.mindseye.network.DAGNode) Collectors(java.util.stream.Collectors) WindowEvent(java.awt.event.WindowEvent) Executors(java.util.concurrent.Executors) List(java.util.List) Stream(java.util.stream.Stream) ScalarStatistics(com.simiacryptus.util.data.ScalarStatistics) LoggingWrapperLayer(com.simiacryptus.mindseye.layers.java.LoggingWrapperLayer) DAGNetwork(com.simiacryptus.mindseye.network.DAGNetwork) IntStream(java.util.stream.IntStream) MonitoringWrapperLayer(com.simiacryptus.mindseye.layers.java.MonitoringWrapperLayer) ActionListener(java.awt.event.ActionListener) ScatterPlot(smile.plot.ScatterPlot) ByteArrayOutputStream(java.io.ByteArrayOutputStream) LinkSource(guru.nidi.graphviz.model.LinkSource) Tensor(com.simiacryptus.mindseye.lang.Tensor) HashMap(java.util.HashMap) Supplier(java.util.function.Supplier) JsonUtil(com.simiacryptus.util.io.JsonUtil) MutableNode(guru.nidi.graphviz.model.MutableNode) Charset(java.nio.charset.Charset) Factory(guru.nidi.graphviz.model.Factory) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) NotebookOutput(com.simiacryptus.util.io.NotebookOutput) WeakReference(java.lang.ref.WeakReference) LinkTarget(guru.nidi.graphviz.model.LinkTarget) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) LongSummaryStatistics(java.util.LongSummaryStatistics) PrintStream(java.io.PrintStream) Logger(org.slf4j.Logger) PlotCanvas(smile.plot.PlotCanvas) RankDir(guru.nidi.graphviz.attribute.RankDir) IOException(java.io.IOException) FileFilter(javax.swing.filechooser.FileFilter) ActionEvent(java.awt.event.ActionEvent) PercentileStatistics(com.simiacryptus.util.data.PercentileStatistics) File(java.io.File) java.awt(java.awt) ComponentAdapter(java.awt.event.ComponentAdapter) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) MonitoredObject(com.simiacryptus.util.MonitoredObject) IntToLongFunction(java.util.function.IntToLongFunction) Link(guru.nidi.graphviz.model.Link) Step(com.simiacryptus.mindseye.opt.Step) Comparator(java.util.Comparator) javax.swing(javax.swing) Nonnull(javax.annotation.Nonnull) LongToIntFunction(java.util.function.LongToIntFunction) IntToLongFunction(java.util.function.IntToLongFunction) IntUnaryOperator(java.util.function.IntUnaryOperator)

Aggregations

Layer (com.simiacryptus.mindseye.lang.Layer)1 Tensor (com.simiacryptus.mindseye.lang.Tensor)1 LoggingWrapperLayer (com.simiacryptus.mindseye.layers.java.LoggingWrapperLayer)1 MonitoringWrapperLayer (com.simiacryptus.mindseye.layers.java.MonitoringWrapperLayer)1 StochasticComponent (com.simiacryptus.mindseye.layers.java.StochasticComponent)1 DAGNetwork (com.simiacryptus.mindseye.network.DAGNetwork)1 DAGNode (com.simiacryptus.mindseye.network.DAGNode)1 Step (com.simiacryptus.mindseye.opt.Step)1 TrainingMonitor (com.simiacryptus.mindseye.opt.TrainingMonitor)1 MonitoredObject (com.simiacryptus.util.MonitoredObject)1 DoubleStatistics (com.simiacryptus.util.data.DoubleStatistics)1 PercentileStatistics (com.simiacryptus.util.data.PercentileStatistics)1 ScalarStatistics (com.simiacryptus.util.data.ScalarStatistics)1 JsonUtil (com.simiacryptus.util.io.JsonUtil)1 NotebookOutput (com.simiacryptus.util.io.NotebookOutput)1 RankDir (guru.nidi.graphviz.attribute.RankDir)1 Factory (guru.nidi.graphviz.model.Factory)1 Graph (guru.nidi.graphviz.model.Graph)1 Link (guru.nidi.graphviz.model.Link)1 LinkSource (guru.nidi.graphviz.model.LinkSource)1