コード例 #1
0
        protected virtual INDArray GeneratePossibleMoves(INDArray values)
        {
            List <int[]> possibleMoves = new List <int[]>();

            int[] valuesInts = values.GetDataAs <int>().Data;
            for (int i = 0; i < values.Length; i++)
            {
                if (valuesInts[i] == 0)
                {
                    int[] valuesIntsClone = (int[])valuesInts.Clone();
                    valuesIntsClone[i] = 1;
                    possibleMoves.Add(valuesIntsClone);

                    _moveOrder.Add(i);
                }
            }

            if (possibleMoves.Count > 0)
            {
                int[] moves = possibleMoves.Aggregate(ArrayUtils.Concatenate);
                return(Handler.NDArray(moves, possibleMoves.Count, 1, 9));
            }

            return(null);
        }
コード例 #2
0
        /// <inheritdoc />
        protected override void OnReported(IRegistry parameterRegistry, IComputationHandler handler, INDArray inputs, INDArray desiredTargets)
        {
            HideLoadingIndicator();

            float[] targetData = inputs.GetDataAs <float>().Data;
            float   min = targetData.Min(), max = targetData.Max();
            float   range = max - min;

            Content.Dispatcher.Invoke(() => RenderRectangle <float>(inputs, r => 0, g => 0, b => (byte)(Math.Pow((b - min) / range, 1.5f) * 255), a => 0xff, 0, 0));
        }
コード例 #3
0
        /// <inheritdoc />
        protected override ADFloat32NDArray ConvertInternal(INDArray array)
        {
            ADFloat32NDArray @internal = array as ADFloat32NDArray;

            if (@internal != null)
            {
                return(@internal);
            }

            return(new ADFloat32NDArray(DiffsharpBackendHandle.BackendTag, array.GetDataAs <float>(), array.Shape));
        }
コード例 #4
0
        /// <inheritdoc />
        protected override CudaFloat32NDArray ConvertInternal(INDArray array)
        {
            CudaFloat32NDArray @internal = array as CudaFloat32NDArray;

            if (@internal != null)
            {
                return(@internal);
            }

            return(new CudaFloat32NDArray(new CudaSigmaDiffDataBuffer <float>(array.GetDataAs <float>(), 0L, array.Length, _cudaBackendHandle.BackendTag, _cudaBackendHandle.CudaContext), (long[])array.Shape.Clone()));
        }
コード例 #5
0
        public void TestConstantValueInitialiserInitialise()
        {
            ConstantValueInitialiser initialiser = new ConstantValueInitialiser(2.0);

            IComputationHandler handler = new CpuFloat32Handler();
            INDArray            array   = handler.NDArray(2L, 1L, 2L, 2L);

            Random random = new Random();

            Assert.Throws <ArgumentNullException>(() => initialiser.Initialise((INDArray)null, handler, random));
            Assert.Throws <ArgumentNullException>(() => initialiser.Initialise((INumber)null, handler, random));
            Assert.Throws <ArgumentNullException>(() => initialiser.Initialise(array, null, random));
            Assert.Throws <ArgumentNullException>(() => initialiser.Initialise(array, handler, null));

            initialiser.Initialise(array, handler, new Random());

            Assert.AreEqual(new float[] { 2, 2, 2, 2, 2, 2, 2, 2 }, array.GetDataAs <float>().GetValuesArrayAs <float>(0, 8));
        }
コード例 #6
0
ファイル: DrawPanel.cs プロジェクト: xiaoxiongnpu/Sigma
        /// <summary>
        /// This method accepts a network pass and processes.
        /// </summary>
        /// <param name="array">The array that is the response from the pass.</param>
        public void ReceivePass(INDArray array)
        {
            array = Handler.SoftMax(Handler.Multiply(array, 10));             // TODO remove hack and fix for very small numbers
            KeyValuePair <double, int>[] sorted = array.GetDataAs <double>().Data.Select((x, i) => new KeyValuePair <double, int>(x, i)).OrderByDescending(x => x.Key).ToArray();

            string text = "";

            for (int i = 0; i < sorted.Length; i++)
            {
                double confidence = Math.Round(sorted[i].Key * 10000) / 100;
                int    number     = sorted[i].Value;
                _guesses[i].Probability = $"{confidence:00.000}";
                _guesses[i].Digit       = number;
                //guesses.Add(new Guess { Accuracy = Math.Round(accuracy.Key * 100), Number = accuracy.Value });
            }

            Content.Dispatcher.Invoke(() =>
            {
                Items.Clear();
                Items.AddRange(_guesses);
            });
        }
コード例 #7
0
 /// <summary>
 /// Render bytes as a rectangle with a x- and y-offset and a given width and height. The data[] can be of arbitrary format and will be mapped with the provided functions. (see<see cref="ApplyTransformation{T}"/> for mor details).
 /// </summary>
 /// <param name="bitmap">The bitmap that will be written to.</param>
 /// <param name="data">The data that will be rendered.</param>
 /// <param name="xOffset">The x-offset.</param>
 /// <param name="yOffset">The y-offste.</param>
 /// <param name="transformationFuncs">The functions that map the data to bytes.</param>
 public static void RenderRectangle <T>(this WriteableBitmap bitmap, INDArray data, int xOffset, int yOffset, params Func <T, byte>[] transformationFuncs) where T : struct
 {
     bitmap.RenderRectangle(data.GetDataAs <T>().ToArray(), (int)data.Shape[1], (int)data.Shape[0], xOffset, yOffset, transformationFuncs);
 }
コード例 #8
0
 /// <summary>
 /// Fill the content from a bitmap with the data from an INDarray. The data can be of arbitrary format and will be mapped with the provided functions. (see <see cref="ApplyTransformation{T}"/> for mor details).
 /// </summary>
 /// <typeparam name="T">The type of the data.</typeparam>
 /// <param name="bitmap">The bitmap that will be written to.</param>
 /// <param name="data">The data that will be written to the new bitmap.</param>
 /// <param name="transformationFuncs">The functions that map the data to bytes.</param>
 public static void Render <T>(this WriteableBitmap bitmap, INDArray data, params Func <T, byte>[] transformationFuncs) where T : struct
 {
     bitmap.Render(data.GetDataAs <T>().ToArray(), transformationFuncs);
 }
コード例 #9
0
 /// <summary>
 /// Render a stream of data with an xOffset. The data can be of arbitrary format and will be mapped with the provided functions. (see <see cref="ApplyTransformation{T}"/> for mor details).
 /// </summary>
 /// <typeparam name="T">The type of the data.</typeparam>
 /// <param name="bitmap">The bitmap that will be written to.</param>
 /// <param name="data">The data that will be written to the new bitmap.</param>
 /// <param name="xOffset">The x-offset.</param>
 /// <param name="transformationFuncs">The functions that map the data to bytes.</param>
 public static void RenderStream <T>(this WriteableBitmap bitmap, INDArray data, int xOffset, params Func <T, byte>[] transformationFuncs) where T : struct
 {
     bitmap.RenderStreamRaw(ApplyTransformation(data.GetDataAs <T>().ToArray(), transformationFuncs), xOffset);
 }
コード例 #10
0
 /// <summary>
 /// Render bytes as a rectangle with a x- and y-offset, where the width and height is automatically taken from the INDarrays shape. The byte[] has to contain all data (so rgb etc).
 /// </summary>
 /// <param name="bitmap">The bitmap that will be written to.</param>
 /// <param name="data">The data that will be rendered.</param>
 /// <param name="xOffset">The x-offset.</param>
 /// <param name="yOffset">The y-offste.</param>
 public static void RenderRectangleRaw(this WriteableBitmap bitmap, INDArray data, int xOffset, int yOffset)
 {
     bitmap.RenderRectangleRaw(data.GetDataAs <byte>().ToArray(), (int)data.Shape[1], (int)data.Shape[0], xOffset, yOffset);
 }
コード例 #11
0
 /// <summary>
 /// Fill the content from a bitmap with a raw INDarray. The INDarray has to contain all data (so rgb etc).
 /// </summary>
 /// <param name="bitmap">The bitmap that will be written to.</param>
 /// <param name="data">The data that will be written to the new bitmap.</param>
 public static void RenderRaw(this WriteableBitmap bitmap, INDArray data)
 {
     bitmap.RenderRaw(data.GetDataAs <byte>().ToArray());
 }
コード例 #12
0
 /// <summary>
 /// Render a stream of bytes with an xOffset.
 /// </summary>
 /// <param name="bitmap">The bitmap that will be written to.</param>
 /// <param name="data">The data that will be written to the new bitmap.</param>
 /// <param name="xOffset">The x-Offset</param>
 public static void RenderStreamRaw(this WriteableBitmap bitmap, INDArray data, int xOffset)
 {
     bitmap.RenderStreamRaw(data.GetDataAs <byte>().ToArray(), xOffset);
 }