mirror of
https://github.com/aportelli/LatAnalyze.git
synced 2025-11-15 12:09:32 +00:00
Compare commits
5 Commits
9a27a58bf2
...
develop
| Author | SHA1 | Date | |
|---|---|---|---|
| e72d8669b1 | |||
| b0782552d1 | |||
| fef0f3704c | |||
| e4861e7b50 | |||
| ee60d083c8 |
@@ -32,9 +32,10 @@ int main(void)
|
|||||||
for (double s = 1.; s < 5.; ++s)
|
for (double s = 1.; s < 5.; ++s)
|
||||||
{
|
{
|
||||||
auto ci = h.confidenceInterval(s);
|
auto ci = h.confidenceInterval(s);
|
||||||
|
|
||||||
cout << static_cast<int>(s) << " sigma(s) interval= [";
|
cout << static_cast<int>(s) << " sigma(s) interval= [";
|
||||||
cout << ci.first << ", " << ci.second << "]" << endl;
|
cout << ci.first << ", " << ci.second << "]" << endl;
|
||||||
|
cout << "P(X > " << s << ") = " << h.pValue(s) + 1. - h.pValue(-s) << endl;
|
||||||
}
|
}
|
||||||
p << PlotHistogram(h);
|
p << PlotHistogram(h);
|
||||||
p << PlotFunction(compile("return exp(-x_0^2/2)/sqrt(2*pi);", 1), -5., 5.);
|
p << PlotFunction(compile("return exp(-x_0^2/2)/sqrt(2*pi);", 1), -5., 5.);
|
||||||
|
|||||||
@@ -166,5 +166,17 @@ auto chi2CcdfVecFunc = [](const double arg[2])
|
|||||||
return gsl_cdf_chisq_Q(arg[0], arg[1]);
|
return gsl_cdf_chisq_Q(arg[0], arg[1]);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
auto hotellingT2PValueVecFunc = [](const double arg[3])
|
||||||
|
{
|
||||||
|
double T2 = arg[0];
|
||||||
|
double n = arg[1];
|
||||||
|
double p = arg[2];
|
||||||
|
double F = (n - p) / (p * (n - 1)) * T2;
|
||||||
|
double p_value = 1.0 - gsl_cdf_fdist_P(F, p, n - p);
|
||||||
|
|
||||||
|
return p_value;
|
||||||
|
};
|
||||||
|
|
||||||
DoubleFunction MATH_NAMESPACE::chi2PValue(chi2PValueVecFunc, 2);
|
DoubleFunction MATH_NAMESPACE::chi2PValue(chi2PValueVecFunc, 2);
|
||||||
DoubleFunction MATH_NAMESPACE::chi2Ccdf(chi2CcdfVecFunc, 2);
|
DoubleFunction MATH_NAMESPACE::chi2Ccdf(chi2CcdfVecFunc, 2);
|
||||||
|
DoubleFunction MATH_NAMESPACE::hotellingT2PValue(hotellingT2PValueVecFunc, 3);
|
||||||
|
|||||||
@@ -160,6 +160,7 @@ namespace MATH_NAMESPACE
|
|||||||
{
|
{
|
||||||
extern DoubleFunction chi2PValue;
|
extern DoubleFunction chi2PValue;
|
||||||
extern DoubleFunction chi2Ccdf;
|
extern DoubleFunction chi2Ccdf;
|
||||||
|
extern DoubleFunction hotellingT2PValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
END_LATAN_NAMESPACE
|
END_LATAN_NAMESPACE
|
||||||
|
|||||||
@@ -511,6 +511,57 @@ PlotImpulses::PlotImpulses(const DVec &x, const DVec &y)
|
|||||||
setCommand("'" + tmpFileName + "' u 1:2 w impulses");
|
setCommand("'" + tmpFileName + "' u 1:2 w impulses");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PlotSteps constructor ////////////////////////////////////////////////////
|
||||||
|
PlotSteps::PlotSteps(const DVec &x, const DVec &y)
|
||||||
|
{
|
||||||
|
if (x.rows() != y.rows())
|
||||||
|
{
|
||||||
|
LATAN_ERROR(Size, "x and y vector does not have the same size");
|
||||||
|
}
|
||||||
|
|
||||||
|
DMat d(x.rows(), 2);
|
||||||
|
string tmpFileName;
|
||||||
|
|
||||||
|
for (Index i = 0; i < x.rows(); ++i)
|
||||||
|
{
|
||||||
|
d(i, 0) = x(i);
|
||||||
|
d(i, 1) = y(i);
|
||||||
|
}
|
||||||
|
tmpFileName = dumpToTmpFile(d);
|
||||||
|
pushTmpFile(tmpFileName);
|
||||||
|
setCommand("'" + tmpFileName + "' u 1:2 w steps");
|
||||||
|
}
|
||||||
|
|
||||||
|
// PlotGrid constructor ////////////////////////////////////////////////////////
|
||||||
|
PlotGrid::PlotGrid(const DVec &x, const DVec &y, const DMat &value)
|
||||||
|
{
|
||||||
|
if (x.size() != value.rows())
|
||||||
|
{
|
||||||
|
LATAN_ERROR(Size, "x vector does not have the same size as value matrix rows");
|
||||||
|
}
|
||||||
|
if (y.size() != value.cols())
|
||||||
|
{
|
||||||
|
LATAN_ERROR(Size, "y vector does not have the same size as value matrix columns");
|
||||||
|
}
|
||||||
|
if (value.rows() < 2 || value.cols() < 2)
|
||||||
|
{
|
||||||
|
LATAN_ERROR(Size, "value matrix must have at least 2 rows and 2 columns");
|
||||||
|
}
|
||||||
|
DMat d(value.cols()+1, value.rows()+1);
|
||||||
|
string tmpFileName;
|
||||||
|
d(0,0) = value.cols();
|
||||||
|
d.row(0).tail(value.cols()) = x;
|
||||||
|
d.col(0).tail(value.rows()) = y;
|
||||||
|
for (Index i = 0; i < value.rows(); ++i)
|
||||||
|
for (Index j = 0; j < value.cols(); ++j)
|
||||||
|
{
|
||||||
|
d(i+1, j+1) = value(j, i);
|
||||||
|
}
|
||||||
|
tmpFileName = dumpToTmpFile(d);
|
||||||
|
pushTmpFile(tmpFileName);
|
||||||
|
setCommand("'" + tmpFileName + "' nonuniform matrix w image");
|
||||||
|
}
|
||||||
|
|
||||||
// PlotMatrixNoRange constructor ///////////////////////////////////////////////
|
// PlotMatrixNoRange constructor ///////////////////////////////////////////////
|
||||||
PlotMatrixNoRange::PlotMatrixNoRange(const DMat &m)
|
PlotMatrixNoRange::PlotMatrixNoRange(const DMat &m)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -191,6 +191,15 @@ public:
|
|||||||
virtual ~PlotHistogram(void) = default;
|
virtual ~PlotHistogram(void) = default;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class PlotSteps: public PlotObject
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
// constructor
|
||||||
|
PlotSteps(const DVec &x, const DVec &y);
|
||||||
|
// destructor
|
||||||
|
virtual ~PlotSteps(void) = default;
|
||||||
|
};
|
||||||
|
|
||||||
class PlotImpulses: public PlotObject
|
class PlotImpulses: public PlotObject
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -200,6 +209,15 @@ public:
|
|||||||
virtual ~PlotImpulses(void) = default;
|
virtual ~PlotImpulses(void) = default;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class PlotGrid: public PlotObject
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
// constructor
|
||||||
|
PlotGrid(const DVec &x, const DVec &y, const DMat &value);
|
||||||
|
// destructor
|
||||||
|
virtual ~PlotGrid(void) = default;
|
||||||
|
};
|
||||||
|
|
||||||
class PlotMatrixNoRange: public PlotObject
|
class PlotMatrixNoRange: public PlotObject
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|||||||
@@ -38,6 +38,10 @@ void filterConvolution(MatType &out, const MatType &data,
|
|||||||
{
|
{
|
||||||
Index n = data.rows(), nf = n*filter.size();
|
Index n = data.rows(), nf = n*filter.size();
|
||||||
|
|
||||||
|
if (&out == &data)
|
||||||
|
{
|
||||||
|
LATAN_ERROR(Argument, "filter convolution does not support in-place operation");
|
||||||
|
}
|
||||||
out.resizeLike(data);
|
out.resizeLike(data);
|
||||||
out.fill(0.);
|
out.fill(0.);
|
||||||
for (unsigned int i = 0; i < filter.size(); ++i)
|
for (unsigned int i = 0; i < filter.size(); ++i)
|
||||||
|
|||||||
@@ -162,6 +162,20 @@ double Histogram::operator()(const double x) const
|
|||||||
return (*this)[static_cast<Index>(i)];
|
return (*this)[static_cast<Index>(i)];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// p-value P(x > x0) ///////////////////////////////////////////////////////////
|
||||||
|
double Histogram::pValue(const double x0) const
|
||||||
|
{
|
||||||
|
Index n = data_.size();
|
||||||
|
double count = 0.;
|
||||||
|
|
||||||
|
FOR_STAT_ARRAY(data_, s)
|
||||||
|
{
|
||||||
|
count += (data_[s] > x0) ? 1. : 0.;
|
||||||
|
}
|
||||||
|
|
||||||
|
return count/n;
|
||||||
|
}
|
||||||
|
|
||||||
// percentiles & confidence interval ///////////////////////////////////////////
|
// percentiles & confidence interval ///////////////////////////////////////////
|
||||||
double Histogram::percentile(const double p) const
|
double Histogram::percentile(const double p) const
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -54,6 +54,8 @@ public:
|
|||||||
double getX(const Index i) const;
|
double getX(const Index i) const;
|
||||||
double operator[](const Index i) const;
|
double operator[](const Index i) const;
|
||||||
double operator()(const double x) const;
|
double operator()(const double x) const;
|
||||||
|
// p-value P(x > x0)
|
||||||
|
double pValue(const double x0) const;
|
||||||
// percentiles & confidence interval
|
// percentiles & confidence interval
|
||||||
double percentile(const double p) const;
|
double percentile(const double p) const;
|
||||||
double median(void) const;
|
double median(void) const;
|
||||||
|
|||||||
Reference in New Issue
Block a user