Guest User

Untitled

a guest
Sep 23rd, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <fstream>
  4. #include "mkl.h"
  5. #include "math.h"
  6. #include <vector>
  7. #include <cmath>
  8. #include <string>
  9.  
  10.  
  11.  
  12. #include <boost/random/linear_congruential.hpp>
  13. #include <boost/random/uniform_int.hpp>
  14. #include <boost/random/uniform_real.hpp>
  15. #include <boost/random/variate_generator.hpp>
  16.  
  17.  
  18. #define EIGEN_USE_MKL_BLAS
  19. #define EIGEN_USE_MKL_LAPACKE
  20.  
  21. #ifndef PI
  22. #define PI 3.141592653589793
  23. #endif
  24.  
  25.  
  26. #include <Eigen/Dense>
  27.  
  28. using namespace Eigen;
  29. using namespace std;
  30.  
  31. // This is a typedef for a random number generator.
  32. // Try boost::mt19937 or boost::ecuyer1988 instead of boost::minstd_rand
  33. typedef boost::minstd_rand base_generator_type;
  34. ////////////////////////////////////////////////
  35.  
  36.  
  37. // THIS IS A TYPEDEF FOR A ROWMAJOR MATRIX
  38. typedef Eigen::Matrix<double,Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> MatrixRMXd;
  39.  
  40. MatrixRMXd negSubset(MatrixXd xmat) {
  41.  
  42. vector<double> nn;
  43. int N = xmat.rows();
  44. int T = xmat.cols();
  45.  
  46. for(int n = 0; n < N; n++) {
  47. for(int t = 0; t < T; t++) {
  48. if( xmat(n,t) < 0) {
  49. nn.push_back(xmat(n,t));
  50. }
  51. }
  52. } // end double for
  53.  
  54. MatrixRMXd mysubset = MatrixRMXd(nn.size(), 1);
  55. for(int i = 0; i < nn.size(); i++) {
  56. mysubset(i,0) = nn[i];
  57. }
  58.  
  59. return(mysubset);
  60. }
  61.  
  62.  
  63. // TEST Policy function getter
  64. int main() {
  65.  
  66.  
  67. int N, T;
  68. N = 15;
  69. T = 8;
  70. MatrixXd xmat(N, T);
  71.  
  72. for(int n = 0; n < N; n++) {
  73. for(int t = 0; t < T; t++) {
  74. int tmp = n * t + t;
  75. if ( (tmp % 2 ) == 0) {
  76. tmp = -1 * tmp;
  77. }
  78. xmat(n,t) = double(tmp);
  79. }
  80. }
  81.  
  82. cout << xmat << endl;
  83.  
  84. double meanneg = (xmat.array() < 0).select(xmat, 0).sum() / (xmat.array() < 0).count();
  85. cout << "MEAN NEG: " << meanneg << endl;
  86.  
  87. cout << "////////////////////////////////////////" << endl;
  88. MatrixRMXd myneg = negSubset(xmat);
  89. cout << myneg.mean() << endl;
  90. }
Add Comment
Please, Sign In to add comment