13 #ifndef XACC_ALGORITHM_RBM_CLASSIFICATION_CLASSICAL_DATAEXP_HPP_ 14 #define XACC_ALGORITHM_RBM_CLASSIFICATION_CLASSICAL_DATAEXP_HPP_ 16 #include "rbm_classification.hpp" 27 return 1./(1.+std::exp(-x));
32 const std::string
name()
const override {
return "data-exp"; }
34 std::tuple<Eigen::MatrixXd, Eigen::VectorXd, Eigen::VectorXd>
35 compute(Eigen::MatrixXd &features, Eigen::MatrixXd &w, Eigen::VectorXd &v,
37 int batch_size = features.rows();
43 Eigen::MatrixXd tmp = features * w;
44 for (
int col = 0; col < tmp.cols(); col++) {
45 for (
int row = 0; row < tmp.rows(); row++) {
46 tmp(row, col) += h(col);
50 for (
int col = 0; col < tmp.cols(); col++) {
51 for (
int row = 0; row < tmp.rows(); row++) {
52 tmp(row, col) = 1./(1.+std::exp(-tmp(row,col)));
56 Eigen::MatrixXd h_probs = tmp;
59 Eigen::MatrixXd w_expectation =
60 (features.transpose() * h_probs) / batch_size;
62 Eigen::VectorXd v_expectation = Eigen::VectorXd::Zero(v.size());
63 Eigen::VectorXd h_expectation = Eigen::VectorXd::Zero(v.size());
65 for (
int i = 0; i < features.rows(); i++) {
66 v_expectation(i) = features.row(i).sum() / features.row(i).size();
67 h_expectation(i) = h_probs.row(i).sum() / h_probs.row(i).size();
70 return std::make_tuple(w_expectation, v_expectation, h_expectation);
const std::string description() const override
Definition: classical_data_expectations.hpp:33
Definition: Accelerator.hpp:25
Definition: rbm_classification.hpp:24
Definition: heterogeneous.hpp:45
Definition: classical_data_expectations.hpp:22
const std::string name() const override
Definition: classical_data_expectations.hpp:32
Definition: classical_data_expectations.hpp:30