RcsPySim
A robot control and simulation library
OMPartial.h
Go to the documentation of this file.
1 /*******************************************************************************
2  Copyright (c) 2020, Fabio Muratore, Honda Research Institute Europe GmbH, and
3  Technical University of Darmstadt.
4  All rights reserved.
5 
6  Redistribution and use in source and binary forms, with or without
7  modification, are permitted provided that the following conditions are met:
8  1. Redistributions of source code must retain the above copyright
9  notice, this list of conditions and the following disclaimer.
10  2. Redistributions in binary form must reproduce the above copyright
11  notice, this list of conditions and the following disclaimer in the
12  documentation and/or other materials provided with the distribution.
13  3. Neither the name of Fabio Muratore, Honda Research Institute Europe GmbH,
14  or Technical University of Darmstadt, nor the names of its contributors may
15  be used to endorse or promote products derived from this software without
16  specific prior written permission.
17 
18  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21  DISCLAIMED. IN NO EVENT SHALL FABIO MURATORE, HONDA RESEARCH INSTITUTE EUROPE GMBH,
22  OR TECHNICAL UNIVERSITY OF DARMSTADT BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
26  IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28  POSSIBILITY OF SUCH DAMAGE.
29 *******************************************************************************/
30 
31 #ifndef _OMPARTIAL_H_
32 #define _OMPARTIAL_H_
33 
34 #include "ObservationModel.h"
35 
36 namespace Rcs
37 {
38 
39 /**
40  * Applies partial observability by masking out certain state variables.
41  */
43 {
44 public:
45  typedef std::vector<unsigned int> IndexList;
46 
47  /**
48  * Create a partial observation model using only the specified indices.
49  * @param wrapped wrapped observation model. takes ownership.
50  * @param indices selected indices. Applied to both state and velocity, assuming their dimensions are equal.
51  * @param exclude set to true to invert the mask and keep only observations not in indices.
52  */
53  OMPartial(ObservationModel* wrapped, IndexList indices, bool exclude = false);
54 
55  /**
56  * Create a partial observation model using only the specified indices.
57  * @param wrapped wrapped observation model. takes ownership.
58  * @param stateIndices selected indices for state.
59  * @param velocityIndices selected indices for velocity.
60  * @param exclude set to true to invert the mask and keep only observations not in indices.
61  */
62  OMPartial(ObservationModel* wrapped, IndexList stateIndices, IndexList velocityIndices, bool exclude = false);
63 
64  /**
65  * Create a partial observation model using a boolean mask.
66  * The mask is applied to both state and velocity, assuming their dimensions are equal.
67  * @param wrapped wrapped observation model. takes ownership.
68  * @param mask true entries will be kept.
69  * @param exclude set to true to invert the mask
70  */
71  static OMPartial* fromMask(ObservationModel* wrapped, const std::vector<bool>& mask, bool exclude = false);
72 
73  /**
74  * Create a partial observation model using a boolean mask.
75  * @param wrapped wrapped observation model. takes ownership.
76  * @param stateMask mask for state. Length must match wrapped->getStateDim().
77  * @param velocityMask mask for velocity. Length must match wrapped->getVelocityDim().
78  * @param exclude set to true to invert the mask
79  */
80  static OMPartial*
81  fromMask(
82  ObservationModel* wrapped, const std::vector<bool>& stateMask, const std::vector<bool>& velocityMask,
83  bool exclude = false);
84 
85 
86  /**
87  * Create a partial observation model using a boolean mask.
88  * @param wrapped wrapped observation model. takes ownership.
89  * @param names selected entry names
90  * @param exclude set to true to invert the mask
91  * @param autoSelectVelocity set to true to automatically exclude the velocity corresponding to a state name
92  */
93  static OMPartial*
94  fromNames(
95  ObservationModel* wrapped, const std::vector<std::string>& names,
96  bool exclude = false,
97  bool autoSelectVelocity = false);
98 
99  virtual ~OMPartial();
100 
101  // not copy- or movable - klocwork doesn't pick up the inherited ones.
103 
104  virtual unsigned int getStateDim() const;
105 
106  virtual unsigned int getVelocityDim() const;
107 
108  virtual void computeObservation(double* state, double* velocity, const MatNd* currentAction, double dt) const;
109 
110  virtual void getLimits(double* minState, double* maxState, double* maxVelocity) const;
111 
112  virtual std::vector<std::string> getStateNames() const;
113 
114  virtual std::vector<std::string> getVelocityNames() const;
115 
116  virtual void reset();
117 
118  virtual std::vector<ObservationModel*> getNested() const;
119 
120 private:
121 
122  // Wrapped full observation model
124 
125  // Vector of indices kept
126  IndexList keptStateIndices;
128 };
129 
130 } /* namespace Rcs */
131 
132 #endif /* _OMPARTIAL_H_ */
OMPartial(ObservationModel *wrapped, IndexList indices, bool exclude=false)
Definition: OMPartial.cpp:92
#define RCSPYSIM_NOCOPY_NOMOVE(cls)
Definition: nocopy.h:40
virtual unsigned int getStateDim() const
Definition: OMPartial.cpp:189
virtual void getLimits(double *minState, double *maxState, double *maxVelocity) const
Definition: OMPartial.cpp:220
virtual ~OMPartial()
Definition: OMPartial.cpp:174
virtual void reset()
Definition: OMPartial.cpp:262
ObservationModel * wrapped
Definition: OMPartial.h:123
IndexList keptStateIndices
Definition: OMPartial.h:126
virtual std::vector< std::string > getStateNames() const
Definition: OMPartial.cpp:246
IndexList keptVelocityIndices
Definition: OMPartial.h:127
static OMPartial * fromMask(ObservationModel *wrapped, const std::vector< bool > &mask, bool exclude=false)
Definition: OMPartial.cpp:116
virtual std::vector< ObservationModel * > getNested() const
Definition: OMPartial.cpp:267
virtual unsigned int getVelocityDim() const
Definition: OMPartial.cpp:194
static OMPartial * fromNames(ObservationModel *wrapped, const std::vector< std::string > &names, bool exclude=false, bool autoSelectVelocity=false)
Definition: OMPartial.cpp:133
std::vector< unsigned int > IndexList
Definition: OMPartial.h:45
virtual void computeObservation(double *state, double *velocity, const MatNd *currentAction, double dt) const
Definition: OMPartial.cpp:199
virtual std::vector< std::string > getVelocityNames() const
Definition: OMPartial.cpp:254