Click or drag to resize

Result Evaluator Example

Below, an example implementation of a RelaxISPlugin_ResultEvaluator is shown.

The function of the plugin is chosen for illustrative purposes.

Requirements
  • Reference to the RelaxIS_SDK.dll

  • .NET Framework 4.7.2 target (class library)

  • Recommended: Development environment with compiler e.g. RelaxIS SDK Code Editor, Microsoft Visual Studio

Demonstrates

This examples illustrates the implementation of a ResultEvaluator plugin.

As an example it fits a second-order polynomial to Y vs. 1 / X values.

Example
C#
// <copyright file="MyResultEvaluator.cs" company="rhd instruments GmbH and Co. KG">
// Copyright (c) rhd instruments GmbH and Co. KG. All rights reserved.
// Licensed under the MIT No Attribution (MIT-0) license. See section 'License' in the 'SDK Examples / Tutorials' topic for full license information.
// </copyright>

namespace RelaxIS_SDK_Examples.Plugins
{
    using System.Collections.Generic;
    using System.Linq;
    using RelaxIS_SDK.Plugins;

    /***
     * ResultEvaluator plugins implement a fitting model that can be applied to data plotted in the
     * Result Preview dialog. It can be a non-linear model that will go through a parameter initialization
     * step and is then fitted to the data.
     */

    /// <summary>
    /// Defines an example <see cref="RelaxISPlugin_ResultEvaluator"/> class.
    /// </summary>
    public class MyResultEvaluator
        : RelaxISPlugin_ResultEvaluator
    {
        // Buffer the parameter names.
        private static readonly string[] Names = new string[] { "a", "b", "c", };

        /***
         * First, implement the default plugin properties Name and Description that describe the plugin.
         * This is mainly used for display purposes.
         */

        /// <inheritdoc/>
        public override string Name
        {
            get { return "MyResultEvaluator"; }
        }

        /// <inheritdoc/>
        public override string Description
        {
            get { return "Fits a polynomial to the data, and inverts the X value before doing so."; }
        }

        /// <inheritdoc/>
        public override string Formula
        {
            get
            {
                return "y = a * x^2 + b * x + c";
            }
        }

        /***
         * The group determines a sorting category when the user selects one of the models.
         */

        /// <inheritdoc/>
        public override string FunctionGroup
        {
            get
            {
                return "My own polynomial fits";
            }
        }

        /***
         * A description of the pre-transformation step for the X-data.
         * This is used for display on the user interface. Override the
         * PreTransformYDescription in case transformation of the Y-values
         * are performed to inform the user about what will happen to the data.
         */

        /// <inheritdoc/>
        public override string PreTransformXDescription
        {
            get
            {
                return "Inverts the X-Value, X' = 1 / X";
            }
        }

        /***
         * Perform an optional pre-transformation step for the data.
         * This means that you get e.g. raw (plotted) X-values from the Result Preview window and recalculate it.
         * An example would be a linearization of an Arrhenius fit, where X -> 1 / X.
         * You can override PreTransformYValue() and PreTransformYError() in the same manner.
         * The result values are the values used for parameter initialization and fitting in this plugin.
         */

        /// <inheritdoc/>
        public override double PreTransformXValue(double XInput)
        {
            // Override the respective Y1 and error functions if you want to transform these as well.
            return 1.0 / XInput;
        }

        /***
         * Get a list of parameter names for display to the user.
         * This list should have the same length as the array returned by GetInitialValues()
         */

        /// <inheritdoc/>
        public override List<string> GetParameterNames()
        {
            return new List<string>(Names);
        }

        /***
         * Get initial values for the model parameters for the given X- and Y-values.
         * These can be edited by the user, but it often makes sense to find good initial
         * parameters automatically in order to save work for the user.
         */

        /// <inheritdoc/>
        public override double[] GetInitialValues(double[] XValues, double[] YValues)
        {
            return new double[] { 1, 1, 1 };
        }

        /***
         * This function is the actual fit function used. X is the pretransformed x-value.
         * The function should calculate the corresponding Y value.
         * In this example this is a second-degree polynomial.
         */

        /// <inheritdoc/>
        public override double XYFunction(double X, double[] Parameters)
        {
            var a = Parameters[0];
            var b = Parameters[1];
            var c = Parameters[2];
            return (a * X * X) + (b * X) + c;
        }

        /***
         * This function allows the determination of further results based on the result parameter and errors of the fit.
         * These are displayed to the user after the fit is completed.
         */

        /// <inheritdoc/>
        public override Dictionary<string, string> GetFurtherEvaluations(double[] ResultParameters, double[] ResultErrors)
        {
            // Here you can add arbitrary further results if that is useful.
            var allOk = ResultParameters.All(p => p < 100 && p > -100);
            var res = new Dictionary<string, string>
            {
                { "All parameters in range?", allOk ? "Yes" : "No" },
            };
            return res;
        }
    }
}
See Also