Пример #1
0
        /// <summary>Predicts the given o.</summary>
        /// <param name="y">The Vector to process.</param>
        /// <returns>An object.</returns>
        public override double Predict(Vector x)
        {
            this.Preprocess(x);

            Network.Forward(x);

            Vector output = Network.Out.Select(n => n.Output).ToVector();

            return(this.OutputFunction != null ? this.OutputFunction.Minimize(output) : output.Max());
        }
Пример #2
0
        /// <summary>Predicts the given o.</summary>
        /// <param name="x">The Vector to process.</param>
        /// <returns>An object.</returns>
        public override double Predict(Vector x)
        {
            Preprocess(x);

            Network.Forward(x);

            var output = Network.Out.Select(n => n.Output).ToVector();

            return(OutputFunction?.Minimize(output) ?? output.Max());
        }
Пример #3
0
        /// <summary>
        ///   Predicts the given x.
        /// </summary>
        /// <param name="x">Vector of features.</param>
        /// <returns>Vector.</returns>
        public Vector PredictSequence(Vector x)
        {
            Preprocess(x);

            Network.Forward(x);

            var output = Network.Out.Select(n => n.Output).ToVector();

            return(OutputFunction != null?OutputFunction.Compute(output) : output);
        }
        private static int VerifyNetwork(Network network)
        {
            int errors = 0;

            var edges = network.GetEdges();

            for (int layer = 0; layer < network.Layers; layer++)
            {
                var nodes = network.GetNodes(layer);

                foreach (var node in nodes)
                {
                    foreach (var iedge in node.In)
                    {
                        if (!edges.Any(a => a.ParentId == iedge.ParentId && a.ChildId == iedge.ChildId))
                            errors++;
                    }
                    foreach (var oedge in node.Out)
                    {
                        if (!edges.Any(a => a.ParentId == oedge.ParentId && a.ChildId == oedge.ChildId))
                            errors++;
                    }

                    if (layer == 0 && node.In.Count > 0) errors++;
                    if (layer == network.Layers - 1 && node.Out.Count > 0) errors++;
                }
            }

            network.Forward(Vector.Ones(network.In.Length - 1));

            if (network.Out.Any(a => double.IsNaN(a.Output) || double.IsInfinity(a.Output))) errors++;

            return errors;
        }