LCOV - code coverage report
Current view: top level - source - FunctionOntologicalClass.h (source / functions) Hit Total Coverage
Test: LibForBES Unit Tests Lines: 1 1 100.0 %
Date: 2016-04-18 Functions: 2 2 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* 
       2             :  * File:   FunctionOntologicalClass.h
       3             :  * Author: Pantelis Sopasakis
       4             :  *
       5             :  * Created on October 28, 2015, 8:07 PM
       6             :  * 
       7             :  * ForBES is free software: you can redistribute it and/or modify
       8             :  * it under the terms of the GNU Lesser General Public License as published by
       9             :  * the Free Software Foundation, either version 3 of the License, or
      10             :  * (at your option) any later version.
      11             :  *  
      12             :  * ForBES is distributed in the hope that it will be useful,
      13             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      14             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
      15             :  * GNU Lesser General Public License for more details.
      16             :  * 
      17             :  * You should have received a copy of the GNU Lesser General Public License
      18             :  * along with ForBES. If not, see <http://www.gnu.org/licenses/>.
      19             :  */
      20             : 
      21             : #ifndef FUNCTIONONTOLOGICALCLASS_H
      22             : #define FUNCTIONONTOLOGICALCLASS_H
      23             : 
      24             : #include <string>
      25             : #include <list>
      26             : #include <iostream>
      27             : 
      28             : using namespace std;
      29             : 
      30             : /**
      31             :  * \brief Ontological class referring to a ForBES function.
      32             :  * 
      33             :  * \see FunctionOntologyRegistry
      34             :  */
      35         586 : class FunctionOntologicalClass {
      36             : public:
      37             : 
      38             :     /**
      39             :      * Creates a new ontological class given its name/unique identifier.
      40             :      * @param name Name of the ontological class.
      41             :      */
      42             :     explicit FunctionOntologicalClass(std::string name);
      43             : 
      44             :     /**
      45             :      * Full constructor
      46             :      * @param does_define_conjugate whether the conjugate is defined
      47             :      * @param does_define_conjugate_grad whether the conj. gradient is defined
      48             :      * @param does_define_f whether f is defined
      49             :      * @param does_define_grad whether the gradient is defined
      50             :      * @param does_define_prox whether the proximal is defined
      51             :      * @param does_define_hessian whether Hessian-vector products are defined
      52             :      * @param does_define_hessian_conj whether conjugate Hessian-vector products are defined
      53             :      * @param name name (identifier) of the %Function category
      54             :      * @param super list of super-classes
      55             :      */
      56             :     FunctionOntologicalClass(
      57             :             bool does_define_conjugate,
      58             :             bool does_define_conjugate_grad,
      59             :             bool does_define_f,
      60             :             bool does_define_grad,
      61             :             bool does_define_prox,
      62             :             bool does_define_hessian,
      63             :             bool does_define_hessian_conj,
      64             :             std::string name,
      65             :             const FunctionOntologicalClass& super);
      66             : 
      67             :     /**
      68             :      * Default destructor.
      69             :      */
      70             :     virtual ~FunctionOntologicalClass();
      71             : 
      72             :     /**
      73             :      * Unique name (identifier) of the ontological class, e.g., "Quadratic".
      74             :      * 
      75             :      * @return Unique name/identifier as a string
      76             :      */
      77             :     std::string getName() const;
      78             : 
      79             :     /** 
      80             :      * Whether this function type defines \f$f(x)\f$.
      81             :      * @return <code>true</code> if \f$f\f$ is defined
      82             :      */
      83             :     bool defines_f() const;
      84             : 
      85             :     /** 
      86             :      * Whether this function type defines the gradient of 
      87             :      * \f$f\f$ at \f$x\f$, \f$\nabla f(x)\f$.
      88             :      * @return <code>true</code> if the gradient of \f$f\f$ is defined
      89             :      */
      90             :     bool defines_grad() const;
      91             : 
      92             :     /**
      93             :      * Whether this function type defines a conjugate \f$f^*(y)\f$
      94             :      * @return <code>true</code> if \f$f^*(y)\f$ is defined
      95             :      */
      96             :     bool defines_conjugate() const;
      97             : 
      98             :     /**
      99             :      * Whether this function type defines the gradient of its conjugate \f$\nabla f^*(y)\f$
     100             :      * @return <code>true</code> if \f$\nabla f^*(y)\f$ is defined
     101             :      */
     102             :     bool defines_conjugate_grad() const;
     103             : 
     104             :     /**
     105             :      * Whether this function defines a proximal \f$\mathrm{prox}_{\gamma f}(v)\f$
     106             :      * @return <code>true</code> if the proximal is defined
     107             :      */
     108             :     bool defines_prox() const;
     109             :     
     110             :     /**
     111             :      * Whether this function defines the Hessian of f, \f$\nabla^2 f(x)\f$
     112             :      * and allows the computation of products of the 
     113             :      * form \f$\langle \nabla^2 f(x), z\rangle,\f$ via \c Function::hessianProduct
     114             :      */
     115             :     bool defines_hessian() const;
     116             :     
     117             :     /**
     118             :      * Whether this function defines the Hessian of the conjugate of f, 
     119             :      * \f$\nabla^2 f^*(x)\f$ and allows the computation of products of the 
     120             :      * form \f$\langle \nabla^2 f^*(x), z\rangle,\f$ via \c Function::hessianProductConj
     121             :      */
     122             :     bool defines_hessian_conj() const;
     123             : 
     124             :     /**
     125             :      * Get the list of super-classes. Notice that the list is returned as an 
     126             :      * object an not as a reference!
     127             :      * 
     128             :      * @return list of super-classes.
     129             :      */
     130             :     std::list<FunctionOntologicalClass> getSuperclasses() const;
     131             : 
     132             :     /**
     133             :      * Add a super-class to the list of existing ones.
     134             :      * 
     135             :      * @param fun_ont_class super-class to be added as an instance of 
     136             :      * \c FunctionOntologicalClass.
     137             :      */
     138             :     void add_superclass(FunctionOntologicalClass fun_ont_class);
     139             :         
     140             :     friend std::ostream& operator<<(std::ostream& os, const FunctionOntologicalClass& obj);
     141             : 
     142             :     void set_defines_conjugate(bool defines_conjugate);
     143             : 
     144             :     void set_defines_conjugate_grad(bool defines_conjugate_grad);
     145             : 
     146             :     /**
     147             :      * Set whether \f$f\f$ is defined
     148             :      * @param defines_f
     149             :      */
     150             :     void set_defines_f(bool defines_f);
     151             : 
     152             :     /**
     153             :      * Set whether \f$\nabla f\f$ is defined
     154             :      * @param defines_grad
     155             :      */
     156             :     void set_defines_grad(bool defines_grad);
     157             : 
     158             :     /**
     159             :      * Set whether \f$\mathrm{prox}_{\gamma f}\f$ is defined
     160             :      * @param defines_prox
     161             :      */
     162             :     void set_defines_prox(bool defines_prox);
     163             :     
     164             :     /**
     165             :      * Specify whether products of the form \f$\langle \nabla^2 f(x), \cdot \rangle\f$
     166             :      * are defined
     167             :      * @param defines_hessian
     168             :      */
     169             :     void set_defines_hessian(bool defines_hessian);
     170             :     
     171             :     /**
     172             :      * Specify whether products of the form \f$\langle \nabla^2 f^*(x), \cdot \rangle\f$
     173             :      * are defined
     174             :      * @param defines_hessian_conj
     175             :      */
     176             :     void set_defines_hessian_conj(bool defines_hessian_conj);
     177             :     
     178             :     bool is_quadratic();
     179             :     bool is_conjugate_quadratic();
     180             : 
     181             : 
     182             : private:
     183             : 
     184             :     friend class FunctionOntologyRegistry;
     185             : 
     186             :     std::string m_name;             /**< Identifier of the ontological class (as string)                                */
     187             :     bool m_defines_f;               /**< Whether this function type defines f(x).                                       */
     188             :     bool m_defines_grad;            /**< Whether this function type defines the gradient of f at x, grad[f](x).         */
     189             :     bool m_defines_conjugate;       /**< Whether this function type defines a conjugate f*(x)                           */
     190             :     bool m_defines_conjugate_grad;  /**< Whether this function type defines the gradient of its conjugate grad[f*](x)   */
     191             :     bool m_defines_prox;            /**< Whether this function defines a proximal prox_{gamma f}(v)                     */
     192             :     bool m_defines_hessian;         /**< Whether this function defines the Hessian of f                                 */
     193             :     bool m_defines_hessian_conj;    /**< Whether this function defines the Hessian of f^*                               */
     194             : 
     195             :     std::list<FunctionOntologicalClass> superClasses; /**< List of super-classes */
     196             : 
     197             : 
     198             : 
     199             : };
     200             : 
     201             : 
     202             : 
     203             : #endif  /* FUNCTIONONTOLOGICALCLASS_H */
     204             : 

Generated by: LCOV version 1.10