Commit a1e97bb9 authored by js9's avatar js9

Adding sample and population statistics (mean,var,skew,kurt)


git-svn-id: http://visit.ilight.com/svn/visit/trunk/src@6481 18c085ea-50e0-402c-830e-de6fd14e8384
parent 3f840aa6
......@@ -175,6 +175,9 @@
# Cyrus Harrison, Wed Mar 5 08:54:06 PST 2008
# Added avtMemoryUsageQuery
#
# Jeremy Meredith, Wed Mar 11 16:26:41 EDT 2009
# Added sample statistics queries (mean, variance, skewness, kurtosis).
#
##############################################################################
@SET_MAKE@
......@@ -256,6 +259,7 @@ Queries_src= \
Queries/avtOriginalDataNumNodesQuery.C \
Queries/avtOriginalDataNumZonesQuery.C \
Queries/avtOriginalDataSpatialExtentsQuery.C \
Queries/avtSampleStatisticsQuery.C \
Queries/avtShapeletDecompositionQuery.C \
Queries/avtSkewnessQuery.C \
Queries/avtSphericalCompactnessFactorQuery.C \
......
......@@ -82,6 +82,7 @@
#include <avtOriginalDataNumNodesQuery.h>
#include <avtOriginalDataNumZonesQuery.h>
#include <avtOriginalDataSpatialExtentsQuery.h>
#include <avtSampleStatisticsQuery.h>
#include <avtShapeletDecompositionQuery.h>
#include <avtSkewnessQuery.h>
#include <avtSphericalCompactnessFactorQuery.h>
......@@ -271,6 +272,9 @@ avtQueryFactory::Instance()
// Cyrus Harrison, Wed Mar 5 08:56:01 PST 2008
// Added Memory Usage Query.
//
// Jeremy Meredith, Wed Mar 11 17:49:06 EDT 2009
// Added sample and population statistics.
//
// ****************************************************************************
......@@ -624,6 +628,14 @@ avtQueryFactory::CreateQuery(const QueryAttributes *qa)
{
query = new avtMemoryUsageQuery();
}
else if (qname == "Sample Statistics")
{
query = new avtSampleStatisticsQuery(false);
}
else if (qname == "Population Statistics")
{
query = new avtSampleStatisticsQuery(true);
}
if (query == NULL && !foundAQuery)
{
......
/*****************************************************************************
*
* Copyright (c) 2000 - 2008, Lawrence Livermore National Security, LLC
* Produced at the Lawrence Livermore National Laboratory
* LLNL-CODE-400142
* All rights reserved.
*
* This file is part of VisIt. For details, see https://visit.llnl.gov/. The
* full copyright notice is contained in the file COPYRIGHT located at the root
* of the VisIt distribution or at http://www.llnl.gov/visit/copyright.html.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the disclaimer below.
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the disclaimer (as noted below) in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of the LLNS/LLNL nor the names of its contributors may
* be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL LAWRENCE LIVERMORE NATIONAL SECURITY,
* LLC, THE U.S. DEPARTMENT OF ENERGY OR CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
*
*****************************************************************************/
// ************************************************************************* //
// avtSampleStatisticsQuery.C //
// ************************************************************************* //
#include <avtSampleStatisticsQuery.h>
#include <vtkCell.h>
#include <vtkCellData.h>
#include <vtkDataSet.h>
#include <vtkDataSetRemoveGhostCells.h>
#include <vtkPointData.h>
#include <vtkUnsignedCharArray.h>
#include <avtCallback.h>
#include <avtParallel.h>
#include <DebugStream.h>
#include <InvalidVariableException.h>
#include <InvalidDimensionsException.h>
#include <NonQueryableInputException.h>
#include <snprintf.h>
#include <float.h>
#include <math.h>
using std::string;
using std::vector;
// ****************************************************************************
// Method: avtSampleStatisticsQuery constructor
//
// Programmer: Jeremy Meredith
// Creation: March 11, 2009
//
// Modifications:
//
// ****************************************************************************
avtSampleStatisticsQuery::avtSampleStatisticsQuery(bool pop)
: avtTwoPassDatasetQuery()
{
populationStatistics = pop;
strcpy(descriptionBuffer, "Calculating sample statistics");
}
// ****************************************************************************
// Method: avtSampleStatisticsQuery destructor
//
// Purpose:
// Defines the destructor. Note: this should not be inlined in the header
// because it causes problems for certain compilers.
//
// Programmer: Jeremy Meredith
// Creation: March 11, 2009
//
// ****************************************************************************
avtSampleStatisticsQuery::~avtSampleStatisticsQuery()
{
;
}
// ****************************************************************************
// Method: avtSampleStatisticsQuery::PreExecute
//
// Purpose:
// This is called before all of the domains are executed.
//
// Programmer: Jeremy Meredith
// Creation: March 11, 2009
//
// Modifications:
//
// ****************************************************************************
void
avtSampleStatisticsQuery::PreExecute(void)
{
avtTwoPassDatasetQuery::PreExecute();
totalvalues = 0;
sum = 0;
mean = 0;
csum2 = 0;
csum3 = 0;
csum4 = 0;
}
// ****************************************************************************
// Method: avtSampleStatisticsQuery::Execute
//
// Purpose:
// Processes a single domain.
//
// Programmer: Jeremy Meredith
// Creation: March 11, 2009
//
// Modifications:
//
// ****************************************************************************
void
avtSampleStatisticsQuery::Execute1(vtkDataSet *ds, const int dom)
{
vtkDataArray *data = ds->GetCellData()->GetScalars();
if (!data)
data = ds->GetPointData()->GetScalars();
if (!data)
cerr << "ERROR\n";
int n = data->GetNumberOfTuples();
totalvalues += n;
for (int i=0; i<n; i++)
{
double v = data->GetTuple1(i);
sum += v;
}
}
// ****************************************************************************
// Method: avtSampleStatisticsQuery::MidExecute
//
// Purpose:
// This is called after all of the domains are executed the first time.
//
// Programmer: Jeremy Meredith
// Creation: March 11, 2009
//
// Modifications:
// ****************************************************************************
void
avtSampleStatisticsQuery::MidExecute(void)
{
SumDoubleAcrossAllProcessors(mean);
mean = sum / double(totalvalues);
}
// ****************************************************************************
// Method: avtSampleStatisticsQuery::Execute2
//
// Purpose:
// Processes a single domain -- second pass.
//
// Programmer: Jeremy Meredith
// Creation: March 11, 2009
//
// Modifications:
//
// ****************************************************************************
void
avtSampleStatisticsQuery::Execute2(vtkDataSet *ds, const int dom)
{
vtkDataArray *data = ds->GetCellData()->GetScalars();
if (!data)
data = ds->GetPointData()->GetScalars();
if (!data)
cerr << "ERROR\n";
int n = data->GetNumberOfTuples();
for (int i=0; i<n; i++)
{
double v = data->GetTuple1(i);
double c = v-mean;
csum2 += c*c;
csum3 += c*c*c;
csum4 += c*c*c*c;
}
}
// ****************************************************************************
// Method: avtSampleStatisticsQuery::PostExecute
//
// Purpose:
// This is called after all of the domains are executed.
//
// Programmer: Jeremy Meredith
// Creation: March 11, 2009
//
// Modifications:
//
// ****************************************************************************
void
avtSampleStatisticsQuery::PostExecute(void)
{
doubleVector values;
double N = totalvalues;
SumDoubleAcrossAllProcessors(csum2);
SumDoubleAcrossAllProcessors(csum3);
SumDoubleAcrossAllProcessors(csum4);
double cmoment2 = csum2 / N;
double cmoment3 = csum3 / N;
double cmoment4 = csum4 / N;
double variance;
double stddev;
double skewness;
double kurtosis;
if (populationStatistics)
{
variance = cmoment2;
skewness = cmoment3 / pow(cmoment2, 3./2.);
kurtosis = cmoment4 / (cmoment2*cmoment2) - 3;
}
else
{
variance = csum2 / (N-1);
skewness = (N * sqrt(N-1) / (N-2)) * csum3 / pow(csum2, 3./2.);
kurtosis = ((N+1)*N / ((N-1)*(N-2)*(N-3))) * csum4/(variance*variance)
- 3*(N-1)*(N-1)/((N-2)*(N-3));
}
stddev = sqrt(variance);
//
// Parent class uses this message to set the Results message
// in the Query Attributes that is sent back to the viewer.
// That is all that is required of this query.
//
char msg[4096];
string floatFormat = queryAtts.GetFloatFormat();
string format =
"Mean = " + floatFormat + "\n"
"Std Dev = " + floatFormat + "\n"
"Variance = " + floatFormat + "\n"
"Skewness = " + floatFormat + "\n"
"Kurtosis = " + floatFormat + "\n";
SNPRINTF(msg, 4096,format.c_str(),
mean, stddev, variance, skewness, kurtosis);
values.push_back(mean);
values.push_back(stddev);
values.push_back(variance);
values.push_back(skewness);
values.push_back(kurtosis);
SetResultMessage(msg);
SetResultValues(values);
}
/*****************************************************************************
*
* Copyright (c) 2000 - 2009, Lawrence Livermore National Security, LLC
* Produced at the Lawrence Livermore National Laboratory
* LLNL-CODE-400142
* All rights reserved.
*
* This file is part of VisIt. For details, see https://visit.llnl.gov/. The
* full copyright notice is contained in the file COPYRIGHT located at the root
* of the VisIt distribution or at http://www.llnl.gov/visit/copyright.html.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the disclaimer below.
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the disclaimer (as noted below) in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of the LLNS/LLNL nor the names of its contributors may
* be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL LAWRENCE LIVERMORE NATIONAL SECURITY,
* LLC, THE U.S. DEPARTMENT OF ENERGY OR CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
*
*****************************************************************************/
// ************************************************************************* //
// avtSampleStatisticsQuery.h //
// ************************************************************************* //
#ifndef AVT_SAMPLE_STATISTICS_QUERY_H
#define AVT_SAMPLE_STATISTICS_QUERY_H
#include <query_exports.h>
#include <avtTwoPassDatasetQuery.h>
#include <string>
#include <vector>
class vtkDataSet;
class vtkCell;
// ****************************************************************************
// Class: avtSampleStatisticsQuery
//
// Purpose:
// This query calculates sample statistics on a data array.
//
// Programmer: Jeremy Meredith
// Creation: March 11, 2009
//
// Modifications:
//
// ****************************************************************************
class QUERY_API avtSampleStatisticsQuery : public avtTwoPassDatasetQuery
{
public:
avtSampleStatisticsQuery(bool population);
virtual ~avtSampleStatisticsQuery();
virtual const char *GetType(void)
{ return "avtSampleStatisticsQuery"; };
virtual const char *GetDescription(void)
{ return descriptionBuffer; };
protected:
bool populationStatistics;
int totalvalues;
double sum;
double mean;
double csum2;
double csum3;
double csum4;
char descriptionBuffer[1024];
virtual void PreExecute(void);
virtual void Execute1(vtkDataSet *, const int);
virtual void MidExecute();
virtual void Execute2(vtkDataSet *, const int);
virtual void PostExecute(void);
};
#endif
../../avt/Queries/Queries/avtSampleStatisticsQuery.h
\ No newline at end of file
......@@ -3719,6 +3719,9 @@ GetUniqueVars(const stringVector &vars, const string &activeVar,
// Cyrus Harrison, Wed Jul 16 12:05:54 PDT 2008
// Moved the Shapelet Decomposition Query into the Shape-Related category.
//
// Jeremy Meredith, Wed Mar 11 17:53:13 EDT 2009
// Added Sample and Population statistics queries.
//
// ****************************************************************************
void
......@@ -3844,6 +3847,8 @@ ViewerQueryManager::InitializeQueryList()
queryTypes->AddQuery("TrajectoryByNode", dq, vr, dnv, 1, TrajVars, to, 2);
queryTypes->AddQuery("Best Fit Line", dq, mr, basic, 1, 0, qo);
queryTypes->AddQuery("Memory Usage", dq, misc_r, basic, 1, 0, qo);
queryTypes->AddQuery("Sample Statistics", dq, vr, ad, 1, 0, qo);
queryTypes->AddQuery("Population Statistics", dq, vr, ad, 1, 0, qo);
queryTypes->SelectAll();
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment