Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature 1705 cdp_prob #1724

Merged
merged 2 commits into from
Mar 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
150 changes: 150 additions & 0 deletions met/src/basic/vx_config/threshold.cc
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,37 @@ return ( n );
////////////////////////////////////////////////////////////////////////


double Or_Node::climo_prob() const

{

if ( !left_child || !right_child ) {

mlog << Error << "\nOr_Node::climo_prob() -> "
<< "node not populated!\n\n";

exit ( 1 );

}

double prob = bad_data_double;
double prob_left = left_child->climo_prob();
double prob_right = right_child->climo_prob();

if ( !is_bad_data(prob_left) && !is_bad_data(prob_right) ) {

prob = min(prob_left + prob_right, 1.0);

}

return ( prob );

}


////////////////////////////////////////////////////////////////////////


bool Or_Node::need_perc() const

{
Expand Down Expand Up @@ -356,6 +387,55 @@ return ( n );
////////////////////////////////////////////////////////////////////////


double And_Node::climo_prob() const

{

if ( !left_child || !right_child ) {

mlog << Error << "\nAnd_Node::climo_prob() -> "
<< "node not populated!\n\n";

exit ( 1 );

}

double prob = bad_data_double;
double prob_left = left_child->climo_prob();
double prob_right = right_child->climo_prob();

//
// For opposing inequalities, compute the difference in percentiles
//

if ( !is_bad_data(prob_left) && !is_bad_data(prob_right) ) {

//
// Support complex threshold types >a&&<b and <a&&>b
//

if ( ( left_child->type() == thresh_gt || left_child->type() == thresh_ge ) &&
( right_child->type() == thresh_lt || right_child->type() == thresh_le ) ) {

prob = max( 0.0, prob_right - ( 1.0 - prob_left ) );

}
else if ( ( left_child->type() == thresh_lt || left_child->type() == thresh_le ) &&
( right_child->type() == thresh_gt || right_child->type() == thresh_ge ) ) {

prob = max( 0.0, prob_left - ( 1.0 - prob_right ) );

}
}

return ( prob );

}


////////////////////////////////////////////////////////////////////////


bool And_Node::need_perc() const

{
Expand Down Expand Up @@ -540,6 +620,23 @@ return ( n );
////////////////////////////////////////////////////////////////////////


double Not_Node::climo_prob() const

{

double prob = bad_data_double;
double prob_child = child->climo_prob();

if ( !is_bad_data(prob_child) ) prob = 1.0 - prob_child;

return ( prob );

}


////////////////////////////////////////////////////////////////////////


bool Not_Node::need_perc() const

{
Expand Down Expand Up @@ -1065,6 +1162,59 @@ return;
////////////////////////////////////////////////////////////////////////


double Simple_Node::climo_prob() const

{

double prob = bad_data_double;

if ( Ptype == perc_thresh_climo_dist ) {

// Climo probability varies based on the threshold type
switch ( op ) {

case thresh_lt:
case thresh_le:

prob = PT/100.0;
break;

case thresh_eq:

prob = 0.0;
break;

case thresh_ne:

prob = 1.0;
break;

case thresh_gt:
case thresh_ge:

prob = 1.0 - PT/100.0;
break;

default:

mlog << Error << "\nSimple_Node::climo_prob() -> "
<< "cannot convert climatological distribution percentile "
<< "threshold to a probability!\n\n";

exit ( 1 );
break;

} // switch
}

return ( prob );

}


////////////////////////////////////////////////////////////////////////


bool Simple_Node::need_perc() const

{
Expand Down
29 changes: 20 additions & 9 deletions met/src/basic/vx_config/threshold.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ class ThreshNode {

virtual double pvalue() const = 0;

virtual double climo_prob() const = 0;

virtual bool need_perc() const = 0;

virtual void set_perc(const NumArray *, const NumArray *, const NumArray *) = 0;
Expand Down Expand Up @@ -197,6 +199,8 @@ class Or_Node : public ThreshNode {

double pvalue() const;

double climo_prob() const;

bool need_perc() const;

void set_perc(const NumArray *, const NumArray *, const NumArray *);
Expand All @@ -217,10 +221,10 @@ class Or_Node : public ThreshNode {
////////////////////////////////////////////////////////////////////////


inline ThreshType Or_Node::type() const { return ( thresh_complex ); }
inline double Or_Node::value() const { return ( bad_data_double ); }
inline PercThreshType Or_Node::ptype() const { return ( no_perc_thresh_type ); }
inline double Or_Node::pvalue() const { return ( bad_data_double ); }
inline ThreshType Or_Node::type() const { return ( thresh_complex ); }
inline double Or_Node::value() const { return ( bad_data_double ); }
inline PercThreshType Or_Node::ptype() const { return ( no_perc_thresh_type ); }
inline double Or_Node::pvalue() const { return ( bad_data_double ); }


////////////////////////////////////////////////////////////////////////
Expand All @@ -244,6 +248,8 @@ class And_Node : public ThreshNode {

double pvalue() const;

double climo_prob() const;

bool need_perc() const;

void set_perc(const NumArray *, const NumArray *, const NumArray *);
Expand Down Expand Up @@ -293,6 +299,8 @@ class Not_Node : public ThreshNode {

double pvalue() const;

double climo_prob() const;

bool need_perc() const;

void set_perc(const NumArray *, const NumArray *, const NumArray *);
Expand Down Expand Up @@ -363,6 +371,8 @@ class Simple_Node : public ThreshNode {

double pvalue() const;

double climo_prob() const;

bool need_perc() const;

void get_simple_nodes(vector<Simple_Node> &) const;
Expand Down Expand Up @@ -435,6 +445,7 @@ class SingleThresh {
double get_value() const;
PercThreshType get_ptype() const;
double get_pvalue() const;
double get_climo_prob() const;
void get_simple_nodes(vector<Simple_Node> &) const;

void multiply_by(const double);
Expand All @@ -451,11 +462,11 @@ class SingleThresh {
////////////////////////////////////////////////////////////////////////


inline ThreshType SingleThresh::get_type() const { return ( node ? node->type() : thresh_na ); }
inline double SingleThresh::get_value() const { return ( node ? node->value() : bad_data_double ); }
inline PercThreshType SingleThresh::get_ptype() const { return ( node ? node->ptype() : no_perc_thresh_type ); }
inline double SingleThresh::get_pvalue() const { return ( node ? node->pvalue() : bad_data_double ); }

inline ThreshType SingleThresh::get_type() const { return ( node ? node->type() : thresh_na ); }
inline double SingleThresh::get_value() const { return ( node ? node->value() : bad_data_double ); }
inline PercThreshType SingleThresh::get_ptype() const { return ( node ? node->ptype() : no_perc_thresh_type ); }
inline double SingleThresh::get_pvalue() const { return ( node ? node->pvalue() : bad_data_double ); }
inline double SingleThresh::get_climo_prob() const { return ( node ? node->climo_prob() : bad_data_double ); }

////////////////////////////////////////////////////////////////////////

Expand Down
39 changes: 7 additions & 32 deletions met/src/libcode/vx_statistics/pair_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1064,46 +1064,21 @@ NumArray derive_climo_prob(const ClimoCDFInfo &cdf_info,
const NumArray &mn_na, const NumArray &sd_na,
const SingleThresh &othresh) {
int i, n_mn, n_sd;
double prob;
NumArray climo_prob, climo_vals;
double prob;

// Number of valid climo mean and standard deviation
n_mn = mn_na.n_valid();
n_sd = sd_na.n_valid();

// For CDP threshold types, the climo probability is constant
if(othresh.get_ptype() == perc_thresh_climo_dist) {

// Climo probability varies based on the threshold type
switch(othresh.get_type()) {

case thresh_lt:
case thresh_le:
prob = othresh.get_pvalue()/100.0;
break;

case thresh_eq:
prob = 0.0;
break;

case thresh_ne:
prob = 1.0;
break;
// Check for constant climo probability
if(!is_bad_data(prob = othresh.get_climo_prob())) {

case thresh_gt:
case thresh_ge:
prob = 1.0 - othresh.get_pvalue()/100.0;
break;

default:
mlog << Error << "\nderive_climo_prob() -> "
<< "climatological threshold \"" << othresh.get_str()
<< "\" cannot be converted to a probability!\n\n";
exit(1);
break;
}
mlog << Debug(4)
<< "For threshold " << othresh.get_str()
<< ", using a constant climatological probability value of "
<< prob << ".\n";

// Add constant climo probability value
climo_prob.add_const(prob, n_mn);
}
// If both mean and standard deviation were provided, use them to
Expand Down