[pktools] 64/375: renamed Histogram to StatFactory
Bas Couwenberg
sebastic at xs4all.nl
Wed Dec 3 21:53:59 UTC 2014
This is an automated email from the git hooks/post-receive script.
sebastic-guest pushed a commit to branch upstream-master
in repository pktools.
commit 46d99cef2eee782b9154eeed76dcd361b917c4f4
Author: Pieter Kempeneers <kempenep at gmail.com>
Date: Tue Feb 19 10:11:04 2013 +0100
renamed Histogram to StatFactory
---
src/algorithms/Filter.h | 72 +++----
src/algorithms/Filter2d.cc | 42 ++--
src/algorithms/Filter2d.h | 2 +-
src/algorithms/Histogram.cc | 63 ------
src/algorithms/Makefile.am | 4 +-
src/algorithms/{Histogram.h => StatFactory.h} | 267 ++++++++++++++++++++------
src/apps/pkclassify_nn.cc | 1 -
src/apps/pkclassify_svm.cc | 1 -
src/apps/pkdumpogr.cc | 1 -
src/apps/pkextract.cc | 20 +-
src/apps/pkfs_nn.cc | 1 -
src/apps/pklas2img.cc | 20 +-
src/apps/pkmosaic.cc | 12 +-
src/apps/pkopt_svm.cc | 1 -
src/apps/pksensormodel.cc | 6 +-
src/apps/pkstat.cc | 38 ++--
src/apps/pkstatogr.cc | 10 +-
17 files changed, 324 insertions(+), 237 deletions(-)
diff --git a/src/algorithms/Filter.h b/src/algorithms/Filter.h
index ed7ae58..7973171 100644
--- a/src/algorithms/Filter.h
+++ b/src/algorithms/Filter.h
@@ -22,7 +22,7 @@ along with pktools. If not, see <http://www.gnu.org/licenses/>.
#include <vector>
#include <iostream>
-#include "Histogram.h"
+#include "StatFactory.h"
#include "imageclasses/ImgReaderGdal.h"
#include "imageclasses/ImgWriterGdal.h"
@@ -89,8 +89,8 @@ template<class T> void Filter::morphology(const vector<T>& input, vector<T>& out
assert(dim);
output.resize((input.size()-offset+down-1)/down);
int i=0;
- Histogram hist;
- vector<T> histBuffer;
+ statfactory::StatFactory stat;
+ vector<T> statBuffer;
short binValue=0;
//start: extend input with mirrored version of itself
for(i=offset;i<dim/2;++i){
@@ -102,9 +102,9 @@ template<class T> void Filter::morphology(const vector<T>& input, vector<T>& out
}
}
if(m_class.size())
- histBuffer.push_back(binValue);
+ statBuffer.push_back(binValue);
else
- histBuffer.push_back(input[i]);
+ statBuffer.push_back(input[i]);
for(int t=1;t<=dim/2;++t){
binValue=0;
for(int iclass=0;iclass<m_class.size();++iclass){
@@ -114,25 +114,25 @@ template<class T> void Filter::morphology(const vector<T>& input, vector<T>& out
}
}
if(m_class.size()){
- histBuffer.push_back(binValue);
- histBuffer.push_back(binValue);
+ statBuffer.push_back(binValue);
+ statBuffer.push_back(binValue);
}
else{
- histBuffer.push_back(input[i+t]);
- histBuffer.push_back(input[i+t]);
+ statBuffer.push_back(input[i+t]);
+ statBuffer.push_back(input[i+t]);
}
}
- assert(histBuffer.size()==dim);
+ assert(statBuffer.size()==dim);
if((i-offset)%down){
- histBuffer.clear();
+ statBuffer.clear();
continue;
}
switch(method){
case(DILATE):
- output[(i-offset+down-1)/down]=hist.max(histBuffer);
+ output[(i-offset+down-1)/down]=stat.max(statBuffer);
break;
case(ERODE):
- output[(i-offset+down-1)/down]=hist.min(histBuffer);
+ output[(i-offset+down-1)/down]=stat.min(statBuffer);
break;
default:
string errorString="method not supported";
@@ -141,13 +141,13 @@ template<class T> void Filter::morphology(const vector<T>& input, vector<T>& out
}
if(verbose){
cout << "buffer: ";
- for(int ibuf=0;ibuf<histBuffer.size();++ibuf)
- cout << histBuffer[ibuf] << " ";
+ for(int ibuf=0;ibuf<statBuffer.size();++ibuf)
+ cout << statBuffer[ibuf] << " ";
cout << "->" << output[(i-offset+down-1)/down] << endl;
}
}
//main
- histBuffer.clear();
+ statBuffer.clear();
for(i=offset+dim/2;i<input.size()-dim/2;++i){
binValue=0;
for(int t=0;t<dim;++t){
@@ -158,21 +158,21 @@ template<class T> void Filter::morphology(const vector<T>& input, vector<T>& out
}
}
if(m_class.size())
- histBuffer.push_back(binValue);
+ statBuffer.push_back(binValue);
else
- histBuffer.push_back(input[i-dim/2+t]);
+ statBuffer.push_back(input[i-dim/2+t]);
}
- assert(histBuffer.size()==dim);
+ assert(statBuffer.size()==dim);
if((i-offset)%down){
- histBuffer.clear();
+ statBuffer.clear();
continue;
}
switch(method){
case(DILATE):
- output[(i-offset+down-1)/down]=hist.max(histBuffer);
+ output[(i-offset+down-1)/down]=stat.max(statBuffer);
break;
case(ERODE):
- output[(i-offset+down-1)/down]=hist.min(histBuffer);
+ output[(i-offset+down-1)/down]=stat.min(statBuffer);
break;
default:
string errorString="method not supported";
@@ -181,11 +181,11 @@ template<class T> void Filter::morphology(const vector<T>& input, vector<T>& out
}
if(verbose){
cout << "buffer: ";
- for(int ibuf=0;ibuf<histBuffer.size();++ibuf)
- cout << histBuffer[ibuf] << " ";
+ for(int ibuf=0;ibuf<statBuffer.size();++ibuf)
+ cout << statBuffer[ibuf] << " ";
cout << "->" << output[(i-offset+down-1)/down] << endl;
}
- histBuffer.clear();
+ statBuffer.clear();
}
//end: extend input with mirrored version of itself
for(i=input.size()-dim/2;i<input.size();++i){
@@ -197,9 +197,9 @@ template<class T> void Filter::morphology(const vector<T>& input, vector<T>& out
}
}
if(m_class.size())
- histBuffer.push_back(binValue);
+ statBuffer.push_back(binValue);
else
- histBuffer.push_back(input[i]);
+ statBuffer.push_back(input[i]);
for(int t=1;t<=dim/2;++t){
binValue=0;
for(int iclass=0;iclass<m_class.size();++iclass){
@@ -209,24 +209,24 @@ template<class T> void Filter::morphology(const vector<T>& input, vector<T>& out
}
}
if(m_class.size()){
- histBuffer.push_back(binValue);
- histBuffer.push_back(binValue);
+ statBuffer.push_back(binValue);
+ statBuffer.push_back(binValue);
}
else{
- histBuffer.push_back(input[i-t]);
- histBuffer.push_back(input[i-t]);
+ statBuffer.push_back(input[i-t]);
+ statBuffer.push_back(input[i-t]);
}
}
if((i-offset)%down){
- histBuffer.clear();
+ statBuffer.clear();
continue;
}
switch(method){
case(DILATE):
- output[(i-offset+down-1)/down]=hist.max(histBuffer);
+ output[(i-offset+down-1)/down]=stat.max(statBuffer);
break;
case(ERODE):
- output[(i-offset+down-1)/down]=hist.min(histBuffer);
+ output[(i-offset+down-1)/down]=stat.min(statBuffer);
break;
default:
string errorString="method not supported";
@@ -235,8 +235,8 @@ template<class T> void Filter::morphology(const vector<T>& input, vector<T>& out
}
if(verbose){
cout << "buffer: ";
- for(int ibuf=0;ibuf<histBuffer.size();++ibuf)
- cout << histBuffer[ibuf] << " ";
+ for(int ibuf=0;ibuf<statBuffer.size();++ibuf)
+ cout << statBuffer[ibuf] << " ";
cout << "->" << output[(i-offset+down-1)/down] << endl;
}
}
diff --git a/src/algorithms/Filter2d.cc b/src/algorithms/Filter2d.cc
index e46af52..f20ed11 100644
--- a/src/algorithms/Filter2d.cc
+++ b/src/algorithms/Filter2d.cc
@@ -22,7 +22,7 @@ along with pktools. If not, see <http://www.gnu.org/licenses/>.
#include <iostream>
#include <cmath>
#include "Filter2d.h"
-#include "Histogram.h"
+#include "StatFactory.h"
// #include "imageclasses/ImgUtils.h"
Filter2d::Filter2d::Filter2d(void)
@@ -410,7 +410,7 @@ void Filter2d::Filter2d::doit(const ImgReaderGdal& input, ImgWriterGdal& output,
{
assert(dimX);
assert(dimY);
- Histogram hist;
+ statfactory::StatFactory stat;
const char* pszMessage;
void* pProgressArg=NULL;
GDALProgressFunc pfnProgress=GDALTermProgress;
@@ -506,41 +506,41 @@ void Filter2d::Filter2d::doit(const ImgReaderGdal& input, ImgWriterGdal& output,
if(windowBuffer.empty())
outBuffer[x/down]=m_noValue;
else
- outBuffer[x/down]=hist.median(windowBuffer);
+ outBuffer[x/down]=stat.median(windowBuffer);
break;
case(VAR):{
if(windowBuffer.empty())
outBuffer[x/down]=m_noValue;
else
- outBuffer[x/down]=hist.var(windowBuffer);
+ outBuffer[x/down]=stat.var(windowBuffer);
break;
}
case(STDEV):{
if(windowBuffer.empty())
outBuffer[x/down]=m_noValue;
else
- outBuffer[x/down]=sqrt(hist.var(windowBuffer));
+ outBuffer[x/down]=sqrt(stat.var(windowBuffer));
break;
}
case(MEAN):{
if(windowBuffer.empty())
outBuffer[x/down]=m_noValue;
else
- outBuffer[x/down]=hist.mean(windowBuffer);
+ outBuffer[x/down]=stat.mean(windowBuffer);
break;
}
case(MIN):{
if(windowBuffer.empty())
outBuffer[x/down]=m_noValue;
else
- outBuffer[x/down]=hist.min(windowBuffer);
+ outBuffer[x/down]=stat.min(windowBuffer);
break;
}
case(ISMIN):{
if(windowBuffer.empty())
outBuffer[x/down]=m_noValue;
else
- outBuffer[x/down]=(hist.min(windowBuffer)==windowBuffer[dimX*dimY/2])? 1:0;
+ outBuffer[x/down]=(stat.min(windowBuffer)==windowBuffer[dimX*dimY/2])? 1:0;
break;
}
case(MINMAX):{
@@ -549,7 +549,7 @@ void Filter2d::Filter2d::doit(const ImgReaderGdal& input, ImgWriterGdal& output,
if(windowBuffer.empty())
outBuffer[x/down]=m_noValue;
else{
- hist.minmax(windowBuffer,windowBuffer.begin(),windowBuffer.end(),min,max);
+ stat.minmax(windowBuffer,windowBuffer.begin(),windowBuffer.end(),min,max);
if(min!=max)
outBuffer[x/down]=0;
else
@@ -561,14 +561,14 @@ void Filter2d::Filter2d::doit(const ImgReaderGdal& input, ImgWriterGdal& output,
if(windowBuffer.empty())
outBuffer[x/down]=m_noValue;
else
- outBuffer[x/down]=hist.max(windowBuffer);
+ outBuffer[x/down]=stat.max(windowBuffer);
break;
}
case(ISMAX):{
if(windowBuffer.empty())
outBuffer[x/down]=m_noValue;
else
- outBuffer[x/down]=(hist.max(windowBuffer)==windowBuffer[dimX*dimY/2])? 1:0;
+ outBuffer[x/down]=(stat.max(windowBuffer)==windowBuffer[dimX*dimY/2])? 1:0;
break;
}
case(ORDER):{
@@ -577,15 +577,15 @@ void Filter2d::Filter2d::doit(const ImgReaderGdal& input, ImgWriterGdal& output,
else{
double lbound=0;
double ubound=dimX*dimY;
- double theMin=hist.min(windowBuffer);
- double theMax=hist.max(windowBuffer);
+ double theMin=stat.min(windowBuffer);
+ double theMax=stat.max(windowBuffer);
double scale=(ubound-lbound)/(theMax-theMin);
outBuffer[x/down]=static_cast<short>(scale*(windowBuffer[dimX*dimY/2]-theMin)+lbound);
}
break;
}
case(SUM):{
- outBuffer[x/down]=hist.sum(windowBuffer);
+ outBuffer[x/down]=stat.sum(windowBuffer);
break;
}
case(HOMOG):
@@ -803,7 +803,7 @@ void Filter2d::Filter2d::morphology(const ImgReaderGdal& input, ImgWriterGdal& o
{
assert(dimX);
assert(dimY);
- Histogram hist;
+ statfactory::StatFactory stat;
for(int iband=0;iband<input.nrOfBand();++iband){
Vector2d<double> inBuffer(dimY,input.nrOfCol());
vector<double> outBuffer(input.nrOfCol());
@@ -843,7 +843,7 @@ void Filter2d::Filter2d::morphology(const ImgReaderGdal& input, ImgWriterGdal& o
for(int x=0;x<input.nrOfCol();++x){
double currentValue=inBuffer[dimY/2][x];
outBuffer[x]=currentValue;
- vector<double> histBuffer;
+ vector<double> statBuffer;
bool currentMasked=false;
double rse=0;
for(int imask=0;imask<m_mask.size();++imask){
@@ -925,19 +925,19 @@ void Filter2d::Filter2d::morphology(const ImgReaderGdal& input, ImgWriterGdal& o
}
}
if(m_class.size())
- histBuffer.push_back(binValue);
+ statBuffer.push_back(binValue);
else
- histBuffer.push_back(inBuffer[indexJ][indexI]);
+ statBuffer.push_back(inBuffer[indexJ][indexI]);
}
}
}
- if(histBuffer.size()){
+ if(statBuffer.size()){
switch(method){
case(DILATE):
- outBuffer[x]=hist.max(histBuffer);
+ outBuffer[x]=stat.max(statBuffer);
break;
case(ERODE):
- outBuffer[x]=hist.min(histBuffer);
+ outBuffer[x]=stat.min(statBuffer);
break;
default:
ostringstream ess;
diff --git a/src/algorithms/Filter2d.h b/src/algorithms/Filter2d.h
index 954f1fc..785d1cf 100644
--- a/src/algorithms/Filter2d.h
+++ b/src/algorithms/Filter2d.h
@@ -372,7 +372,7 @@ template<class T1, class T2> void Filter2d::doit(const Vector2d<T1>& inputVector
break;
}
case(MIXED):{
- enum Type { BF=11, CF=12, MF=13, NF=20, W=30 };
+ enum MixType { BF=11, CF=12, MF=13, NF=20, W=30 };
double nBF=occurrence[BF];
double nCF=occurrence[CF];
double nMF=occurrence[MF];
diff --git a/src/algorithms/Histogram.cc b/src/algorithms/Histogram.cc
deleted file mode 100644
index cd51498..0000000
--- a/src/algorithms/Histogram.cc
+++ /dev/null
@@ -1,63 +0,0 @@
-/**********************************************************************
-Histogram.cc: class for statistical operations on vectors
-Copyright (C) 2008-2012 Pieter Kempeneers
-
-This file is part of pktools
-
-pktools is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-pktools is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with pktools. If not, see <http://www.gnu.org/licenses/>.
-***********************************************************************/
-#include "Histogram.h"
-
-
-Histogram::Histogram(){
-}
-
-void Histogram::signature(double m1, double m2, double& k, double& alpha, double& beta, double e)
-{
- double y=m1*m1/m2;
- beta=F_1(y,0.1,10.0,e);
- double fb=F(beta);
- double g=exp(lgamma(1.0/beta));
- alpha=m1*g/exp(lgamma(2.0/beta));
- k=beta/(2*alpha*g);
-// cout << "y, alpha, beta: " << y << ", " << alpha << ", " << beta << endl;
-}
-
-double Histogram::F(double x)
-{
- double g2=exp(lgamma(2.0/x));
- return(g2*g2/exp(lgamma(3.0/x))/exp(lgamma(1.0/x)));
-}
-
-//x1 is under estimate, x2 is over estimate, e is error
-double Histogram::F_1(double y, double x1, double x2, double e)
-{
- double f1=F(x1);
- double f2=F(x2);
- assert(f1!=f2);
- double x=x1+(x2-x1)*(y-f1)/(f2-f1);
- double f=F(x);
- while(f-y>=e||y-f>=e){
- if(f<y)
- x1=x;
- else
- x2=x;
- if(x1==x2)
- return x1;
- assert(f1!=f2);
- x=x1+(x2-x1)*(y-f1)/(f2-f1);
- f=F(x);
- }
- return x;
-}
diff --git a/src/algorithms/Makefile.am b/src/algorithms/Makefile.am
index b00098e..3ef425a 100644
--- a/src/algorithms/Makefile.am
+++ b/src/algorithms/Makefile.am
@@ -12,7 +12,7 @@ noinst_LIBRARIES = libalgorithms.a
libalgorithms_adir = $(includedir)/algorithms
# the list of header files that belong to the library (to be installed later)
-libalgorithms_a_HEADERS = Egcs.h Filter2d.h Filter.h Histogram.h ConfusionMatrix.h svm.h FeatureSelector.h
+libalgorithms_a_HEADERS = Egcs.h Filter2d.h Filter.h StatFactory.h ConfusionMatrix.h svm.h FeatureSelector.h
if USE_FANN
libalgorithms_a_HEADERS += myfann_cpp.h
@@ -23,5 +23,5 @@ libalgorithms_a_HEADERS += SensorModel.h OptFactory.h
endif
# the sources to add to the library and to add to the source distribution
-libalgorithms_a_SOURCES = $(libalgorithms_a_HEADERS) Egcs.cc Filter2d.cc Filter.cc Histogram.cc ConfusionMatrix.cc svm.cpp
+libalgorithms_a_SOURCES = $(libalgorithms_a_HEADERS) Egcs.cc Filter2d.cc Filter.cc ConfusionMatrix.cc svm.cpp
###############################################################################
diff --git a/src/algorithms/Histogram.h b/src/algorithms/StatFactory.h
similarity index 59%
rename from src/algorithms/Histogram.h
rename to src/algorithms/StatFactory.h
index 8d41dff..98e44f3 100644
--- a/src/algorithms/Histogram.h
+++ b/src/algorithms/StatFactory.h
@@ -1,6 +1,6 @@
/**********************************************************************
-Histogram.h: class for statistical operations on vectors
-Copyright (C) 2008-2012 Pieter Kempeneers
+StatFactory.h: class for statistical operations on vectors
+Copyright (C) 2008-2013 Pieter Kempeneers
This file is part of pktools
@@ -17,8 +17,8 @@ GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with pktools. If not, see <http://www.gnu.org/licenses/>.
***********************************************************************/
-#ifndef _HISTOGRAM_H_
-#define _HISTOGRAM_H_
+#ifndef _STATFACTORY_H_
+#define _STATFACTORY_H_
#include <iostream>
#include <vector>
@@ -29,22 +29,21 @@ along with pktools. If not, see <http://www.gnu.org/licenses/>.
#include <fstream>
#include <algorithm>
#include <gsl/gsl_fit.h>
-//#include <gsl/gsl_errno.h>
-
-/* #include "newmat/newmat.h" */
-/* #include "newmat/newmatap.h" */
-/* #include "newmat/newmatio.h" */
+#include <gsl/gsl_errno.h>
+#include <gsl/gsl_spline.h>
using namespace std;
// using namespace NEWMAT;
-namespace histogram
+namespace statfactory
{
+
+ enum INTERPOLATION_TYPE {UNDEFINED=0,POLYNOMIAL=1,CSPLINE=2,PERIODIC=3,AKIMA=4,AKIMA_PERIODIC=5,LINEAR=6};
-class Histogram{
+class StatFactory{
public:
- Histogram(void);
- virtual ~Histogram(void){};
+ StatFactory(void){};
+ virtual ~StatFactory(void){};
template<class T> T max(const vector<T>& v) const;
template<class T> T min(const vector<T>& v) const;
// template<class T> typename vector<T>::const_iterator max(const vector<T>& v, typename vector<T>::const_iterator begin, typename vector<T>::const_iterator end) const;
@@ -76,22 +75,16 @@ public:
template<class T> double correlation(const vector<T>& x, const vector<T>& y, int delay=0) const;
template<class T> double cross_correlation(const vector<T>& x, const vector<T>& y, int maxdelay, vector<T>& z) const;
template<class T> double linear_regression(const vector<T>& x, const vector<T>& y, double &c0, double &c1) const;
+ template<class T> void interpolateUp(const vector< vector<T> >& input, vector< vector<T> >& output, double start, double end, double step, int type=0);
+ template<class T> void interpolateUp(const vector<T>& input, vector<T>& output, int nbin);
+ template<class T> void interpolateUp(double* input, int dim, vector<T>& output, int nbin);
+ template<class T> void interpolateDown(const vector<T>& input, vector<T>& output, int nbin);
+ template<class T> void interpolateDown(double* input, int dim, vector<T>& output, int nbin);
+
private:
- double F(double x);
- double F_1(double y, double x1, double x2, double e);
};
-// template<class T> typename vector<T>::const_iterator Histogram::max(const vector<T>& v, typename vector<T>::const_iterator begin, typename vector<T>::const_iterator end) const
-// {
-// typename vector<T>::const_iterator tmpIt=begin;
-// for (typename vector<T>::const_iterator it = begin; it!=end; ++it){
-// if(*tmpIt<*it)
-// tmpIt=it;
-// }
-// return tmpIt;
-// }
-
-template<class T> typename vector<T>::iterator Histogram::max(const vector<T>& v, typename vector<T>::iterator begin, typename vector<T>::iterator end) const
+template<class T> typename vector<T>::iterator StatFactory::max(const vector<T>& v, typename vector<T>::iterator begin, typename vector<T>::iterator end) const
{
typename vector<T>::iterator tmpIt=begin;
for (typename vector<T>::iterator it = begin; it!=end; ++it){
@@ -101,7 +94,7 @@ template<class T> typename vector<T>::iterator Histogram::max(const vector<T>& v
return tmpIt;
}
-template<class T> T Histogram::max(const vector<T>& v) const
+template<class T> T StatFactory::max(const vector<T>& v) const
{
T maxValue=*(v.begin());
for (typename vector<T>::const_iterator it = v.begin(); it!=v.end(); ++it){
@@ -111,7 +104,7 @@ template<class T> T Histogram::max(const vector<T>& v) const
return maxValue;
}
-template<class T> T Histogram::min(const vector<T>& v) const
+template<class T> T StatFactory::min(const vector<T>& v) const
{
T minValue=*(v.begin());
for (typename vector<T>::const_iterator it = v.begin(); it!=v.end(); ++it){
@@ -121,7 +114,7 @@ template<class T> T Histogram::min(const vector<T>& v) const
return minValue;
}
-template<class T> typename vector<T>::const_iterator Histogram::absmax(const vector<T>& v, typename vector<T>::const_iterator begin, typename vector<T>::const_iterator end) const
+template<class T> typename vector<T>::const_iterator StatFactory::absmax(const vector<T>& v, typename vector<T>::const_iterator begin, typename vector<T>::const_iterator end) const
{
typename vector<T>::const_iterator tmpIt=begin;
for (typename vector<T>::const_iterator it = begin; it!=end; ++it){
@@ -131,7 +124,7 @@ template<class T> typename vector<T>::const_iterator Histogram::absmax(const vec
return tmpIt;
}
-template<class T> typename vector<T>::const_iterator Histogram::min(const vector<T>& v, typename vector<T>::const_iterator begin, typename vector<T>::const_iterator end) const
+template<class T> typename vector<T>::const_iterator StatFactory::min(const vector<T>& v, typename vector<T>::const_iterator begin, typename vector<T>::const_iterator end) const
{
typename vector<T>::const_iterator tmpIt=begin;
for (typename vector<T>::const_iterator it = begin; it!=end; ++it){
@@ -141,7 +134,7 @@ template<class T> typename vector<T>::const_iterator Histogram::min(const vector
return tmpIt;
}
-template<class T> typename vector<T>::const_iterator Histogram::absmin(const vector<T>& v, typename vector<T>::const_iterator begin, typename vector<T>::const_iterator end) const
+template<class T> typename vector<T>::const_iterator StatFactory::absmin(const vector<T>& v, typename vector<T>::const_iterator begin, typename vector<T>::const_iterator end) const
{
typename vector<T>::const_iterator tmpIt=begin;
for (typename vector<T>::const_iterator it = begin; it!=end; ++it){
@@ -150,7 +143,7 @@ template<class T> typename vector<T>::const_iterator Histogram::absmin(const vec
}
}
-template<class T> void Histogram::minmax(const vector<T>& v, typename vector<T>::const_iterator begin, typename vector<T>::const_iterator end, T& theMin, T& theMax) const
+template<class T> void StatFactory::minmax(const vector<T>& v, typename vector<T>::const_iterator begin, typename vector<T>::const_iterator end, T& theMin, T& theMax) const
{
theMin=*begin;
theMax=*begin;
@@ -162,7 +155,7 @@ template<class T> void Histogram::minmax(const vector<T>& v, typename vector<T>:
}
}
-template<class T> T Histogram::sum(const vector<T>& v) const
+template<class T> T StatFactory::sum(const vector<T>& v) const
{
typename vector<T>::const_iterator it;
T tmpSum=0;
@@ -171,13 +164,13 @@ template<class T> T Histogram::sum(const vector<T>& v) const
return tmpSum;
}
-template<class T> double Histogram::mean(const vector<T>& v) const
+template<class T> double StatFactory::mean(const vector<T>& v) const
{
assert(v.size());
return static_cast<double>(sum(v))/v.size();
}
-template<class T> T Histogram::median(const vector<T>& v) const
+template<class T> T StatFactory::median(const vector<T>& v) const
{
vector<T> tmpV=v;
sort(tmpV.begin(),tmpV.end());
@@ -187,7 +180,7 @@ template<class T> T Histogram::median(const vector<T>& v) const
return 0.5*(tmpV[tmpV.size()/2-1]+tmpV[tmpV.size()/2]);
}
-template<class T> double Histogram::var(const vector<T>& v) const
+template<class T> double StatFactory::var(const vector<T>& v) const
{
typename vector<T>::const_iterator it;
double v1=0;
@@ -206,7 +199,7 @@ template<class T> double Histogram::var(const vector<T>& v) const
return v1;
}
-template<class T> double Histogram::moment(const vector<T>& v, int n) const
+template<class T> double StatFactory::moment(const vector<T>& v, int n) const
{
assert(v.size());
typename vector<T>::const_iterator it;
@@ -219,7 +212,7 @@ template<class T> double Histogram::moment(const vector<T>& v, int n) const
}
//central moment
-template<class T> double Histogram::cmoment(const vector<T>& v, int n) const
+template<class T> double StatFactory::cmoment(const vector<T>& v, int n) const
{
assert(v.size());
typename vector<T>::const_iterator it;
@@ -231,19 +224,19 @@ template<class T> double Histogram::cmoment(const vector<T>& v, int n) const
return m/v.size();
}
-template<class T> double Histogram::skewness(const vector<T>& v) const
+template<class T> double StatFactory::skewness(const vector<T>& v) const
{
return cmoment(v,3)/pow(var(v),1.5);
}
-template<class T> double Histogram::kurtosis(const vector<T>& v) const
+template<class T> double StatFactory::kurtosis(const vector<T>& v) const
{
double m2=cmoment(v,2);
double m4=cmoment(v,4);
return m4/m2/m2-3.0;
}
-template<class T> void Histogram::meanVar(const vector<T>& v, double& m1, double& v1) const
+template<class T> void StatFactory::meanVar(const vector<T>& v, double& m1, double& v1) const
{
typename vector<T>::const_iterator it;
v1=0;
@@ -256,7 +249,7 @@ template<class T> void Histogram::meanVar(const vector<T>& v, double& m1, double
assert(v1>=0);
}
-template<class T1, class T2> void Histogram::scale2byte(const vector<T1>& input, vector<T2>& output, unsigned char lbound, unsigned char ubound) const
+template<class T1, class T2> void StatFactory::scale2byte(const vector<T1>& input, vector<T2>& output, unsigned char lbound, unsigned char ubound) const
{
output.resize(input.size());
T1 minimum=min(input);
@@ -267,7 +260,7 @@ template<class T1, class T2> void Histogram::scale2byte(const vector<T1>& input,
output[i]=scale*(input[i]-(minimum))+lbound;
}
-template<class T> void Histogram::distribution (const vector<T>& input, typename vector<T>::const_iterator begin, typename vector<T>::const_iterator end, vector<int>& output, int nbin, T &minimum, T &maximum, const string &filename)
+template<class T> void StatFactory::distribution (const vector<T>& input, typename vector<T>::const_iterator begin, typename vector<T>::const_iterator end, vector<int>& output, int nbin, T &minimum, T &maximum, const string &filename)
{
if(maximum<=minimum)
minmax(input,begin,end,minimum,maximum);
@@ -307,7 +300,7 @@ template<class T> void Histogram::distribution (const vector<T>& input, typenam
}
}
-template<class T> void Histogram::percentiles (const vector<T>& input, typename vector<T>::const_iterator begin, typename vector<T>::const_iterator end, vector<T>& output, int nbin, T &minimum, T &maximum, const string &filename)
+template<class T> void StatFactory::percentiles (const vector<T>& input, typename vector<T>::const_iterator begin, typename vector<T>::const_iterator end, vector<T>& output, int nbin, T &minimum, T &maximum, const string &filename)
{
if(maximum<=minimum)
minmax(input,begin,end,minimum,maximum);
@@ -354,7 +347,7 @@ template<class T> void Histogram::percentiles (const vector<T>& input, typename
}
}
-// template<class T> void Histogram::cumulative (const vector<T>& input, typename vector<T>::const_iterator begin, typename vector<T>::const_iterator end, vector<int>& output, int nbin, T &minimum, T &maximum)
+// template<class T> void StatFactory::cumulative (const vector<T>& input, typename vector<T>::const_iterator begin, typename vector<T>::const_iterator end, vector<int>& output, int nbin, T &minimum, T &maximum)
// {
// assert(nbin>1);
// assert(input.size());
@@ -375,14 +368,14 @@ template<class T> void Histogram::percentiles (const vector<T>& input, typename
// }
// }
-template<class T> void Histogram::signature(const vector<T>& input, double&k, double& alpha, double& beta, double e)
+template<class T> void StatFactory::signature(const vector<T>& input, double&k, double& alpha, double& beta, double e)
{
double m1=moment(input,1);
double m2=moment(input,2);
signature(m1,m2,k,alpha,beta,e);
}
-template<class T> void Histogram::normalize(const vector<T>& input, vector<double>& output){
+template<class T> void StatFactory::normalize(const vector<T>& input, vector<double>& output){
double total=sum(input);
if(total){
output.resize(input.size());
@@ -393,7 +386,7 @@ template<class T> void Histogram::normalize(const vector<T>& input, vector<doubl
output=input;
}
-template<class T> void Histogram::normalize_pct(vector<T>& input){
+template<class T> void StatFactory::normalize_pct(vector<T>& input){
double total=sum(input);
if(total){
typename vector<T>::iterator it;
@@ -402,7 +395,7 @@ template<class T> void Histogram::normalize_pct(vector<T>& input){
}
}
-template<class T> double Histogram::rmse(const vector<T>& x, const vector<T>& y) const{
+template<class T> double StatFactory::rmse(const vector<T>& x, const vector<T>& y) const{
assert(x.size()==y.size());
assert(x.size());
double mse=0;
@@ -413,7 +406,7 @@ template<class T> double Histogram::rmse(const vector<T>& x, const vector<T>& y)
return sqrt(mse);
}
-template<class T> double Histogram::correlation(const vector<T>& x, const vector<T>& y, int delay) const{
+template<class T> double StatFactory::correlation(const vector<T>& x, const vector<T>& y, int delay) const{
double meanX=0;
double meanY=0;
double varX=0;
@@ -442,7 +435,7 @@ template<class T> double Histogram::correlation(const vector<T>& x, const vector
return 0;
}
-template<class T> double Histogram::cross_correlation(const vector<T>& x, const vector<T>& y, int maxdelay, vector<T>& z) const{
+template<class T> double StatFactory::cross_correlation(const vector<T>& x, const vector<T>& y, int maxdelay, vector<T>& z) const{
z.clear();
double sumCorrelation=0;
for (int delay=-maxdelay;delay<maxdelay;delay++) {
@@ -452,7 +445,7 @@ template<class T> double Histogram::cross_correlation(const vector<T>& x, const
return sumCorrelation;
}
- template<class T> double Histogram::linear_regression(const vector<T>& x, const vector<T>& y, double &c0, double &c1) const{
+ template<class T> double StatFactory::linear_regression(const vector<T>& x, const vector<T>& y, double &c0, double &c1) const{
assert(x.size()==y.size());
assert(x.size());
double cov00;
@@ -463,13 +456,175 @@ template<class T> double Histogram::cross_correlation(const vector<T>& x, const
return (1-sumsq/var(y)/(y.size()-1));
}
+//alternatively: use GNU scientific library:
+// gsl_stats_correlation (const double data1[], const size_t stride1, const double data2[], const size_t stride2, const size_t n)
+
+template<class T> void StatFactory::interpolateUp(const vector< vector<T> >& input, vector< vector<T> >& output, double start, double end, double step, int type)
+{
+ int nsample=input.size()-1;//first sample contains wavelength
+ int nband=input[0].size();
+ output.clear();
+ output.resize(nsample+1);//first sample contains wavelength
+ start=(start)?start:floor(input[0][0]);
+ end=(end)?end:ceil(input[0].back());
+ for(double xi=start;xi<=end;xi+=step)
+ output[0].push_back(xi);
+ for(int isample=1;isample<nsample+1;++isample){
+ gsl_interp_accel *acc=gsl_interp_accel_alloc();
+ gsl_spline *spline;
+ switch(type){
+ case(POLYNOMIAL):
+ spline=gsl_spline_alloc(gsl_interp_polynomial,nband);
+ break;
+ case(CSPLINE):
+ spline=gsl_spline_alloc(gsl_interp_cspline,nband);
+ break;
+ case(PERIODIC):
+ spline=gsl_spline_alloc(gsl_interp_cspline_periodic,nband);
+ break;
+ case(AKIMA):
+ spline=gsl_spline_alloc(gsl_interp_akima,nband);
+ break;
+ case(PERIODIC):
+ spline=gsl_spline_alloc(gsl_interp_akima_periodic,nband);
+ break;
+ case(LINEAR):
+ default:
+ spline=gsl_spline_alloc(gsl_interp_linear,nband);
+ break;
+ case(UNDEFINED):
+ default:{
+ string errorString="Error: interpolation type not defined: ";
+ errorString+=type;
+ throw(errorString);
+ break;
+ }
+ }
+ gsl_spline_init(spline,&(input[0][0]),&(input[isample][0]),nband);
+ for(double xi=start;xi<=end;xi+=step){
+ if(!type&&xi>input[0].back())
+ output[isample].push_back(output[isample].back());
+ else
+ output[isample].push_back(gsl_spline_eval(spline,xi,acc));
+ }
+ gsl_spline_free(spline);
+ gsl_interp_accel_free(acc);
+
+ }
+}
+
+template<class T> void StatFactory::interpolateUp(const vector<T>& input, vector<T>& output, int nbin)
+{
+ assert(input.size());
+ assert(nbin);
+ output.clear();
+ int dim=input.size();
+ for(int i=0;i<dim;++i){
+ double deltaX=0;
+ double left=input[i];
+ if(i<dim-1){
+ double right=(i<dim-1)? input[i+1]:input[i];
+ deltaX=(right-left)/static_cast<double>(nbin);
+ for(int x=0;x<nbin;++x){
+ output.push_back(left+x*deltaX);
+ }
+ }
+ else
+ output.push_back(input.back());
+ }
}
+template<class T> void StatFactory::interpolateUp(double* input, int dim, vector<T>& output, int nbin)
+{
+ assert(nbin);
+ output.clear();
+ for(int i=0;i<dim;++i){
+ double deltaX=0;
+ double left=input[i];
+ if(i<dim-1){
+ double right=(i<dim-1)? input[i+1]:input[i];
+ deltaX=(right-left)/static_cast<double>(nbin);
+ for(int x=0;x<nbin;++x){
+ output.push_back(left+x*deltaX);
+ }
+ }
+ else
+ output.push_back(input[dim-1]);
+ }
+}
-//alternatively: use GNU scientific library:
-// gsl_stats_correlation (const double data1[], const size_t stride1, const double data2[], const size_t stride2, const size_t n)
+template<class T> void StatFactory::interpolateDown(const vector<T>& input, vector<T>& output, int nbin)
+{
+ assert(input.size());
+ assert(nbin);
+ output.clear();
+ int dim=input.size();
+ int x=0;
+ output.push_back(input[0]);
+ for(int i=1;i<dim;++i){
+ if(i%nbin)
+ continue;
+ else{
+ x=(i-1)/nbin+1;
+ output.push_back(input[i]);
+ }
+ }
+}
+
+template<class T> void StatFactory::interpolateDown(double* input, int dim, vector<T>& output, int nbin)
+{
+ assert(nbin);
+ output.clear();
+ int x=0;
+ output.push_back(input[0]);
+ for(int i=1;i<dim;++i){
+ if(i%nbin)
+ continue;
+ else{
+ x=(i-1)/nbin+1;
+ output.push_back(input[i]);
+ }
+ }
+}
+}
+
+#endif /* _STATFACTORY_H_ */
+// void Histogram::signature(double m1, double m2, double& k, double& alpha, double& beta, double e)
+// {
+// double y=m1*m1/m2;
+// beta=F_1(y,0.1,10.0,e);
+// double fb=F(beta);
+// double g=exp(lgamma(1.0/beta));
+// alpha=m1*g/exp(lgamma(2.0/beta));
+// k=beta/(2*alpha*g);
+// // cout << "y, alpha, beta: " << y << ", " << alpha << ", " << beta << endl;
+// }
-using namespace histogram;
+// double Histogram::F(double x)
+// {
+// double g2=exp(lgamma(2.0/x));
+// return(g2*g2/exp(lgamma(3.0/x))/exp(lgamma(1.0/x)));
+// }
-#endif /* _HISTOGRAM_H_ */
+// //x1 is under estimate, x2 is over estimate, e is error
+// double Histogram::F_1(double y, double x1, double x2, double e)
+// {
+// double f1=F(x1);
+// double f2=F(x2);
+// assert(f1!=f2);
+// double x=x1+(x2-x1)*(y-f1)/(f2-f1);
+// double f=F(x);
+// while(f-y>=e||y-f>=e){
+// if(f<y)
+// x1=x;
+// else
+// x2=x;
+// if(x1==x2)
+// return x1;
+// assert(f1!=f2);
+// x=x1+(x2-x1)*(y-f1)/(f2-f1);
+// f=F(x);
+// }
+// return x;
+// }
diff --git a/src/apps/pkclassify_nn.cc b/src/apps/pkclassify_nn.cc
index 8b2465c..70433f5 100644
--- a/src/apps/pkclassify_nn.cc
+++ b/src/apps/pkclassify_nn.cc
@@ -317,7 +317,6 @@ int main(int argc, char *argv[])
assert(offset_opt.size()==nband);
if(scale_opt.size()>1)
assert(scale_opt.size()==nband);
- Histogram hist;
for(int iband=0;iband<nband;++iband){
if(verbose_opt[0]>=1)
cout << "scaling for band" << iband << endl;
diff --git a/src/apps/pkclassify_svm.cc b/src/apps/pkclassify_svm.cc
index 56fdfa9..ca7200d 100644
--- a/src/apps/pkclassify_svm.cc
+++ b/src/apps/pkclassify_svm.cc
@@ -349,7 +349,6 @@ int main(int argc, char *argv[])
assert(offset_opt.size()==nband);
if(scale_opt.size()>1)
assert(scale_opt.size()==nband);
- Histogram hist;
for(int iband=0;iband<nband;++iband){
if(verbose_opt[0]>=1)
std::cout << "scaling for band" << iband << std::endl;
diff --git a/src/apps/pkdumpogr.cc b/src/apps/pkdumpogr.cc
index 53a498b..1d2536e 100644
--- a/src/apps/pkdumpogr.cc
+++ b/src/apps/pkdumpogr.cc
@@ -23,7 +23,6 @@ along with pktools. If not, see <http://www.gnu.org/licenses/>.
#include <assert.h>
#include "base/Optionpk.h"
#include "imageclasses/ImgReaderOgr.h"
-#include "algorithms/Histogram.h"
#include "pkdumpogr.h"
int main(int argc, char *argv[])
diff --git a/src/apps/pkextract.cc b/src/apps/pkextract.cc
index b950de8..8a7dde0 100644
--- a/src/apps/pkextract.cc
+++ b/src/apps/pkextract.cc
@@ -27,7 +27,7 @@ along with pktools. If not, see <http://www.gnu.org/licenses/>.
#include "imageclasses/ImgReaderGdal.h"
#include "imageclasses/ImgWriterOgr.h"
#include "base/Optionpk.h"
-#include "algorithms/Histogram.h"
+#include "algorithms/StatFactory.h"
#ifndef PI
#define PI 3.1415926535897932384626433832795
@@ -101,7 +101,7 @@ int main(int argc, char *argv[])
if(verbose_opt[0])
std::cout << class_opt << std::endl;
- Histogram hist;
+ statfactory::StatFactory stat;
Vector2d<unsigned int> posdata;
unsigned long int nsample=0;
unsigned long int ntotalvalid=0;
@@ -1590,8 +1590,8 @@ int main(int argc, char *argv[])
case(2):{//proportion classes
if(verbose_opt[0])
std::cout << "number of points in polygon: " << nPointPolygon << std::endl;
- hist.normalize_pct(polyValues);
- // hist.sum(polyValues);
+ stat.normalize_pct(polyValues);
+ // stat.sum(polyValues);
for(int index=0;index<polyValues.size();++index){
double theValue=polyValues[index];
ostringstream fs;
@@ -1607,7 +1607,7 @@ int main(int argc, char *argv[])
assert(polygon_opt[0]);//not implemented for points
if(verbose_opt[0])
std::cout << "number of points in polygon: " << nPointPolygon << std::endl;
- hist.normalize_pct(polyValues);
+ stat.normalize_pct(polyValues);
assert(polyValues.size()==2);//11:broadleaved, 12:coniferous
if(polyValues[0]>=75)//broadleaved
writePolygonFeature->SetField(label_opt[0].c_str(),static_cast<int>(11));
@@ -1633,7 +1633,7 @@ int main(int argc, char *argv[])
if(verbose_opt[0])
std::cout << "number of points in polygon: " << nPointPolygon << std::endl;
//search for min class
- //todo: change to minClass=hist.max(class_opt) once Optionpk is implemented...
+ //todo: change to minClass=stat.max(class_opt) once Optionpk is implemented...
int minClass=class_opt[class_opt.size()-1];//!hard coded for now, maximum class is last entry in class_opt
for(int iclass=0;iclass<class_opt.size();++iclass){
if(polyValues[iclass]>0){
@@ -2151,8 +2151,8 @@ int main(int argc, char *argv[])
case(2):{//proportion classes
if(verbose_opt[0])
std::cout << "number of points in polygon: " << nPointPolygon << std::endl;
- hist.normalize_pct(polyValues);
- // hist.sum(polyValues);
+ stat.normalize_pct(polyValues);
+ // stat.sum(polyValues);
for(int index=0;index<polyValues.size();++index){
double theValue=polyValues[index];
ostringstream fs;
@@ -2168,7 +2168,7 @@ int main(int argc, char *argv[])
assert(polygon_opt[0]);//not implemented for points
if(verbose_opt[0])
std::cout << "number of points in polygon: " << nPointPolygon << std::endl;
- hist.normalize_pct(polyValues);
+ stat.normalize_pct(polyValues);
assert(polyValues.size()==2);//11:broadleaved, 12:coniferous
if(polyValues[0]>=75)//broadleaved
writePolygonFeature->SetField(label_opt[0].c_str(),static_cast<int>(11));
@@ -2194,7 +2194,7 @@ int main(int argc, char *argv[])
if(verbose_opt[0])
std::cout << "number of points in polygon: " << nPointPolygon << std::endl;
//search for min class
- //todo: change to minClass=hist.max(class_opt) once Optionpk is implemented...
+ //todo: change to minClass=stat.max(class_opt) once Optionpk is implemented...
int minClass=class_opt[class_opt.size()-1];//!hard coded for now, maximum class is last entry in class_opt
for(int iclass=0;iclass<class_opt.size();++iclass){
if(polyValues[iclass]>0){
diff --git a/src/apps/pkfs_nn.cc b/src/apps/pkfs_nn.cc
index c97f41e..82fbf53 100644
--- a/src/apps/pkfs_nn.cc
+++ b/src/apps/pkfs_nn.cc
@@ -314,7 +314,6 @@ int main(int argc, char *argv[])
assert(offset_opt.size()==nband);
if(scale_opt.size()>1)
assert(scale_opt.size()==nband);
- Histogram hist;
for(int iband=0;iband<nband;++iband){
if(verbose_opt[0]>1)
std::cout << "scaling for band" << iband << std::endl;
diff --git a/src/apps/pklas2img.cc b/src/apps/pklas2img.cc
index 78f32da..8496c8a 100644
--- a/src/apps/pklas2img.cc
+++ b/src/apps/pklas2img.cc
@@ -23,7 +23,7 @@ along with pktools. If not, see <http://www.gnu.org/licenses/>.
#include "imageclasses/ImgWriterGdal.h"
#include "imageclasses/ImgReaderOgr.h"
#include "fileclasses/FileReaderLas.h"
-#include "algorithms/Histogram.h"
+#include "algorithms/StatFactory.h"
#include "algorithms/Filter2d.h"
int main(int argc,char **argv) {
@@ -316,7 +316,7 @@ int main(int argc,char **argv) {
std::cout << "processing LiDAR points" << std::endl;
progress=0;
pfnProgress(progress,pszMessage,pProgressArg);
- Histogram hist;
+ statfactory::StatFactory stat;
//fill inputData in outputData
if(composite_opt[0]=="profile"){
assert(postFilter_opt[0]=="none");
@@ -332,17 +332,17 @@ int main(int argc,char **argv) {
if(!inputData[irow][icol].size())
outputData[irow][icol]=(static_cast<float>((flag_opt[0])));
else{
- Histogram hist;
+ statfactory::StatFactory stat;
if(composite_opt[0]=="min")
- outputData[irow][icol]=hist.min(inputData[irow][icol]);
+ outputData[irow][icol]=stat.min(inputData[irow][icol]);
else if(composite_opt[0]=="max")
- outputData[irow][icol]=hist.max(inputData[irow][icol]);
+ outputData[irow][icol]=stat.max(inputData[irow][icol]);
else if(composite_opt[0]=="median")
- outputData[irow][icol]=hist.median(inputData[irow][icol]);
+ outputData[irow][icol]=stat.median(inputData[irow][icol]);
else if(composite_opt[0]=="mean")
- outputData[irow][icol]=hist.mean(inputData[irow][icol]);
+ outputData[irow][icol]=stat.mean(inputData[irow][icol]);
else if(composite_opt[0]=="sum")
- outputData[irow][icol]=hist.sum(inputData[irow][icol]);
+ outputData[irow][icol]=stat.sum(inputData[irow][icol]);
else if(composite_opt[0]=="first")
outputData[irow][icol]=inputData[irow][icol][0];
else if(composite_opt[0]=="last")
@@ -355,11 +355,11 @@ int main(int argc,char **argv) {
}
float min=0;
float max=0;
- hist.minmax(inputData[irow][icol],inputData[irow][icol].begin(),inputData[irow][icol].end(),min,max);
+ stat.minmax(inputData[irow][icol],inputData[irow][icol].begin(),inputData[irow][icol].end(),min,max);
if(verbose_opt[0])
std::cout << "min,max: " << min << "," << max << std::endl;
if(max>min){
- hist.percentiles(inputData[irow][icol],inputData[irow][icol].begin(),inputData[irow][icol].end(),profile,nband,min,max);
+ stat.percentiles(inputData[irow][icol],inputData[irow][icol].begin(),inputData[irow][icol].end(),profile,nband,min,max);
assert(profile.size()==nband);
for(int iband=0;iband<nband;++iband)
outputProfile[iband][icol]=profile[iband];
diff --git a/src/apps/pkmosaic.cc b/src/apps/pkmosaic.cc
index 62ae98c..75b907b 100644
--- a/src/apps/pkmosaic.cc
+++ b/src/apps/pkmosaic.cc
@@ -26,7 +26,7 @@ along with pktools. If not, see <http://www.gnu.org/licenses/>.
#include "imageclasses/ImgReaderOgr.h"
#include "base/Vector2d.h"
#include "base/Optionpk.h"
-#include "algorithms/Histogram.h"
+#include "algorithms/StatFactory.h"
using namespace std;
@@ -383,7 +383,7 @@ int main(int argc, char *argv[])
vector<short> fileBuffer(ncol);//holds the number of used files
Vector2d<short> maxBuffer;//buffer used for maximum voting
Vector2d<double> readBuffer(nband);
- Histogram hist;
+ statfactory::StatFactory stat;
if(mrule_opt[0]==1)//ndvi
assert(ruleBand_opt.size()==2);
if(mrule_opt[0]==6){//max voting
@@ -814,7 +814,7 @@ int main(int argc, char *argv[])
else{
for(int icol=0;icol<imgWriter.nrOfCol();++icol){
vector<short>::iterator maxit=maxBuffer[icol].begin();
- maxit=hist.max(maxBuffer[icol],maxBuffer[icol].begin(),maxBuffer[icol].end());
+ maxit=stat.max(maxBuffer[icol],maxBuffer[icol].begin(),maxBuffer[icol].end());
writeBuffer[0][icol]=distance(maxBuffer[icol].begin(),maxit);
fileBuffer[icol]=*(maxit);
}
@@ -838,17 +838,17 @@ int main(int argc, char *argv[])
case(5):
assert(storeBuffer[bands[iband]][icol].size()==fileBuffer[icol]);
if(storeBuffer[bands[iband]][icol].size())
- writeBuffer[iband][icol]=hist.mean(storeBuffer[bands[iband]][icol]);
+ writeBuffer[iband][icol]=stat.mean(storeBuffer[bands[iband]][icol]);
break;
case(7):
assert(storeBuffer[bands[iband]][icol].size()==fileBuffer[icol]);
if(storeBuffer[bands[iband]][icol].size())
- writeBuffer[iband][icol]=hist.median(storeBuffer[bands[iband]][icol]);
+ writeBuffer[iband][icol]=stat.median(storeBuffer[bands[iband]][icol]);
break;
case(8)://sum
assert(storeBuffer[bands[iband]][icol].size()==fileBuffer[icol]);
if(storeBuffer[bands[iband]][icol].size())
- writeBuffer[iband][icol]=hist.sum(storeBuffer[bands[iband]][icol]);
+ writeBuffer[iband][icol]=stat.sum(storeBuffer[bands[iband]][icol]);
break;
default:
break;
diff --git a/src/apps/pkopt_svm.cc b/src/apps/pkopt_svm.cc
index 903f046..5b30995 100644
--- a/src/apps/pkopt_svm.cc
+++ b/src/apps/pkopt_svm.cc
@@ -337,7 +337,6 @@ int main(int argc, char *argv[])
assert(offset_opt.size()==nband);
if(scale_opt.size()>1)
assert(scale_opt.size()==nband);
- Histogram hist;
for(int iband=0;iband<nband;++iband){
if(verbose_opt[0]>1)
std::cout << "scaling for band" << iband << std::endl;
diff --git a/src/apps/pksensormodel.cc b/src/apps/pksensormodel.cc
index 9faf0e1..a63a589 100644
--- a/src/apps/pksensormodel.cc
+++ b/src/apps/pksensormodel.cc
@@ -25,7 +25,7 @@ along with pktools. If not, see <http://www.gnu.org/licenses/>.
#include <nlopt.hpp>
#include "base/Optionpk.h"
#include "algorithms/OptFactory.h"
-#include "algorithms/Histogram.h"
+#include "algorithms/StatFactory.h"
#include "pksensormodel.h"
double objFunction(const std::vector<double> &x, std::vector<double> &grad, void *my_func_data){
@@ -599,7 +599,6 @@ int main(int argc, char *argv[])
std::cout << "opening output file: " << output_opt[0] << std::endl;
outputStream.open(output_opt[0].c_str());
}
- Histogram hist;
vector<double> errorv;
oSourceSRS.importFromEPSG(4326);
@@ -657,7 +656,8 @@ int main(int argc, char *argv[])
if(mean_opt[0]){
double theMean=0;
double theVar=0;
- hist.meanVar(errorv,theMean,theVar);
+ statfactory::StatFactory stat;
+ stat.meanVar(errorv,theMean,theVar);
if(output_opt.size())
outputStream << setprecision(12) << "mean stddev: " << theMean << " " << sqrt(theVar) << std::endl;
else
diff --git a/src/apps/pkstat.cc b/src/apps/pkstat.cc
index 1467dac..bec8c1a 100644
--- a/src/apps/pkstat.cc
+++ b/src/apps/pkstat.cc
@@ -23,7 +23,7 @@ along with pktools. If not, see <http://www.gnu.org/licenses/>.
#include <math.h>
#include "base/Optionpk.h"
#include "fileclasses/FileReaderAscii.h"
-#include "algorithms/Histogram.h"
+#include "algorithms/StatFactory.h"
using namespace std;
@@ -91,7 +91,7 @@ int main(int argc, char *argv[])
}
vector< vector<double> > dataVector(col_opt.size());
- vector< vector<int> > histVector(col_opt.size());
+ vector< vector<int> > statVector(col_opt.size());
FileReaderAscii asciiReader(input_opt[0]);
asciiReader.setFieldSeparator(fs_opt[0]);
@@ -103,7 +103,7 @@ int main(int argc, char *argv[])
assert(dataVector.size());
double minValue=min_opt[0];
double maxValue=max_opt[0];
- Histogram hist;
+ statfactory::StatFactory stat;
for(int icol=0;icol<col_opt.size();++icol){
if(!dataVector[icol].size()){
std::cerr << "Warning: dataVector[" << icol << "] is empty" << std::endl;
@@ -112,56 +112,56 @@ int main(int argc, char *argv[])
if(size_opt[0])
cout << "sample size column " << col_opt[icol] << ": " << dataVector[icol].size() << endl;
if(mean_opt[0])
- cout << "mean value column " << col_opt[icol] << ": " << hist.mean(dataVector[icol]) << endl;
+ cout << "mean value column " << col_opt[icol] << ": " << stat.mean(dataVector[icol]) << endl;
if(var_opt[0])
- cout << "variance value column " << col_opt[icol] << ": " << hist.var(dataVector[icol]) << endl;
+ cout << "variance value column " << col_opt[icol] << ": " << stat.var(dataVector[icol]) << endl;
if(stdev_opt[0])
- cout << "standard deviation column " << col_opt[icol] << ": " << sqrt(hist.var(dataVector[icol])) << endl;
+ cout << "standard deviation column " << col_opt[icol] << ": " << sqrt(stat.var(dataVector[icol])) << endl;
if(skewness_opt[0])
- cout << "skewness value column " << col_opt[icol] << ": " << hist.skewness(dataVector[icol]) << endl;
+ cout << "skewness value column " << col_opt[icol] << ": " << stat.skewness(dataVector[icol]) << endl;
if(kurtosis_opt[0])
- cout << "kurtosis value column " << col_opt[icol] << ": " << hist.kurtosis(dataVector[icol]) << endl;
+ cout << "kurtosis value column " << col_opt[icol] << ": " << stat.kurtosis(dataVector[icol]) << endl;
if(sum_opt[0]){
cout << setprecision(2);
- cout << fixed << "sum column " << col_opt[icol] << ": " << (hist.sum(dataVector[icol])) << endl;
+ cout << fixed << "sum column " << col_opt[icol] << ": " << (stat.sum(dataVector[icol])) << endl;
}
if(median_opt[0])
- cout << "median value column " << col_opt[icol] << ": " << hist.median(dataVector[icol]) << endl;
+ cout << "median value column " << col_opt[icol] << ": " << stat.median(dataVector[icol]) << endl;
if(minmax_opt[0]){
- cout << "min value column " << col_opt[icol] << ": " << hist.min(dataVector[icol]) << endl;
- cout << "max value column " << col_opt[icol] << ": " << hist.max(dataVector[icol]) << endl;
+ cout << "min value column " << col_opt[icol] << ": " << stat.min(dataVector[icol]) << endl;
+ cout << "max value column " << col_opt[icol] << ": " << stat.max(dataVector[icol]) << endl;
}
if(histogram_opt[0]){
if(verbose_opt[0])
std::cout << "calculating histogram for col " << icol << std::endl;
- hist.distribution(dataVector[icol],dataVector[icol].begin(),dataVector[icol].end(),histVector[icol],nbin_opt[0],minValue,maxValue);
+ stat.distribution(dataVector[icol],dataVector[icol].begin(),dataVector[icol].end(),statVector[icol],nbin_opt[0],minValue,maxValue);
if(verbose_opt[0])
std::cout << "min and max values: " << minValue << ", " << maxValue << std::endl;
}
}
if(correlation_opt[0]){
assert(dataVector.size()==2);
- cout << "correlation between columns " << col_opt[0] << " and " << col_opt[1] << ": " << hist.correlation(dataVector[0],dataVector[1]) << endl;
+ cout << "correlation between columns " << col_opt[0] << " and " << col_opt[1] << ": " << stat.correlation(dataVector[0],dataVector[1]) << endl;
}
if(rmse_opt[0]){
assert(dataVector.size()==2);
- cout << "root mean square error between columns " << col_opt[0] << " and " << col_opt[1] << ": " << hist.rmse(dataVector[0],dataVector[1]) << endl;
+ cout << "root mean square error between columns " << col_opt[0] << " and " << col_opt[1] << ": " << stat.rmse(dataVector[0],dataVector[1]) << endl;
}
if(reg_opt[0]){
assert(dataVector.size()==2);
double c0=0;
double c1=0;
- double r2=hist.linear_regression(dataVector[0],dataVector[1],c0,c1);
+ double r2=stat.linear_regression(dataVector[0],dataVector[1],c0,c1);
cout << "linear regression between columns: " << col_opt[0] << " and " << col_opt[1] << ": " << c0 << "+" << c1 << " * x " << " with R^2 (square correlation coefficient): " << r2 << endl;
}
if(histogram_opt[0]){
- for(int irow=0;irow<histVector.begin()->size();++irow){
+ for(int irow=0;irow<statVector.begin()->size();++irow){
std::cout << (maxValue-minValue)*irow/(nbin_opt[0]-1)+minValue << " ";
for(int icol=0;icol<col_opt.size();++icol){
if(relative_opt[0])
- std::cout << 100.0*static_cast<double>(histVector[icol][irow])/static_cast<double>(dataVector[icol].size());
+ std::cout << 100.0*static_cast<double>(statVector[icol][irow])/static_cast<double>(dataVector[icol].size());
else
- std::cout << histVector[icol][irow];
+ std::cout << statVector[icol][irow];
if(icol<col_opt.size()-1)
cout << " ";
}
diff --git a/src/apps/pkstatogr.cc b/src/apps/pkstatogr.cc
index a1d497b..076259f 100644
--- a/src/apps/pkstatogr.cc
+++ b/src/apps/pkstatogr.cc
@@ -23,7 +23,7 @@ along with pktools. If not, see <http://www.gnu.org/licenses/>.
#include <assert.h>
#include "base/Optionpk.h"
#include "imageclasses/ImgReaderOgr.h"
-#include "algorithms/Histogram.h"
+#include "algorithms/StatFactory.h"
int main(int argc, char *argv[])
{
@@ -70,7 +70,7 @@ int main(int argc, char *argv[])
ImgReaderOgr inputReader(input_opt[0]);
vector<double> theData;
- Histogram hist;
+ statfactory::StatFactory stat;
//todo: implement ALL
for(int ifield=0;ifield<fieldname_opt.size();++ifield){
@@ -84,10 +84,10 @@ int main(int argc, char *argv[])
int nbin=(nbin_opt[0]>1)? nbin_opt[0] : 2;
std::cout << " --fname " << fieldname_opt[ifield];
try{
- hist.distribution(theData,theData.begin(),theData.end(),binData,nbin,minimum,maximum);
+ stat.distribution(theData,theData.begin(),theData.end(),binData,nbin,minimum,maximum);
double theMean=0;
double theVar=0;
- hist.meanVar(theData,theMean,theVar);
+ stat.meanVar(theData,theMean,theVar);
if(mean_opt[0])
std::cout << " --mean " << theMean;
if(stdev_opt[0])
@@ -97,7 +97,7 @@ int main(int argc, char *argv[])
if(max_opt[0])
cout << " -M " << maximum;
if(median_opt[0])
- std::cout << " -median " << hist.median(theData);
+ std::cout << " -median " << stat.median(theData);
if(size_opt[0])
std::cout << " -size " << theData.size();
std::cout << std::endl;
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-grass/pktools.git
More information about the Pkg-grass-devel
mailing list