当前位置: 首页>>代码示例>>C++>>正文


C++ TestCase::getHypothesis方法代码示例

本文整理汇总了C++中TestCase::getHypothesis方法的典型用法代码示例。如果您正苦于以下问题:C++ TestCase::getHypothesis方法的具体用法?C++ TestCase::getHypothesis怎么用?C++ TestCase::getHypothesis使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TestCase的用法示例。


在下文中一共展示了TestCase::getHypothesis方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: oneSampleZTest

/**
 * \brief Runs a one-sample Z test on a vector of numbers.
 * \param[in] values The vector of numbers.
 * \param[in] distributionMean The mean of the entire population.
 * \param[in] distributionStandardDeviation the standard deviation of the entire population.
 * \param[in] The confidence level (commonly used values: 0.95, 0.999)
 * \param[in] testCase The test case containing the hypothesis and null hypothesis chosen in germanStudentsTest()
 */
void StatisticalTesting::oneSampleZTest(const std::vector<double>& values,
		const double& distributionMean, const double& distributionStandardDeviation,
		const double& confidenceLevel, const TestCase& testCase) {

	/**
	 * TODO: Execute the Z test for the given vector of numbers and either
	 * reject the null hypothesis or state that you cannot reject the null hypothesis.
	 */

	/*
	 * Available methods:
	 * - lookupZTable(double Z): returns the cumulative density function
	 *       of the standard normal distribution at Z (see slide 23 for examples).
	 * - testCase.getHypothesis(): returns the hypothesis (see germanStudentsTest() above)
	 * - testCase.getNullHypothesis(): returns the null hypothesis (see germanStudentsTest() above)
	 *
	 * For both the hypothesis and the null hypothesis, the following methods are available:
	 * - hypothesis.getDirection(): Returns one element from the following enumeration:
	 *       LESS, GREATER, AT_LEAST, AT_MOST, EQUAL, or DIFFERENT.
	 * - hypothesis.reject(): Rejects the hypothesis.
	 * - hypothesis.cannotReject(): States that we cannot reject the hypothesis based on the data.
	 */
	double zscore = zScore(values,distributionMean,distributionStandardDeviation);
	double zlookup = lookupZTable(zscore);
	const Hypothesis& h1 = testCase.getHypothesis();
	const Hypothesis& h0 = testCase.getNullHypothesis();
	double zconfidence = 0;
	normal s;
	/* If greater or lesser the area of significance is on one side of curve. so we use quantile with same
	 * confidence level. Else we can divide alpha by 2 for two sided test
	 *
	 */
	if (h0.getDirection()==AT_MOST) 	{
		zconfidence = confidenceLevel;
		if (zlookup>zconfidence)
			h0.reject();
			else 		{
				h0.cannotReject();
			}
	}
	else {
		if(h0.getDirection()==AT_LEAST)
		{
			zconfidence = (1-confidenceLevel);
			if (zlookup<zconfidence)
				h0.reject();
				else {
					h0.cannotReject();
				}
		}
		else {
			double left_boundry = (1-confidenceLevel);
			double right_boundry = confidenceLevel;
						if((zlookup<left_boundry)||(zlookup>right_boundry))
							h0.reject();
							else 	{
								h0.cannotReject();
							}
		}
	}
}
开发者ID:CheHaoKang,项目名称:HumanoidRobotics,代码行数:69,代码来源:StatisticalTesting.cpp

示例2: oneSampleTTest

/**
 * \brief Runs a one-sample t test on a vector of numbers.
 * \param[in] values The vector of numbers.
 * \param[in] distributionMean The mean of the entire population.
 * \param[in] The confidence level (commonly used values: 0.95, 0.999)
 * \param[in] testCase The test case containing the hypothesis and null hypothesis chosen in germanStudentsTest()
 */
void StatisticalTesting::oneSampleTTest(const std::vector<double>& values, const double& distributionMean,
		const double& confidenceLevel, const TestCase& testCase) {
	/**
	 * TODO: Execute the one sample T test for the given vector of numbers and either
	 * reject the null hypothesis or state that you cannot reject the null hypothesis.
	 */

	/*
	 * Available methods:
	 * - lookupTTable(size_t degreeOfFreedom, double confidenceLevel, TestType testType):
	 *       returns the quantile function of the student's t distribution (see slide
	 *       of the standard normal distribution at Z (see slide 29 for examples).
	 *       testType can be either ONE_SIDED or TWO_SIDED.
	 * - testCase.getHypothesis(): returns the hypothesis (see germanStudentsTest() above)
	 * - testCase.getNullHypothesis(): returns the null hypothesis (see germanStudentsTest() above)
	 *
	 * For both the hypothesis and the null hypothesis, the following methods are available:
	 * - hypothesis.getDirection(): Returns one element from the following enumeration:
	 *       LESS, GREATER, AT_LEAST, AT_MOST, EQUAL, or DIFFERENT.
	 * - hypothesis.reject(): Rejects the hypothesis.
	 * - hypothesis.cannotReject(): States that we cannot reject the hypothesis based on the data.
	 */
	size_t dof = values.size() -1;
	double tscore = tValue(values,distributionMean);
	double tlookup ;
	const Hypothesis& h1 = testCase.getHypothesis();
	const Hypothesis& h0 = testCase.getNullHypothesis();
		/* If greater or lesser the area of significance is on one side of curve. so we use quantile with same
		 * confidence level. Else we can divide alpha by 2 for two sided test
		 *
		 */
		if (h0.getDirection()==AT_MOST) 	{
			tlookup = lookupTTable(dof,confidenceLevel,StatisticalTesting::ONE_SIDED);
			if (tscore >tlookup )
				h0.reject();
				else 		{
					h0.cannotReject();
				}
		}
		else {
			if(h0.getDirection()==AT_LEAST)
			{
				tlookup = lookupTTable(dof,(1-confidenceLevel),StatisticalTesting::ONE_SIDED);
				if (tscore < tlookup )
					h0.reject();
					else {
						h0.cannotReject();
					}
			}
			else {
				double right_boundry = lookupTTable(dof,confidenceLevel,StatisticalTesting::ONE_SIDED);
				double left_boundry = lookupTTable(dof,(1-confidenceLevel),StatisticalTesting::ONE_SIDED);
							if((tscore<left_boundry)||(tscore>right_boundry))
								h0.reject();
								else 	{
									h0.cannotReject();
								}
			}
		}


}
开发者ID:CheHaoKang,项目名称:HumanoidRobotics,代码行数:69,代码来源:StatisticalTesting.cpp


注:本文中的TestCase::getHypothesis方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。