/// <summary>
        /// Construct a function regression evaluator with the provided parameter sampling info and function to regress.
        /// </summary>
        public FnRegressionEvaluator(IFunction fn, ParamSamplingInfo paramSamplingInfo, double gradientMseWeight, IBlackBoxProbe blackBoxProbe)
        {
            _paramSamplingInfo = paramSamplingInfo;
            _gradientMseWeight = gradientMseWeight;
            _yMseWeight        = 1.0 - gradientMseWeight;
            _blackBoxProbe     = blackBoxProbe;

            // Predetermine target responses.
            int sampleCount = _paramSamplingInfo._sampleCount;

            _yArrTarget        = new double[sampleCount];
            _gradientArrTarget = new double[sampleCount];

            FunctionProbe fnProbe = new FunctionProbe(paramSamplingInfo);

            fnProbe.Probe(fn, _yArrTarget);
            FnRegressionUtils.CalcGradients(paramSamplingInfo, _yArrTarget, _gradientArrTarget);
        }
Beispiel #2
0
        /// <summary>
        /// Constructs with the details of the function regression problem to be visualized.
        /// </summary>
        /// <param name="fn">The function being regressed.</param>
        /// <param name="generativeMode">Indicates that blackbox has no inputs; it will generate a waveform as a function of time.</param>
        /// <param name="paramSamplingInfo">Parameter sampling info.</param>
        /// <param name="genomeDecoder">Genome decoder.</param>
        public FnRegressionView2D(IFunction fn, ParamSamplingInfo paramSamplingInfo, bool generativeMode, IGenomeDecoder <NeatGenome, IBlackBox> genomeDecoder)
        {
            InitializeComponent();
            InitGraph(string.Empty, string.Empty, string.Empty);

            _fn = fn;
            _paramSamplingInfo = paramSamplingInfo;
            _generativeMode    = generativeMode;
            _genomeDecoder     = genomeDecoder;

            // Determine the mid output value of the function (over the specified sample points) and a scaling factor
            // to apply the to neural network response for it to be able to recreate the function (because the neural net
            // output range is [0,1] when using the logistic function as the neuron activation function).
            double mid, scale;

            FnRegressionUtils.CalcFunctionMidAndScale(fn, paramSamplingInfo, out mid, out scale);
            if (generativeMode)
            {
                _blackBoxProbe = new GenerativeBlackBoxProbe(paramSamplingInfo, mid, scale);
            }
            else
            {
                _blackBoxProbe = new BlackBoxProbe(paramSamplingInfo, mid, scale);
            }

            _yArrTarget = new double[paramSamplingInfo._sampleCount];

            // Pre-build plot point objects.
            _plotPointListTarget   = new PointPairList();
            _plotPointListResponse = new PointPairList();

            double[] xArr = paramSamplingInfo._xArr;
            for (int i = 0; i < xArr.Length; i++)
            {
                double x = xArr[i];
                _plotPointListTarget.Add(x, _fn.GetValue(x));
                _plotPointListResponse.Add(x, 0.0);
            }

            // Bind plot points to graph.
            zed.GraphPane.AddCurve("Target", _plotPointListTarget, Color.Black, SymbolType.None);
            zed.GraphPane.AddCurve("Network Response", _plotPointListResponse, Color.Red, SymbolType.None);
        }
        /// <summary>
        /// Construct a new instance.
        /// </summary>
        /// <param name="fn">The target function.</param>
        /// <param name="paramSamplingInfo">Sampling (defines the x range and sampling density).</param>
        /// <param name="gradientMseWeight">The fitness weighting to assign to the gradient mean squared error (MSE) score.</param>
        public FuncRegressionEvaluationScheme(
            Func <double, double> fn,
            ParamSamplingInfo paramSamplingInfo,
            double gradientMseWeight)
        {
            _paramSamplingInfo = paramSamplingInfo;
            _gradientMseWeight = gradientMseWeight;

            // Alloc arrays.
            int sampleCount = _paramSamplingInfo.SampleResolution;

            _yArrTarget        = new double[sampleCount];
            _gradientArrTarget = new double[sampleCount];

            // Predetermine target responses.
            FuncRegressionUtils.Probe(fn, paramSamplingInfo, _yArrTarget);
            FuncRegressionUtils.CalcGradients(paramSamplingInfo, _yArrTarget, _gradientArrTarget);

            // Create blackbox probe.
            _blackBoxProbe = CreateBlackBoxProbe(fn, paramSamplingInfo);
        }
        /// <summary>
        /// Construct a new instance.
        /// </summary>
        /// <param name="paramSamplingInfo">Parameter sampling info.</param>
        /// <param name="gradientMseWeight">Fitness weighting to apply to the gradient fitness score.</param>
        /// <param name="yArrTarget">Array of target y values (function output values).</param>
        /// <param name="gradientArrTarget">Array of target gradient values.</param>
        /// <param name="blackBoxProbe">Black box probe. For obtaining the y value response array from an instance of <see cref="IBlackBox{T}"/>.</param>
        internal FuncRegressionEvaluator(
            ParamSamplingInfo paramSamplingInfo,
            double gradientMseWeight,
            double[] yArrTarget,
            double[] gradientArrTarget,
            IBlackBoxProbe blackBoxProbe)
        {
            _paramSamplingInfo = paramSamplingInfo;
            _gradientMseWeight = gradientMseWeight;
            _yMseWeight        = 1.0 - gradientMseWeight;

            _yArrTarget        = yArrTarget;
            _gradientArrTarget = gradientArrTarget;

            // Alloc working arrays for receiving black box outputs.
            int sampleCount = _paramSamplingInfo.SampleResolution;

            _yArr        = new double[sampleCount];
            _gradientArr = new double[sampleCount];

            _blackBoxProbe = blackBoxProbe;
        }