Use 'Type' and typedef conventions for loss functions.
This commit is contained in:
@@ -57,7 +57,7 @@ template<
|
||||
* layer.
|
||||
*/
|
||||
template<
|
||||
typename OutputLayerType = NegativeLogLikelihood<>,
|
||||
typename OutputLayerType = NegativeLogLikelihood,
|
||||
typename InitializationRuleType = RandomInitialization,
|
||||
typename MatType = arma::mat>
|
||||
class FFN
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace ann /** Artificial Neural Network. */ {
|
||||
* arma::sp_mat or arma::cube).
|
||||
*/
|
||||
template<typename MatType = arma::mat>
|
||||
class BCELoss
|
||||
class BCELossType
|
||||
{
|
||||
public:
|
||||
/**
|
||||
@@ -38,7 +38,7 @@ class BCELoss
|
||||
* @param reduction Reduction type. If true, it returns the mean of
|
||||
* the loss. Else, it returns the sum.
|
||||
*/
|
||||
BCELoss(const double eps = 1e-10, const bool reduction = true);
|
||||
BCELossType(const double eps = 1e-10, const bool reduction = true);
|
||||
|
||||
/**
|
||||
* Computes the cross-entropy function.
|
||||
@@ -84,13 +84,17 @@ class BCELoss
|
||||
|
||||
//! Reduction type. If true, performs mean of loss else sum.
|
||||
bool reduction;
|
||||
}; // class BCELoss
|
||||
}; // class BCELossType
|
||||
|
||||
typedef BCELossType<arma::mat> BCELoss;
|
||||
|
||||
/**
|
||||
* Adding alias of BCELoss.
|
||||
* Alias of BCELossType.
|
||||
*/
|
||||
typedef BCELossType<arma::mat> CrossEntropyError;
|
||||
|
||||
template<typename MatType = arma::mat>
|
||||
using CrossEntropyError = BCELoss<MatType>;
|
||||
using CrossEntropyErrorType = BCELossType<MatType>;
|
||||
|
||||
} // namespace ann
|
||||
} // namespace mlpack
|
||||
|
||||
@@ -19,14 +19,14 @@ namespace mlpack {
|
||||
namespace ann /** Artificial Neural Network. */ {
|
||||
|
||||
template<typename MatType>
|
||||
BCELoss<MatType>::BCELoss(
|
||||
BCELossType<MatType>::BCELossType(
|
||||
const double eps, const bool reduction) : eps(eps), reduction(reduction)
|
||||
{
|
||||
// Nothing to do here.
|
||||
}
|
||||
|
||||
template<typename MatType>
|
||||
typename MatType::elem_type BCELoss<MatType>::Forward(
|
||||
typename MatType::elem_type BCELossType<MatType>::Forward(
|
||||
const MatType& prediction,
|
||||
const MatType& target)
|
||||
{
|
||||
@@ -40,7 +40,7 @@ typename MatType::elem_type BCELoss<MatType>::Forward(
|
||||
}
|
||||
|
||||
template<typename MatType>
|
||||
void BCELoss<MatType>::Backward(
|
||||
void BCELossType<MatType>::Backward(
|
||||
const MatType& prediction,
|
||||
const MatType& target,
|
||||
MatType& loss)
|
||||
@@ -52,7 +52,7 @@ void BCELoss<MatType>::Backward(
|
||||
|
||||
template<typename MatType>
|
||||
template<typename Archive>
|
||||
void BCELoss<MatType>::serialize(
|
||||
void BCELossType<MatType>::serialize(
|
||||
Archive& ar,
|
||||
const uint32_t /* version */)
|
||||
{
|
||||
|
||||
@@ -33,11 +33,11 @@ namespace ann /** Artificial Neural Network. */ {
|
||||
* arma::sp_mat or arma::cube).
|
||||
*/
|
||||
template<typename MatType = arma::mat>
|
||||
class CosineEmbeddingLoss
|
||||
class CosineEmbeddingLossType
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Create the CosineEmbeddingLoss object.
|
||||
* Create the CosineEmbeddingLossType object.
|
||||
*
|
||||
* @param margin Increases cosine distance in case of dissimilarity.
|
||||
* Refer definition of cosine-embedding-loss above.
|
||||
@@ -47,7 +47,7 @@ class CosineEmbeddingLoss
|
||||
* Specifies reduction method i.e. sum or mean corresponding
|
||||
* to 0 and 1 respectively. Default value = 0.
|
||||
*/
|
||||
CosineEmbeddingLoss(const double margin = 0.0,
|
||||
CosineEmbeddingLossType(const double margin = 0.0,
|
||||
const bool similarity = true,
|
||||
const bool takeMean = false);
|
||||
|
||||
@@ -103,7 +103,9 @@ class CosineEmbeddingLoss
|
||||
|
||||
//! Locally-stored value of takeMean hyper-parameter.
|
||||
bool takeMean;
|
||||
}; // class CosineEmbeddingLoss
|
||||
}; // class CosineEmbeddingLossType
|
||||
|
||||
typedef CosineEmbeddingLossType<arma::mat> CosineEmbeddingLoss;
|
||||
|
||||
} // namespace ann
|
||||
} // namespace mlpack
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace mlpack {
|
||||
namespace ann /** Artificial Neural Network. */ {
|
||||
|
||||
template<typename MatType>
|
||||
CosineEmbeddingLoss<MatType>::CosineEmbeddingLoss(
|
||||
CosineEmbeddingLossType<MatType>::CosineEmbeddingLossType(
|
||||
const double margin, const bool similarity, const bool takeMean):
|
||||
margin(margin), similarity(similarity), takeMean(takeMean)
|
||||
{
|
||||
@@ -27,7 +27,7 @@ CosineEmbeddingLoss<MatType>::CosineEmbeddingLoss(
|
||||
}
|
||||
|
||||
template<typename MatType>
|
||||
typename MatType::elem_type CosineEmbeddingLoss<MatType>::Forward(
|
||||
typename MatType::elem_type CosineEmbeddingLossType<MatType>::Forward(
|
||||
const MatType& prediction,
|
||||
const MatType& target)
|
||||
{
|
||||
@@ -63,7 +63,7 @@ typename MatType::elem_type CosineEmbeddingLoss<MatType>::Forward(
|
||||
}
|
||||
|
||||
template<typename MatType>
|
||||
void CosineEmbeddingLoss<MatType>::Backward(
|
||||
void CosineEmbeddingLossType<MatType>::Backward(
|
||||
const MatType& prediction,
|
||||
const MatType& target,
|
||||
MatType& loss)
|
||||
@@ -101,7 +101,7 @@ void CosineEmbeddingLoss<MatType>::Backward(
|
||||
|
||||
template<typename MatType>
|
||||
template<typename Archive>
|
||||
void CosineEmbeddingLoss<MatType>::serialize(
|
||||
void CosineEmbeddingLossType<MatType>::serialize(
|
||||
Archive& ar, const uint32_t /* version */)
|
||||
{
|
||||
ar(CEREAL_NVP(margin));
|
||||
|
||||
@@ -44,15 +44,15 @@ namespace ann /** Artificial Neural Network. */ {
|
||||
* arma::sp_mat or arma::cube).
|
||||
*/
|
||||
template<typename MatType = arma::mat>
|
||||
class DiceLoss
|
||||
class DiceLossType
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Create the DiceLoss object.
|
||||
* Create the DiceLossType object.
|
||||
*
|
||||
* @param smooth The Laplace smoothing parameter.
|
||||
*/
|
||||
DiceLoss(const double smooth = 1);
|
||||
DiceLossType(const double smooth = 1);
|
||||
|
||||
/**
|
||||
* Computes the dice loss function.
|
||||
@@ -90,7 +90,9 @@ class DiceLoss
|
||||
private:
|
||||
//! The parameter to avoid overfitting.
|
||||
double smooth;
|
||||
}; // class DiceLoss
|
||||
}; // class DiceLossType
|
||||
|
||||
typedef DiceLossType<arma::mat> DiceLoss;
|
||||
|
||||
} // namespace ann
|
||||
} // namespace mlpack
|
||||
|
||||
@@ -19,13 +19,13 @@ namespace mlpack {
|
||||
namespace ann /** Artificial Neural Network. */ {
|
||||
|
||||
template<typename MatType>
|
||||
DiceLoss<MatType>::DiceLoss(const double smooth) : smooth(smooth)
|
||||
DiceLossType<MatType>::DiceLossType(const double smooth) : smooth(smooth)
|
||||
{
|
||||
// Nothing to do here.
|
||||
}
|
||||
|
||||
template<typename MatType>
|
||||
typename MatType::elem_type DiceLoss<MatType>::Forward(
|
||||
typename MatType::elem_type DiceLossType<MatType>::Forward(
|
||||
const MatType& prediction,
|
||||
const MatType& target)
|
||||
{
|
||||
@@ -35,7 +35,7 @@ typename MatType::elem_type DiceLoss<MatType>::Forward(
|
||||
}
|
||||
|
||||
template<typename MatType>
|
||||
void DiceLoss<MatType>::Backward(
|
||||
void DiceLossType<MatType>::Backward(
|
||||
const MatType& prediction,
|
||||
const MatType& target,
|
||||
MatType& loss)
|
||||
@@ -49,7 +49,7 @@ void DiceLoss<MatType>::Backward(
|
||||
|
||||
template<typename MatType>
|
||||
template<typename Archive>
|
||||
void DiceLoss<MatType>::serialize(
|
||||
void DiceLossType<MatType>::serialize(
|
||||
Archive& ar,
|
||||
const uint32_t /* version */)
|
||||
{
|
||||
|
||||
@@ -27,13 +27,13 @@ namespace ann /** Artificial Neural Network. */ {
|
||||
* arma::sp_mat or arma::cube).
|
||||
*/
|
||||
template<typename MatType = arma::mat>
|
||||
class EarthMoverDistance
|
||||
class EarthMoverDistanceType
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Create the EarthMoverDistance object.
|
||||
* Create the EarthMoverDistanceType object.
|
||||
*/
|
||||
EarthMoverDistance();
|
||||
EarthMoverDistanceType();
|
||||
|
||||
/**
|
||||
* Ordinary feed forward pass of a neural network.
|
||||
@@ -61,8 +61,10 @@ class EarthMoverDistance
|
||||
* Serialize the layer.
|
||||
*/
|
||||
template<typename Archive>
|
||||
void serialize(Archive& ar, const uint32_t /* version */);
|
||||
}; // class EarthMoverDistance
|
||||
void serialize(Archive& ar, const uint32_t /* version */) { }
|
||||
}; // class EarthMoverDistanceType
|
||||
|
||||
typedef EarthMoverDistanceType<arma::mat> EarthMoverDistance;
|
||||
|
||||
} // namespace ann
|
||||
} // namespace mlpack
|
||||
|
||||
@@ -19,13 +19,13 @@ namespace mlpack {
|
||||
namespace ann /** Artificial Neural Network. */ {
|
||||
|
||||
template<typename MatType>
|
||||
EarthMoverDistance<MatType>::EarthMoverDistance()
|
||||
EarthMoverDistanceType<MatType>::EarthMoverDistanceType()
|
||||
{
|
||||
// Nothing to do here.
|
||||
}
|
||||
|
||||
template<typename MatType>
|
||||
typename MatType::elem_type EarthMoverDistance<MatType>::Forward(
|
||||
typename MatType::elem_type EarthMoverDistanceType<MatType>::Forward(
|
||||
const MatType& prediction,
|
||||
const MatType& target)
|
||||
{
|
||||
@@ -33,7 +33,7 @@ typename MatType::elem_type EarthMoverDistance<MatType>::Forward(
|
||||
}
|
||||
|
||||
template<typename MatType>
|
||||
void EarthMoverDistance<MatType>::Backward(
|
||||
void EarthMoverDistanceType<MatType>::Backward(
|
||||
const MatType& /* prediction */,
|
||||
const MatType& target,
|
||||
MatType& loss)
|
||||
@@ -41,15 +41,6 @@ void EarthMoverDistance<MatType>::Backward(
|
||||
loss = -target;
|
||||
}
|
||||
|
||||
template<typename MatType>
|
||||
template<typename Archive>
|
||||
void EarthMoverDistance<MatType>::serialize(
|
||||
Archive& /* ar */,
|
||||
const uint32_t /* version */)
|
||||
{
|
||||
/* Nothing to do here */
|
||||
}
|
||||
|
||||
} // namespace ann
|
||||
} // namespace mlpack
|
||||
|
||||
|
||||
@@ -29,13 +29,13 @@ namespace ann /** Artificial Neural Network. */ {
|
||||
* arma::sp_mat or arma::cube).
|
||||
*/
|
||||
template<typename MatType = arma::mat>
|
||||
class EmptyLoss
|
||||
class EmptyLossType
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Create the EmptyLoss object.
|
||||
* Create the EmptyLossType object.
|
||||
*/
|
||||
EmptyLoss();
|
||||
EmptyLossType();
|
||||
|
||||
/**
|
||||
* Computes the Empty loss function.
|
||||
@@ -58,10 +58,12 @@ class EmptyLoss
|
||||
const MatType& target,
|
||||
MatType& loss);
|
||||
|
||||
//! Serialize the EmptyLoss.
|
||||
//! Serialize the EmptyLossType.
|
||||
template<typename Archive>
|
||||
void serialize(Archive& ar, const uint32_t /* version */) { }
|
||||
}; // class EmptyLoss
|
||||
}; // class EmptyLossType
|
||||
|
||||
typedef EmptyLossType<arma::mat> EmptyLoss;
|
||||
|
||||
} // namespace ann
|
||||
} // namespace mlpack
|
||||
|
||||
@@ -21,20 +21,20 @@ namespace mlpack {
|
||||
namespace ann /** Artificial Neural Network. */ {
|
||||
|
||||
template<typename MatType>
|
||||
EmptyLoss<MatType>::EmptyLoss()
|
||||
EmptyLossType<MatType>::EmptyLossType()
|
||||
{
|
||||
// Nothing to do here.
|
||||
}
|
||||
|
||||
template<typename MatType>
|
||||
double EmptyLoss<MatType>::Forward(
|
||||
double EmptyLossType<MatType>::Forward(
|
||||
const MatType& /* prediction */, const MatType& /* target */)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
template<typename MatType>
|
||||
void EmptyLoss<MatType>::Backward(
|
||||
void EmptyLossType<MatType>::Backward(
|
||||
const MatType& /* prediction */,
|
||||
const MatType& target,
|
||||
MatType& loss)
|
||||
|
||||
@@ -30,13 +30,13 @@ namespace ann /** Artificial Neural Network. */ {
|
||||
* arma::sp_mat or arma::cube).
|
||||
*/
|
||||
template<typename MatType = arma::mat>
|
||||
class HingeEmbeddingLoss
|
||||
class HingeEmbeddingLossType
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Create the Hinge Embedding object.
|
||||
*/
|
||||
HingeEmbeddingLoss();
|
||||
HingeEmbeddingLossType();
|
||||
|
||||
/**
|
||||
* Computes the Hinge Embedding loss function.
|
||||
@@ -65,7 +65,9 @@ class HingeEmbeddingLoss
|
||||
*/
|
||||
template<typename Archive>
|
||||
void serialize(Archive& ar, const uint32_t /* version */) { }
|
||||
}; // class HingeEmbeddingLoss
|
||||
}; // class HingeEmbeddingLossType
|
||||
|
||||
typedef HingeEmbeddingLossType<arma::mat> HingeEmbeddingLoss;
|
||||
|
||||
} // namespace ann
|
||||
} // namespace mlpack
|
||||
|
||||
@@ -20,13 +20,13 @@ namespace mlpack {
|
||||
namespace ann /** Artificial Neural Network. */ {
|
||||
|
||||
template<typename MatType>
|
||||
HingeEmbeddingLoss<MatType>::HingeEmbeddingLoss()
|
||||
HingeEmbeddingLossType<MatType>::HingeEmbeddingLossType()
|
||||
{
|
||||
// Nothing to do here.
|
||||
}
|
||||
|
||||
template<typename MatType>
|
||||
typename MatType::elem_type HingeEmbeddingLoss<MatType>::Forward(
|
||||
typename MatType::elem_type HingeEmbeddingLossType<MatType>::Forward(
|
||||
const MatType& prediction,
|
||||
const MatType& target)
|
||||
{
|
||||
@@ -35,7 +35,7 @@ typename MatType::elem_type HingeEmbeddingLoss<MatType>::Forward(
|
||||
}
|
||||
|
||||
template<typename MatType>
|
||||
void HingeEmbeddingLoss<MatType>::Backward(
|
||||
void HingeEmbeddingLossType<MatType>::Backward(
|
||||
const MatType& prediction,
|
||||
const MatType& target,
|
||||
MatType& loss)
|
||||
|
||||
@@ -31,11 +31,11 @@ namespace ann /** Artificial Neural Network. */ {
|
||||
* arma::sp_mat or arma::cube).
|
||||
*/
|
||||
template<typename MatType = arma::mat>
|
||||
class HingeLoss
|
||||
class HingeLossType
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Create HingeLoss object.
|
||||
* Create HingeLossType object.
|
||||
*
|
||||
* @param reduction Specifies the reduction to apply to the output. If false,
|
||||
* 'mean' reduction is used, where sum of the output will be
|
||||
@@ -43,7 +43,7 @@ class HingeLoss
|
||||
* true, 'sum' reduction is used and the output will be
|
||||
* summed. It is set to true by default.
|
||||
*/
|
||||
HingeLoss(const bool reduction = true);
|
||||
HingeLossType(const bool reduction = true);
|
||||
|
||||
/**
|
||||
* Computes the Hinge loss function.
|
||||
@@ -81,7 +81,9 @@ class HingeLoss
|
||||
private:
|
||||
//! The boolean value that tells if reduction is sum or mean.
|
||||
bool reduction;
|
||||
}; // class HingeLoss
|
||||
}; // class HingeLossType
|
||||
|
||||
typedef HingeLossType<arma::mat> HingeLoss;
|
||||
|
||||
} // namespace ann
|
||||
} // namespace mlpack
|
||||
|
||||
@@ -20,14 +20,14 @@ namespace mlpack {
|
||||
namespace ann /** Artificial Neural Network. */ {
|
||||
|
||||
template<typename MatType>
|
||||
HingeLoss<MatType>::HingeLoss(const bool reduction):
|
||||
HingeLossType<MatType>::HingeLossType(const bool reduction):
|
||||
reduction(reduction)
|
||||
{
|
||||
// Nothing to do here.
|
||||
}
|
||||
|
||||
template<typename MatType>
|
||||
typename MatType::elem_type HingeLoss<MatType>::Forward(
|
||||
typename MatType::elem_type HingeLossType<MatType>::Forward(
|
||||
const MatType& prediction,
|
||||
const MatType& target)
|
||||
{
|
||||
@@ -45,7 +45,7 @@ typename MatType::elem_type HingeLoss<MatType>::Forward(
|
||||
}
|
||||
|
||||
template<typename MatType>
|
||||
void HingeLoss<MatType>::Backward(
|
||||
void HingeLossType<MatType>::Backward(
|
||||
const MatType& prediction,
|
||||
const MatType& target,
|
||||
MatType& loss)
|
||||
@@ -59,7 +59,7 @@ void HingeLoss<MatType>::Backward(
|
||||
|
||||
template<typename MatType>
|
||||
template<typename Archive>
|
||||
void HingeLoss<MatType>::serialize(
|
||||
void HingeLossType<MatType>::serialize(
|
||||
Archive& ar,
|
||||
const uint32_t /* version */)
|
||||
{
|
||||
|
||||
@@ -30,17 +30,17 @@ namespace ann /** Artificial Neural Network. */ {
|
||||
* arma::sp_mat or arma::cube).
|
||||
*/
|
||||
template<typename MatType = arma::mat>
|
||||
class HuberLoss
|
||||
class HuberLossType
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Create the HuberLoss object.
|
||||
* Create the HuberLossType object.
|
||||
*
|
||||
* @param delta The threshold value upto which squared error is followed and
|
||||
* after which absolute error is considered.
|
||||
* @param mean If true then mean loss is computed otherwise sum.
|
||||
*/
|
||||
HuberLoss(const double delta = 1.0, const bool mean = true);
|
||||
HuberLossType(const double delta = 1.0, const bool mean = true);
|
||||
|
||||
/**
|
||||
* Computes the Huber Loss function.
|
||||
@@ -86,7 +86,9 @@ class HuberLoss
|
||||
|
||||
//! Reduction type. If true, performs mean of loss else sum.
|
||||
bool mean;
|
||||
}; // class HuberLoss
|
||||
}; // class HuberLossType
|
||||
|
||||
typedef HuberLossType<arma::mat> HuberLoss;
|
||||
|
||||
} // namespace ann
|
||||
} // namespace mlpack
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace mlpack {
|
||||
namespace ann /** Artificial Neural Network. */ {
|
||||
|
||||
template<typename MatType>
|
||||
HuberLoss<MatType>::HuberLoss(
|
||||
HuberLossType<MatType>::HuberLossType(
|
||||
const double delta,
|
||||
const bool mean):
|
||||
delta(delta),
|
||||
@@ -29,7 +29,7 @@ HuberLoss<MatType>::HuberLoss(
|
||||
}
|
||||
|
||||
template<typename MatType>
|
||||
typename MatType::elem_type HuberLoss<MatType>::Forward(
|
||||
typename MatType::elem_type HuberLossType<MatType>::Forward(
|
||||
const MatType& prediction,
|
||||
const MatType& target)
|
||||
{
|
||||
@@ -45,7 +45,7 @@ typename MatType::elem_type HuberLoss<MatType>::Forward(
|
||||
}
|
||||
|
||||
template<typename MatType>
|
||||
void HuberLoss<MatType>::Backward(
|
||||
void HuberLossType<MatType>::Backward(
|
||||
const MatType& prediction,
|
||||
const MatType& target,
|
||||
MatType& loss)
|
||||
@@ -66,7 +66,7 @@ void HuberLoss<MatType>::Backward(
|
||||
|
||||
template<typename MatType>
|
||||
template<typename Archive>
|
||||
void HuberLoss<MatType>::serialize(
|
||||
void HuberLossType<MatType>::serialize(
|
||||
Archive& ar,
|
||||
const uint32_t /* version */)
|
||||
{
|
||||
|
||||
@@ -39,7 +39,7 @@ namespace ann /** Artificial Neural Network. */ {
|
||||
* arma::sp_mat or arma::cube).
|
||||
*/
|
||||
template<typename MatType = arma::mat>
|
||||
class KLDivergence
|
||||
class KLDivergenceType
|
||||
{
|
||||
public:
|
||||
/**
|
||||
@@ -48,7 +48,7 @@ class KLDivergence
|
||||
*
|
||||
* @param takeMean Boolean variable to specify whether to take mean or not.
|
||||
*/
|
||||
KLDivergence(const bool takeMean = false);
|
||||
KLDivergenceType(const bool takeMean = false);
|
||||
|
||||
/**
|
||||
* Computes the Kullback–Leibler divergence error function.
|
||||
@@ -86,7 +86,9 @@ class KLDivergence
|
||||
private:
|
||||
//! Boolean variable for taking mean or not.
|
||||
bool takeMean;
|
||||
}; // class KLDivergence
|
||||
}; // class KLDivergenceType
|
||||
|
||||
typedef KLDivergenceType<arma::mat> KLDivergence;
|
||||
|
||||
} // namespace ann
|
||||
} // namespace mlpack
|
||||
|
||||
@@ -20,14 +20,14 @@ namespace mlpack {
|
||||
namespace ann /** Artificial Neural Network. */ {
|
||||
|
||||
template<typename MatType>
|
||||
KLDivergence<MatType>::KLDivergence(const bool takeMean) :
|
||||
KLDivergenceType<MatType>::KLDivergenceType(const bool takeMean) :
|
||||
takeMean(takeMean)
|
||||
{
|
||||
// Nothing to do here.
|
||||
}
|
||||
|
||||
template<typename MatType>
|
||||
typename MatType::elem_type KLDivergence<MatType>::Forward(
|
||||
typename MatType::elem_type KLDivergenceType<MatType>::Forward(
|
||||
const MatType& prediction,
|
||||
const MatType& target)
|
||||
{
|
||||
@@ -43,7 +43,7 @@ typename MatType::elem_type KLDivergence<MatType>::Forward(
|
||||
}
|
||||
|
||||
template<typename MatType>
|
||||
void KLDivergence<MatType>::Backward(
|
||||
void KLDivergenceType<MatType>::Backward(
|
||||
const MatType& prediction,
|
||||
const MatType& target,
|
||||
MatType& loss)
|
||||
@@ -61,7 +61,7 @@ void KLDivergence<MatType>::Backward(
|
||||
|
||||
template<typename MatType>
|
||||
template<typename Archive>
|
||||
void KLDivergence<MatType>::serialize(
|
||||
void KLDivergenceType<MatType>::serialize(
|
||||
Archive& ar,
|
||||
const uint32_t /* version */)
|
||||
{
|
||||
|
||||
@@ -27,16 +27,16 @@ namespace ann /** Artificial Neural Network. */ {
|
||||
* arma::sp_mat or arma::cube).
|
||||
*/
|
||||
template<typename MatType = arma::mat>
|
||||
class L1Loss
|
||||
class L1LossType
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Create the L1Loss object.
|
||||
* Create the L1LossType object.
|
||||
*
|
||||
* @param mean Reduction type. If true, it returns the mean of
|
||||
* the loss. Else, it returns the sum.
|
||||
*/
|
||||
L1Loss(const bool mean = true);
|
||||
L1LossType(const bool mean = true);
|
||||
|
||||
/**
|
||||
* Computes the L1 Loss function.
|
||||
@@ -74,7 +74,9 @@ class L1Loss
|
||||
private:
|
||||
//! Reduction type. If true, performs mean of loss else sum.
|
||||
bool mean;
|
||||
}; // class L1Loss
|
||||
}; // class L1LossType
|
||||
|
||||
typedef L1LossType<arma::mat> L1Loss;
|
||||
|
||||
} // namespace ann
|
||||
} // namespace mlpack
|
||||
|
||||
@@ -19,14 +19,14 @@ namespace mlpack {
|
||||
namespace ann /** Artificial Neural Network. */ {
|
||||
|
||||
template<typename MatType>
|
||||
L1Loss<MatType>::L1Loss(const bool mean):
|
||||
L1LossType<MatType>::L1LossType(const bool mean):
|
||||
mean(mean)
|
||||
{
|
||||
// Nothing to do here.
|
||||
}
|
||||
|
||||
template<typename MatType>
|
||||
typename MatType::elem_type L1Loss<MatType>::Forward(
|
||||
typename MatType::elem_type L1LossType<MatType>::Forward(
|
||||
const MatType& prediction,
|
||||
const MatType& target)
|
||||
{
|
||||
@@ -37,7 +37,7 @@ typename MatType::elem_type L1Loss<MatType>::Forward(
|
||||
}
|
||||
|
||||
template<typename MatType>
|
||||
void L1Loss<MatType>::Backward(
|
||||
void L1LossType<MatType>::Backward(
|
||||
const MatType& prediction,
|
||||
const MatType& target,
|
||||
MatType& loss)
|
||||
@@ -47,7 +47,7 @@ void L1Loss<MatType>::Backward(
|
||||
|
||||
template<typename MatType>
|
||||
template<typename Archive>
|
||||
void L1Loss<MatType>::serialize(
|
||||
void L1LossType<MatType>::serialize(
|
||||
Archive& ar,
|
||||
const uint32_t /* version */)
|
||||
{
|
||||
|
||||
@@ -29,7 +29,7 @@ namespace ann /** Artificial Neural Network. */ {
|
||||
* arma::sp_mat or arma::cube).
|
||||
*/
|
||||
template<typename MatType = arma::mat>
|
||||
class LogCoshLoss
|
||||
class LogCoshLossType
|
||||
{
|
||||
public:
|
||||
/**
|
||||
@@ -43,7 +43,7 @@ class LogCoshLoss
|
||||
* function more sensitive to small losses around the
|
||||
* origin. Default value = 1.0.
|
||||
*/
|
||||
LogCoshLoss(const double a = 1.0);
|
||||
LogCoshLossType(const double a = 1.0);
|
||||
|
||||
/**
|
||||
* Computes the Log-Hyperbolic-Cosine loss function.
|
||||
@@ -81,7 +81,9 @@ class LogCoshLoss
|
||||
private:
|
||||
//! Hyperparameter a for smoothening function curve.
|
||||
double a;
|
||||
}; // class LogCoshLoss
|
||||
}; // class LogCoshLossType
|
||||
|
||||
typedef LogCoshLossType<arma::mat> LogCoshLoss;
|
||||
|
||||
} // namespace ann
|
||||
} // namespace mlpack
|
||||
|
||||
@@ -20,14 +20,14 @@ namespace mlpack {
|
||||
namespace ann /** Artificial Neural Network. */ {
|
||||
|
||||
template<typename MatType>
|
||||
LogCoshLoss<MatType>::LogCoshLoss(const double a) :
|
||||
LogCoshLossType<MatType>::LogCoshLossType(const double a) :
|
||||
a(a)
|
||||
{
|
||||
Log::Assert(a > 0, "Hyper-Parameter \'a\' must be positive");
|
||||
}
|
||||
|
||||
template<typename MatType>
|
||||
typename MatType::elem_type LogCoshLoss<MatType>::Forward(
|
||||
typename MatType::elem_type LogCoshLossType<MatType>::Forward(
|
||||
const MatType& prediction,
|
||||
const MatType& target)
|
||||
{
|
||||
@@ -35,7 +35,7 @@ typename MatType::elem_type LogCoshLoss<MatType>::Forward(
|
||||
}
|
||||
|
||||
template<typename MatType>
|
||||
void LogCoshLoss<MatType>::Backward(
|
||||
void LogCoshLossType<MatType>::Backward(
|
||||
const MatType& prediction,
|
||||
const MatType& target,
|
||||
MatType& loss)
|
||||
@@ -45,7 +45,7 @@ void LogCoshLoss<MatType>::Backward(
|
||||
|
||||
template<typename MatType>
|
||||
template<typename Archive>
|
||||
void LogCoshLoss<MatType>::serialize(
|
||||
void LogCoshLossType<MatType>::serialize(
|
||||
Archive& ar,
|
||||
const uint32_t /* version */)
|
||||
{
|
||||
|
||||
@@ -29,15 +29,15 @@ namespace ann /** Artificial Neural Network. */ {
|
||||
* arma::sp_mat or arma::cube).
|
||||
*/
|
||||
template<typename MatType = arma::mat>
|
||||
class MarginRankingLoss
|
||||
class MarginRankingLossType
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Create the MarginRankingLoss object with Hyperparameter margin.
|
||||
* Create the MarginRankingLossType object with Hyperparameter margin.
|
||||
* Hyperparameter margin defines a minimum distance between correctly ranked
|
||||
* samples.
|
||||
*/
|
||||
MarginRankingLoss(const double margin = 1.0);
|
||||
MarginRankingLossType(const double margin = 1.0);
|
||||
|
||||
/**
|
||||
* Computes the Margin Ranking Loss function.
|
||||
@@ -75,7 +75,9 @@ class MarginRankingLoss
|
||||
private:
|
||||
//! The margin value used in calculating Margin Ranking Loss.
|
||||
double margin;
|
||||
}; // class MarginRankingLoss
|
||||
}; // class MarginRankingLossType
|
||||
|
||||
typedef MarginRankingLossType<arma::mat> MarginRankingLoss;
|
||||
|
||||
} // namespace ann
|
||||
} // namespace mlpack
|
||||
|
||||
@@ -19,14 +19,14 @@ namespace mlpack {
|
||||
namespace ann /** Artifical Neural Network. */ {
|
||||
|
||||
template<typename MatType>
|
||||
MarginRankingLoss<MatType>::MarginRankingLoss(
|
||||
MarginRankingLossType<MatType>::MarginRankingLossType(
|
||||
const double margin) : margin(margin)
|
||||
{
|
||||
// Nothing to do here.
|
||||
}
|
||||
|
||||
template<typename MatType>
|
||||
typename MatType::elem_type MarginRankingLoss<MatType>::Forward(
|
||||
typename MatType::elem_type MarginRankingLossType<MatType>::Forward(
|
||||
const MatType& prediction,
|
||||
const MatType& target)
|
||||
{
|
||||
@@ -40,7 +40,7 @@ typename MatType::elem_type MarginRankingLoss<MatType>::Forward(
|
||||
}
|
||||
|
||||
template<typename MatType>
|
||||
void MarginRankingLoss<MatType>::Backward(
|
||||
void MarginRankingLossType<MatType>::Backward(
|
||||
const MatType& prediction,
|
||||
const MatType& target,
|
||||
MatType& loss)
|
||||
@@ -58,7 +58,7 @@ void MarginRankingLoss<MatType>::Backward(
|
||||
|
||||
template<typename MatType>
|
||||
template<typename Archive>
|
||||
void MarginRankingLoss<MatType>::serialize(
|
||||
void MarginRankingLossType<MatType>::serialize(
|
||||
Archive& ar,
|
||||
const uint32_t /* version */)
|
||||
{
|
||||
|
||||
@@ -43,13 +43,13 @@ namespace ann /** Artificial Neural Network. */ {
|
||||
* arma::sp_mat or arma::cube).
|
||||
*/
|
||||
template<typename MatType = arma::mat>
|
||||
class MeanAbsolutePercentageError
|
||||
class MeanAbsolutePercentageErrorType
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Create the MeanAbsolutePercentageError object.
|
||||
* Create the MeanAbsolutePercentageErrorType object.
|
||||
*/
|
||||
MeanAbsolutePercentageError();
|
||||
MeanAbsolutePercentageErrorType();
|
||||
|
||||
/**
|
||||
* Computes the mean absolute percentage error function.
|
||||
@@ -78,7 +78,9 @@ class MeanAbsolutePercentageError
|
||||
*/
|
||||
template<typename Archive>
|
||||
void serialize(Archive& ar, const unsigned int /* version */) { }
|
||||
}; // class MeanAbsolutePercentageError
|
||||
}; // class MeanAbsolutePercentageErrorType
|
||||
|
||||
typedef MeanAbsolutePercentageErrorType<arma::mat> MeanAbsolutePercentageError;
|
||||
|
||||
} // namespace ann
|
||||
} // namespace mlpack
|
||||
|
||||
@@ -19,13 +19,13 @@ namespace mlpack {
|
||||
namespace ann /** Artificial Neural Network. */ {
|
||||
|
||||
template<typename MatType>
|
||||
MeanAbsolutePercentageError<MatType>::MeanAbsolutePercentageError()
|
||||
MeanAbsolutePercentageErrorType<MatType>::MeanAbsolutePercentageErrorType()
|
||||
{
|
||||
// Nothing to do here.
|
||||
}
|
||||
|
||||
template<typename MatType>
|
||||
typename MatType::elem_type MeanAbsolutePercentageError<MatType>::Forward(
|
||||
typename MatType::elem_type MeanAbsolutePercentageErrorType<MatType>::Forward(
|
||||
const MatType& prediction,
|
||||
const MatType& target)
|
||||
{
|
||||
@@ -34,7 +34,7 @@ typename MatType::elem_type MeanAbsolutePercentageError<MatType>::Forward(
|
||||
}
|
||||
|
||||
template<typename MatType>
|
||||
void MeanAbsolutePercentageError<MatType>::Backward(
|
||||
void MeanAbsolutePercentageErrorType<MatType>::Backward(
|
||||
const MatType& prediction,
|
||||
const MatType& target,
|
||||
MatType& loss)
|
||||
|
||||
@@ -27,13 +27,13 @@ namespace ann /** Artificial Neural Network. */ {
|
||||
* arma::sp_mat or arma::cube).
|
||||
*/
|
||||
template<typename MatType = arma::mat>
|
||||
class MeanBiasError
|
||||
class MeanBiasErrorType
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Create the MeanBiasError object.
|
||||
* Create the MeanBiasErrorType object.
|
||||
*/
|
||||
MeanBiasError();
|
||||
MeanBiasErrorType();
|
||||
|
||||
/**
|
||||
* Computes the mean bias error function.
|
||||
@@ -62,7 +62,9 @@ class MeanBiasError
|
||||
*/
|
||||
template<typename Archive>
|
||||
void serialize(Archive& ar, const uint32_t /* version */);
|
||||
}; // class MeanBiasError
|
||||
}; // class MeanBiasErrorType
|
||||
|
||||
typedef MeanBiasErrorType<arma::mat> MeanBiasError;
|
||||
|
||||
} // namespace ann
|
||||
} // namespace mlpack
|
||||
|
||||
@@ -20,13 +20,13 @@ namespace mlpack {
|
||||
namespace ann /** Artificial Neural Network. */ {
|
||||
|
||||
template<typename MatType>
|
||||
MeanBiasError<MatType>::MeanBiasError()
|
||||
MeanBiasErrorType<MatType>::MeanBiasErrorType()
|
||||
{
|
||||
// Nothing to do here.
|
||||
}
|
||||
|
||||
template<typename MatType>
|
||||
typename MatType::elem_type MeanBiasError<MatType>::Forward(
|
||||
typename MatType::elem_type MeanBiasErrorType<MatType>::Forward(
|
||||
const MatType& prediction,
|
||||
const MatType& target)
|
||||
{
|
||||
@@ -34,7 +34,7 @@ typename MatType::elem_type MeanBiasError<MatType>::Forward(
|
||||
}
|
||||
|
||||
template<typename MatType>
|
||||
void MeanBiasError<MatType>::Backward(
|
||||
void MeanBiasErrorType<MatType>::Backward(
|
||||
const MatType& prediction,
|
||||
const MatType& /* target */,
|
||||
MatType& loss)
|
||||
|
||||
@@ -28,13 +28,13 @@ namespace ann /** Artificial Neural Network. */ {
|
||||
* arma::sp_mat or arma::cube).
|
||||
*/
|
||||
template<typename MatType = arma::mat>
|
||||
class MeanSquaredError
|
||||
class MeanSquaredErrorType
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Create the MeanSquaredError object.
|
||||
* Create the MeanSquaredErrorType object.
|
||||
*/
|
||||
MeanSquaredError();
|
||||
MeanSquaredErrorType();
|
||||
|
||||
/**
|
||||
* Computes the mean squared error function.
|
||||
@@ -63,7 +63,9 @@ class MeanSquaredError
|
||||
*/
|
||||
template<typename Archive>
|
||||
void serialize(Archive& ar, const uint32_t /* version */) { }
|
||||
}; // class MeanSquaredError
|
||||
}; // class MeanSquaredErrorType
|
||||
|
||||
typedef MeanSquaredErrorType<arma::mat> MeanSquaredError;
|
||||
|
||||
} // namespace ann
|
||||
} // namespace mlpack
|
||||
|
||||
@@ -19,13 +19,13 @@ namespace mlpack {
|
||||
namespace ann /** Artificial Neural Network. */ {
|
||||
|
||||
template<typename MatType>
|
||||
MeanSquaredError<MatType>::MeanSquaredError()
|
||||
MeanSquaredErrorType<MatType>::MeanSquaredErrorType()
|
||||
{
|
||||
// Nothing to do here.
|
||||
}
|
||||
|
||||
template<typename MatType>
|
||||
typename MatType::elem_type MeanSquaredError<MatType>::Forward(
|
||||
typename MatType::elem_type MeanSquaredErrorType<MatType>::Forward(
|
||||
const MatType& prediction,
|
||||
const MatType& target)
|
||||
{
|
||||
@@ -33,7 +33,7 @@ typename MatType::elem_type MeanSquaredError<MatType>::Forward(
|
||||
}
|
||||
|
||||
template<typename MatType>
|
||||
void MeanSquaredError<MatType>::Backward(
|
||||
void MeanSquaredErrorType<MatType>::Backward(
|
||||
const MatType& prediction,
|
||||
const MatType& target,
|
||||
MatType& loss)
|
||||
|
||||
@@ -27,13 +27,13 @@ namespace ann /** Artificial Neural Network. */ {
|
||||
* arma::sp_mat or arma::cube).
|
||||
*/
|
||||
template<typename MatType = arma::mat>
|
||||
class MeanSquaredLogarithmicError
|
||||
class MeanSquaredLogarithmicErrorType
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Create the MeanSquaredLogarithmicError object.
|
||||
* Create the MeanSquaredLogarithmicErrorType object.
|
||||
*/
|
||||
MeanSquaredLogarithmicError();
|
||||
MeanSquaredLogarithmicErrorType();
|
||||
|
||||
/**
|
||||
* Computes the mean squared logarithmic error function.
|
||||
@@ -62,7 +62,9 @@ class MeanSquaredLogarithmicError
|
||||
*/
|
||||
template<typename Archive>
|
||||
void serialize(Archive& ar, const uint32_t /* version */) { }
|
||||
}; // class MeanSquaredLogarithmicError
|
||||
}; // class MeanSquaredLogarithmicErrorType
|
||||
|
||||
typedef MeanSquaredLogarithmicErrorType<arma::mat> MeanSquaredLogarithmicError;
|
||||
|
||||
} // namespace ann
|
||||
} // namespace mlpack
|
||||
|
||||
@@ -19,14 +19,13 @@ namespace mlpack {
|
||||
namespace ann /** Artificial Neural Network. */ {
|
||||
|
||||
template<typename MatType>
|
||||
MeanSquaredLogarithmicError<MatType>
|
||||
::MeanSquaredLogarithmicError()
|
||||
MeanSquaredLogarithmicErrorType<MatType>::MeanSquaredLogarithmicErrorType()
|
||||
{
|
||||
// Nothing to do here.
|
||||
}
|
||||
|
||||
template<typename MatType>
|
||||
typename MatType::elem_type MeanSquaredLogarithmicError<MatType>::Forward(
|
||||
typename MatType::elem_type MeanSquaredLogarithmicErrorType<MatType>::Forward(
|
||||
const MatType& prediction,
|
||||
const MatType& target)
|
||||
{
|
||||
@@ -35,7 +34,7 @@ typename MatType::elem_type MeanSquaredLogarithmicError<MatType>::Forward(
|
||||
}
|
||||
|
||||
template<typename MatType>
|
||||
void MeanSquaredLogarithmicError<MatType>::Backward(
|
||||
void MeanSquaredLogarithmicErrorType<MatType>::Backward(
|
||||
const MatType& prediction,
|
||||
const MatType& target,
|
||||
MatType& loss)
|
||||
|
||||
@@ -28,11 +28,11 @@ namespace ann /** Artificial Neural Network. */ {
|
||||
* arma::sp_mat or arma::cube).
|
||||
*/
|
||||
template<typename MatType = arma::mat>
|
||||
class MultiLabelSoftMarginLoss
|
||||
class MultiLabelSoftMarginLossType
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Create the MultiLabelSoftMarginLoss object.
|
||||
* Create the MultiLabelSoftMarginLossType object.
|
||||
*
|
||||
* @param reduction Specifies the reduction to apply to the output. If false,
|
||||
* 'mean' reduction is used, where sum of the output will be
|
||||
@@ -42,7 +42,7 @@ class MultiLabelSoftMarginLoss
|
||||
* @param weights A manual rescaling weight given to each class. It is a
|
||||
* (1, numClasses) row vector.
|
||||
*/
|
||||
MultiLabelSoftMarginLoss(
|
||||
MultiLabelSoftMarginLossType(
|
||||
const bool reduction = true,
|
||||
const arma::Row<typename MatType::elem_type>& weights =
|
||||
arma::Row<typename MatType::elem_type>());
|
||||
@@ -98,7 +98,9 @@ class MultiLabelSoftMarginLoss
|
||||
|
||||
// An internal parameter used during initialisation of class weights.
|
||||
bool weighted;
|
||||
}; // class MultiLabelSoftMarginLoss
|
||||
}; // class MultiLabelSoftMarginLossType
|
||||
|
||||
typedef MultiLabelSoftMarginLossType<arma::mat> MultiLabelSoftMarginLoss;
|
||||
|
||||
} // namespace ann
|
||||
} // namespace mlpack
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace mlpack {
|
||||
namespace ann /** Artifical Neural Network. */ {
|
||||
|
||||
template<typename MatType>
|
||||
MultiLabelSoftMarginLoss<MatType>::MultiLabelSoftMarginLoss(
|
||||
MultiLabelSoftMarginLossType<MatType>::MultiLabelSoftMarginLossType(
|
||||
const bool reduction,
|
||||
const arma::Row<typename MatType::elem_type>& weights) :
|
||||
reduction(reduction),
|
||||
@@ -33,7 +33,7 @@ MultiLabelSoftMarginLoss<MatType>::MultiLabelSoftMarginLoss(
|
||||
}
|
||||
|
||||
template<typename MatType>
|
||||
typename MatType::elem_type MultiLabelSoftMarginLoss<MatType>::Forward(
|
||||
typename MatType::elem_type MultiLabelSoftMarginLossType<MatType>::Forward(
|
||||
const MatType& input, const MatType& target)
|
||||
{
|
||||
if (!weighted)
|
||||
@@ -54,7 +54,7 @@ typename MatType::elem_type MultiLabelSoftMarginLoss<MatType>::Forward(
|
||||
}
|
||||
|
||||
template<typename MatType>
|
||||
void MultiLabelSoftMarginLoss<MatType>::Backward(
|
||||
void MultiLabelSoftMarginLossType<MatType>::Backward(
|
||||
const MatType& input,
|
||||
const MatType& target,
|
||||
MatType& output)
|
||||
@@ -70,7 +70,7 @@ void MultiLabelSoftMarginLoss<MatType>::Backward(
|
||||
|
||||
template<typename MatType>
|
||||
template<typename Archive>
|
||||
void MultiLabelSoftMarginLoss<MatType>::serialize(
|
||||
void MultiLabelSoftMarginLossType<MatType>::serialize(
|
||||
Archive& ar,
|
||||
const unsigned int /* version */)
|
||||
{
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* @file methods/ann/loss_functions/negative_log_likelihood.hpp
|
||||
* @author Marcus Edel
|
||||
*
|
||||
* Definition of the NegativeLogLikelihood class.
|
||||
* Definition of the NegativeLogLikelihoodType class.
|
||||
*
|
||||
* mlpack is free software; you may redistribute it and/or modify it under the
|
||||
* terms of the 3-clause BSD license. You should have received a copy of the
|
||||
@@ -29,13 +29,13 @@ namespace ann /** Artificial Neural Network. */ {
|
||||
* arma::sp_mat or arma::cube).
|
||||
*/
|
||||
template<typename MatType = arma::mat>
|
||||
class NegativeLogLikelihood
|
||||
class NegativeLogLikelihoodType
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Create the NegativeLogLikelihoodLayer object.
|
||||
* Create the NegativeLogLikelihoodTypeLayer object.
|
||||
*/
|
||||
NegativeLogLikelihood();
|
||||
NegativeLogLikelihoodType();
|
||||
|
||||
/**
|
||||
* Computes the Negative log likelihood.
|
||||
@@ -69,7 +69,9 @@ class NegativeLogLikelihood
|
||||
*/
|
||||
template<typename Archive>
|
||||
void serialize(Archive& /* ar */, const uint32_t /* version */) { }
|
||||
}; // class NegativeLogLikelihood
|
||||
}; // class NegativeLogLikelihoodType
|
||||
|
||||
typedef NegativeLogLikelihoodType<arma::mat> NegativeLogLikelihood;
|
||||
|
||||
} // namespace ann
|
||||
} // namespace mlpack
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* @file methods/ann/loss_functions/negative_log_likelihood_impl.hpp
|
||||
* @author Marcus Edel
|
||||
*
|
||||
* Implementation of the NegativeLogLikelihood class.
|
||||
* Implementation of the NegativeLogLikelihoodType class.
|
||||
*
|
||||
* mlpack is free software; you may redistribute it and/or modify it under the
|
||||
* terms of the 3-clause BSD license. You should have received a copy of the
|
||||
@@ -19,13 +19,13 @@ namespace mlpack {
|
||||
namespace ann /** Artificial Neural Network. */ {
|
||||
|
||||
template<typename MatType>
|
||||
NegativeLogLikelihood<MatType>::NegativeLogLikelihood()
|
||||
NegativeLogLikelihoodType<MatType>::NegativeLogLikelihoodType()
|
||||
{
|
||||
// Nothing to do here.
|
||||
}
|
||||
|
||||
template<typename MatType>
|
||||
double NegativeLogLikelihood<MatType>::Forward(
|
||||
double NegativeLogLikelihoodType<MatType>::Forward(
|
||||
const MatType& prediction,
|
||||
const MatType& target)
|
||||
{
|
||||
@@ -42,7 +42,7 @@ double NegativeLogLikelihood<MatType>::Forward(
|
||||
}
|
||||
|
||||
template<typename MatType>
|
||||
void NegativeLogLikelihood<MatType>::Backward(
|
||||
void NegativeLogLikelihoodType<MatType>::Backward(
|
||||
const MatType& prediction,
|
||||
const MatType& target,
|
||||
MatType& loss)
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* @file methods/ann/loss_functions/poisson_nll_loss.hpp
|
||||
* @author Mrityunjay Tripathi
|
||||
*
|
||||
* Definition of the PoissonNLLLoss class. It is the negative log likelihood of
|
||||
* Definition of the PoissonNLLLossType class. It is the negative log likelihood of
|
||||
* the Poisson distribution.
|
||||
*
|
||||
* mlpack is free software; you may redistribute it and/or modify it under the
|
||||
@@ -30,11 +30,11 @@ namespace ann /** Artificial Neural Network. */ {
|
||||
* arma::sp_mat or arma::cube).
|
||||
*/
|
||||
template<typename MatType = arma::mat>
|
||||
class PoissonNLLLoss
|
||||
class PoissonNLLLossType
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Create the PoissonNLLLoss object.
|
||||
* Create the PoissonNLLLossType object.
|
||||
*
|
||||
* @param logInput If true the loss is computed as
|
||||
* \f$ \exp(input) - target \cdot input \f$, if false then the loss is
|
||||
@@ -44,7 +44,7 @@ class PoissonNLLLoss
|
||||
* @param eps A small value to prevent 0 in denominators and logarithms.
|
||||
* @param mean When true, mean loss is computed otherwise total loss.
|
||||
*/
|
||||
PoissonNLLLoss(const bool logInput = true,
|
||||
PoissonNLLLossType(const bool logInput = true,
|
||||
const bool full = false,
|
||||
const typename MatType::elem_type eps = 1e-08,
|
||||
const bool mean = true);
|
||||
@@ -135,7 +135,9 @@ class PoissonNLLLoss
|
||||
|
||||
//! Boolean value that tells if mean of the total loss has to be taken.
|
||||
bool mean;
|
||||
}; // class PoissonNLLLoss
|
||||
}; // class PoissonNLLLossType
|
||||
|
||||
typedef PoissonNLLLossType<arma::mat> PoissonNLLLoss;
|
||||
|
||||
} // namespace ann
|
||||
} // namespace mlpack
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* @file methods/ann/loss_functions/poisson_nll_loss_impl.hpp
|
||||
* @author Mrityunjay Tripathi
|
||||
*
|
||||
* Implementation of the PoissonNLLLoss class.
|
||||
* Implementation of the PoissonNLLLossType class.
|
||||
*
|
||||
* mlpack is free software; you may redistribute it and/or modify it under the
|
||||
* terms of the 3-clause BSD license. You should have received a copy of the
|
||||
@@ -20,7 +20,7 @@ namespace mlpack {
|
||||
namespace ann /** Artificial Neural Network. */ {
|
||||
|
||||
template<typename MatType>
|
||||
PoissonNLLLoss<MatType>::PoissonNLLLoss(
|
||||
PoissonNLLLossType<MatType>::PoissonNLLLossType(
|
||||
const bool logInput,
|
||||
const bool full,
|
||||
const typename MatType::elem_type eps,
|
||||
@@ -34,7 +34,7 @@ PoissonNLLLoss<MatType>::PoissonNLLLoss(
|
||||
}
|
||||
|
||||
template<typename MatType>
|
||||
typename MatType::elem_type PoissonNLLLoss<MatType>::Forward(
|
||||
typename MatType::elem_type PoissonNLLLossType<MatType>::Forward(
|
||||
const MatType& prediction,
|
||||
const MatType& target)
|
||||
{
|
||||
@@ -60,7 +60,7 @@ typename MatType::elem_type PoissonNLLLoss<MatType>::Forward(
|
||||
}
|
||||
|
||||
template<typename MatType>
|
||||
void PoissonNLLLoss<MatType>::Backward(
|
||||
void PoissonNLLLossType<MatType>::Backward(
|
||||
const MatType& prediction,
|
||||
const MatType& target,
|
||||
MatType& loss)
|
||||
@@ -78,7 +78,7 @@ void PoissonNLLLoss<MatType>::Backward(
|
||||
|
||||
template<typename MatType>
|
||||
template<typename Archive>
|
||||
void PoissonNLLLoss<MatType>::serialize(
|
||||
void PoissonNLLLossType<MatType>::serialize(
|
||||
Archive& ar,
|
||||
const uint32_t /* version */)
|
||||
{
|
||||
|
||||
@@ -33,13 +33,13 @@ template<
|
||||
typename MatType = arma::mat,
|
||||
typename DistType = BernoulliDistribution<MatType>
|
||||
>
|
||||
class ReconstructionLoss
|
||||
class ReconstructionLossType
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Create the ReconstructionLoss object.
|
||||
* Create the ReconstructionLossType object.
|
||||
*/
|
||||
ReconstructionLoss();
|
||||
ReconstructionLossType();
|
||||
|
||||
/**
|
||||
* Computes the reconstruction loss.
|
||||
@@ -72,7 +72,9 @@ class ReconstructionLoss
|
||||
private:
|
||||
//! Locally-stored distribution object.
|
||||
DistType dist;
|
||||
}; // class ReconstructionLoss
|
||||
}; // class ReconstructionLossType
|
||||
|
||||
typedef ReconstructionLossType<arma::mat> ReconstructionLoss;
|
||||
|
||||
} // namespace ann
|
||||
} // namespace mlpack
|
||||
|
||||
@@ -19,13 +19,13 @@ namespace mlpack {
|
||||
namespace ann /** Artificial Neural Network. */ {
|
||||
|
||||
template<typename MatType, typename DistType>
|
||||
ReconstructionLoss<MatType, DistType>::ReconstructionLoss()
|
||||
ReconstructionLossType<MatType, DistType>::ReconstructionLossType()
|
||||
{
|
||||
// Nothing to do here.
|
||||
}
|
||||
|
||||
template<typename MatType, typename DistType>
|
||||
typename MatType::elem_type ReconstructionLoss<MatType, DistType>::Forward(
|
||||
typename MatType::elem_type ReconstructionLossType<MatType, DistType>::Forward(
|
||||
const MatType& prediction, const MatType& target)
|
||||
{
|
||||
dist = DistType(prediction);
|
||||
@@ -33,7 +33,7 @@ typename MatType::elem_type ReconstructionLoss<MatType, DistType>::Forward(
|
||||
}
|
||||
|
||||
template<typename MatType, typename DistType>
|
||||
void ReconstructionLoss<MatType, DistType>::Backward(
|
||||
void ReconstructionLossType<MatType, DistType>::Backward(
|
||||
const MatType& /* prediction */,
|
||||
const MatType& target,
|
||||
MatType& loss)
|
||||
@@ -44,7 +44,7 @@ void ReconstructionLoss<MatType, DistType>::Backward(
|
||||
|
||||
template<typename MatType, typename DistType>
|
||||
template<typename Archive>
|
||||
void ReconstructionLoss<MatType, DistType>::serialize(
|
||||
void ReconstructionLossType<MatType, DistType>::serialize(
|
||||
Archive& ar,
|
||||
const uint32_t /* version */)
|
||||
{
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace mlpack {
|
||||
namespace ann /** Artificial Neural Network. */ {
|
||||
|
||||
/**
|
||||
* The SigmoidCrossEntropyError performance function measures the network's
|
||||
* The SigmoidCrossEntropyErrorType performance function measures the network's
|
||||
* performance according to the cross-entropy function between the input and
|
||||
* target distributions. This function calculates the cross entropy
|
||||
* given the real values instead of providing the sigmoid activations.
|
||||
@@ -46,13 +46,13 @@ namespace ann /** Artificial Neural Network. */ {
|
||||
* arma::sp_mat or arma::cube).
|
||||
*/
|
||||
template<typename MatType = arma::mat>
|
||||
class SigmoidCrossEntropyError
|
||||
class SigmoidCrossEntropyErrorType
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Create the SigmoidCrossEntropyError object.
|
||||
* Create the SigmoidCrossEntropyErrorType object.
|
||||
*/
|
||||
SigmoidCrossEntropyError();
|
||||
SigmoidCrossEntropyErrorType();
|
||||
|
||||
/**
|
||||
* Computes the Sigmoid CrossEntropy Error functions.
|
||||
@@ -82,7 +82,9 @@ class SigmoidCrossEntropyError
|
||||
*/
|
||||
template<typename Archive>
|
||||
void serialize(Archive& ar, const uint32_t /* version */) { }
|
||||
}; // class SigmoidCrossEntropy
|
||||
}; // class SigmoidCrossEntropyErrorType
|
||||
|
||||
typedef SigmoidCrossEntropyErrorType<arma::mat> SigmoidCrossEntropyError;
|
||||
|
||||
} // namespace ann
|
||||
} // namespace mlpack
|
||||
|
||||
@@ -21,13 +21,14 @@ namespace mlpack {
|
||||
namespace ann /** Artificial Neural Network. */ {
|
||||
|
||||
template<typename MatType>
|
||||
SigmoidCrossEntropyError<MatType>::SigmoidCrossEntropyError()
|
||||
SigmoidCrossEntropyErrorType<MatType>::SigmoidCrossEntropyErrorType()
|
||||
{
|
||||
// Nothing to do here.
|
||||
}
|
||||
|
||||
template<typename MatType>
|
||||
inline typename MatType::elem_type SigmoidCrossEntropyError<MatType>::Forward(
|
||||
inline typename MatType::elem_type
|
||||
SigmoidCrossEntropyErrorType<MatType>::Forward(
|
||||
const MatType& prediction,
|
||||
const MatType& target)
|
||||
{
|
||||
@@ -43,7 +44,7 @@ inline typename MatType::elem_type SigmoidCrossEntropyError<MatType>::Forward(
|
||||
}
|
||||
|
||||
template<typename MatType>
|
||||
inline void SigmoidCrossEntropyError<MatType>::Backward(
|
||||
inline void SigmoidCrossEntropyErrorType<MatType>::Backward(
|
||||
const MatType& prediction,
|
||||
const MatType& target,
|
||||
MatType& loss)
|
||||
|
||||
@@ -28,11 +28,11 @@ namespace ann /** Artificial Neural Network. */ {
|
||||
* arma::sp_mat or arma::cube).
|
||||
*/
|
||||
template<typename MatType = arma::mat>
|
||||
class SoftMarginLoss
|
||||
class SoftMarginLossType
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Create the SoftMarginLoss object.
|
||||
* Create the SoftMarginLossType object.
|
||||
*
|
||||
* @param reduction Specifies the reduction to apply to the output. If false,
|
||||
* 'mean' reduction is used, where sum of the output will be
|
||||
@@ -40,7 +40,7 @@ class SoftMarginLoss
|
||||
* true, 'sum' reduction is used and the output will be
|
||||
* summed. It is set to true by default.
|
||||
*/
|
||||
SoftMarginLoss(const bool reduction = true);
|
||||
SoftMarginLossType(const bool reduction = true);
|
||||
|
||||
/**
|
||||
* Computes the Soft Margin Loss function.
|
||||
@@ -78,7 +78,9 @@ class SoftMarginLoss
|
||||
private:
|
||||
//! The boolean value that tells if reduction is sum or mean.
|
||||
bool reduction;
|
||||
}; // class SoftMarginLoss
|
||||
}; // class SoftMarginLossType
|
||||
|
||||
typedef SoftMarginLossType<arma::mat> SoftMarginLoss;
|
||||
|
||||
} // namespace ann
|
||||
} // namespace mlpack
|
||||
|
||||
@@ -19,14 +19,14 @@ namespace mlpack {
|
||||
namespace ann /** Artifical Neural Network. */ {
|
||||
|
||||
template<typename MatType>
|
||||
SoftMarginLoss<MatType>::
|
||||
SoftMarginLoss(const bool reduction) : reduction(reduction)
|
||||
SoftMarginLossType<MatType>::
|
||||
SoftMarginLossType(const bool reduction) : reduction(reduction)
|
||||
{
|
||||
// Nothing to do here.
|
||||
}
|
||||
|
||||
template<typename MatType>
|
||||
typename MatType::elem_type SoftMarginLoss<MatType>::Forward(
|
||||
typename MatType::elem_type SoftMarginLossType<MatType>::Forward(
|
||||
const MatType& prediction, const MatType& target)
|
||||
{
|
||||
MatType loss = arma::log(1 + arma::exp(-target % prediction));
|
||||
@@ -39,7 +39,7 @@ typename MatType::elem_type SoftMarginLoss<MatType>::Forward(
|
||||
}
|
||||
|
||||
template<typename MatType>
|
||||
void SoftMarginLoss<MatType>::Backward(
|
||||
void SoftMarginLossType<MatType>::Backward(
|
||||
const MatType& prediction,
|
||||
const MatType& target,
|
||||
MatType& loss)
|
||||
@@ -56,7 +56,7 @@ void SoftMarginLoss<MatType>::Backward(
|
||||
|
||||
template<typename MatType>
|
||||
template<typename Archive>
|
||||
void SoftMarginLoss<MatType>::serialize(
|
||||
void SoftMarginLossType<MatType>::serialize(
|
||||
Archive& ar, const uint32_t /* version */)
|
||||
{
|
||||
ar(CEREAL_NVP(reduction));
|
||||
|
||||
@@ -42,17 +42,17 @@ namespace ann /** Artificial Neural Network. */ {
|
||||
* arma::sp_mat or arma::cube).
|
||||
*/
|
||||
template<typename MatType = arma::mat>
|
||||
class TripletMarginLoss
|
||||
class TripletMarginLossType
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Create the TripletMarginLoss object.
|
||||
* Create the TripletMarginLossType object.
|
||||
*
|
||||
* @param margin The minimum value by which the distance between
|
||||
* Anchor and Negative sample exceeds the distance
|
||||
* between Anchor and Positive sample.
|
||||
*/
|
||||
TripletMarginLoss(const double margin = 1.0);
|
||||
TripletMarginLossType(const double margin = 1.0);
|
||||
|
||||
/**
|
||||
* Computes the Triplet Margin Loss function.
|
||||
@@ -88,7 +88,9 @@ class TripletMarginLoss
|
||||
private:
|
||||
//! The margin value used in calculating Triplet Margin Loss.
|
||||
double margin;
|
||||
}; // class TripletLossMargin
|
||||
}; // class TripletMarginLoss
|
||||
|
||||
typedef TripletMarginLossType<arma::mat> TripletMarginLoss;
|
||||
|
||||
} // namespace ann
|
||||
} // namespace mlpack
|
||||
|
||||
@@ -20,14 +20,14 @@ namespace mlpack {
|
||||
namespace ann /** Artifical Neural Network. */ {
|
||||
|
||||
template<typename MatType>
|
||||
TripletMarginLoss<MatType>::TripletMarginLoss(const double margin) :
|
||||
TripletMarginLossType<MatType>::TripletMarginLossType(const double margin) :
|
||||
margin(margin)
|
||||
{
|
||||
// Nothing to do here.
|
||||
}
|
||||
|
||||
template<typename MatType>
|
||||
typename MatType::elem_type TripletMarginLoss<MatType>::Forward(
|
||||
typename MatType::elem_type TripletMarginLossType<MatType>::Forward(
|
||||
const MatType& prediction,
|
||||
const MatType& target)
|
||||
{
|
||||
@@ -41,7 +41,7 @@ typename MatType::elem_type TripletMarginLoss<MatType>::Forward(
|
||||
}
|
||||
|
||||
template<typename MatType>
|
||||
void TripletMarginLoss<MatType>::Backward(
|
||||
void TripletMarginLossType<MatType>::Backward(
|
||||
const MatType& prediction,
|
||||
const MatType& target,
|
||||
MatType& loss)
|
||||
@@ -54,7 +54,7 @@ void TripletMarginLoss<MatType>::Backward(
|
||||
|
||||
template<typename MatType>
|
||||
template<typename Archive>
|
||||
void TripletMarginLoss<MatType>::serialize(
|
||||
void TripletMarginLossType<MatType>::serialize(
|
||||
Archive& ar,
|
||||
const unsigned int /* version */)
|
||||
{
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* @file methods/ann/loss_functions/vr_class_reward.hpp
|
||||
* @author Marcus Edel
|
||||
*
|
||||
* Definition of the VRClassReward class, which implements the variance
|
||||
* Definition of the VRClassRewardType class, which implements the variance
|
||||
* reduced classification reinforcement layer.
|
||||
*
|
||||
* mlpack is free software; you may redistribute it and/or modify it under the
|
||||
@@ -30,16 +30,16 @@ namespace ann /** Artificial Neural Network. */ {
|
||||
* arma::sp_mat or arma::cube).
|
||||
*/
|
||||
template<typename MatType = arma::mat>
|
||||
class VRClassReward
|
||||
class VRClassRewardType
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Create the VRClassReward object.
|
||||
* Create the VRClassRewardType object.
|
||||
*
|
||||
* @param scale Parameter used to scale the reward.
|
||||
* @param sizeAverage Take the average over all batches.
|
||||
*/
|
||||
VRClassReward(const double scale = 1, const bool sizeAverage = true);
|
||||
VRClassRewardType(const double scale = 1, const bool sizeAverage = true);
|
||||
|
||||
/**
|
||||
* Ordinary feed forward pass of a neural network, evaluating the function
|
||||
@@ -112,7 +112,9 @@ class VRClassReward
|
||||
|
||||
//! Locally-stored network modules.
|
||||
std::vector<Layer<MatType>*> network;
|
||||
}; // class VRClassReward
|
||||
}; // class VRClassRewardType
|
||||
|
||||
typedef VRClassRewardType<arma::mat> VRClassReward;
|
||||
|
||||
} // namespace ann
|
||||
} // namespace mlpack
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* @file methods/ann/loss_functions/vr_class_reward_impl.hpp
|
||||
* @author Marcus Edel
|
||||
*
|
||||
* Implementation of the VRClassReward class, which implements the variance
|
||||
* Implementation of the VRClassRewardType class, which implements the variance
|
||||
* reduced classification reinforcement layer.
|
||||
*
|
||||
* mlpack is free software; you may redistribute it and/or modify it under the
|
||||
@@ -20,7 +20,7 @@ namespace mlpack {
|
||||
namespace ann /** Artificial Neural Network. */ {
|
||||
|
||||
template<typename MatType>
|
||||
VRClassReward<MatType>::VRClassReward(
|
||||
VRClassRewardType<MatType>::VRClassRewardType(
|
||||
const double scale,
|
||||
const bool sizeAverage) :
|
||||
scale(scale),
|
||||
@@ -31,7 +31,7 @@ VRClassReward<MatType>::VRClassReward(
|
||||
}
|
||||
|
||||
template<typename MatType>
|
||||
typename MatType::elem_type VRClassReward<MatType>::Forward(
|
||||
typename MatType::elem_type VRClassRewardType<MatType>::Forward(
|
||||
const MatType& input, const MatType& target)
|
||||
{
|
||||
double output = 0;
|
||||
@@ -61,7 +61,7 @@ typename MatType::elem_type VRClassReward<MatType>::Forward(
|
||||
}
|
||||
|
||||
template<typename MatType>
|
||||
void VRClassReward<MatType>::Backward(
|
||||
void VRClassRewardType<MatType>::Backward(
|
||||
const MatType& input,
|
||||
const MatType& target,
|
||||
MatType& output)
|
||||
@@ -89,7 +89,7 @@ void VRClassReward<MatType>::Backward(
|
||||
|
||||
template<typename MatType>
|
||||
template<typename Archive>
|
||||
void VRClassReward<MatType>::serialize(
|
||||
void VRClassRewardType<MatType>::serialize(
|
||||
Archive& ar, const uint32_t /* version */)
|
||||
{
|
||||
ar(scale);
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace ann /** Artificial Neural Network. */ {
|
||||
* @tparam InitializationRuleType Rule used to initialize the weight matrix.
|
||||
*/
|
||||
template<
|
||||
typename OutputLayerType = NegativeLogLikelihood<>,
|
||||
typename OutputLayerType = NegativeLogLikelihood,
|
||||
typename InitializationRuleType = RandomInitialization,
|
||||
typename MatType = arma::mat>
|
||||
class RNN
|
||||
|
||||
@@ -139,7 +139,7 @@ TEST_CASE("GradientAddLayerTest", "[ANNLayerTest]")
|
||||
input(arma::randu(10, 1)),
|
||||
target(arma::mat("0"))
|
||||
{
|
||||
model = new FFN<NegativeLogLikelihood<>, NguyenWidrowInitialization>();
|
||||
model = new FFN<NegativeLogLikelihood, NguyenWidrowInitialization>();
|
||||
model->ResetData(input, target);
|
||||
model->Add<IdentityLayer>();
|
||||
model->Add<Linear>(10, 10);
|
||||
@@ -161,7 +161,7 @@ TEST_CASE("GradientAddLayerTest", "[ANNLayerTest]")
|
||||
|
||||
arma::mat& Parameters() { return model->Parameters(); }
|
||||
|
||||
FFN<NegativeLogLikelihood<>, NguyenWidrowInitialization>* model;
|
||||
FFN<NegativeLogLikelihood, NguyenWidrowInitialization>* model;
|
||||
arma::mat input, target;
|
||||
} function;
|
||||
|
||||
@@ -466,7 +466,7 @@ TEST_CASE("NoAlphaDropoutTest", "[ANNLayerTest]")
|
||||
// input(arma::randu(10, 1)),
|
||||
// target(arma::mat("1"))
|
||||
// {
|
||||
// model = new FFN<NegativeLogLikelihood<>, NguyenWidrowInitialization>();
|
||||
// model = new FFN<NegativeLogLikelihood, NguyenWidrowInitialization>();
|
||||
// model->ResetData(input, target);
|
||||
// model->Add<IdentityLayer<> >();
|
||||
// model->Add<Linear<> >(10, 10);
|
||||
@@ -488,7 +488,7 @@ TEST_CASE("NoAlphaDropoutTest", "[ANNLayerTest]")
|
||||
|
||||
// arma::mat& Parameters() { return model->Parameters(); }
|
||||
|
||||
// FFN<NegativeLogLikelihood<>, NguyenWidrowInitialization>* model;
|
||||
// FFN<NegativeLogLikelihood, NguyenWidrowInitialization>* model;
|
||||
// arma::mat input, target;
|
||||
// } function;
|
||||
|
||||
@@ -579,7 +579,7 @@ TEST_CASE("GradientLinear3DLayerTest", "[ANNLayerTest]")
|
||||
target(1, 1) = 1;
|
||||
target(1, 2) = 1;
|
||||
|
||||
model = new FFN<MeanSquaredError<>, RandomInitialization>();
|
||||
model = new FFN<MeanSquaredError, RandomInitialization>();
|
||||
model->ResetData(input, target);
|
||||
model->Add<Linear3D>(outSize);
|
||||
model->InputDimensions() = std::vector<size_t>{ 4, 2 };
|
||||
@@ -599,7 +599,7 @@ TEST_CASE("GradientLinear3DLayerTest", "[ANNLayerTest]")
|
||||
|
||||
arma::mat& Parameters() { return model->Parameters(); }
|
||||
|
||||
FFN<MeanSquaredError<>, RandomInitialization>* model;
|
||||
FFN<MeanSquaredError, RandomInitialization>* model;
|
||||
arma::mat input, target;
|
||||
const size_t inSize;
|
||||
const size_t outSize;
|
||||
@@ -655,7 +655,7 @@ TEST_CASE("GradientLinear3DLayerTest", "[ANNLayerTest]")
|
||||
// input(arma::randu(10, 1)),
|
||||
// target(arma::mat("1"))
|
||||
// {
|
||||
// model = new FFN<NegativeLogLikelihood<>, NguyenWidrowInitialization>();
|
||||
// model = new FFN<NegativeLogLikelihood, NguyenWidrowInitialization>();
|
||||
// model->ResetData(input, target);
|
||||
// model->Add<IdentityLayer<> >();
|
||||
// model->Add<NoisyLinear<> >(10, 10);
|
||||
@@ -677,7 +677,7 @@ TEST_CASE("GradientLinear3DLayerTest", "[ANNLayerTest]")
|
||||
|
||||
// arma::mat& Parameters() { return model->Parameters(); }
|
||||
|
||||
// FFN<NegativeLogLikelihood<>, NguyenWidrowInitialization>* model;
|
||||
// FFN<NegativeLogLikelihood, NguyenWidrowInitialization>* model;
|
||||
// arma::mat input, target;
|
||||
// } function;
|
||||
|
||||
@@ -808,7 +808,7 @@ TEST_CASE("GradientLinearNoBiasLayerTest", "[ANNLayerTest]")
|
||||
input(arma::randu(10, 1)),
|
||||
target(arma::mat("0"))
|
||||
{
|
||||
model = new FFN<NegativeLogLikelihood<>, NguyenWidrowInitialization>();
|
||||
model = new FFN<NegativeLogLikelihood, NguyenWidrowInitialization>();
|
||||
model->ResetData(input, target);
|
||||
model->Add<Linear>(10);
|
||||
model->Add<LinearNoBias>(2);
|
||||
@@ -829,7 +829,7 @@ TEST_CASE("GradientLinearNoBiasLayerTest", "[ANNLayerTest]")
|
||||
|
||||
arma::mat& Parameters() { return model->Parameters(); }
|
||||
|
||||
FFN<NegativeLogLikelihood<>, NguyenWidrowInitialization>* model;
|
||||
FFN<NegativeLogLikelihood, NguyenWidrowInitialization>* model;
|
||||
arma::mat input, target;
|
||||
} function;
|
||||
|
||||
@@ -843,7 +843,7 @@ TEST_CASE("GradientLinearNoBiasLayerTest", "[ANNLayerTest]")
|
||||
// {
|
||||
// for (size_t i = 0; i < 5; ++i)
|
||||
// {
|
||||
// NegativeLogLikelihood<> module;
|
||||
// NegativeLogLikelihood module;
|
||||
// const size_t inputElements = math::RandInt(5, 100);
|
||||
// arma::mat input;
|
||||
// RandomInitialization init(0, 1);
|
||||
@@ -909,8 +909,8 @@ TEST_CASE("GradientFlexibleReLULayerTest", "[ANNLayerTest]")
|
||||
input(arma::randu(2, 1)),
|
||||
target(arma::mat("0"))
|
||||
{
|
||||
model = new FFN<NegativeLogLikelihood<>, RandomInitialization>(
|
||||
NegativeLogLikelihood<>(), RandomInitialization(0.1, 0.5));
|
||||
model = new FFN<NegativeLogLikelihood, RandomInitialization>(
|
||||
NegativeLogLikelihood(), RandomInitialization(0.1, 0.5));
|
||||
|
||||
model->ResetData(input, target);
|
||||
model->Add<Linear>(2, 2);
|
||||
@@ -933,7 +933,7 @@ TEST_CASE("GradientFlexibleReLULayerTest", "[ANNLayerTest]")
|
||||
|
||||
arma::mat& Parameters() { return model->Parameters(); }
|
||||
|
||||
FFN<NegativeLogLikelihood<>, RandomInitialization>* model;
|
||||
FFN<NegativeLogLikelihood, RandomInitialization>* model;
|
||||
arma::mat input, target;
|
||||
} function;
|
||||
|
||||
@@ -1129,8 +1129,8 @@ TEST_CASE("SimpleJoinLayerTest", "[ANNLayerTest]")
|
||||
// RandomInitialization init(0.5, 0.5);
|
||||
|
||||
// // Create model with user defined rho parameter.
|
||||
// RNN<NegativeLogLikelihood<>, RandomInitialization> modelA(
|
||||
// rho, false, NegativeLogLikelihood<>(), init);
|
||||
// RNN<NegativeLogLikelihood, RandomInitialization> modelA(
|
||||
// rho, false, NegativeLogLikelihood(), init);
|
||||
// modelA.Add<IdentityLayer<> >();
|
||||
// modelA.Add<Linear<> >(1, 10);
|
||||
|
||||
@@ -1139,8 +1139,8 @@ TEST_CASE("SimpleJoinLayerTest", "[ANNLayerTest]")
|
||||
// modelA.Add<LogSoftMax<> >();
|
||||
|
||||
// // Create model without user defined rho parameter.
|
||||
// RNN<NegativeLogLikelihood<> > modelB(
|
||||
// rho, false, NegativeLogLikelihood<>(), init);
|
||||
// RNN<NegativeLogLikelihood> modelB(
|
||||
// rho, false, NegativeLogLikelihood(), init);
|
||||
// modelB.Add<IdentityLayer<> >();
|
||||
// modelB.Add<Linear<> >(1, 10);
|
||||
|
||||
@@ -1169,7 +1169,7 @@ TEST_CASE("SimpleJoinLayerTest", "[ANNLayerTest]")
|
||||
// {
|
||||
// const size_t rho = 5;
|
||||
|
||||
// model = new RNN<NegativeLogLikelihood<> >(rho);
|
||||
// model = new RNN<NegativeLogLikelihood>(rho);
|
||||
// model->ResetData(input, target);
|
||||
// model->Add<IdentityLayer<> >();
|
||||
// model->Add<Linear<> >(1, 10);
|
||||
@@ -1191,7 +1191,7 @@ TEST_CASE("SimpleJoinLayerTest", "[ANNLayerTest]")
|
||||
|
||||
// arma::mat& Parameters() { return model->Parameters(); }
|
||||
|
||||
// RNN<NegativeLogLikelihood<> >* model;
|
||||
// RNN<NegativeLogLikelihood>* model;
|
||||
// arma::cube input, target;
|
||||
// } function;
|
||||
|
||||
@@ -1233,8 +1233,8 @@ TEST_CASE("SimpleJoinLayerTest", "[ANNLayerTest]")
|
||||
// RandomInitialization init(0.5, 0.5);
|
||||
|
||||
// // Create model with user defined rho parameter.
|
||||
// RNN<NegativeLogLikelihood<>, RandomInitialization> modelA(
|
||||
// rho, false, NegativeLogLikelihood<>(), init);
|
||||
// RNN<NegativeLogLikelihood, RandomInitialization> modelA(
|
||||
// rho, false, NegativeLogLikelihood(), init);
|
||||
// modelA.Add<IdentityLayer<> >();
|
||||
// modelA.Add<Linear<> >(1, 10);
|
||||
|
||||
@@ -1243,8 +1243,8 @@ TEST_CASE("SimpleJoinLayerTest", "[ANNLayerTest]")
|
||||
// modelA.Add<LogSoftMax<> >();
|
||||
|
||||
// // Create model without user defined rho parameter.
|
||||
// RNN<NegativeLogLikelihood<> > modelB(
|
||||
// rho, false, NegativeLogLikelihood<>(), init);
|
||||
// RNN<NegativeLogLikelihood> modelB(
|
||||
// rho, false, NegativeLogLikelihood(), init);
|
||||
// modelB.Add<IdentityLayer<> >();
|
||||
// modelB.Add<Linear<> >(1, 10);
|
||||
|
||||
@@ -1273,7 +1273,7 @@ TEST_CASE("SimpleJoinLayerTest", "[ANNLayerTest]")
|
||||
// {
|
||||
// const size_t rho = 5;
|
||||
|
||||
// model = new RNN<NegativeLogLikelihood<> >(rho);
|
||||
// model = new RNN<NegativeLogLikelihood>(rho);
|
||||
// model->ResetData(input, target);
|
||||
// model->Add<IdentityLayer<> >();
|
||||
// model->Add<Linear<> >(1, 10);
|
||||
@@ -1295,7 +1295,7 @@ TEST_CASE("SimpleJoinLayerTest", "[ANNLayerTest]")
|
||||
|
||||
// arma::mat& Parameters() { return model->Parameters(); }
|
||||
|
||||
// RNN<NegativeLogLikelihood<> >* model;
|
||||
// RNN<NegativeLogLikelihood>* model;
|
||||
// arma::cube input, target;
|
||||
// } function;
|
||||
|
||||
@@ -1338,16 +1338,16 @@ TEST_CASE("SimpleJoinLayerTest", "[ANNLayerTest]")
|
||||
// arma::cube target = arma::ones(1, 1, 5);
|
||||
// const size_t rho = 5;
|
||||
|
||||
// RNN<NegativeLogLikelihood<> > *model1 =
|
||||
// new RNN<NegativeLogLikelihood<> >(rho);
|
||||
// RNN<NegativeLogLikelihood> *model1 =
|
||||
// new RNN<NegativeLogLikelihood>(rho);
|
||||
// model1->ResetData(input, target);
|
||||
// model1->Add<IdentityLayer<> >();
|
||||
// model1->Add<Linear<> >(1, 10);
|
||||
// model1->Add<FastLSTM<> >(10, 3, rho);
|
||||
// model1->Add<LogSoftMax<> >();
|
||||
|
||||
// RNN<NegativeLogLikelihood<> > *model2 =
|
||||
// new RNN<NegativeLogLikelihood<> >(rho);
|
||||
// RNN<NegativeLogLikelihood> *model2 =
|
||||
// new RNN<NegativeLogLikelihood>(rho);
|
||||
// model2->ResetData(input, target);
|
||||
// model2->Add<IdentityLayer<> >();
|
||||
// model2->Add<Linear<> >(1, 10);
|
||||
@@ -1370,16 +1370,16 @@ TEST_CASE("SimpleJoinLayerTest", "[ANNLayerTest]")
|
||||
// arma::cube target = arma::ones(1, 1, 5);
|
||||
// const size_t rho = 5;
|
||||
|
||||
// RNN<NegativeLogLikelihood<> > *model1 =
|
||||
// new RNN<NegativeLogLikelihood<> >(rho);
|
||||
// RNN<NegativeLogLikelihood> *model1 =
|
||||
// new RNN<NegativeLogLikelihood>(rho);
|
||||
// model1->ResetData(input, target);
|
||||
// model1->Add<IdentityLayer<> >();
|
||||
// model1->Add<Linear<> >(1, 10);
|
||||
// model1->Add<LSTM<> >(10, 3, rho);
|
||||
// model1->Add<LogSoftMax<> >();
|
||||
|
||||
// RNN<NegativeLogLikelihood<> > *model2 =
|
||||
// new RNN<NegativeLogLikelihood<> >(rho);
|
||||
// RNN<NegativeLogLikelihood> *model2 =
|
||||
// new RNN<NegativeLogLikelihood>(rho);
|
||||
// model2->ResetData(input, target);
|
||||
// model2->Add<IdentityLayer<> >();
|
||||
// model2->Add<Linear<> >(1, 10);
|
||||
@@ -1605,7 +1605,7 @@ TEST_CASE("SimpleJoinLayerTest", "[ANNLayerTest]")
|
||||
// {
|
||||
// const size_t rho = 5;
|
||||
|
||||
// model = new RNN<NegativeLogLikelihood<> >(rho);
|
||||
// model = new RNN<NegativeLogLikelihood>(rho);
|
||||
// model->ResetData(input, target);
|
||||
// model->Add<IdentityLayer<> >();
|
||||
// model->Add<Linear<> >(1, 10);
|
||||
@@ -1628,7 +1628,7 @@ TEST_CASE("SimpleJoinLayerTest", "[ANNLayerTest]")
|
||||
|
||||
// arma::mat& Parameters() { return model->Parameters(); }
|
||||
|
||||
// RNN<NegativeLogLikelihood<> >* model;
|
||||
// RNN<NegativeLogLikelihood>* model;
|
||||
// arma::cube input, target;
|
||||
// } function;
|
||||
|
||||
@@ -1734,8 +1734,8 @@ TEST_CASE("SimpleJoinLayerTest", "[ANNLayerTest]")
|
||||
// RandomInitialization init(0.5, 0.5);
|
||||
//
|
||||
// // Create model with user defined rho parameter.
|
||||
// RNN<NegativeLogLikelihood<>, RandomInitialization> modelA(
|
||||
// rho, false, NegativeLogLikelihood<>(), init);
|
||||
// RNN<NegativeLogLikelihood, RandomInitialization> modelA(
|
||||
// rho, false, NegativeLogLikelihood(), init);
|
||||
// modelA.Add<IdentityLayer<> >();
|
||||
// modelA.Add<Linear<> >(1, 10);
|
||||
//
|
||||
@@ -1744,8 +1744,8 @@ TEST_CASE("SimpleJoinLayerTest", "[ANNLayerTest]")
|
||||
// modelA.Add<LogSoftMax<> >();
|
||||
//
|
||||
// // Create model without user defined rho parameter.
|
||||
// RNN<NegativeLogLikelihood<> > modelB(
|
||||
// rho, false, NegativeLogLikelihood<>(), init);
|
||||
// RNN<NegativeLogLikelihood> modelB(
|
||||
// rho, false, NegativeLogLikelihood(), init);
|
||||
// modelB.Add<IdentityLayer<> >();
|
||||
// modelB.Add<Linear<> >(1, 10);
|
||||
//
|
||||
@@ -1774,7 +1774,7 @@ TEST_CASE("SimpleJoinLayerTest", "[ANNLayerTest]")
|
||||
// {
|
||||
// const size_t rho = 5;
|
||||
//
|
||||
// model = new RNN<NegativeLogLikelihood<> >(rho);
|
||||
// model = new RNN<NegativeLogLikelihood>(rho);
|
||||
// model->ResetData(input, target);
|
||||
// model->Add<IdentityLayer<> >();
|
||||
// model->Add<Linear<> >(1, 10);
|
||||
@@ -1796,7 +1796,7 @@ TEST_CASE("SimpleJoinLayerTest", "[ANNLayerTest]")
|
||||
//
|
||||
// arma::mat& Parameters() { return model->Parameters(); }
|
||||
//
|
||||
// RNN<NegativeLogLikelihood<> >* model;
|
||||
// RNN<NegativeLogLikelihood>* model;
|
||||
// arma::cube input, target;
|
||||
// } function;
|
||||
//
|
||||
@@ -1838,8 +1838,8 @@ TEST_CASE("SimpleJoinLayerTest", "[ANNLayerTest]")
|
||||
// RandomInitialization init(0.5, 0.5);
|
||||
//
|
||||
// // Create model with user defined rho parameter.
|
||||
// RNN<NegativeLogLikelihood<>, RandomInitialization> modelA(
|
||||
// rho, false, NegativeLogLikelihood<>(), init);
|
||||
// RNN<NegativeLogLikelihood, RandomInitialization> modelA(
|
||||
// rho, false, NegativeLogLikelihood(), init);
|
||||
// modelA.Add<IdentityLayer<> >();
|
||||
// modelA.Add<Linear<> >(1, 10);
|
||||
//
|
||||
@@ -1848,8 +1848,8 @@ TEST_CASE("SimpleJoinLayerTest", "[ANNLayerTest]")
|
||||
// modelA.Add<LogSoftMax<> >();
|
||||
//
|
||||
// // Create model without user defined rho parameter.
|
||||
// RNN<NegativeLogLikelihood<> > modelB(
|
||||
// rho, false, NegativeLogLikelihood<>(), init);
|
||||
// RNN<NegativeLogLikelihood> modelB(
|
||||
// rho, false, NegativeLogLikelihood(), init);
|
||||
// modelB.Add<IdentityLayer<> >();
|
||||
// modelB.Add<Linear<> >(1, 10);
|
||||
//
|
||||
@@ -1878,7 +1878,7 @@ TEST_CASE("SimpleJoinLayerTest", "[ANNLayerTest]")
|
||||
// {
|
||||
// const size_t rho = 5;
|
||||
//
|
||||
// model = new RNN<NegativeLogLikelihood<> >(rho);
|
||||
// model = new RNN<NegativeLogLikelihood>(rho);
|
||||
// model->ResetData(input, target);
|
||||
// model->Add<IdentityLayer<> >();
|
||||
// model->Add<Linear<> >(1, 10);
|
||||
@@ -1900,7 +1900,7 @@ TEST_CASE("SimpleJoinLayerTest", "[ANNLayerTest]")
|
||||
//
|
||||
// arma::mat& Parameters() { return model->Parameters(); }
|
||||
//
|
||||
// RNN<NegativeLogLikelihood<> >* model;
|
||||
// RNN<NegativeLogLikelihood>* model;
|
||||
// arma::cube input, target;
|
||||
// } function;
|
||||
//
|
||||
@@ -1943,16 +1943,16 @@ TEST_CASE("SimpleJoinLayerTest", "[ANNLayerTest]")
|
||||
// arma::cube target = arma::ones(1, 1, 5);
|
||||
// const size_t rho = 5;
|
||||
//
|
||||
// RNN<NegativeLogLikelihood<> > *model1 =
|
||||
// new RNN<NegativeLogLikelihood<> >(rho);
|
||||
// RNN<NegativeLogLikelihood> *model1 =
|
||||
// new RNN<NegativeLogLikelihood>(rho);
|
||||
// model1->ResetData(input, target);
|
||||
// model1->Add<IdentityLayer<> >();
|
||||
// model1->Add<Linear<> >(1, 10);
|
||||
// model1->Add<FastLSTM<> >(10, 3, rho);
|
||||
// model1->Add<LogSoftMax<> >();
|
||||
//
|
||||
// RNN<NegativeLogLikelihood<> > *model2 =
|
||||
// new RNN<NegativeLogLikelihood<> >(rho);
|
||||
// RNN<NegativeLogLikelihood> *model2 =
|
||||
// new RNN<NegativeLogLikelihood>(rho);
|
||||
// model2->ResetData(input, target);
|
||||
// model2->Add<IdentityLayer<> >();
|
||||
// model2->Add<Linear<> >(1, 10);
|
||||
@@ -1975,16 +1975,16 @@ TEST_CASE("SimpleJoinLayerTest", "[ANNLayerTest]")
|
||||
// arma::cube target = arma::ones(1, 1, 5);
|
||||
// const size_t rho = 5;
|
||||
//
|
||||
// RNN<NegativeLogLikelihood<> > *model1 =
|
||||
// new RNN<NegativeLogLikelihood<> >(rho);
|
||||
// RNN<NegativeLogLikelihood> *model1 =
|
||||
// new RNN<NegativeLogLikelihood>(rho);
|
||||
// model1->ResetData(input, target);
|
||||
// model1->Add<IdentityLayer<> >();
|
||||
// model1->Add<Linear<> >(1, 10);
|
||||
// model1->Add<LSTM<> >(10, 3, rho);
|
||||
// model1->Add<LogSoftMax<> >();
|
||||
//
|
||||
// RNN<NegativeLogLikelihood<> > *model2 =
|
||||
// new RNN<NegativeLogLikelihood<> >(rho);
|
||||
// RNN<NegativeLogLikelihood> *model2 =
|
||||
// new RNN<NegativeLogLikelihood>(rho);
|
||||
// model2->ResetData(input, target);
|
||||
// model2->Add<IdentityLayer<> >();
|
||||
// model2->Add<Linear<> >(1, 10);
|
||||
@@ -2210,7 +2210,7 @@ TEST_CASE("SimpleJoinLayerTest", "[ANNLayerTest]")
|
||||
// {
|
||||
// const size_t rho = 5;
|
||||
//
|
||||
// model = new RNN<NegativeLogLikelihood<> >(rho);
|
||||
// model = new RNN<NegativeLogLikelihood>(rho);
|
||||
// model->ResetData(input, target);
|
||||
// model->Add<IdentityLayer<> >();
|
||||
// model->Add<Linear<> >(1, 10);
|
||||
@@ -2233,7 +2233,7 @@ TEST_CASE("SimpleJoinLayerTest", "[ANNLayerTest]")
|
||||
//
|
||||
// arma::mat& Parameters() { return model->Parameters(); }
|
||||
//
|
||||
// RNN<NegativeLogLikelihood<> >* model;
|
||||
// RNN<NegativeLogLikelihood>* model;
|
||||
// arma::cube input, target;
|
||||
// } function;
|
||||
//
|
||||
@@ -2449,7 +2449,7 @@ TEST_CASE("ConcatLayerParametersTest", "[ANNLayerTest]")
|
||||
// input(arma::randu(10, 1)),
|
||||
// target(arma::mat("0"))
|
||||
// {
|
||||
// model = new FFN<NegativeLogLikelihood<>, NguyenWidrowInitialization>();
|
||||
// model = new FFN<NegativeLogLikelihood, NguyenWidrowInitialization>();
|
||||
// model->ResetData(input, target);
|
||||
// model->Add<IdentityLayer>();
|
||||
// model->Add<Linear>(10, 10);
|
||||
@@ -2475,7 +2475,7 @@ TEST_CASE("ConcatLayerParametersTest", "[ANNLayerTest]")
|
||||
|
||||
// arma::mat& Parameters() { return model->Parameters(); }
|
||||
|
||||
// FFN<NegativeLogLikelihood<>, NguyenWidrowInitialization>* model;
|
||||
// FFN<NegativeLogLikelihood, NguyenWidrowInitialization>* model;
|
||||
// Concat* concat;
|
||||
// arma::mat input, target;
|
||||
// } function;
|
||||
@@ -2517,7 +2517,7 @@ TEST_CASE("GradientConcatenateLayerTest", "[ANNLayerTest]")
|
||||
input(arma::randu(10, 1)),
|
||||
target(arma::mat("0"))
|
||||
{
|
||||
model = new FFN<NegativeLogLikelihood<>, NguyenWidrowInitialization>();
|
||||
model = new FFN<NegativeLogLikelihood, NguyenWidrowInitialization>();
|
||||
model->ResetData(input, target);
|
||||
model->Add<IdentityLayer>();
|
||||
model->Add<Linear>(10, 5);
|
||||
@@ -2546,7 +2546,7 @@ TEST_CASE("GradientConcatenateLayerTest", "[ANNLayerTest]")
|
||||
|
||||
arma::mat& Parameters() { return model->Parameters(); }
|
||||
|
||||
FFN<NegativeLogLikelihood<>, NguyenWidrowInitialization>* model;
|
||||
FFN<NegativeLogLikelihood, NguyenWidrowInitialization>* model;
|
||||
Concatenate* concatenate;
|
||||
arma::mat input, target;
|
||||
} function;
|
||||
@@ -2725,7 +2725,7 @@ TEST_CASE("GradientSoftmaxTest", "[ANNLayerTest]")
|
||||
input(arma::randu(10, 1)),
|
||||
target(arma::mat("1; 0"))
|
||||
{
|
||||
model = new FFN<MeanSquaredError<>, RandomInitialization>;
|
||||
model = new FFN<MeanSquaredError, RandomInitialization>;
|
||||
model->ResetData(input, target);
|
||||
model->Add<Linear>(10, 10);
|
||||
model->Add<ReLULayer>();
|
||||
@@ -2747,7 +2747,7 @@ TEST_CASE("GradientSoftmaxTest", "[ANNLayerTest]")
|
||||
|
||||
arma::mat& Parameters() { return model->Parameters(); }
|
||||
|
||||
FFN<MeanSquaredError<> >* model;
|
||||
FFN<MeanSquaredError>* model;
|
||||
arma::mat input, target;
|
||||
} function;
|
||||
|
||||
@@ -3086,7 +3086,7 @@ TEST_CASE("SimpleBicubicInterpolationLayerTest", "[ANNLayerTest]")
|
||||
// input(arma::randn(32, 2048)),
|
||||
// target(arma::zeros(1, 2048))
|
||||
// {
|
||||
// model = new FFN<NegativeLogLikelihood<>, NguyenWidrowInitialization>();
|
||||
// model = new FFN<NegativeLogLikelihood, NguyenWidrowInitialization>();
|
||||
// model->ResetData(input, target);
|
||||
// model->Add<IdentityLayer<> >();
|
||||
// model->Add<Linear<> >(32, 4);
|
||||
@@ -3109,7 +3109,7 @@ TEST_CASE("SimpleBicubicInterpolationLayerTest", "[ANNLayerTest]")
|
||||
|
||||
// arma::mat& Parameters() { return model->Parameters(); }
|
||||
|
||||
// FFN<NegativeLogLikelihood<>, NguyenWidrowInitialization>* model;
|
||||
// FFN<NegativeLogLikelihood, NguyenWidrowInitialization>* model;
|
||||
// arma::mat input, target;
|
||||
// } function;
|
||||
|
||||
@@ -3160,7 +3160,7 @@ TEST_CASE("GradientVirtualBatchNormTest", "[ANNLayerTest]")
|
||||
{
|
||||
arma::mat referenceBatch = arma::mat(input.memptr(), input.n_rows, 4);
|
||||
|
||||
model = new FFN<NegativeLogLikelihood<>, NguyenWidrowInitialization>();
|
||||
model = new FFN<NegativeLogLikelihood, NguyenWidrowInitialization>();
|
||||
model->ResetData(input, target);
|
||||
model->Add<IdentityLayer>();
|
||||
model->Add<Linear>(5, 5);
|
||||
@@ -3183,7 +3183,7 @@ TEST_CASE("GradientVirtualBatchNormTest", "[ANNLayerTest]")
|
||||
|
||||
arma::mat& Parameters() { return model->Parameters(); }
|
||||
|
||||
FFN<NegativeLogLikelihood<>, NguyenWidrowInitialization>* model;
|
||||
FFN<NegativeLogLikelihood, NguyenWidrowInitialization>* model;
|
||||
arma::mat input, target;
|
||||
} function;
|
||||
|
||||
@@ -3221,7 +3221,7 @@ TEST_CASE("VirtualBatchNormLayerParametersTest", "[ANNLayerTest]")
|
||||
// input(arma::randn(5, 4)),
|
||||
// target(arma::zeros(1, 4))
|
||||
// {
|
||||
// model = new FFN<NegativeLogLikelihood<>, NguyenWidrowInitialization>();
|
||||
// model = new FFN<NegativeLogLikelihood, NguyenWidrowInitialization>();
|
||||
// model->ResetData(input, target);
|
||||
// model->Add<IdentityLayer<> >();
|
||||
// model->Add<Linear<> >(5, 5);
|
||||
@@ -3242,7 +3242,7 @@ TEST_CASE("VirtualBatchNormLayerParametersTest", "[ANNLayerTest]")
|
||||
|
||||
// arma::mat& Parameters() { return model->Parameters(); }
|
||||
|
||||
// FFN<NegativeLogLikelihood<>, NguyenWidrowInitialization>* model;
|
||||
// FFN<NegativeLogLikelihood, NguyenWidrowInitialization>* model;
|
||||
// arma::mat input, target;
|
||||
// } function;
|
||||
|
||||
@@ -3399,7 +3399,7 @@ TEST_CASE("GradientTransposedConvolutionLayerTest", "[ANNLayerTest]")
|
||||
input(arma::linspace<arma::colvec>(0, 35, 36)),
|
||||
target(arma::mat("0"))
|
||||
{
|
||||
model = new FFN<NegativeLogLikelihood<>, RandomInitialization>();
|
||||
model = new FFN<NegativeLogLikelihood, RandomInitialization>();
|
||||
model->ResetData(input, target);
|
||||
model->Add<TransposedConvolution>(1, 1, 3, 3, 2, 2, 1, 1, 6, 6, 12, 12);
|
||||
model->Add<LogSoftMax>();
|
||||
@@ -3419,7 +3419,7 @@ TEST_CASE("GradientTransposedConvolutionLayerTest", "[ANNLayerTest]")
|
||||
|
||||
arma::mat& Parameters() { return model->Parameters(); }
|
||||
|
||||
FFN<NegativeLogLikelihood<>, RandomInitialization>* model;
|
||||
FFN<NegativeLogLikelihood, RandomInitialization>* model;
|
||||
arma::mat input, target;
|
||||
} function;
|
||||
|
||||
@@ -3565,7 +3565,7 @@ TEST_CASE("SimpleMultiplyMergeLayerTest", "[ANNLayerTest]")
|
||||
// input(arma::linspace<arma::colvec>(0, 35, 36)),
|
||||
// target(arma::mat("0"))
|
||||
// {
|
||||
// model = new FFN<NegativeLogLikelihood<>, RandomInitialization>();
|
||||
// model = new FFN<NegativeLogLikelihood, RandomInitialization>();
|
||||
// model->ResetData(input, target);
|
||||
// model->Add<IdentityLayer<> >();
|
||||
// model->Add<AtrousConvolution<> >(1, 1, 3, 3, 1, 1, 0, 0, 6, 6, 2, 2);
|
||||
@@ -3586,7 +3586,7 @@ TEST_CASE("SimpleMultiplyMergeLayerTest", "[ANNLayerTest]")
|
||||
|
||||
// arma::mat& Parameters() { return model->Parameters(); }
|
||||
|
||||
// FFN<NegativeLogLikelihood<>, RandomInitialization>* model;
|
||||
// FFN<NegativeLogLikelihood, RandomInitialization>* model;
|
||||
// arma::mat input, target;
|
||||
// } function;
|
||||
|
||||
@@ -3747,7 +3747,7 @@ TEST_CASE("SimpleMultiplyMergeLayerTest", "[ANNLayerTest]")
|
||||
// input(arma::randn(10, 256)),
|
||||
// target(arma::zeros(1, 256))
|
||||
// {
|
||||
// model = new FFN<NegativeLogLikelihood<>, NguyenWidrowInitialization>();
|
||||
// model = new FFN<NegativeLogLikelihood, NguyenWidrowInitialization>();
|
||||
// model->ResetData(input, target);
|
||||
// model->Add<IdentityLayer<> >();
|
||||
// model->Add<Linear<> >(10, 10);
|
||||
@@ -3770,7 +3770,7 @@ TEST_CASE("SimpleMultiplyMergeLayerTest", "[ANNLayerTest]")
|
||||
//
|
||||
// arma::mat& Parameters() { return model->Parameters(); }
|
||||
//
|
||||
// FFN<NegativeLogLikelihood<>, NguyenWidrowInitialization>* model;
|
||||
// FFN<NegativeLogLikelihood, NguyenWidrowInitialization>* model;
|
||||
// arma::mat input, target;
|
||||
// } function;
|
||||
//
|
||||
@@ -3824,7 +3824,7 @@ TEST_CASE("GradientLayerNormTest", "[ANNLayerTest]")
|
||||
input(arma::randn(10, 256)),
|
||||
target(arma::zeros(1, 256))
|
||||
{
|
||||
model = new FFN<NegativeLogLikelihood<>, NguyenWidrowInitialization>();
|
||||
model = new FFN<NegativeLogLikelihood, NguyenWidrowInitialization>();
|
||||
model->ResetData(input, target);
|
||||
model->Add<IdentityLayer>();
|
||||
model->Add<Linear>(10, 10);
|
||||
@@ -3847,7 +3847,7 @@ TEST_CASE("GradientLayerNormTest", "[ANNLayerTest]")
|
||||
|
||||
arma::mat& Parameters() { return model->Parameters(); }
|
||||
|
||||
FFN<NegativeLogLikelihood<>, NguyenWidrowInitialization>* model;
|
||||
FFN<NegativeLogLikelihood, NguyenWidrowInitialization>* model;
|
||||
arma::mat input, target;
|
||||
} function;
|
||||
|
||||
@@ -4154,7 +4154,7 @@ TEST_CASE("GradientReparametrizationLayerTest", "[ANNLayerTest]")
|
||||
input(arma::randu(10, 1)),
|
||||
target(arma::mat("0"))
|
||||
{
|
||||
model = new FFN<NegativeLogLikelihood<>, NguyenWidrowInitialization>();
|
||||
model = new FFN<NegativeLogLikelihood, NguyenWidrowInitialization>();
|
||||
model->ResetData(input, target);
|
||||
model->Add<IdentityLayer>();
|
||||
model->Add<Linear>(10, 6);
|
||||
@@ -4177,7 +4177,7 @@ TEST_CASE("GradientReparametrizationLayerTest", "[ANNLayerTest]")
|
||||
|
||||
arma::mat& Parameters() { return model->Parameters(); }
|
||||
|
||||
FFN<NegativeLogLikelihood<>, NguyenWidrowInitialization>* model;
|
||||
FFN<NegativeLogLikelihood, NguyenWidrowInitialization>* model;
|
||||
arma::mat input, target;
|
||||
} function;
|
||||
|
||||
@@ -4197,7 +4197,7 @@ TEST_CASE("GradientReparametrizationLayerBetaTest", "[ANNLayerTest]")
|
||||
input(arma::randu(10, 2)),
|
||||
target(arma::mat("0 0"))
|
||||
{
|
||||
model = new FFN<NegativeLogLikelihood<>, NguyenWidrowInitialization>();
|
||||
model = new FFN<NegativeLogLikelihood, NguyenWidrowInitialization>();
|
||||
model->ResetData(input, target);
|
||||
model->Add<IdentityLayer>();
|
||||
model->Add<Linear>(10, 6);
|
||||
@@ -4221,7 +4221,7 @@ TEST_CASE("GradientReparametrizationLayerBetaTest", "[ANNLayerTest]")
|
||||
|
||||
arma::mat& Parameters() { return model->Parameters(); }
|
||||
|
||||
FFN<NegativeLogLikelihood<>, NguyenWidrowInitialization>* model;
|
||||
FFN<NegativeLogLikelihood, NguyenWidrowInitialization>* model;
|
||||
arma::mat input, target;
|
||||
} function;
|
||||
|
||||
@@ -4356,7 +4356,7 @@ TEST_CASE("HighwayLayerParametersTest", "[ANNLayerTest]")
|
||||
// input(arma::randu(5, 1)),
|
||||
// target(arma::mat("0"))
|
||||
// {
|
||||
// model = new FFN<NegativeLogLikelihood<>, NguyenWidrowInitialization>();
|
||||
// model = new FFN<NegativeLogLikelihood, NguyenWidrowInitialization>();
|
||||
// model->ResetData(input, target);
|
||||
// model->Add<IdentityLayer>();
|
||||
// model->Add<Linear>(5, 10);
|
||||
@@ -4386,7 +4386,7 @@ TEST_CASE("HighwayLayerParametersTest", "[ANNLayerTest]")
|
||||
|
||||
// arma::mat& Parameters() { return model->Parameters(); }
|
||||
|
||||
// FFN<NegativeLogLikelihood<>, NguyenWidrowInitialization>* model;
|
||||
// FFN<NegativeLogLikelihood, NguyenWidrowInitialization>* model;
|
||||
// Highway* highway;
|
||||
// arma::mat input, target;
|
||||
// } function;
|
||||
@@ -4406,7 +4406,7 @@ TEST_CASE("HighwayLayerParametersTest", "[ANNLayerTest]")
|
||||
// input(arma::randu(10, 1)),
|
||||
// target(arma::mat("0"))
|
||||
// {
|
||||
// model = new FFN<NegativeLogLikelihood<>, NguyenWidrowInitialization>();
|
||||
// model = new FFN<NegativeLogLikelihood, NguyenWidrowInitialization>();
|
||||
// model->ResetData(input, target);
|
||||
// model->Add<IdentityLayer>();
|
||||
// model->Add<Linear>(10, 10);
|
||||
@@ -4435,7 +4435,7 @@ TEST_CASE("HighwayLayerParametersTest", "[ANNLayerTest]")
|
||||
|
||||
// arma::mat& Parameters() { return model->Parameters(); }
|
||||
|
||||
// FFN<NegativeLogLikelihood<>, NguyenWidrowInitialization>* model;
|
||||
// FFN<NegativeLogLikelihood, NguyenWidrowInitialization>* model;
|
||||
// Sequential* sequential;
|
||||
// arma::mat input, target;
|
||||
// } function;
|
||||
@@ -4455,7 +4455,7 @@ TEST_CASE("HighwayLayerParametersTest", "[ANNLayerTest]")
|
||||
// input(arma::randu(10, 1)),
|
||||
// target(arma::mat("0"))
|
||||
// {
|
||||
// model = new FFN<NegativeLogLikelihood<>, NguyenWidrowInitialization>();
|
||||
// model = new FFN<NegativeLogLikelihood, NguyenWidrowInitialization>();
|
||||
// model->ResetData(input, target);
|
||||
// model->Add<Linear>(10, 10);
|
||||
|
||||
@@ -4480,7 +4480,7 @@ TEST_CASE("HighwayLayerParametersTest", "[ANNLayerTest]")
|
||||
|
||||
// arma::mat& Parameters() { return model->Parameters(); }
|
||||
|
||||
// FFN<NegativeLogLikelihood<>, NguyenWidrowInitialization>* model;
|
||||
// FFN<NegativeLogLikelihood, NguyenWidrowInitialization>* model;
|
||||
// WeightNorm* weightNorm;
|
||||
// arma::mat input, target;
|
||||
// } function;
|
||||
@@ -4521,7 +4521,7 @@ TEST_CASE("HighwayLayerParametersTest", "[ANNLayerTest]")
|
||||
// arma::mat input(5, 100, arma::fill::randu);
|
||||
// arma::mat output(5, 100, arma::fill::randu);
|
||||
|
||||
// FFN<NegativeLogLikelihood<>, ann::RandomInitialization> model;
|
||||
// FFN<NegativeLogLikelihood, ann::RandomInitialization> model;
|
||||
// model.Add<Linear<>>(input.n_rows, 10);
|
||||
// model.Add<LayerType>(layer);
|
||||
// model.Add<ReLULayer<>>();
|
||||
@@ -4535,7 +4535,7 @@ TEST_CASE("HighwayLayerParametersTest", "[ANNLayerTest]")
|
||||
// model.Predict(input, originalOutput);
|
||||
|
||||
// // Now serialize the model.
|
||||
// FFN<NegativeLogLikelihood<>, ann::RandomInitialization> xmlModel, jsonModel,
|
||||
// FFN<NegativeLogLikelihood, ann::RandomInitialization> xmlModel, jsonModel,
|
||||
// binaryModel;
|
||||
// SerializeObjectAll(model, xmlModel, jsonModel, binaryModel);
|
||||
|
||||
@@ -4678,7 +4678,7 @@ TEST_CASE("GradientConvolutionLayerTest", "[ANNLayerTest]")
|
||||
input(arma::linspace<arma::colvec>(0, 35, 36)),
|
||||
target(arma::mat("1"))
|
||||
{
|
||||
model = new FFN<NegativeLogLikelihood<>, RandomInitialization>();
|
||||
model = new FFN<NegativeLogLikelihood, RandomInitialization>();
|
||||
model->ResetData(input, target);
|
||||
model->Add<Convolution>(1, 3, 3, 1, 1, std::tuple<size_t, size_t>(0, 0),
|
||||
std::tuple<size_t, size_t>(0, 0), "same");
|
||||
@@ -4701,7 +4701,7 @@ TEST_CASE("GradientConvolutionLayerTest", "[ANNLayerTest]")
|
||||
|
||||
arma::mat& Parameters() { return model->Parameters(); }
|
||||
|
||||
FFN<NegativeLogLikelihood<>, RandomInitialization>* model;
|
||||
FFN<NegativeLogLikelihood, RandomInitialization>* model;
|
||||
arma::mat input, target;
|
||||
} function;
|
||||
|
||||
@@ -5425,7 +5425,7 @@ TEST_CASE("TransposedConvolutionalLayerOptionalParameterTest", "[ANNLayerTest]")
|
||||
// input(arma::randn(16, 1024)),
|
||||
// target(arma::zeros(1, 1024))
|
||||
// {
|
||||
// model = new FFN<NegativeLogLikelihood<>, NguyenWidrowInitialization>();
|
||||
// model = new FFN<NegativeLogLikelihood, NguyenWidrowInitialization>();
|
||||
// model->ResetData(input, target);
|
||||
// model->Add<IdentityLayer<>>();
|
||||
// model->Add<Convolution<>>(1, 2, 3, 3, 1, 1, 0, 0, 4, 4);
|
||||
@@ -5448,7 +5448,7 @@ TEST_CASE("TransposedConvolutionalLayerOptionalParameterTest", "[ANNLayerTest]")
|
||||
|
||||
// arma::mat& Parameters() { return model->Parameters(); }
|
||||
|
||||
// FFN<NegativeLogLikelihood<>, NguyenWidrowInitialization>* model;
|
||||
// FFN<NegativeLogLikelihood, NguyenWidrowInitialization>* model;
|
||||
// arma::mat input, target;
|
||||
// } function;
|
||||
|
||||
@@ -6091,7 +6091,7 @@ TEST_CASE("GradientMultiheadAttentionTest", "[ANNLayerTest]")
|
||||
keyPaddingMask = arma::zeros(1, srcSeqLen);
|
||||
keyPaddingMask(srcSeqLen - 1) = std::numeric_limits<double>::lowest();
|
||||
|
||||
model = new FFN<NegativeLogLikelihood<>, XavierInitialization>();
|
||||
model = new FFN<NegativeLogLikelihood, XavierInitialization>();
|
||||
model->ResetData(input, target);
|
||||
// attnModule = new MultiheadAttention(tgtSeqLen, srcSeqLen, embedDim,
|
||||
// nHeads);
|
||||
@@ -6118,7 +6118,7 @@ TEST_CASE("GradientMultiheadAttentionTest", "[ANNLayerTest]")
|
||||
|
||||
arma::mat& Parameters() { return model->Parameters(); }
|
||||
|
||||
FFN<NegativeLogLikelihood<>, XavierInitialization>* model;
|
||||
FFN<NegativeLogLikelihood, XavierInitialization>* model;
|
||||
// MultiheadAttention* attnModule;
|
||||
|
||||
arma::mat input, target, attnMask, keyPaddingMask;
|
||||
@@ -6294,7 +6294,7 @@ TEST_CASE("GradientInstanceNormLayerTest", "[ANNLayerTest]")
|
||||
arma::mat target;
|
||||
target.ones(1, 1024);
|
||||
|
||||
model = new FFN<NegativeLogLikelihood<>, NguyenWidrowInitialization>();
|
||||
model = new FFN<NegativeLogLikelihood, NguyenWidrowInitialization>();
|
||||
model->ResetData(input, target);
|
||||
model->Add<IdentityLayer<> >();
|
||||
model->Add<Convolution<> >(1, 2, 3, 3, 1, 1, 0, 0, 4, 4);
|
||||
@@ -6317,7 +6317,7 @@ TEST_CASE("GradientInstanceNormLayerTest", "[ANNLayerTest]")
|
||||
|
||||
arma::mat& Parameters() { return model->Parameters(); }
|
||||
|
||||
FFN<NegativeLogLikelihood<>, NguyenWidrowInitialization>* model;
|
||||
FFN<NegativeLogLikelihood, NguyenWidrowInitialization>* model;
|
||||
arma::mat input, target;
|
||||
} function;
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ TEST_CASE("FFNCallbackTest", "[CallbackTest]")
|
||||
if (!data::Load("lab3.csv", labels))
|
||||
FAIL("Cannot load test dataset lab3.csv!");
|
||||
|
||||
FFN<MeanSquaredError<>, RandomInitialization> model;
|
||||
FFN<MeanSquaredError, RandomInitialization> model;
|
||||
|
||||
model.Add<Linear>(2);
|
||||
model.Add<Sigmoid>();
|
||||
@@ -74,7 +74,7 @@ TEST_CASE("FFNWithOptimizerCallbackTest", "[CallbackTest]")
|
||||
if (!data::Load("lab3.csv", labels))
|
||||
FAIL("Cannot load test dataset lab3.csv!");
|
||||
|
||||
FFN<MeanSquaredError<>, RandomInitialization> model;
|
||||
FFN<MeanSquaredError, RandomInitialization> model;
|
||||
|
||||
model.Add<Linear>(2);
|
||||
model.Add<Sigmoid>();
|
||||
@@ -99,8 +99,8 @@ TEST_CASE("RNNCallbackTest", "[CallbackTest]")
|
||||
RandomInitialization init(0.5, 0.5);
|
||||
|
||||
// Create model with user defined rho parameter.
|
||||
RNN<NegativeLogLikelihood<>, RandomInitialization> model(
|
||||
rho, false, NegativeLogLikelihood<>(), init);
|
||||
RNN<NegativeLogLikelihood, RandomInitialization> model(
|
||||
rho, false, NegativeLogLikelihood(), init);
|
||||
model.Add<Linear>(10);
|
||||
|
||||
// Use LSTM layer with 3 units.
|
||||
@@ -124,8 +124,8 @@ TEST_CASE("RNNWithOptimizerCallbackTest", "[CallbackTest]")
|
||||
RandomInitialization init(0.5, 0.5);
|
||||
|
||||
// Create model with user defined rho parameter.
|
||||
RNN<NegativeLogLikelihood<>, RandomInitialization> model(
|
||||
rho, false, NegativeLogLikelihood<>(), init);
|
||||
RNN<NegativeLogLikelihood, RandomInitialization> model(
|
||||
rho, false, NegativeLogLikelihood(), init);
|
||||
model.Add<Linear>(10);
|
||||
|
||||
// Use LSTM layer with 3 units.
|
||||
|
||||
@@ -81,7 +81,7 @@ TEST_CASE("PaddingTest", "[ConvolutionalNetworktest]")
|
||||
X.load("mnist_first250_training_4s_and_9s.arm");
|
||||
|
||||
// Create the network.
|
||||
FFN<NegativeLogLikelihood<>, RandomInitialization> model;
|
||||
FFN<NegativeLogLikelihood, RandomInitialization> model;
|
||||
|
||||
model.Add<Padding>(1, 2, 3, 4);
|
||||
|
||||
@@ -129,7 +129,7 @@ TEST_CASE("MaxPoolingTest", "[ConvolutionalNetworkTest]")
|
||||
X.col(2) = arma::vec("3, 4, 1, -1, 5, 5, 5, 5");
|
||||
|
||||
// Create the network.
|
||||
FFN<NegativeLogLikelihood<>, RandomInitialization> model;
|
||||
FFN<NegativeLogLikelihood, RandomInitialization> model;
|
||||
model.Add<MaxPooling>(2, 2);
|
||||
|
||||
arma::mat results;
|
||||
@@ -204,7 +204,7 @@ TEST_CASE("VanillaNetworkTest", "[ConvolutionalNetworkTest]")
|
||||
bool success = false;
|
||||
for (size_t trial = 0; trial < 5; ++trial)
|
||||
{
|
||||
FFN<NegativeLogLikelihood<>, RandomInitialization> model;
|
||||
FFN<NegativeLogLikelihood, RandomInitialization> model;
|
||||
|
||||
model.Add<Convolution>(8, 5, 5, 1, 1, 0, 0);
|
||||
model.Add<ReLU>();
|
||||
@@ -253,7 +253,7 @@ TEST_CASE("VanillaNetworkTest", "[ConvolutionalNetworkTest]")
|
||||
|
||||
TEST_CASE("VanillaNetworkBatchSizeTest", "[ConvolutionalNetworkTest]")
|
||||
{
|
||||
FFN<NegativeLogLikelihood<>, RandomInitialization> model;
|
||||
FFN<NegativeLogLikelihood, RandomInitialization> model;
|
||||
|
||||
model.Add<Convolution>(8, 5, 5, 1, 1, 0, 0);
|
||||
model.Add<ReLU>();
|
||||
@@ -400,8 +400,8 @@ TEST_CASE("CheckCopyVanillaNetworkTest", "[ConvolutionalNetworkTest]")
|
||||
// of iterations using random weights. If this works 1 of 5 times, I'm fine
|
||||
// with that. All I want to know is that the network is able to escape from
|
||||
// local minima and to solve the task.
|
||||
FFN<NegativeLogLikelihood<>, RandomInitialization> *model =
|
||||
new FFN<NegativeLogLikelihood<>, RandomInitialization>;
|
||||
FFN<NegativeLogLikelihood, RandomInitialization> *model =
|
||||
new FFN<NegativeLogLikelihood, RandomInitialization>;
|
||||
|
||||
model->Add<Convolution>(8, 5, 5, 1, 1, 0, 0);
|
||||
model->Add<ReLU>();
|
||||
@@ -417,8 +417,8 @@ TEST_CASE("CheckCopyVanillaNetworkTest", "[ConvolutionalNetworkTest]")
|
||||
model->Add<LogSoftMax>();
|
||||
model->InputDimensions() = std::vector<size_t>({ 28, 28 });
|
||||
|
||||
FFN<NegativeLogLikelihood<>, RandomInitialization> *model1 =
|
||||
new FFN<NegativeLogLikelihood<>, RandomInitialization>;
|
||||
FFN<NegativeLogLikelihood, RandomInitialization> *model1 =
|
||||
new FFN<NegativeLogLikelihood, RandomInitialization>;
|
||||
|
||||
model1->Add<Convolution>(8, 5, 5, 1, 1, 0, 0);
|
||||
model1->Add<ReLU>();
|
||||
|
||||
@@ -220,7 +220,7 @@ TEST_CASE("MSEMatResponsesTest", "[CVTest]")
|
||||
arma::mat data("1 2");
|
||||
arma::mat trainingResponses("1 2; 3 4");
|
||||
|
||||
FFN<MeanSquaredError<>, ConstInitialization> ffn(MeanSquaredError<>(),
|
||||
FFN<MeanSquaredError, ConstInitialization> ffn(MeanSquaredError(),
|
||||
ConstInitialization(0));
|
||||
ffn.Add<Linear>(2);
|
||||
|
||||
|
||||
@@ -102,7 +102,7 @@ TEST_CASE("RBFNetworkTest", "[FeedForwardNetworkTest]")
|
||||
KMeans<> kmeans;
|
||||
kmeans.Cluster(trainData, 8, centroids);
|
||||
|
||||
FFN<MeanSquaredError<> > model;
|
||||
FFN<MeanSquaredError> model;
|
||||
model.Add<RBF>(8, centroids);
|
||||
model.Add<Linear>(3);
|
||||
|
||||
@@ -134,7 +134,7 @@ TEST_CASE("RBFNetworkTest", "[FeedForwardNetworkTest]")
|
||||
KMeans<> kmeans1;
|
||||
kmeans1.Cluster(dataset, 140, centroids1);
|
||||
|
||||
FFN<MeanSquaredError<> > model1;
|
||||
FFN<MeanSquaredError> model1;
|
||||
model1.Add<RBF>(140, centroids1, 4.1);
|
||||
model1.Add<Linear>(2);
|
||||
|
||||
|
||||
@@ -137,13 +137,13 @@ TEST_CASE("CheckCopyMovingVanillaNetworkTest", "[FeedForwardNetworkTest]")
|
||||
* +-----+ +-----+
|
||||
*/
|
||||
|
||||
FFN<NegativeLogLikelihood<> > *model = new FFN<NegativeLogLikelihood<> >;
|
||||
FFN<NegativeLogLikelihood> *model = new FFN<NegativeLogLikelihood>;
|
||||
model->Add<Linear>(8);
|
||||
model->Add<Sigmoid>();
|
||||
model->Add<Linear>(3);
|
||||
model->Add<LogSoftMax>();
|
||||
|
||||
FFN<NegativeLogLikelihood<> > *model1 = new FFN<NegativeLogLikelihood<> >;
|
||||
FFN<NegativeLogLikelihood> *model1 = new FFN<NegativeLogLikelihood>;
|
||||
model1->Add<Linear>(8);
|
||||
model1->Add<Sigmoid>();
|
||||
model1->Add<Linear>(3);
|
||||
@@ -171,12 +171,12 @@ TEST_CASE("CheckCopyMovingReparametrizationNetworkTest",
|
||||
|
||||
// Construct a feed forward network with trainData.n_rows input nodes,
|
||||
// followed by a linear layer and then a reparametrization layer.
|
||||
FFN<NegativeLogLikelihood<> > *model = new FFN<NegativeLogLikelihood<> >;
|
||||
FFN<NegativeLogLikelihood> *model = new FFN<NegativeLogLikelihood>;
|
||||
model->Add<Linear>(8);
|
||||
model->Add<Reparametrization>(false, true, 1);
|
||||
model->Add<LogSoftMax>();
|
||||
|
||||
FFN<NegativeLogLikelihood<> > *model1 = new FFN<NegativeLogLikelihood<> >;
|
||||
FFN<NegativeLogLikelihood> *model1 = new FFN<NegativeLogLikelihood>;
|
||||
model1->Add<Linear>(8);
|
||||
model1->Add<Reparametrization>(false, true, 1);
|
||||
model1->Add<LogSoftMax>();
|
||||
@@ -208,12 +208,12 @@ TEST_CASE("CheckCopyMovingReparametrizationNetworkTest",
|
||||
// * followed by a linear layer and then a reparametrization layer.
|
||||
// */
|
||||
//
|
||||
// FFN<NegativeLogLikelihood<> > *model = new FFN<NegativeLogLikelihood<> >;
|
||||
// FFN<NegativeLogLikelihood> *model = new FFN<NegativeLogLikelihood>;
|
||||
// model->Add<Linear<> >(trainData.n_rows, 8);
|
||||
// model->Add<Reparametrization<> >(4, false, true, 1);
|
||||
// model->Add<LogSoftMax<> >();
|
||||
//
|
||||
// FFN<NegativeLogLikelihood<> > *model1 = new FFN<NegativeLogLikelihood<> >;
|
||||
// FFN<NegativeLogLikelihood> *model1 = new FFN<NegativeLogLikelihood>;
|
||||
// model1->Add<Linear<> >(trainData.n_rows, 8);
|
||||
// model1->Add<Reparametrization<> >(4, false, true, 1);
|
||||
// model1->Add<LogSoftMax<> >();
|
||||
@@ -240,13 +240,13 @@ TEST_CASE("CheckCopyMovingLinear3DNetworkTest", "[FeedForwardNetworkTest]")
|
||||
|
||||
// Construct a feed forward network with trainData.n_rows input nodes,
|
||||
// followed by a linear layer and then a Linear3D layer.
|
||||
FFN<NegativeLogLikelihood<> > *model = new FFN<NegativeLogLikelihood<> >;
|
||||
FFN<NegativeLogLikelihood> *model = new FFN<NegativeLogLikelihood>;
|
||||
model->Add<Linear>(8);
|
||||
model->Add<Sigmoid>();
|
||||
model->Add<Linear3D>(3);
|
||||
model->Add<LogSoftMax>();
|
||||
|
||||
FFN<NegativeLogLikelihood<> > *model1 = new FFN<NegativeLogLikelihood<> >;
|
||||
FFN<NegativeLogLikelihood> *model1 = new FFN<NegativeLogLikelihood>;
|
||||
model1->Add<Linear>(8);
|
||||
model1->Add<Sigmoid>();
|
||||
model1->Add<Linear3D>(3);
|
||||
@@ -270,7 +270,7 @@ TEST_CASE("CheckCopyMovingNoisyLinearTest", "[FeedForwardNetworkTest]")
|
||||
arma::mat output = arma::mat("0");
|
||||
|
||||
// Check copying constructor.
|
||||
FFN<NegativeLogLikelihood<>> *model1 = new FFN<NegativeLogLikelihood<>>();
|
||||
FFN<NegativeLogLikelihood> *model1 = new FFN<NegativeLogLikelihood>();
|
||||
model1->ResetData(input, output);
|
||||
model1->Add<NoisyLinear>(5);
|
||||
model1->Add<Linear>(1);
|
||||
@@ -280,7 +280,7 @@ TEST_CASE("CheckCopyMovingNoisyLinearTest", "[FeedForwardNetworkTest]")
|
||||
CheckCopyFunction(model1, input, output);
|
||||
|
||||
// Check moving constructor.
|
||||
FFN<NegativeLogLikelihood<>> *model2 = new FFN<NegativeLogLikelihood<>>();
|
||||
FFN<NegativeLogLikelihood> *model2 = new FFN<NegativeLogLikelihood>();
|
||||
model2->ResetData(input, output);
|
||||
model2->Add<NoisyLinear>(5);
|
||||
model2->Add<Linear>(1);
|
||||
@@ -301,7 +301,7 @@ TEST_CASE("CheckCopyMovingConcatenateTest", "[FeedForwardNetworkTest]")
|
||||
arma::mat output = arma::mat("1");
|
||||
|
||||
// Check copying constructor.
|
||||
FFN<NegativeLogLikelihood<>> *model1 = new FFN<NegativeLogLikelihood<>>();
|
||||
FFN<NegativeLogLikelihood> *model1 = new FFN<NegativeLogLikelihood>();
|
||||
model1->ResetData(input, output);
|
||||
model1->Add<Linear>(5);
|
||||
|
||||
@@ -319,7 +319,7 @@ TEST_CASE("CheckCopyMovingConcatenateTest", "[FeedForwardNetworkTest]")
|
||||
CheckCopyFunction(model1, input, output);
|
||||
|
||||
// Check moving constructor.
|
||||
FFN<NegativeLogLikelihood<>> *model2 = new FFN<NegativeLogLikelihood<>>();
|
||||
FFN<NegativeLogLikelihood> *model2 = new FFN<NegativeLogLikelihood>();
|
||||
model2->ResetData(input, output);
|
||||
model2->Add<Linear>(5);
|
||||
|
||||
@@ -349,14 +349,14 @@ TEST_CASE("CheckCopyMovingDropoutNetworkTest", "[FeedForwardNetworkTest]")
|
||||
arma::mat trainLabels = trainData.row(trainData.n_rows - 1) - 1;
|
||||
trainData.shed_row(trainData.n_rows - 1);
|
||||
|
||||
FFN<NegativeLogLikelihood<> > *model = new FFN<NegativeLogLikelihood<> >;
|
||||
FFN<NegativeLogLikelihood> *model = new FFN<NegativeLogLikelihood>;
|
||||
model->Add<Linear>(8);
|
||||
model->Add<Sigmoid>();
|
||||
model->Add<Dropout>(0.3);
|
||||
model->Add<Linear>(3);
|
||||
model->Add<LogSoftMax>();
|
||||
|
||||
FFN<NegativeLogLikelihood<> > *model1 = new FFN<NegativeLogLikelihood<> >;
|
||||
FFN<NegativeLogLikelihood> *model1 = new FFN<NegativeLogLikelihood>;
|
||||
model1->Add<Linear>(8);
|
||||
model1->Add<Sigmoid>();
|
||||
model1->Add<Dropout>(0.3);
|
||||
@@ -398,13 +398,13 @@ TEST_CASE("CheckCopyMovingVanillaNetworkTestNoBias", "[FeedForwardNetworkTest]")
|
||||
* +-----+ +--+--+ +-----+
|
||||
*/
|
||||
|
||||
FFN<NegativeLogLikelihood<> > *model = new FFN<NegativeLogLikelihood<> >;
|
||||
FFN<NegativeLogLikelihood> *model = new FFN<NegativeLogLikelihood>;
|
||||
model->Add<LinearNoBias>(8);
|
||||
model->Add<Sigmoid>();
|
||||
model->Add<LinearNoBias>(3);
|
||||
model->Add<LogSoftMax>();
|
||||
|
||||
FFN<NegativeLogLikelihood<> > *model1 = new FFN<NegativeLogLikelihood<> >;
|
||||
FFN<NegativeLogLikelihood> *model1 = new FFN<NegativeLogLikelihood>;
|
||||
model1->Add<LinearNoBias>(8);
|
||||
model1->Add<Sigmoid>();
|
||||
model1->Add<LinearNoBias>(3);
|
||||
@@ -436,12 +436,12 @@ TEST_CASE("CheckCopyMovingVanillaNetworkTestNoBias", "[FeedForwardNetworkTest]")
|
||||
// * followed by a linear layer and then a reparametrization layer.
|
||||
// */
|
||||
//
|
||||
// FFN<NegativeLogLikelihood<> > *model = new FFN<NegativeLogLikelihood<> >;
|
||||
// FFN<NegativeLogLikelihood> *model = new FFN<NegativeLogLikelihood>;
|
||||
// model->Add<LinearNoBias<> >(trainData.n_rows, 8);
|
||||
// model->Add<Reparametrization<> >(4, false, true, 1);
|
||||
// model->Add<LogSoftMax<> >();
|
||||
//
|
||||
// FFN<NegativeLogLikelihood<> > *model1 = new FFN<NegativeLogLikelihood<> >;
|
||||
// FFN<NegativeLogLikelihood> *model1 = new FFN<NegativeLogLikelihood>;
|
||||
// model1->Add<LinearNoBias<> >(trainData.n_rows, 8);
|
||||
// model1->Add<Reparametrization<> >(4, false, true, 1);
|
||||
// model1->Add<LogSoftMax<> >();
|
||||
@@ -497,7 +497,7 @@ TEST_CASE("FFVanillaNetworkTest", "[FeedForwardNetworkTest]")
|
||||
* +-----+ +-----+
|
||||
*/
|
||||
|
||||
FFN<NegativeLogLikelihood<> > model;
|
||||
FFN<NegativeLogLikelihood> model;
|
||||
model.Add<Linear>(8);
|
||||
model.Add<Sigmoid>();
|
||||
model.Add<Linear>(3);
|
||||
@@ -518,7 +518,7 @@ TEST_CASE("FFVanillaNetworkTest", "[FeedForwardNetworkTest]")
|
||||
arma::mat labels = arma::zeros(1, dataset.n_cols);
|
||||
labels.submat(0, labels.n_cols / 2, 0, labels.n_cols - 1).fill(1);
|
||||
|
||||
FFN<NegativeLogLikelihood<> > model1;
|
||||
FFN<NegativeLogLikelihood> model1;
|
||||
model1.Add<Linear>(10);
|
||||
model1.Add<Sigmoid>();
|
||||
model1.Add<Linear>(2);
|
||||
@@ -539,7 +539,7 @@ TEST_CASE("ForwardBackwardTest", "[FeedForwardNetworkTest]")
|
||||
arma::mat labels = arma::zeros(1, dataset.n_cols);
|
||||
labels.submat(0, labels.n_cols / 2, 0, labels.n_cols - 1).fill(1);
|
||||
|
||||
FFN<NegativeLogLikelihood<> > model;
|
||||
FFN<NegativeLogLikelihood> model;
|
||||
model.Add<Linear>(50);
|
||||
model.Add<Sigmoid>();
|
||||
model.Add<Linear>(10);
|
||||
@@ -645,7 +645,7 @@ TEST_CASE("DropoutNetworkTest", "[FeedForwardNetworkTest]")
|
||||
* +-----+
|
||||
*/
|
||||
|
||||
FFN<NegativeLogLikelihood<> > model;
|
||||
FFN<NegativeLogLikelihood> model;
|
||||
model.Add<Linear>(8);
|
||||
model.Add<Sigmoid>();
|
||||
model.Add<Dropout>();
|
||||
@@ -668,7 +668,7 @@ TEST_CASE("DropoutNetworkTest", "[FeedForwardNetworkTest]")
|
||||
arma::mat labels = arma::zeros(1, dataset.n_cols);
|
||||
labels.submat(0, labels.n_cols / 2, 0, labels.n_cols - 1).fill(1);
|
||||
|
||||
FFN<NegativeLogLikelihood<> > model1;
|
||||
FFN<NegativeLogLikelihood> model1;
|
||||
model1.Add<Linear>(10);
|
||||
model1.Add<Sigmoid>();
|
||||
model.Add<Dropout>();
|
||||
@@ -693,7 +693,7 @@ TEST_CASE("HighwayNetworkTest", "[FeedForwardNetworkTest]")
|
||||
arma::mat labels = arma::zeros(1, dataset.n_cols);
|
||||
labels.submat(0, labels.n_cols / 2, 0, labels.n_cols - 1).fill(1);
|
||||
|
||||
FFN<NegativeLogLikelihood<> > model;
|
||||
FFN<NegativeLogLikelihood> model;
|
||||
model.Add<Linear>(10);
|
||||
Highway* highway = new Highway();
|
||||
highway->Add<Linear>(10);
|
||||
@@ -750,7 +750,7 @@ TEST_CASE("DropConnectNetworkTest", "[FeedForwardNetworkTest]")
|
||||
*
|
||||
*/
|
||||
|
||||
FFN<NegativeLogLikelihood<> > model;
|
||||
FFN<NegativeLogLikelihood> model;
|
||||
model.Add<Linear>(8);
|
||||
model.Add<Sigmoid>();
|
||||
model.Add<DropConnect>(3);
|
||||
@@ -771,7 +771,7 @@ TEST_CASE("DropConnectNetworkTest", "[FeedForwardNetworkTest]")
|
||||
arma::mat labels = arma::zeros(1, dataset.n_cols);
|
||||
labels.submat(0, labels.n_cols / 2, 0, labels.n_cols - 1).fill(1);
|
||||
|
||||
FFN<NegativeLogLikelihood<> > model1;
|
||||
FFN<NegativeLogLikelihood> model1;
|
||||
model1.Add<Linear>(10);
|
||||
model1.Add<Sigmoid>();
|
||||
model1.Add<DropConnect>(2);
|
||||
@@ -787,7 +787,7 @@ TEST_CASE("DropConnectNetworkTest", "[FeedForwardNetworkTest]")
|
||||
*/
|
||||
TEST_CASE("FFNMiscTest", "[FeedForwardNetworkTest]")
|
||||
{
|
||||
FFN<MeanSquaredError<>> model;
|
||||
FFN<MeanSquaredError> model;
|
||||
model.Add<Linear>(3);
|
||||
model.Add<ReLU>();
|
||||
|
||||
@@ -822,7 +822,7 @@ TEST_CASE("FFSerializationTest", "[FeedForwardNetworkTest]")
|
||||
// Vanilla neural net with logistic activation function.
|
||||
// Because 92% of the patients are not hyperthyroid the neural
|
||||
// network must be significant better than 92%.
|
||||
FFN<NegativeLogLikelihood<> > model;
|
||||
FFN<NegativeLogLikelihood> model;
|
||||
model.Add<Linear>(8);
|
||||
model.Add<Sigmoid>();
|
||||
model.Add<Dropout>();
|
||||
@@ -833,7 +833,7 @@ TEST_CASE("FFSerializationTest", "[FeedForwardNetworkTest]")
|
||||
|
||||
model.Train(trainData, trainLabels, opt);
|
||||
|
||||
FFN<NegativeLogLikelihood<>> xmlModel, jsonModel, binaryModel;
|
||||
FFN<NegativeLogLikelihood> xmlModel, jsonModel, binaryModel;
|
||||
xmlModel.Add<Linear>(10); // Layer that will get removed.
|
||||
|
||||
// Serialize into other models.
|
||||
@@ -874,7 +874,7 @@ TEST_CASE("FFSerializationTest", "[FeedForwardNetworkTest]")
|
||||
// // Vanilla neural net with logistic activation function.
|
||||
// // Because 92% of the patients are not hyperthyroid the neural
|
||||
// // network must be significant better than 92%.
|
||||
// FFN<NegativeLogLikelihood<> > model;
|
||||
// FFN<NegativeLogLikelihood> model;
|
||||
// model.Add<Linear<> >(trainData.n_rows, 8);
|
||||
// model.Add<PReLU<> >();
|
||||
// model.Add<Dropout<> >();
|
||||
@@ -885,7 +885,7 @@ TEST_CASE("FFSerializationTest", "[FeedForwardNetworkTest]")
|
||||
//
|
||||
// model.Train(trainData, trainLabels, opt);
|
||||
//
|
||||
// FFN<NegativeLogLikelihood<>> xmlModel, jsonModel, binaryModel;
|
||||
// FFN<NegativeLogLikelihood> xmlModel, jsonModel, binaryModel;
|
||||
// xmlModel.Add<Linear<>>(10, 10); // Layer that will get removed.
|
||||
//
|
||||
// // Serialize into other models.
|
||||
@@ -924,7 +924,7 @@ TEST_CASE("FFSerializationTest", "[FeedForwardNetworkTest]")
|
||||
// testData.shed_row(testData.n_rows - 1);
|
||||
// testLabels -= 1; // The labels should be between 0 and numClasses - 1.
|
||||
//
|
||||
// FFN<NegativeLogLikelihood<>, RandomInitialization, CustomLayer<> > model;
|
||||
// FFN<NegativeLogLikelihood, RandomInitialization, CustomLayer<> > model;
|
||||
// model.Add<Linear<> >(trainData.n_rows, 8);
|
||||
// model.Add<CustomLayer<> >();
|
||||
// model.Add<Linear<> >(8, 3);
|
||||
@@ -943,7 +943,7 @@ TEST_CASE("FFSerializationTest", "[FeedForwardNetworkTest]")
|
||||
*/
|
||||
TEST_CASE("PartialForwardTest", "[FeedForwardNetworkTest]")
|
||||
{
|
||||
FFN<NegativeLogLikelihood<>, RandomInitialization> model;
|
||||
FFN<NegativeLogLikelihood, RandomInitialization> model;
|
||||
model.Add<Linear>(10);
|
||||
|
||||
// Add a new Add<> module which adds a (learnable) constant term to the input.
|
||||
@@ -1012,7 +1012,7 @@ TEST_CASE("FFNTrainReturnObjective", "[FeedForwardNetworkTest]")
|
||||
// Vanilla neural net with logistic activation function.
|
||||
// Because 92% of the patients are not hyperthyroid the neural
|
||||
// network must be significantly better than 92%.
|
||||
FFN<NegativeLogLikelihood<> > model;
|
||||
FFN<NegativeLogLikelihood> model;
|
||||
model.Add<Linear>(8);
|
||||
model.Add<Sigmoid>();
|
||||
model.Add<Dropout>();
|
||||
@@ -1032,7 +1032,7 @@ TEST_CASE("FFNTrainReturnObjective", "[FeedForwardNetworkTest]")
|
||||
TEST_CASE("FFNReturnModel", "[FeedForwardNetworkTest]")
|
||||
{
|
||||
// Create dummy network.
|
||||
FFN<NegativeLogLikelihood<> > model;
|
||||
FFN<NegativeLogLikelihood> model;
|
||||
Linear* linearA = new Linear(3);
|
||||
model.Add(linearA);
|
||||
Linear* linearB = new Linear(4);
|
||||
@@ -1082,7 +1082,7 @@ TEST_CASE("OptimizerTest", "[FeedForwardNetworkTest]")
|
||||
testData.shed_row(testData.n_rows - 1);
|
||||
testLabels -= 1; // The labels should be between 0 and numClasses.
|
||||
|
||||
FFN<NegativeLogLikelihood<>, RandomInitialization> model;
|
||||
FFN<NegativeLogLikelihood, RandomInitialization> model;
|
||||
model.Add<Linear>(8);
|
||||
model.Add<Linear>(3);
|
||||
model.Add<LogSoftMax>();
|
||||
@@ -1112,7 +1112,7 @@ TEST_CASE("FFNCheckInputShapeTest", "[FeedForwardNetworkTest]")
|
||||
arma::mat testLabels = testData.row(testData.n_rows - 1);
|
||||
testData.shed_row(testData.n_rows - 1);
|
||||
|
||||
FFN<NegativeLogLikelihood<>, RandomInitialization> model;
|
||||
FFN<NegativeLogLikelihood, RandomInitialization> model;
|
||||
model.Add<Linear>(8);
|
||||
model.Add<Linear>(3);
|
||||
model.Add<LogSoftMax>();
|
||||
|
||||
@@ -214,13 +214,13 @@ TEST_CASE("NetworkInitTest", "[InitRulesTest]")
|
||||
{
|
||||
arma::mat input = arma::ones(5, 1);
|
||||
arma::mat response;
|
||||
NegativeLogLikelihood<> outputLayer;
|
||||
NegativeLogLikelihood outputLayer;
|
||||
|
||||
// Create a simple network and use the RandomInitialization rule to
|
||||
// initialize the network parameters.
|
||||
RandomInitialization randomInit(0.5, 0.5);
|
||||
|
||||
FFN<NegativeLogLikelihood<>, RandomInitialization> randomModel(
|
||||
FFN<NegativeLogLikelihood, RandomInitialization> randomModel(
|
||||
std::move(outputLayer), randomInit);
|
||||
randomModel.Add<Linear>(5);
|
||||
randomModel.Add<Linear>(2);
|
||||
@@ -233,7 +233,7 @@ TEST_CASE("NetworkInitTest", "[InitRulesTest]")
|
||||
|
||||
// Create a simple network and use the OrthogonalInitialization rule to
|
||||
// initialize the network parameters.
|
||||
FFN<NegativeLogLikelihood<>, OrthogonalInitialization> orthogonalModel;
|
||||
FFN<NegativeLogLikelihood, OrthogonalInitialization> orthogonalModel;
|
||||
orthogonalModel.Add<Linear>(5);
|
||||
orthogonalModel.Add<Linear>(2);
|
||||
orthogonalModel.Add<LogSoftMax>();
|
||||
@@ -243,8 +243,8 @@ TEST_CASE("NetworkInitTest", "[InitRulesTest]")
|
||||
|
||||
// Create a simple network and use the ZeroInitialization rule to
|
||||
// initialize the network parameters.
|
||||
FFN<NegativeLogLikelihood<>, ConstInitialization>
|
||||
zeroModel(NegativeLogLikelihood<>(), ConstInitialization(0));
|
||||
FFN<NegativeLogLikelihood, ConstInitialization>
|
||||
zeroModel(NegativeLogLikelihood(), ConstInitialization(0));
|
||||
zeroModel.Add<Linear>(5);
|
||||
zeroModel.Add<Linear>(2);
|
||||
zeroModel.Add<LogSoftMax>();
|
||||
@@ -258,7 +258,7 @@ TEST_CASE("NetworkInitTest", "[InitRulesTest]")
|
||||
// parameters.
|
||||
KathirvalavakumarSubavathiInitialization kathirvalavakumarSubavathiInit(
|
||||
input, 1.5);
|
||||
FFN<NegativeLogLikelihood<>, KathirvalavakumarSubavathiInitialization>
|
||||
FFN<NegativeLogLikelihood, KathirvalavakumarSubavathiInitialization>
|
||||
ksModel(std::move(outputLayer), kathirvalavakumarSubavathiInit);
|
||||
ksModel.Add<Linear>(5);
|
||||
ksModel.Add<Linear>(2);
|
||||
@@ -269,7 +269,7 @@ TEST_CASE("NetworkInitTest", "[InitRulesTest]")
|
||||
|
||||
// Create a simple network and use the OivsInitialization rule to
|
||||
// initialize the network parameters.
|
||||
FFN<NegativeLogLikelihood<>, OivsInitialization<> > oivsModel;
|
||||
FFN<NegativeLogLikelihood, OivsInitialization<> > oivsModel;
|
||||
oivsModel.Add<Linear>(5);
|
||||
oivsModel.Add<Linear>(2);
|
||||
oivsModel.Add<LogSoftMax>();
|
||||
@@ -279,7 +279,7 @@ TEST_CASE("NetworkInitTest", "[InitRulesTest]")
|
||||
|
||||
// Create a simple network and use the GaussianInitialization rule to
|
||||
// initialize the network parameters.
|
||||
FFN<NegativeLogLikelihood<>, GaussianInitialization> gaussianModel;
|
||||
FFN<NegativeLogLikelihood, GaussianInitialization> gaussianModel;
|
||||
gaussianModel.Add<Linear>(5);
|
||||
gaussianModel.Add<Linear>(2);
|
||||
gaussianModel.Add<LogSoftMax>();
|
||||
|
||||
@@ -75,8 +75,8 @@ void BuildVanillaNetwork(MatType& trainData,
|
||||
// Cauchy’s Inequality Based on Sensitivity Analysis" paper.
|
||||
KathirvalavakumarSubavathiInitialization init(trainData, 4.59);
|
||||
|
||||
FFN<MeanSquaredError<>, KathirvalavakumarSubavathiInitialization>
|
||||
model(MeanSquaredError<>(), init);
|
||||
FFN<MeanSquaredError, KathirvalavakumarSubavathiInitialization>
|
||||
model(MeanSquaredError(), init);
|
||||
|
||||
model.Add<Linear>(hiddenLayerSize);
|
||||
model.Add<LeakyReLU>();
|
||||
|
||||
@@ -53,7 +53,7 @@ using namespace mlpack::ann;
|
||||
TEST_CASE("HuberLossTest", "[LossFunctionsTest]")
|
||||
{
|
||||
arma::mat input, target, output;
|
||||
HuberLoss<> module;
|
||||
HuberLoss module;
|
||||
|
||||
// Test the Forward function.
|
||||
input = arma::mat("17.45 12.91 13.63 29.01 7.12 15.47 31.52 31.97");
|
||||
@@ -82,10 +82,10 @@ TEST_CASE("PoissonNLLLossTest", "[LossFunctionsTest]")
|
||||
arma::mat input, target, input4, target4;
|
||||
arma::mat output1, output2, output3, output4;
|
||||
arma::mat expOutput1, expOutput2, expOutput3, expOutput4;
|
||||
PoissonNLLLoss<> module1;
|
||||
PoissonNLLLoss<> module2(true, true, 1e-08, false);
|
||||
PoissonNLLLoss<> module3(true, true, 1e-08, true);
|
||||
PoissonNLLLoss<> module4(false, true, 1e-08, true);
|
||||
PoissonNLLLoss module1;
|
||||
PoissonNLLLoss module2(true, true, 1e-08, false);
|
||||
PoissonNLLLoss module3(true, true, 1e-08, true);
|
||||
PoissonNLLLoss module4(false, true, 1e-08, true);
|
||||
|
||||
// Test the Forward function on a user generated input.
|
||||
input = arma::mat("1.0 1.0 1.9 1.6 -1.9 3.7 -1.0 0.5");
|
||||
@@ -148,7 +148,7 @@ TEST_CASE("SimpleKLDivergenceTest", "[LossFunctionsTest]")
|
||||
{
|
||||
arma::mat input, target, output;
|
||||
double loss;
|
||||
KLDivergence<> module(true);
|
||||
KLDivergence module(true);
|
||||
|
||||
// Test the Forward function. Loss should be 0 if input = target.
|
||||
input = arma::ones(10, 1);
|
||||
@@ -163,7 +163,7 @@ TEST_CASE("SimpleKLDivergenceTest", "[LossFunctionsTest]")
|
||||
TEST_CASE("SimpleMeanSquaredLogarithmicErrorTest", "[LossFunctionsTest]")
|
||||
{
|
||||
arma::mat input, output, target;
|
||||
MeanSquaredLogarithmicError<> module;
|
||||
MeanSquaredLogarithmicError module;
|
||||
|
||||
// Test the Forward function on a user generator input and compare it against
|
||||
// the manually calculated result.
|
||||
@@ -198,7 +198,7 @@ TEST_CASE("KLDivergenceMeanTest", "[LossFunctionsTest]")
|
||||
{
|
||||
arma::mat input, target, output;
|
||||
double loss;
|
||||
KLDivergence<> module(true);
|
||||
KLDivergence module(true);
|
||||
|
||||
// Test the Forward function.
|
||||
input = arma::mat("1 1 1 1 1 1 1 1 1 1");
|
||||
@@ -219,7 +219,7 @@ TEST_CASE("KLDivergenceNoMeanTest", "[LossFunctionsTest]")
|
||||
{
|
||||
arma::mat input, target, output;
|
||||
double loss;
|
||||
KLDivergence<> module(false);
|
||||
KLDivergence module(false);
|
||||
|
||||
// Test the Forward function.
|
||||
input = arma::mat("1 1 1 1 1 1 1 1 1 1");
|
||||
@@ -239,7 +239,7 @@ TEST_CASE("KLDivergenceNoMeanTest", "[LossFunctionsTest]")
|
||||
TEST_CASE("SimpleMeanSquaredErrorTest", "[LossFunctionsTest]")
|
||||
{
|
||||
arma::mat input, output, target;
|
||||
MeanSquaredError<> module;
|
||||
MeanSquaredError module;
|
||||
|
||||
// Test the Forward function on a user generator input and compare it against
|
||||
// the manually calculated result.
|
||||
@@ -276,8 +276,8 @@ TEST_CASE("SimpleMeanSquaredErrorTest", "[LossFunctionsTest]")
|
||||
TEST_CASE("SimpleBinaryCrossEntropyLossTest", "[LossFunctionsTest]")
|
||||
{
|
||||
arma::mat input1, input2, input3, output, target1, target2, target3;
|
||||
BCELoss<> module1(1e-6, false);
|
||||
BCELoss<> module2(1e-6, true);
|
||||
BCELoss module1(1e-6, false);
|
||||
BCELoss module2(1e-6, true);
|
||||
// Test the Forward function on a user generator input and compare it against
|
||||
// the manually calculated result.
|
||||
input1 = arma::mat("0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5");
|
||||
@@ -329,7 +329,7 @@ TEST_CASE("SimpleSigmoidCrossEntropyErrorTest", "[LossFunctionsTest]")
|
||||
{
|
||||
arma::mat input1, input2, input3, output, target1,
|
||||
target2, target3, expectedOutput;
|
||||
SigmoidCrossEntropyError<> module;
|
||||
SigmoidCrossEntropyError module;
|
||||
|
||||
// Test the Forward function on a user generator input and compare it against
|
||||
// the calculated result.
|
||||
@@ -388,7 +388,7 @@ TEST_CASE("SimpleSigmoidCrossEntropyErrorTest", "[LossFunctionsTest]")
|
||||
TEST_CASE("SimpleEarthMoverDistanceLayerTest", "[LossFunctionsTest]")
|
||||
{
|
||||
arma::mat input1, input2, output, target1, target2, expectedOutput;
|
||||
EarthMoverDistance<> module;
|
||||
EarthMoverDistance module;
|
||||
|
||||
// Test the Forward function on a user generator input and compare it against
|
||||
// the manually calculated result.
|
||||
@@ -433,7 +433,7 @@ TEST_CASE("GradientMeanSquaredErrorTest", "[LossFunctionsTest]")
|
||||
input = arma::randu(10, 1);
|
||||
target = arma::randu(2, 1);
|
||||
|
||||
model = new FFN<MeanSquaredError<>, NguyenWidrowInitialization>();
|
||||
model = new FFN<MeanSquaredError, NguyenWidrowInitialization>();
|
||||
model->ResetData(input, target);
|
||||
model->Add<Linear>(2);
|
||||
model->Add<Sigmoid>();
|
||||
@@ -454,7 +454,7 @@ TEST_CASE("GradientMeanSquaredErrorTest", "[LossFunctionsTest]")
|
||||
|
||||
arma::mat& Parameters() { return model->Parameters(); }
|
||||
|
||||
FFN<MeanSquaredError<>, NguyenWidrowInitialization>* model;
|
||||
FFN<MeanSquaredError, NguyenWidrowInitialization>* model;
|
||||
arma::mat input, target;
|
||||
} function;
|
||||
|
||||
@@ -474,7 +474,7 @@ TEST_CASE("GradientReconstructionLossTest", "[LossFunctionsTest]")
|
||||
input = arma::randu(10, 1);
|
||||
target = arma::randu(2, 1);
|
||||
|
||||
model = new FFN<ReconstructionLoss<>, NguyenWidrowInitialization>();
|
||||
model = new FFN<ReconstructionLoss, NguyenWidrowInitialization>();
|
||||
model->ResetData(input, target);
|
||||
model->Add<Linear>(2);
|
||||
model->Add<Sigmoid>();
|
||||
@@ -495,7 +495,7 @@ TEST_CASE("GradientReconstructionLossTest", "[LossFunctionsTest]")
|
||||
|
||||
arma::mat& Parameters() { return model->Parameters(); }
|
||||
|
||||
FFN<ReconstructionLoss<>, NguyenWidrowInitialization>* model;
|
||||
FFN<ReconstructionLoss, NguyenWidrowInitialization>* model;
|
||||
arma::mat input, target;
|
||||
} function;
|
||||
|
||||
@@ -509,7 +509,7 @@ TEST_CASE("DiceLossTest", "[LossFunctionsTest]")
|
||||
{
|
||||
arma::mat input1, input2, target, output;
|
||||
double loss;
|
||||
DiceLoss<> module;
|
||||
DiceLoss module;
|
||||
|
||||
// Test the Forward function. Loss should be 0 if input = target.
|
||||
input1 = arma::ones(10, 1);
|
||||
@@ -549,7 +549,7 @@ TEST_CASE("DiceLossTest", "[LossFunctionsTest]")
|
||||
TEST_CASE("SimpleMeanBiasErrorTest", "[LossFunctionsTest]")
|
||||
{
|
||||
arma::mat input, output, target;
|
||||
MeanBiasError<> module;
|
||||
MeanBiasError module;
|
||||
|
||||
// Test the Forward function on a user generator input and compare it against
|
||||
// the manually calculated result.
|
||||
@@ -588,7 +588,7 @@ TEST_CASE("LogCoshLossTest", "[LossFunctionsTest]")
|
||||
{
|
||||
arma::mat input, target, output;
|
||||
double loss;
|
||||
LogCoshLoss<> module(2);
|
||||
LogCoshLoss module(2);
|
||||
|
||||
// Test the Forward function. Loss should be 0 if input = target.
|
||||
input = arma::ones(10, 1);
|
||||
@@ -627,7 +627,7 @@ TEST_CASE("HingeEmbeddingLossTest", "[LossFunctionsTest]")
|
||||
{
|
||||
arma::mat input, target, output;
|
||||
double loss;
|
||||
HingeEmbeddingLoss<> module;
|
||||
HingeEmbeddingLoss module;
|
||||
|
||||
// Test the Forward function. Loss should be 0 if input = target.
|
||||
input = arma::ones(10, 1);
|
||||
@@ -665,7 +665,7 @@ TEST_CASE("HingeEmbeddingLossTest", "[LossFunctionsTest]")
|
||||
TEST_CASE("SimpleL1LossTest", "[LossFunctionsTest]")
|
||||
{
|
||||
arma::mat input1, input2, output, target1, target2;
|
||||
L1Loss<> module(false);
|
||||
L1Loss module(false);
|
||||
|
||||
// Test the Forward function on a user generator input and compare it against
|
||||
// the manually calculated result.
|
||||
@@ -702,7 +702,7 @@ TEST_CASE("CosineEmbeddingLossTest", "[LossFunctionsTest]")
|
||||
{
|
||||
arma::mat input1, input2, y, output;
|
||||
double loss;
|
||||
CosineEmbeddingLoss<> module;
|
||||
CosineEmbeddingLoss module;
|
||||
|
||||
// Test the Forward function. Loss should be 0 if input1 = input2 and y = 1.
|
||||
input1 = arma::mat(1, 10);
|
||||
@@ -750,7 +750,7 @@ TEST_CASE("CosineEmbeddingLossTest", "[LossFunctionsTest]")
|
||||
TEST_CASE("MarginRankingLossTest", "[LossFunctionsTest]")
|
||||
{
|
||||
arma::mat input, input1, input2, target, output;
|
||||
MarginRankingLoss<> module;
|
||||
MarginRankingLoss module;
|
||||
|
||||
// Test the Forward function on a user generator input and compare it against
|
||||
// the manually calculated result.
|
||||
@@ -794,8 +794,8 @@ TEST_CASE("SoftMarginLossTest", "[LossFunctionsTest]")
|
||||
{
|
||||
arma::mat input, target, output, expectedOutput;
|
||||
double loss;
|
||||
SoftMarginLoss<> module1;
|
||||
SoftMarginLoss<> module2(false);
|
||||
SoftMarginLoss module1;
|
||||
SoftMarginLoss module2(false);
|
||||
|
||||
input = arma::mat("0.1778 0.0957 0.1397 0.1203 0.2403 0.1925 -0.2264 -0.3400 "
|
||||
"-0.3336");
|
||||
@@ -849,7 +849,7 @@ TEST_CASE("SoftMarginLossTest", "[LossFunctionsTest]")
|
||||
TEST_CASE("MeanAbsolutePercentageErrorTest", "[LossFunctionsTest]")
|
||||
{
|
||||
arma::mat input, target, output, expectedOutput;
|
||||
MeanAbsolutePercentageError<> module;
|
||||
MeanAbsolutePercentageError module;
|
||||
|
||||
input = arma::mat("3 -0.5 2 7");
|
||||
target = arma::mat("2.5 0.2 2 8");
|
||||
@@ -876,7 +876,7 @@ TEST_CASE("MeanAbsolutePercentageErrorTest", "[LossFunctionsTest]")
|
||||
TEST_CASE("VRClassRewardLayerParametersTest", "[LossFunctionsTest]")
|
||||
{
|
||||
// Parameter order : scale, sizeAverage.
|
||||
VRClassReward<> layer(2, false);
|
||||
VRClassReward layer(2, false);
|
||||
|
||||
// Make sure we can get the parameters successfully.
|
||||
REQUIRE(layer.Scale() == 2);
|
||||
@@ -890,7 +890,7 @@ TEST_CASE("TripletMarginLossTest")
|
||||
{
|
||||
arma::mat anchor, positive, negative;
|
||||
arma::mat input, target, output;
|
||||
TripletMarginLoss<> module;
|
||||
TripletMarginLoss module;
|
||||
|
||||
// Test the Forward function on a user generated input and compare it against
|
||||
// the manually calculated result.
|
||||
@@ -938,8 +938,8 @@ TEST_CASE("HingeLossTest", "[LossFunctionsTest]")
|
||||
{
|
||||
arma::mat input, target, target_b, output;
|
||||
double loss, loss_b;
|
||||
HingeLoss<> module1;
|
||||
HingeLoss<> module2(false);
|
||||
HingeLoss module1;
|
||||
HingeLoss module2(false);
|
||||
|
||||
// Test the Forward function. Loss should be 0 if input = target.
|
||||
input = arma::ones(10, 1);
|
||||
@@ -1015,8 +1015,8 @@ TEST_CASE("MultiLabelSoftMarginLossTest", "[LossFunctionsTest]")
|
||||
{
|
||||
arma::mat input, target, output, expectedOutput;
|
||||
double loss;
|
||||
MultiLabelSoftMarginLoss<> module1;
|
||||
MultiLabelSoftMarginLoss<> module2(false);
|
||||
MultiLabelSoftMarginLoss module1;
|
||||
MultiLabelSoftMarginLoss module2(false);
|
||||
|
||||
input = arma::mat("0.1778 0.0957 0.1397 0.1203 0.2403 0.1925 -0.2264 -0.3400 "
|
||||
"-0.3336");
|
||||
@@ -1074,8 +1074,8 @@ TEST_CASE("MultiLabelSoftMarginLossWeightedTest", "[LossFunctionsTest]")
|
||||
arma::rowvec weights;
|
||||
double loss;
|
||||
weights = arma::mat("1 2 3");
|
||||
MultiLabelSoftMarginLoss<> module1(true, weights);
|
||||
MultiLabelSoftMarginLoss<> module2(false, weights);
|
||||
MultiLabelSoftMarginLoss module1(true, weights);
|
||||
MultiLabelSoftMarginLoss module2(false, weights);
|
||||
|
||||
input = arma::mat("0.1778 0.0957 0.1397 0.2256 0.1203 0.2403 0.1925 0.3144 "
|
||||
"-0.2264 -0.3400 -0.3336 -0.8695");
|
||||
|
||||
@@ -571,7 +571,7 @@ void GenerateNoisySinRNN(arma::cube& data,
|
||||
*/
|
||||
double RNNSineTest(size_t hiddenUnits, size_t rho, size_t numEpochs = 100)
|
||||
{
|
||||
RNN<MeanSquaredError<> > net(rho, true);
|
||||
RNN<MeanSquaredError> net(rho, true);
|
||||
net.Add<LinearNoBias>(hiddenUnits);
|
||||
net.Add<LSTM>(hiddenUnits);
|
||||
net.Add<LinearNoBias>(1);
|
||||
@@ -853,8 +853,8 @@ TEST_CASE("RNNFFNTest", "[RecurrentNetworkTest]")
|
||||
{
|
||||
// We'll create an RNN with *no* BPTT, just a simple single-layer linear
|
||||
// network.
|
||||
RNN<MeanSquaredError<>, ConstInitialization> rnn;
|
||||
FFN<MeanSquaredError<>, ConstInitialization> ffn;
|
||||
RNN<MeanSquaredError, ConstInitialization> rnn;
|
||||
FFN<MeanSquaredError, ConstInitialization> ffn;
|
||||
|
||||
rnn.Add<Linear>(10);
|
||||
rnn.Add<Sigmoid>();
|
||||
|
||||
Reference in New Issue
Block a user