[ff1121]: src / include / function / Function.h  Maximize  Restore  History

Download this file

132 lines (124 with data), 4.6 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#ifndef FUNCTION_H_
#define FUNCTION_H_
#include <string>
#include <vector>
namespace jags {
class Range;
/**
* Base class for functions.
*
* Function objects contain only constant data members and all member
* functions are constant. Hence only one object needs to be
* instantiated for each subclass.
*
* The FuncTab class provides a convenient way of storing Function
* objects and referencing them by name.
*
* @see FuncTab
* @short BUGS-language function or operator
*/
class Function
{
const std::string _name;
const unsigned int _npar;
public:
/**
* Constructor.
* @param name name of the function as used in the BUGS language
* @param npar number of parameters. If npar == 0 then the function
* takes a variable number of parameters.
*/
Function(std::string const &name, unsigned int npar);
virtual ~Function ();
/**
* Returns the BUGS language name of the function
*/
std::string const &name () const;
/**
* Returns an alternate name for the function. The default
* implementation returns an empty string. However, this function
* may be overridden to return a non-empty string giving an
* alternate name for the function.
*/
virtual std::string alias() const;
/**
* Returns the number of parameters. A variadic function returns 0.
*/
unsigned int npar() const;
/**
* Returns true if the function returns integer values. The
* default implementation returns false. A function that returns
* integer values will need to overload this.
*
* @param mask Vector indicating whether parameters are discrete
* or not.
*/
virtual bool isDiscreteValued(std::vector<bool> const &mask) const;
/**
* Tests whether the function preserves scale transformations, i.e.
* it can be represented element-wise in the form f(x)[i] = B[i] * x[i].
*
* It is permitted for the isScale function to return false
* negatives, i.e. to return false when the function does preserve
* scale transformations. Since most functions are not scale
* transformations, the default method returns false.
*
* @param mask boolean vector of length equal to the number of
* parameters. The mask indicates a subset of parameters (those
* with value true) that are themselves scale transformations of
* x. The others are not functions of x. At least one element of
* mask must be true.
*
* @param isfixed boolean vector. This may be empty, in which case
* it is ignored. A non-empty vector must have length equal to
* mask, and denotes the parameters whose values are fixed. In
* this case the test is more restrictive, and returns true only
* if the coefficient B[i] is fixed for all i, assuming that the
* parameters for which mask is true are themselves fixed scale
* transformations.
*
* @see DeterministicNode#isClosed
*/
virtual bool isScale(std::vector<bool> const &mask,
std::vector<bool> const &isfixed) const;
/**
* Tests whether the function preserves linear transformations, i.e.
* a function of the form f(x) = A + B %*% x.
*
* All scale functions are linear functions. Therefore, the
* default method calls isScale. It only needs to be overridden
* for linear functions that are not scale functions.
*
* @see Function#isScale
*/
virtual bool isLinear(std::vector<bool> const &mask,
std::vector<bool> const &isfixed) const;
/**
* Tests whether the function preserves power transformations,
* i.e. can be expressed as f(x) = a*b^x for some value of a,b,
* where a,b, and x are all scalar.
*
* The default method returns false.
*/
virtual bool isPower(std::vector<bool> const &mask,
std::vector<bool> const &isfixed) const;
/**
* Returns a BUGS-language expression representing the function call.
* The default behaviour for a function named "foo" is to return
* "foo(arg1,arg2)". Functions that are represented as prefix or infix
* operators need to override this function.
*
* @param par Vector of parameter names for the function
*/
virtual std::string deparse(std::vector<std::string> const &par) const;
};
/**
* Checks that a vector of parameters of length npar is consistent
* with the function.
*/
inline bool checkNPar(Function const *func, unsigned int npar)
{
return (func->npar() == 0 && npar > 0) || func->npar() == npar;
}
} /* namespace jags */
#endif /* FUNCTION_H_ */

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks