/usr/include/shark/Models/ImpulseNoiseModel.h is in libshark-dev 3.0.1+ds1-2ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | /*!
*
*
* \brief Implements a Model which corrupts the input by setting values of the input to a given value
*
*
*
* \author O. Krause
* \date 2014
*
*
* \par Copyright 1995-2015 Shark Development Team
*
* <BR><HR>
* This file is part of Shark.
* <http://image.diku.dk/shark/>
*
* Shark is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Shark is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Shark. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef SHARK_MODELS_ImpulseNOISEMODEL_H
#define SHARK_MODELS_ImpulseNOISEMODEL_H
#include <shark/Models/AbstractModel.h>
#include <shark/Rng/GlobalRng.h>
#include <shark/Core/OpenMP.h>
namespace shark {
/// \brief Model which corrupts the data using Impulse noise
///
/// We define impulse noise as a noise which randomly sets the value of an element
/// in a vector to a given value, 0 by default. We chose the name as with for example
/// a noise of 1, impulses can be seen in the visualised vectors.
///
/// very input dimension is tested independently.
///
/// This noise can be used to implement denoising autoencoders for binary data.
class ImpulseNoiseModel : public AbstractModel<RealVector,RealVector>
{
private:
std::size_t m_numInputs;
double m_prob;
double m_value;
public:
/// Default Constructor; use setStructure later
ImpulseNoiseModel(){
m_features |= HAS_FIRST_PARAMETER_DERIVATIVE;
}
/// Constructor creating a model with given input size and a probability to set values of the input to a given value.
ImpulseNoiseModel(unsigned int inputs, double prob, double value = 0.0)
: m_numInputs(inputs), m_prob(prob), m_value(value){
m_features |= HAS_FIRST_PARAMETER_DERIVATIVE;
}
/// \brief From INameable: return the class name.
std::string name() const
{ return "ImpulseNoiseModel"; }
/// obtain the input dimension
size_t inputSize() const{
return m_numInputs;
}
/// obtain the output dimension
size_t outputSize() const{
return m_numInputs;
}
/// obtain the parameter vector
RealVector parameterVector() const{
return RealVector();
}
/// overwrite the parameter vector
void setParameterVector(RealVector const& newParameters)
{
SIZE_CHECK(newParameters.size() == 0);
}
/// return the number of parameter
size_t numberOfParameters() const{
return 0;
}
boost::shared_ptr<State> createState()const{
return boost::shared_ptr<State>(new EmptyState());
}
/// \brief Add noise to the input
void eval(BatchInputType const& inputs, BatchOutputType& outputs)const{
SIZE_CHECK(inputs.size2() == inputSize());
SHARK_CRITICAL_REGION{
outputs = inputs;
for(std::size_t i = 0; i != outputs.size1(); ++i){
for(std::size_t j = 0; j != outputs.size2(); ++j){
if(Rng::coinToss(m_prob)){
outputs(i,j) = m_value;
}
}
}
}
}
/// Evaluate the model: output = matrix * input + offset
void eval(BatchInputType const& inputs, BatchOutputType& outputs, State& state)const{
eval(inputs,outputs);
}
void weightedParameterDerivative(
BatchInputType const& patterns, RealVector const& coefficients, State const& state, RealVector& gradient
)const{
gradient.resize(0);
}
};
}
#endif
|