public NNFetch Predict(Matrix <float> X, Vector <float> y = null, params object[] parameters)
        {
            float[][] preds = nn.Forward(X, true);

            NNFetch nnFetch = new NNFetch(X.RowCount);

            nnFetch.AddSampleToPreds(preds[0].Select(x => (double)x).ToArray());

            if (nn.ComputeSDOutput == true)
            {
                nnFetch.AddSampleToSigmas(preds[1].Select(x => Global.ToSigma(Global.TrimPhi(x))).ToArray());
            }

            nnFetch.SetCost(0);

            return(nnFetch);
        }
        public NNFetch Predict(Matrix <float> X, Vector <float> y = null, params object[] parameters)
        {
            if (X.RowCount > Global.TFMAXBATCHSIZE)
            {
                throw new Exception();
            }

            int minSample = 1;

            if (parameters != null && parameters.Length != 0)
            {
                minSample = (int)parameters[0];
            }

            int iter = minSample % numSamples == 0 ? minSample / numSamples : minSample / numSamples + 1;


            NNFetch nnFetch = new NNFetch(X.RowCount);

            List <float> costs = new List <float>();

            for (int i = 0; i < iter; i++)
            {
                var runner = _session.GetRunner();

                runner.AddInput(_input, X.ToArray());

                runner.AddInput(_decay, 0F);

                if (y != null)
                {
                    runner.AddInput(_output, y.ToArray());
                }

                foreach (TFOutput pred in _preds)
                {
                    runner.Fetch(pred);
                }

                if (y != null)
                {
                    runner.Fetch(_cost);
                }


                var result = runner.Run();


                if (y != null)
                {
                    costs.Add((float)result.Last().GetValue());
                }

                for (int j = 0; j < _preds.Length; j++)
                {
                    nnFetch.AddSampleToPreds(((float[])result[j].GetValue()).Select(x => (double)x).ToArray());
                }
            }

            if (y != null)
            {
                nnFetch.SetCost(costs.Average());
            }


            return(nnFetch);
        }
        public override int H(IState state, bool verbose)
        {
            int h;

            bool cached = hCache.TryGetValue(state.GetHashCodeLong(), out h);

            if (cached == false)
            {
                List <TrainingInstance> trainingInstances = new List <TrainingInstance>()
                {
                    new TrainingInstance(state, 0)
                };

                var data = representationSolve.BuildData(trainingInstances);

                NNFetch nnFetch = nnSolve.Predict(data.Item1);

                double pred = nnFetch.Preds[0][0];

                int hUnadj = 0;

                if (verbose == true)
                {
                    hUnadj = (int)Math.Round(representationSolve.ResponseFuncInv(pred), 0);;
                }

                if (confLevel == null)
                {
                    pred = representationSolve.ResponseFuncInv(pred);
                }
                else
                {
                    if (l2Loss == true)
                    {
                        pred = MathNet.Numerics.Distributions.Normal.InvCDF(nnFetch.Preds[0][0], nnFetch.Sigmas[0][0], (double)confLevel);
                    }
                    else
                    {
                        pred = Global.InvLaplace(nnFetch.Preds[0][0], nnFetch.Sigmas[0][0], (double)confLevel);
                    }

                    pred = representationSolve.ResponseFuncInv(pred);
                }



                h = (int)Math.Round(pred, 0);

                if (verbose == true)
                {
                    Console.WriteLine("h: " + h + " hUnadj: " + hUnadj);
                }

                if (representationSolve.MultHeuristic == null)
                {
                    if (h < 0)
                    {
                        h = 0;
                    }
                }
                else
                {
                    h = Math.Max(h, representationSolve.MultHeuristic.HArr.Max());
                }

                if (hCache.Count > Global.HCAHCEMAXRECORDS)
                {
                    ClearCache();
                }

                hCache[state.GetHashCodeLong()] = h;
            }



            return(h);
        }