Free cookie consent management tool by TermsFeed Policy Generator

source: stable/HeuristicLab.ExtLibs/HeuristicLab.AutoDiff/1.0/AutoDiff-1.0/ICompiledTerm.cs @ 11974

Last change on this file since 11974 was 8703, checked in by gkronber, 12 years ago

#1960 added HL wrapper plugin for AutoDiff

File size: 4.1 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Collections.ObjectModel;
6using System.Diagnostics.Contracts;
7
8namespace AutoDiff
9{
10    /// <summary>
11    /// Represents a term after it has been compiled for efficient evaluation/differentiation.
12    /// </summary>
13    [ContractClass(typeof(CompiledTermContract))]
14    public interface ICompiledTerm
15    {
16        /// <summary>
17        /// Evaluates the compiled term at the given point.
18        /// </summary>
19        /// <param name="arg">The point at which to evaluate.</param>
20        /// <returns>The value of the function represented by the term at the given point.</returns>
21        /// <remarks>The number at <c>arg[i]</c> is the value assigned to the variable <c>Variables[i]</c>.</remarks>
22        double Evaluate(params double[] arg);
23
24        /// <summary>
25        /// Computes the gradient of the compiled term at the given point.
26        /// </summary>
27        /// <param name="arg">The point at which to differentiate.</param>
28        /// <returns>A tuple, where the first item is the gradient at <paramref name="arg"/> and the second item is
29        /// the value at <paramref name="arg"/>. That is, the second value is the same as running <see cref="Evaluate"/> on
30        /// <paramref name="arg"/>.</returns>
31        /// <remarks>The number at <c>arg[i]</c> is the value assigned to the variable <c>Variables[i]</c>.</remarks>
32        Tuple<double[], double> Differentiate<T>(T arg) where T : IList<double>;
33
34        /// <summary>
35        /// Computes the gradient of the compiled term at the given point.
36        /// </summary>
37        /// <param name="arg">The point at which to differentiate.</param>
38        /// <returns>A tuple, where the first item is the gradient at <paramref name="arg"/> and the second item is
39        /// the value at <paramref name="arg"/>. That is, the second value is the same as running <see cref="Evaluate"/> on
40        /// <paramref name="arg"/>.</returns>
41        /// <remarks>The number at <c>arg[i]</c> is the value assigned to the variable <c>Variables[i]</c>.</remarks>
42        Tuple<double[], double> Differentiate(params double[] arg);
43
44        /// <summary>
45        /// The collection of variables contained in this compiled term.
46        /// </summary>
47        /// <remarks>
48        /// The order of variables in this collection specifies the meaning of each argument in <see cref="Differentiate"/> or
49        /// <see cref="Evaluate"/>. That is, the variable at <c>Variables[i]</c> corresponds to the i-th parameter of <see cref="Differentiate"/>
50        /// and <see cref="Evaluate"/>.
51        /// </remarks>
52        ReadOnlyCollection<Variable> Variables { get; }
53    }
54
55    [ContractClassFor(typeof(ICompiledTerm))]
56    abstract class CompiledTermContract : ICompiledTerm
57    {
58        public double Evaluate(params double[] arg)
59        {
60            Contract.Requires(arg != null);
61            Contract.Requires(arg.Length == Variables.Count);
62            return default(double);
63        }
64
65        public Tuple<double[], double> Differentiate<T>(T arg)
66            where T : IList<double>
67        {
68            Contract.Requires(arg != null);
69            Contract.Requires(arg.Count == Variables.Count);
70            Contract.Ensures(Contract.Result<Tuple<double[], double>>() != null);
71            Contract.Ensures(Contract.Result<Tuple<double[], double>>().Item1.Length == arg.Count);
72            return null;
73        }
74
75        public Tuple<double[], double> Differentiate(params double[] arg)
76        {
77            Contract.Requires(arg != null);
78            Contract.Requires(arg.Length == Variables.Count);
79            Contract.Ensures(Contract.Result<Tuple<double[], double>>() != null);
80            Contract.Ensures(Contract.Result<Tuple<double[], double>>().Item1.Length == arg.Length);
81            return null;
82        }
83
84        public ReadOnlyCollection<Variable> Variables
85        {
86            get
87            {
88                Contract.Ensures(Contract.Result<ReadOnlyCollection<Variable>>() != null);
89                return null;
90            }
91        }
92    }
93
94}
Note: See TracBrowser for help on using the repository browser.