- use normalize per training sample
git-svn-id: http://moon:8086/svn/software/trunk/projects/RBM@555 b431acfa-c32f-4a4a-93f1-934dc6c82436
This commit is contained in:
+15
-2
@@ -66,7 +66,7 @@ MatrixXd Rbm::sample(MatrixXd const &src)
|
|||||||
|
|
||||||
noiseUniform(n);
|
noiseUniform(n);
|
||||||
|
|
||||||
return (src.array() > n.array()).cast<double>();
|
return (src.array() >= n.array()).cast<double>();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Rbm::sample(MatrixXd &dst, MatrixXd const &src)
|
void Rbm::sample(MatrixXd &dst, MatrixXd const &src)
|
||||||
@@ -86,6 +86,7 @@ RowVectorXd Rbm::probsLogistic(RowVectorXd const &src)
|
|||||||
|
|
||||||
MatrixXd Rbm::normalizeData(MatrixXd const &src)
|
MatrixXd Rbm::normalizeData(MatrixXd const &src)
|
||||||
{
|
{
|
||||||
|
#if 0
|
||||||
double mean = src.array().mean();
|
double mean = src.array().mean();
|
||||||
cout << "mean" << ": " << endl << mean << endl;
|
cout << "mean" << ": " << endl << mean << endl;
|
||||||
|
|
||||||
@@ -94,7 +95,19 @@ MatrixXd Rbm::normalizeData(MatrixXd const &src)
|
|||||||
double stddev = sqrt(x2.array().mean());
|
double stddev = sqrt(x2.array().mean());
|
||||||
cout << "stddev" << ": " << endl << stddev << endl;
|
cout << "stddev" << ": " << endl << stddev << endl;
|
||||||
|
|
||||||
return x;
|
return x/stddev;
|
||||||
|
|
||||||
|
#else
|
||||||
|
MatrixXd mean = src.colwise().mean();
|
||||||
|
MatrixXd x = src - mean.replicate(src.rows(), 1);
|
||||||
|
MatrixXd x2 = x.cwiseProduct(x);
|
||||||
|
|
||||||
|
|
||||||
|
MatrixXd stddev_inv = x2.colwise().mean();
|
||||||
|
stddev_inv = stddev_inv.array().sqrt().cwiseInverse();
|
||||||
|
return x*stddev_inv.replicate(src.rows(), 1);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user