Example #1
0
 public function getStandardDeviation()
 {
     $values = [];
     foreach ($this->data as $row) {
         $values[] = $row['Close'];
     }
     return std($values);
 }
Example #2
0
    if (preg_match('/.*Test\\.php/', $file) !== 1) {
        continue;
    }
    $filePath = __DIR__ . '/' . $file;
    if (!file_exists($filePath) && !is_file($filePath)) {
        continue;
    }
    echo PHP_EOL . $file . ' | ';
    require_once __DIR__ . '/' . $file;
    $className = explode('.', $file)[0];
    $class = new ReflectionClass($className);
    foreach ($class->getMethods() as $method) {
        if (preg_match('/test.*/', $method) !== 1) {
            continue;
        }
        if ($filterMethodRegexp && preg_match('#' . $filterMethodRegexp . '#', strtolower($method)) !== 1) {
            continue;
        }
        $reflectionMethod = new ReflectionMethod($class->getName(), $method->name);
        try {
            if (!$reflectionMethod->isPublic()) {
                continue;
            }
            $reflectionMethod->invoke($class->newInstance());
        } catch (Exception $e) {
            std(toString($e));
            d($e);
        }
    }
    echo PHP_EOL;
}
Example #3
0
 function testClassDiv($div, $data, $classes, $gender, $showResult = false)
 {
     global $tests, $students, $subjects;
     $tests++;
     $score = array();
     /*$score:array(
     			1(性别)=>array(
     				1(班号)=>array(
     					1(科目号)=>array(
     						学号=>本科分数
     					)
     				)
     			)
     		)
     		*/
     //将div分班方案分解为score分数表
     for ($subject = 0; $subject < $subjects; $subject++) {
         foreach ($div as $gender_in_array1 => $array1) {
             foreach ($array1 as $class => $array2) {
                 foreach ($array2 as $student) {
                     $score[$gender_in_array1][$class][$subject][$student] = $data[$student][$subject];
                 }
             }
         }
     }
     //$_SESSION['score']=$score;
     //print_r($score);
     $result = array();
     for ($subject = 0; $subject < $subjects; $subject++) {
         for ($class = 0; $class < $classes; $class++) {
             $result[$class][$subject]['num'] = count($score[$gender][$class][$subject]);
             //得到每班每学科的人数
             $result[$class][$subject]['sum'] = array_sum($score[$gender][$class][$subject]);
             //得到每班每学科的和
             $result[$class][$subject]['aver'] = $result[$class][$subject]['sum'] / $result[$class][$subject]['num'];
             //得到每班每学科的平均值
             //$result[$class][$subject]['std']=std($score[$gender][$class][$subject],$result[$class][$subject]['aver']);//得到每班每学科的标准差
         }
     }
     if ($showResult) {
         echo "\n<br>result" . $gender . ": ";
         print_r($result);
     }
     /*for($subject=0;$subject<$subjects;$subject++){
     			for($class=0;$class<$classes;$class++){
     		
     				$std[]=$result[$class][$subject]['std'];
     		
     			}
     		}
     		
     		$std_sum=array_sum($std);//各班各学科的标准差的和*/
     $aver_std = array();
     for ($subject = 0; $subject < $subjects; $subject++) {
         $aver = array();
         for ($class = 0; $class < $classes; $class++) {
             $aver[] = $result[$class][$subject]['aver'];
         }
         $aver_std[] = std($aver);
     }
     $aver_std_sum = array_sum($aver_std);
     //各班每学科总分的标差的和
     return $aver_std_sum;
 }
Example #4
0
function coefficient_of_variation($arr)
{
    return std($arr) / mean($arr) * 100;
}