Creating a histogram with boost.accumulator and stl

#include <vector>
#include <algorithm>
#include <iostream>
#include <functional>

#include <boost/range/algorithm.hpp>
#include <boost/range/algorithm_ext.hpp>
#include <boost/accumulators/accumulators.hpp>
#include <boost/accumulators/statistics/density.hpp>
#include <boost/accumulators/statistics/stats.hpp>

using namespace std;
using namespace std::placeholders;
using namespace boost;
using namespace boost::accumulators;

typedef accumulator_set<double, features<tag::density> > acc;
typedef iterator_range<std::vector<std::pair<double, double> >::iterator > histogram_type;

template <typename T>
class data_filler
{
public:
data_filler(){}
T operator()() { return rand()/(T)RAND_MAX; }
};

int main(int argc, char** argv)
{

acc myAccumulator( tag::density::num_bins = 20, tag::density::cache_size = 10);

vector<double> lines(100);
iota(lines,0);
for(auto &i:lines) i/=100;
boost::copy(lines, ostream_iterator<double>(cout,” “));
std::for_each(lines.begin(), lines.end(),std::ref(myAccumulator));

histogram_type hist = density(myAccumulator);

double total = 0.0;

for( int i = 0; i < hist.size(); i++ )
{
std::cout << “Bin lower bound: ” << hist[i].first << “, Value: ” << hist[i].second << std::endl;
total += hist[i].second;
}

std::cout << “Total: ” << total << std::endl; //should be 1 (and it is)

return 0;
}

intall lua 5.2.1 on scientific linux 6

 

  • download lua
  • unzip
  • check that intel compiler modules are unloaded
  • &gt; make linux
  • &gt; make local
  • &gt; mv install ~/modules/lua/5.2.1
  • edit modfiles:

 

&gt; cat modules/modfiles/lua/5.2.1

#%Module1.0

proc ModulesHelp { } {

  puts stderr “This module sets up lua 5.2.1 in your environment.”

}

 

module-whatis “This module sets up lua 5.2.1 in your environment.”

 

set LUA_DIR /global/home/users/kigumen/modules/lua/5.2.1

setenv LUA_DIR $LUA_DIR

prepend-path PATH       $LUA_DIR/bin

prepend-path MANPATH    $LUA_DIR/man

  • add to .bashrc

if [ -d “/global/home/users/kigumen/modules/modfiles” ] ; then    MODULEPATH=”$MODULEPATH:/global/home/users/kigumen/modules/modfiles”

fi

  • add to .bashrc module load lua

installing latest gcc compiler on scientific linux or centos

  • install zlib
  • add zlib to ld path> export LD_LIBRARY_PATH=”/global/home/users/kigumen/modules/zlib/1.2.7/lib/:$LD_LIBRARY_PATH”
  • download bzr source.
  • extract it.
  • get gsrc:
  1. ./bzr-2.5.1/bzr checkout bzr://bzr.savannah.gnu.org/gsrc/trunk/ gsrc
  1. $ cd gsrc
  2. $ ./bootstrap # to create the configure script
  3. $ mkdir ../gnu
  4. $ ./configure –prefix=$HOME/gnu # directory to install the packages
  5. $ make -C gnu/gcc
  6. $ make -C gnu/gcc install

ssh using connectBot to amazon ec2 (aws)

  1. enable password access to ec2 http://bensnotepad.com/enable-password-access-to-your-amazon-ec2-linux-instance/
  2. (optional) use a public key instead of a password http://www.arbi.se/using-connectbot-for-ssh-with-pubkey-authentication/

use libboost with intel compiler 12.1 under ubuntu 11.10

by default ubuntu installs libboost 1.46 library as libbooost-all-dev. it doesn’t work with icpc, icpc gives errors:

Read more…

Search for text in multiple pdf/ps files and count the occurrence of the text. (ubuntu, linux)

to convert pdf to text use pdftotext from poppler-utils:

sudo apt-get install poppler-utils

this function uses find to locate all *.pdf files in the current directory, converts pdf to text and counts appearance of the search term in the file:

spdf () { find . -name "*.pdf" -print0| while read -d $'' file; do co=$(pdftotext -q "$file" - |grep -c $1); if [ $co -ne 0 ]; then echo $co - "$file" ; fi ; done }

use:

> spdf modes

will list files that contain the word “modes” and will tell you how many times it is mentioned in the file. i’m not sure but may be it just list the lines that contain the word(s).

this would be useful if you search for publications and want to see which one is more relevant. one way to find out is to see which one mentions your term the most.

for ps use

sps () { find . -name "*.ps" -print0| while read -d $'' file; do co=$(ps2txt "$file" |grep -c $1); if [ $co -ne 0 ]; then echo $co - "$file" ; fi ; done }

Running ubuntu 11.04 partition in windows 7 VirtualBox

the title means that you have a dual-boot and you would like to access an existing  linux partition using virtual box.

in short: 1) create .vmdk file using VboxManage.exe. 2) create VM 3) check  “Use host I/O cache” Read more…

Follow

Get every new post delivered to your Inbox.