/// <summary>
        /// Applies the transformation to a set of input vectors,
        /// producing an associated set of output vectors.
        /// </summary>
        /// <param name="input">The input data to which
        /// the transformation should be applied.</param>
        /// <param name="result">The location to where to store the
        /// result of this transformation.</param>
        /// <returns>The output generated by applying this
        /// transformation to the given input.</returns>
        public int[] Transform(TInput[] input, int[] result)
        {
            // Detect all activation centroids
            Parallel.For(0, input.Length, ParallelOptions, i =>
            {
                int j = classifier.Decide(input[i]);
                Interlocked.Increment(ref result[j]);
            });

            return(result);
        }
        /// <summary>
        /// Applies the transformation to a set of input vectors,
        /// producing an associated set of output vectors.
        /// </summary>
        /// <param name="input">The input data to which
        /// the transformation should be applied.</param>
        /// <param name="result">The location to where to store the
        /// result of this transformation.</param>
        /// <returns>The output generated by applying this
        /// transformation to the given input.</returns>
        public int[] Transform(IList <TPoint> input, int[] result)
        {
            // Detect all activation centroids
            Parallel.For(0, input.Count, ParallelOptions, i =>
            {
                TFeature x = input[i].Descriptor;
                int j      = classifier.Decide(x);
                Interlocked.Increment(ref result[j]);
            });

            return(result);
        }
        protected override void OnHandle(object sender, FrameEventArgs eventArgs)
        {
            var frame     = eventArgs.frame;
            var rightHand = frame.Hands.FirstOrDefault(hand => hand.IsRight);

            if (rightHand == null)
            {
                _eventAggregator
                .GetEvent <AfterFrameHandleEvent>()
                .Publish(
                    new AfterFrameHandleEventArgs()
                {
                    ErrorMessage = "Right hand is required!"
                });

                return;
            }

            var controllerOutput = _controllerOutputService.GetControllerOutput(rightHand);
            var decision         = _classifier.Decide(controllerOutput);

            _eventAggregator
            .GetEvent <AfterFrameHandleEvent>()
            .Publish(
                new AfterFrameHandleEventArgs()
            {
                OutputClass = (OutputClass)decision
            });

            Debug.WriteLine((OutputClass)decision);
        }
Esempio n. 4
0
 /// <summary>
 ///   Estimates a <see cref="ConfusionMatrix"/> directly from a classifier, a set of inputs and its expected outputs.
 /// </summary>
 ///
 /// <typeparam name="TInput">The type of the inputs accepted by the classifier.</typeparam>
 ///
 /// <param name="classifier">The classifier.</param>
 /// <param name="inputs">The input vectors.</param>
 /// <param name="expected">The expected outputs associated with each input vector.</param>
 ///
 /// <returns>A <see cref="ConfusionMatrix"/> capturing the performance of the classifier when
 ///   trying to predict the outputs <paramref name="expected"/> from the <paramref name="inputs"/>.</returns>
 ///
 public static ConfusionMatrix Estimate <TInput>(IClassifier <TInput, bool> classifier, TInput[] inputs, bool[] expected)
 {
     return(new ConfusionMatrix(expected: expected, predicted: classifier.Decide(inputs)));
 }
 /// <summary>
 ///   Estimates a <see cref="GeneralConfusionMatrix"/> directly from a classifier, a set of inputs and its expected outputs.
 /// </summary>
 ///
 /// <typeparam name="TInput">The type of the inputs accepted by the classifier.</typeparam>
 ///
 /// <param name="classifier">The classifier.</param>
 /// <param name="inputs">The input vectors.</param>
 /// <param name="expected">The expected outputs associated with each input vector.</param>
 ///
 /// <returns>A <see cref="GeneralConfusionMatrix"/> capturing the performance of the classifier when
 ///   trying to predict the outputs <paramref name="expected"/> from the <paramref name="inputs"/>.</returns>
 ///
 public static GeneralConfusionMatrix Estimate <TInput>(IClassifier <TInput, bool> classifier, TInput[] inputs, bool[] expected)
 {
     return(new GeneralConfusionMatrix(expected: Accord.Statistics.Classes.ToZeroOne(expected),
                                       predicted: Accord.Statistics.Classes.ToZeroOne(classifier.Decide(inputs))));
 }
 /// <summary>
 ///   Estimates a <see cref="GeneralConfusionMatrix"/> directly from a classifier, a set of inputs and its expected outputs.
 /// </summary>
 ///
 /// <typeparam name="TInput">The type of the inputs accepted by the classifier.</typeparam>
 ///
 /// <param name="classifier">The classifier.</param>
 /// <param name="inputs">The input vectors.</param>
 /// <param name="expected">The expected outputs associated with each input vector.</param>
 ///
 /// <returns>A <see cref="GeneralConfusionMatrix"/> capturing the performance of the classifier when
 ///   trying to predict the outputs <paramref name="expected"/> from the <paramref name="inputs"/>.</returns>
 ///
 public static GeneralConfusionMatrix Estimate <TInput>(IClassifier <TInput, int> classifier, TInput[] inputs, int[] expected)
 {
     return(new GeneralConfusionMatrix(expected: expected, predicted: classifier.Decide(inputs)));
 }