Using boost's skewed_normal_distribution - c++

I am fairly new to c++ and boost.
I want to create a set of numbers that derived from a skewed distribution using Boost's skewed_normal_distribution class.
I'm not sure how to even start. I want to define a distribution with mean 0.05, variance 0.95, but a skew of 0.5. The following code doesn't work and I realise I need to set up a variate_generator as well.
Can anyone provide some pointers? I am not finding the boost documentation page on skew_normal_distribution very intuitive but that might be because of my inexperience.
Note the main problem I am getting is the message:
‘skew_normal_distribution’ is not a member of ‘boost’
Many thanks
#include <boost/random.hpp>
#include <boost/random/normal_distribution.hpp>
#include <boost/math/distributions/skew_normal.hpp>
int main () {
boost::skew_normal_distribution<> normal(0.05, 0.95, 0.5);
return 0;
}

Use boost::math::skew_normal_distribution instead of boost::skew_normal_distribution for the message
skew_normal_distribution is not a member of boost

Related

Can't find entry point (_ZSt28__throw_bad_array_new_lengthv) in DLL (filepath)

The error
The exact error is the title of the question.
It happens when I use vectorName.push_back() function.
I recreated it with just this simple code:
#include <iostream>
#include <vector>
using namespace std;
int main() {
vector <int> vec = {};
vec.push_back(2);
return 0;
}
Compiler and setup information
Im using msys2, and
I set it up using this guide
I have no idea if this is relevant or not, but I used tdm-gcc before this.
Research
A fix is almost nowhere to be found, or i just didn't look hard enough. I have found some posts about the _ZSt28__throw_bad_array_new_lengthv, but not with entry point. And because I didn't find anything about this exact issue, I didn't try anything.

C++ - Using #include directives to change program configuration in Arduino

I have used an Arduino with my electric circuit. The circuit is still a prototype and I am still changing it and trying new Configurations. That means that on each run, I would like a different version of double measurePower() to be executed. Call it Polymorphism, if you will.
So far, I have done the following, to change the configuration on demand, by changing only one line:
main.c:
#include config.h
config.h:
#include circuit_1.h // change this to circuit_i.h, whenever you want.
// define var1, var2, ...
circuit_1.h:
double measurePower() {
// calculate based on some config.
}
circuit_2.h:
double measurePower() {
// calculate based on another config.
}
But after running into #include related errors, and looking online, I realize that this is not the best Idea. So my question is, how can I keep Polymorphism, and also possibly keep the compiled executable smaller. So, is there a practical solution using directives only?

What is the parameter `Distance d = Distance()` in OpenCV's hierachicalClustering function?

I've gone through questions, the source code, and other examples, and I can't for the life of me understand what the Distance d = Distance() parameter means in the function
template<typename Distance> int flann::hierarchicalClustering(const Mat& features, Mat& centers, const cvflann::KMeansIndexParams& params, Distance d=Distance())
It's addressed in the comments of this question, but I can't find the Distance type anywhere. I've imported the following files:
#include "opencv2/contrib/contrib.hpp"
#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/video/tracking.hpp"
#include "opencv2/nonfree/features2d.hpp"
#include "opencv2/flann/flann.hpp"
I've checked the cv, cvflann, and cv::flann namespaces and can't find anything.
Here's my code:
int tmp = cv::flann::hierarchicalClustering<cv::L2<float>>(descriptors, centers, params, ______ );
The ___ is obviously where this last parameter goes. I've tried something like cv::L2<float>() but that doesn't work either.
In the source code it looks like a template.
I've also tried:
int tmp = cv::flann::hierarchicalClustering<float, float>(descriptors, centers, params);
and I get the error "no instance of overloaded function "cv::flann::hierachicalClustering" matches the argument list. Argument types are: (cv::Mat, cv::Mat, cv::KMeansIndexParams).
I am using OpenCV 2.4.11.
Any ideas?
There's also more documentation in the FLANN user manual. It looks like it was copied verbatim into OpenCV.
The parameter Distance d = Distance() is a default method argument that sets a distance algorithm. Usually, this will be FLANN_DIST_L2. Why you can't find the Distance "type" anywhere is because it's actually a typename. OpenCV opted to use C++ specialization (via templates) instead of inheritance to make sure that different distance functions have the same traits.
This is a nontrivial subject, so http://www.gotw.ca/publications/mxc++-item-4.htm should provide a fairly painless introduction. If I whet your appetite, check out Andrei Alexandrescu's seminal Modern C++ Design.
Adding this for future reference, since I was just struggling with the OpenCV FLANN classes myself
This worked for me:
// define parameters
cvflann::KMeansIndexParams kmeansParams(10, 100, cvflann::FLANN_CENTERS_KMEANSPP);
// note cvflann - not cv::flann - namespace there
int nClusters = flann::hierarchicalClustering<flann::L2<float>>(samples, centers, kmeansParams );
// note regular flann namespace here
the issue was that marcman was using <cv::L2<float>> instead of <flann::L2<float>>
The flann namespaces are super confusing, and documentation is lacking
and it's a struggle to figure it out in the IDE due to the templating.

error: 'subrange' is not a member of 'boost::numeric::ublas'

I'm trying to learn boost::ublas but am having some trouble compiling code with the subrange function. As usual, the boost docs don't really seem to shed light on this. Here's what I've done:
#include <boost/numeric/ublas/matrix.hpp>
void DoNothing()
{
boost::numeric::ublas::matrix<double> a(1,2);
boost::numeric::ublas::subrange(a,boost::numeric::ublas::range(0,1),boost::numeric::ublas:range(0,2));
}
Here's the error message I'm getting:
test.cpp:14:5: error: ‘subrange’ is not a member of
‘boost::numeric::ublas’
boost::numeric::ublas::subrange(a,boost::numeric::ublas::range(0,1),boost::numeric::ublas::range(0,2));
^
I'm guessing I haven't included a header file that I need, but I've read through the documentation (http://www.boost.org/doc/libs/1_52_0/libs/numeric/ublas/doc/operations_overview.htm) but can't see anything to suggest which header, if any, I need to add to make this work.
#include <boost/numeric/ublas/matrix_proxy.hpp>

Intersection_inserter was not declared in this scope

I am trying to calculate the overlap area between two ellipses. I am approximating the ellipses with polygons now and I have found an example that apparently used an old version of Boost.Geometry, as per this answer. From the second answer to this question, I can see that this is an old example as well, since some of the header files are not there in v1.53.
I have replaced those with:
#include <boost/geometry/geometries/adapted/c_array.hpp>
#include <boost/geometry/multi/multi.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
#include <boost/geometry/geometries/polygon.hpp>
#include <boost/geometry/io/wkt/wkt.hpp>
#include <boost/geometry/multi/geometries/multi_polygon.hpp>
and also added this code:
typedef boost::geometry::model::d2::point_xy<double,
boost::geometry::cs::cartesian> point_2d;
typedef boost::geometry::model::polygon<point_2d> polygon_2d;
and almost everything works. The only problem is with this:
polygon_2d poly, poly2;
typedef std::vector<polygon_2d > polygon_list;
polygon_list v;
intersection_inserter<polygon_2d >(poly2, poly, std::back_inserter(v));
I am getting an error:
intersection_inserter was not declared in this scope
expected primary expression before '>' token
The documentation of boost on the matter here is from 2009, so I guess it does not apply anymore... Their example is written the same as mine, as far as I can tell. I have found the place on the header file intersection.hpp where intersection_inserter is defined but I cannot make heads or tails of it...
I am getting the same error both in VS2012 in win7 and Qt 4.7.4 in Linux Mint 14. Any help would be greatly appreciated!
I cannot find any reference to intersection_inserter in the current boost documentation. Perhaps this functionality has been removed?
It seems that the "official" way to calculate intersections in boost::geometry is through the intersection function, as documented (with example) here