public static LearningApi UseActionModule <TIN, TOUT>(this LearningApi api, Func <TIN, IContext, TOUT> moduleFunction)
        {
            var mod = new FunctionModule <TIN, TOUT>(moduleFunction);

            api.AddModule(mod, $"ActionModule-{Guid.NewGuid().ToString()}");
            return(api);
        }
Esempio n. 2
0
        /// <summary>
        /// Enables simplified implementation of some module functionality in a form
        /// of injected function.
        /// </summary>
        /// <typeparam name="TIN">Input value.</typeparam>
        /// <typeparam name="TOUT">Function output value.</typeparam>
        /// <param name="api"></param>
        /// <param name="moduleFunction">Function, which implements the module functionality.</param>
        /// <param name="moduleName">The unique module name. If not specified it is automatically created.
        /// If loading and saving of model is used and action modules are used, then action modules cannot be persisted.
        /// In this case after loading of the model, you will need to use ReplaceActionModule by giving the name, which was
        /// used by calling UseActionModule before model was saved.</param>
        /// <returns>Output value of the module defined by <see cref="TOUT"/></returns>
        public static LearningApi UseActionModule <TIN, TOUT>(this LearningApi api, Func <TIN, IContext, TOUT> moduleFunction, string moduleName = null)
        {
            var mod = new FunctionModule <TIN, TOUT>(moduleFunction);

            if (String.IsNullOrEmpty(moduleName))
            {
                moduleName = $"ActionModule-{Guid.NewGuid().ToString()}";
            }

            api.AddModule(mod, moduleName);

            return(api);
        }