Example #1
0
	/**
	 * Generates gaussian bell curve of student's votes
	 *
	 * @param 	string		$class
	 * @param 	string		$school_year
	 * @param 	boolean		$admin_id
	 * @return	array
	 */
    public function getGaussDataByClassAndSchoolYearAndAdmin($class = FALSE, $school_year = FALSE, $admin_id = FALSE)
    {
        $this->db->select('ROUND(SUM(user_vote) / SUM(max_vote) * 10, 0) AS percentage');
        $this->db->join('projects', 'projects.id = results.project_id', 'left');
        $this->db->where('projects.is_activated', TRUE);

        if($class) $this->db->where('class', $class);
        if($school_year) $this->db->where('school_year', $school_year);
        if($admin_id) $this->db->where('admin_id', $admin_id);

        $this->db->group_by('user_id');
        $this->db->order_by('percentage', 'ASC');
        $result = $this->db->get('results')->result();

        $this->load->helper('graph');
        return gauss($result, 'percentage');
    }
Example #2
0
 public function testGauss()
 {
     $total = 10000;
     $collector = array();
     for ($i = 0; $i < $total; $i++) {
         $collector[] = gauss();
     }
     $min = min($collector);
     $max = max($collector);
     $range = $max - $min;
     $min15 = $min + $range * 0.15;
     $min30 = $min + $range * 0.3;
     $min45 = $min + $range * 0.45;
     $max15 = $max - $range * 0.15;
     $max30 = $max - $range * 0.3;
     $max45 = $max - $range * 0.45;
     $c0_15 = count(array_filter($collector, function ($elem) use($min, $min15, $min30, $min45) {
         return $min <= $elem and $elem <= $min15;
     }));
     $c15_30 = count(array_filter($collector, function ($elem) use($min, $min15, $min30, $min45) {
         return $min15 <= $elem and $elem <= $min30;
     }));
     $c30_45 = count(array_filter($collector, function ($elem) use($min, $min15, $min30, $min45) {
         return $min30 <= $elem and $elem <= $min45;
     }));
     $this->assertTrue($c0_15 < $c15_30);
     $this->assertTrue($c15_30 < $c30_45);
     $c0_15 = count(array_filter($collector, function ($elem) use($max, $max15, $max30, $max45) {
         return $max15 <= $elem and $elem <= $max;
     }));
     $c15_30 = count(array_filter($collector, function ($elem) use($max, $max15, $max30, $max45) {
         return $max30 <= $elem and $elem <= $max15;
     }));
     $c30_45 = count(array_filter($collector, function ($elem) use($max, $max15, $max30, $max45) {
         return $max45 <= $elem and $elem <= $max30;
     }));
     $this->assertTrue($c0_15 < $c15_30);
     $this->assertTrue($c15_30 < $c30_45);
 }
Example #3
0
function random_gauss_ms($m = 0.0, $s = 1.0)
{
    // N(m,s)
    // returns random number with normal distribution:
    //  mean=m
    //  std dev=s
    return gauss() * $s + $m;
}
Example #4
0
    for ($j = 0; $j < 4; $j++) {
        echo "<td width='10'>" . $matriz[$i][$j] . "</td>";
    }
    echo "</tr>";
}
echo "</table></center>";
# DESPEJANDO PARA HALLAR A ?
$e2 = gauss($matriz[0][0], $matriz[1][0]);
$e3 = gauss($matriz[0][0], $matriz[2][0]);
# GENERANDO NUEVAS ECUACIONES DE 2 Y 3 MULTIPLICADO EL VALOR DEL DESPEJE CON LA ECUACION (1,1) Y SUMANDO CON ECUACION (2,3)
for ($j = 0; $j < 4; $j++) {
    $matriz[1][$j] = $e2 * $matriz[0][$j] + $matriz[1][$j];
    $matriz[2][$j] = $e3 * $matriz[0][$j] + $matriz[2][$j];
}
# DESPEJANDO PARA HALLAR A?
$e3 = gauss($matriz[1][1], $matriz[2][1]);
# GENERANDO NUEVA ECUACION 3
for ($j = 0; $j < 4; $j++) {
    $matriz[2][$j] = $e3 * $matriz[1][$j] + $matriz[2][$j];
}
?>
                                </td>
                                </tr>
                             <tr>
                             <td colspan="3">
                                	<?php 
# MOSTRANDO NUEVA MATRIZ GENERADA
echo "<center><table width='200' border='1'>";
for ($i = 0; $i < 3; $i++) {
    echo "<tr>";
    for ($j = 0; $j < 4; $j++) {
Example #5
0
function gauss_ms($m = 0.0, $s = 1.0)
{
    return gauss() * $s + $m;
}