Пример #1
0
function maximum_likelihood_models($opps, $debugML = false)
{
    if ($debugML) {
        echo "Grades for this student and KC:\n";
        foreach ($opps as $j => $opp) {
            $yy = reset($opp);
            $gg = $yy['grade'];
            echo " {$gg}";
        }
        echo "\n";
    }
    $maxll = false;
    $allll = array();
    $allGain = array();
    // Step through possible chances for learning skill.
    for ($step = 0; $step < count($opps); $step++) {
        $cbl = 0;
        $wbl = 0;
        $cal = 0;
        $wal = 0;
        foreach ($opps as $j => $opp) {
            $yy = reset($opp);
            if ($j < $step) {
                if ($yy['grade'] == 'correct') {
                    $cbl++;
                } else {
                    $wbl++;
                }
            } else {
                if ($yy['grade'] == 'correct') {
                    $cal++;
                } else {
                    $wal++;
                }
            }
        }
        // Values for guess and slip are from maximum likelihood.
        $pg = $cbl + $wbl > 0 ? $cbl / ($cbl + $wbl) : false;
        $ps = $cal + $wal > 0 ? $wal / ($cal + $wal) : false;
        $allSlip[$step] = $ps;
        // Calculate the log likelihood for model with step at $step.
        // Note that this number is negative (so we are trying to maximize it)
        // Also, note that the case $step=0 corresponds to not learning.
        $ll = 0;
        $ll += $cbl > 0 ? $cbl * log($pg) : 0.0;
        $ll += $wbl > 0 ? $wbl * log(1.0 - $pg) : 0.0;
        $ll += $wal > 0 ? $wal * log($ps) : 0.0;
        $ll += $cal > 0 ? $cal * log(1.0 - $ps) : 0.0;
        $allll[$step] = $ll;
        // Maximum likelihood estimator for the learning gain 1-g-s
        $allGain[$step] = $ps !== false && $pg !== false ? 1 - $ps - $pg : false;
        // Find maximum value.
        if ($maxll === false || $ll > $maxll) {
            $maxll = $ll;
            // Only count cases where step occurs inside student data
            $maxv = array('logLike' => $ll, 'learn' => $step, 'pg' => $pg, 'ps' => $ps);
            if ($step == 0) {
                $maxv0 = $maxv;
            }
        }
        if ($debugML) {
            echo ' (' . $step . ',' . print2($pg) . ',' . print2($ps) . ',' . number_format($ll, 3) . ',' . ')';
            // echo " <$cbl,$wbl,$cal,$wal>";
        }
    }
    if ($debugML) {
        echo "\n";
    }
    // Find relative probabilities for learning on each step.
    //
    // We are are going from "the probability of producing seen behavior
    // for a given L" to "the probablitiy of a certain L given the
    // seen behavior."  Thus, we are assuming that the
    // prior p.d.f. for a given L is constant.  See Section 33.1.4 of
    // http://pdg.lbl.gov/2011/reviews/rpp2011-rev-statistics.pdf
    //
    // Elements where learning cannot be determined are left empty.
    //
    // In fact, we use AIC to determine the relative probability
    // of different models with various values of L.  When there
    // is a fit with a step, there are two model parameters.  When no
    // learning is found ($i=0), there is one model parameter.
    // See http://en.wikipedia.org/wiki/Akaike_information_criterion
    $maxv['opps'] = count($opps);
    $maxv['learnHereProb'] = array();
    $sum = 0;
    // Include no learning case.
    // There is no way to measure learning on last step.
    for ($i = 0; $i < count($allll); $i++) {
        // Using AIC, to determing the relative probability.
        $val = exp($allll[$i] - ($i == 0 ? 1 : 2));
        $maxv['learnHereProb'][$i] = $val;
        $sum += $val;
    }
    // Next, normalize probabilities;
    for ($i = 0; $i < count($allll); $i++) {
        $maxv['learnHereProb'][$i] /= $sum;
    }
    // If no significant model-weighted gain is seen, then
    // model has failed, "point of learning" doesn't exist.
    // There are two possible strategies to determine learning:
    // 1.  The best fit parameters predict positive learning or
    // 2.  The model predicts positive learning with probability
    //     greater than some confidence level.
    //
    // The model weighted gain is about 1/2 for any data
    // where the initial rate cbl/(cbl+wbl) is equal to the
    // final rate cal/(cal+wal).
    // This includes all correct, all wrong, or some
    // random rate of correctness.
    //  get all fits where there is enough data to fit.
    $maxv['valid'] = count($opps) >= 3;
    // Otherwise, use the value from learn=0
    if (!$maxv['valid']) {
        $maxv['learn'] = 0;
        $maxv['pg'] = false;
        $maxv['ps'] = $maxv0['ps'];
        $maxv['logLike'] = $maxv0['logLike'];
    }
    // Associated learning gains
    $maxv['learnGain'] = $allGain;
    $maxv['slip'] = $allSlip;
    if ($debugML) {
        if ($maxv['valid']) {
            echo ' model with pg=' . number_format($pg, 3) . ', ps=' . number_format($ps, 3) . ', logLike=' . number_format($maxv['logLike'], 3);
        } else {
            echo ' no learning: ps=' . number_format($ps, 2);
        }
        echo "\n";
    }
    return $maxv;
}
Пример #2
0
function GetPage($res = '', $tab)
{
    if ($tab == 1) {
        $data = '
		<fieldset id="fiel_bank">
	    	<legend>ბარათები</legend>
		    <div class="inner-table">
			    <div id="dt_example" class="ex_highlight_row">
			        <div id="container" class="overhead_container">
			        	<div id="button_area"></div>
			            <div id="dynamic">
								<table class="display" style="width: 900px" id="table-3">
					                    <thead>
					                        <tr id="datatable_header">
					                            <th>ID</th>
					                            <th class="min">ბარათის ნომერი</th>
					                            <th style="width: 150px">თარიღი </th>
					                            <th style="width: 150px">თანხა</th>
					                            <th style="width: 150px">ფილიალი</th>
					                            <th style="width: 150px">შენიშვნა</th>

					                        </tr>
					                    </thead>
					                    <thead>
					                        <tr class="search_header">
					                            <th class="colum_hidden">
					                            	<input type="text" name="search_id" value="ფილტრი" class="search_init" />
					                            </th>
					                            <th>
					                                <input type="text" name="search_aleter" value="ფილტრი" class="search_init" />
					                            </th>
					                            <th>
					                                <input type="text" name="search_client" value="ფილტრი" class="search_init" />
					                            </th>
					                            	                            <th>
					                                <input type="text" name="search_client" value="ფილტრი" class="search_init" />
					                            </th>
					                            	                            <th>
					                                <input type="text" name="search_client" value="ფილტრი" class="search_init" />
					                            </th>
					                            <th>
					                                <input type="text" name="search_client" value="ფილტრი" class="search_init" />
					                            </th>
					                        </tr>
					                    </thead>
										<tfoot>
					                        <tr>
					                            <th>&nbsp;</th>
					                            <th>&nbsp;</th>
					                            <th><p align="right">ჯამი:<br/>სულ ჯამი:</th>
					                            <th align="left">&nbsp;</th>
					                            <th>&nbsp;</th>
												<th>&nbsp;</th>
					                        </tr>
					                    </tfoot>
					                </table>



			            </div>
			        </div>
			    </div>
			</div>
		</fieldset>
<input type="hidden" id="inv_id" value="' . $_REQUEST['id'] . '">
	    </div>
	<div class="inner-table" >


	</div>';
    } else {
        global $sum;
        $later = 'b';
        $reQ = mysql_fetch_assoc(mysql_query("\n\t\t\tSELECT\n\t\t\t\t\t CONCAT('ბ–',`a_letter`.`id`) AS id,\n\t\t\t\t\ta_letter.request_date as start_date,\n\t\t\t\t\t`a_letter`.`finish_date` as end_date,\n\t\t\t\t\trequest_sources.`name` as source,\n\t\t\t\t\tCONCAT(`client`.`name`,'  (',`client_objects`.`name`, ')') AS `client`,\n\t\t\t\t\t`client_objects`.`id` as `obj_id`,\n\t\t\t\t\t`a_letter`.`b_letter_status` as `b_letter_status`,\n\t\t\t\t\t`a_letter`.`b_letter_overhead_id` as `overhead_id`,\n\t\t\t\t\tclient_object_persons.`name` as client_p,\n\t\t\t\t\tpersons.`name` as obj_p\n\t\t\tFROM\t\t\t`a_letter`\n\t\t\tLEFT JOIN\t\t`client_objects` ON `a_letter`.`client_object_id` = `client_objects`.`id`\n\t\t\tLEFT JOIN\t\t`client` ON `client`.`id` = `client_objects`.`client_id`\n\t\t\tLEFT JOIN   \trequest_sources ON request_sources.id=a_letter.source\n\t\t\tLEFT JOIN   \tpersons ON a_letter.receiver=persons.id\n\t\t\tLEFT JOIN   \tclient_object_persons ON client_object_persons.id=a_letter.requester\n\t\t\tWHERE\t\t\t`a_letter`.`id` = '{$res['id']}'\nUNION\n\t\t\tSELECT CONCAT('ე–',`d_letter`.`id`) AS id,\n\t\t\t\t\t\td_letter.request_date as start_date,\n\t\t\t\t\t\t`d_letter`.`finish_date` as end_date,\n\t\t\t\t\t\trequest_sources.`name` as source,\n\t\t\t\t\t\tCONCAT(`client`.`name`,'(',`client_objects`.`name`, ')') AS `client`,\n\t\t\t\t\t\t`client_objects`.`id` as `obj_id`,\n\t\t\t\t\t\t`d_letter`.`e_letter_status` as `e_letter_status`,\n\t\t\t\t\t\t`d_letter`.`e_letter_overhead_id` as `overhead_id`,\n\t\t\t\t\t\tclient_object_persons.`name` as client_p,\n\t\t\t\t\t\tpersons.`name` as obj_p\n\t\t\tFROM\t\t\t`d_letter`\n\t\t\tLEFT JOIN\t\t`client_objects` ON `d_letter`.`client_object_id` = `client_objects`.`id`\n\t\t\tLEFT JOIN\t\t`client` ON `client`.`id` = `client_objects`.`client_id`\n\t\t\tLEFT JOIN   \trequest_sources ON request_sources.id=d_letter.source\n\t\t\tLEFT JOIN   \tpersons ON d_letter.receiver=persons.id\n\t\t\tLEFT JOIN   \tclient_object_persons ON client_object_persons.id=d_letter.requester\n\t\t\tWHERE\t\t\t`d_letter`.`id` = '{$res['id']}'"));
        $m = "\n\t\t</table>\n\t\t</fieldset>\n\n\t\t\t<fieldset style='margin-top: 4px;'>\n\t\t\t<legend></legend>\n\t\t\t\t<table width='90%'>\n\t\t\t\t<tr>\n\t\t\t\t<td>მიმწოდებელი: {$reQ['client_p']}</td>\n\t\t\t\t<td></td>\n\t\t\t\t<td>მიმღები: {$reQ['obj_p']}</td>\n\t\t\t\t<td></td>\n\t\t\t\t</tr>\n\t\t\t\t</table>\n\t\t\t</fieldset>\t";
        $data = "\n\t\t<div id='dialog-form'>\n\t\t\t\t<fieldset>\n\t\t\t\t\t<legend>{$reQ['client']}</legend>\n\t\t\t\t\t<table width='100%'>\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<td>შეკვეთის N: {$res['id']}</td>\n\t\t\t\t\t\t\t<td></td>\n\t\t\t\t\t\t\t<td>შეკვეთის დრო: {$reQ['start_date']}</td>\n\t\t\t\t\t\t\t<td></td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<td>შეკვეთის ფომა: {$reQ['source']}</td>\n\t\t\t\t\t\t\t<td></td>\n\t\t\t\t\t\t\t<td>მიტანის დრო: {$reQ['end_date']}</td>\n\t\t\t\t\t\t\t<td></td>\n\t\t\t\t\t\t</tr>\n\n</table>\n\t\t\t\t</fieldset>\n\t\t\t\t<div style='padding: 2px;'></div>\n\t\t\t\t<fieldset>\n\t";
        if (substr($reQ[id], 0, 3) == 'ე') {
            if ($_REQUEST['rw'] == 'wr' & $_REQUEST['tab'] == 0) {
                $data .= '<table class="display dataTable" style="width: 550px !important; border:1px solid black !important;" cellpadding="0" cellspacing="0">
		<tr class="ui-widget-header" style="border:1px solid black !important; color: white !important;">
		<td style="width: 25% !important; font-size: 9pt; border:1px solid black !important; vertical-align: middle !important; text-align: center;"><span>მოდელი</span></td>
		<td style="width: 20% !important; font-size: 9pt; border:1px solid black !important; vertical-align: middle !important; text-align: center;">რაოდენობა</td>
		</tr>';
                $data .= print4($res['id']);
                $data .= $m;
            } elseif ($_REQUEST['rw'] == 'wr' & $_REQUEST['tab'] == 1) {
                $data .= '<table class="display dataTable" style="width: 550px !important; height:25px;  border:1px solid black !important;" cellpadding="0" cellspacing="0">
		<tr  class="ui-widget-header" style="border:1px solid black !important; color: white !important;">
		<td style="width: 45% !important; font-size: 9pt; border:1px solid black !important; vertical-align: middle !important; text-align: center;"><span>შტრიხკოდი</span></td>
		<td style="width: 25% !important; font-size: 9pt; border:1px solid black !important; vertical-align: middle !important; text-align: center;"><span>მოდელი</span></td>
		<td style="width: 20% !important; font-size: 9pt; border:1px solid black !important; vertical-align: middle !important; text-align: center;">სტატუსი</td>
		</tr>';
                $data .= print5($res['id']);
                $data .= $m;
            } else {
                $data .= '<table class="display dataTable"  style="width: 550px !important; border:1px solid black !important;" cellpadding="0" cellspacing="0">
		<tr style="background-color: black !important; border:1px solid black !important; color: white !important;">
		<td style="width: 45% !important; font-size: 9pt; border:1px solid black !important; vertical-align: middle !important; text-align: center;"><span>სერვისი</span></td>
		<td style="width: 25% !important; font-size: 9pt; border:1px solid black !important; vertical-align: middle !important; text-align: center;"><span>მოდელი</span></td>
		<td style="width: 20% !important; font-size: 9pt; border:1px solid black !important; vertical-align: middle !important; text-align: center;">შტრიხკოდი</td>
		<td style="width: 10% !important; font-size: 9pt; border:1px solid black !important; vertical-align: middle !important; text-align: center;">ფასი</td>
		</tr>';
                $data .= print2($res['id']);
            }
        } else {
            if ($_REQUEST['rw'] == 'wr' & $_REQUEST['tab'] == 0) {
                $data .= '<table class="display dataTable" style="width: 550px" cellpadding="0" cellspacing="0">
		<thead class="ui-widget-header">
		<tr style="border:1px !important; height:25px; color: white !important;">
		<td style="width: 25% !important; font-size: 9pt; border:1px solid black !important; vertical-align: middle !important; text-align: center;"><span>მოდელი</span></td>
		<td style="width: 20% !important; font-size: 9pt; border:1px solid black !important; vertical-align: middle !important; text-align: center;">რაოდენობა</td>
		</tr>
		</thead>';
                $data .= print3($res['id']);
                $data .= $m;
            } elseif ($_REQUEST['rw'] == 'wr' & $_REQUEST['tab'] == 1) {
                $data .= '<table class="display dataTable" style="width: 550px !important; border:1px solid black !important;" cellpadding="0" cellspacing="0">
		<thead class="ui-widget-header">
		<tr  class="ui-widget-header" style="border:1px solid black !important; color: white !important;">
		<td style="width: 45% !important; font-size: 9pt; border:1px solid black !important; vertical-align: middle !important; text-align: center;"><span>შტრიხკოდი</span></td>
		<td style="width: 25% !important; font-size: 9pt; border:1px solid black !important; vertical-align: middle !important; text-align: center;"><span>მოდელი</span></td>
		<td style="width: 20% !important; font-size: 9pt; border:1px solid black !important; vertical-align: middle !important; text-align: center;">სტატუსი</td>
		</tr>
		</thead>';
                $data .= print5($res['id']);
                $data .= $m;
            } else {
                $data .= '
					<table  style="width: 550px !important; border:1px solid black !important;" cellpadding="0" cellspacing="0">
						<tr style="background-color: #D9D9D9;border:1px solid black !important;">
							<td style="background-color: #D9D9D9; font-size: 100%  !important; border:1px solid black !important;">&nbsp;</td>
							<td style="background-color: #D9D9D9; font-size: 100%  !important; border:1px solid black !important;">&nbsp;</td>
							<td colspan="9"  style="background-color: #D9D9D9; font-size: 100%  !important; border:1px solid black !important; text-align: center;">ჩატარებული სამუშაოები</td>
							<td style="background-color: #D9D9D9; font-size: 100%  !important; border:1px solid black !important;">&nbsp;</td>
	                        <td style="background-color: #D9D9D9; font-size: 100%  !important; border:1px solid black !important;">&nbsp;</td>						
	                   </tr>
						<tr style="background-color: #D9D9D9;!important; border:1px solid black !important;">
							<td style="width: 170px;font-size: 9pt; border:1px solid black !important; vertical-align: middle !important; text-align: center;"><span>შტრიხკოდი</span></td>
							<td style="width: 110px;font-size: 9pt; border:1px solid black !important; vertical-align: middle !important; text-align: center;"><span>მოდელი</span></td>
							<td style="width: 25px !important; border:1px solid black !important;"><span style="writing-mode: tb-rl; -webkit-transform: rotate(270deg);	white-space: nowrap; display: block;width: 8px;	margin-top: 80px; margin-left: 4px;">ტონერი</span></td>
							<td style="width: 25px !important; border:1px solid black !important;"><span style="writing-mode: tb-rl; -webkit-transform: rotate(270deg);	white-space: nowrap; display: block;width: 8px;	margin-top: 80px; margin-left: 4px;">ბარაბანი</span></td>
							<td style="width: 25px !important; border:1px solid black !important;"><span style="writing-mode: tb-rl; -webkit-transform: rotate(270deg);	white-space: nowrap; display: block;width: 8px;	margin-top: 80px; margin-left: 4px;">მაგნიტ. ლილ.</span></td>
							<td style="width: 25px !important; border:1px solid black !important;"><span style="writing-mode: tb-rl; -webkit-transform: rotate(270deg);	white-space: nowrap; display: block;width: 8px;	margin-top: 80px; margin-left: 4px;">რეზინის PCR</span></td>
							<td style="width: 25px !important; border:1px solid black !important;"><span style="writing-mode: tb-rl; -webkit-transform: rotate(270deg);	white-space: nowrap; display: block;width: 8px;	margin-top: 80px; margin-left: 4px;">გამწ. რაკელი</span></td>
							<td style="width: 25px !important; border:1px solid black !important;"><span style="writing-mode: tb-rl; -webkit-transform: rotate(270deg);	white-space: nowrap; display: block;width: 8px;	margin-top: 80px; margin-left: 4px;">დოზ. რაკელი</span></td>
							<td style="width: 25px !important; border:1px solid black !important;"><span style="writing-mode: tb-rl; -webkit-transform: rotate(270deg);	white-space: nowrap; display: block;width: 8px;	margin-top: 80px; margin-left: 4px;">ჩიპი</span></td>
							<td style="width: 25px !important; border:1px solid black !important;"><span style="writing-mode: tb-rl; -webkit-transform: rotate(270deg);	white-space: nowrap; display: block;width: 8px;	margin-top: 80px; margin-left: 4px;">კორპუსი</span></td>
	                        <td style="width: 25px !important; border:1px solid black !important;"><span style="writing-mode: tb-rl; -webkit-transform: rotate(270deg);	white-space: nowrap; display: block;width: 8px;	margin-top: 80px; margin-left: 4px;">სერვ გარაშე</span></td>   
							<td style="width: 25px !important; border:1px solid black !important;"><span style="writing-mode: tb-rl; -webkit-transform: rotate(270deg);	white-space: nowrap; display: block;width: 8px;	margin-top: 80px; margin-left: 4px;">საგარანტიო</span></td>
							<td style="font-size: 100%  !important; width: 110px !important; vertical-align: middle !important; text-align: center;">&nbsp;ფასი&nbsp;</td>
						</tr>';
                $data .= print1($res['id']);
                $data .= '</table>
					<table >
						<div style="text-align: right; font-size: 10pt; margin-top: 4px;">
							<p>თანხა სულ :&nbsp;<span style="border-bottom: 1px solid #000; padding: 0 30px; margin-left: 0px;">' . addNull($sum) . '&nbsp;&nbsp;ლარი</span></p>
						</div>
					</table>';
            }
        }
        $data .= '



	    </div>
	<div class="inner-table" >


	</div>';
    }
    return $data;
}
Пример #3
0
if (false) {
    ksort($allKCStudent);
    foreach ($allKCStudent as $kc => $ss) {
        foreach ($ss as $thisSection => $st) {
            foreach ($st as $thisName => $xx) {
                echo "{$kc} {$thisSection} {$thisName}\n";
                foreach ($xx as $yyy) {
                    $yy = reset($yyy);
                    // return first element.
                    $g = $yy['grade'];
                    $dt = $yy['dt'];
                    $id = $yy['id'];
                    $tt = $yy['timeStamp'];
                    $clientID = $yy['clientID'];
                    $err = isset($yy['error']) ? $yy['error'] : '';
                    echo "    ({$g}," . print2($dt) . ",{$err})\n";
                }
                echo "\n";
            }
        }
    }
}
function skipKC($kc)
{
    // none:  entries where assigment of blame failed
    // select-mc-answer  answer multiple-choice questions
    return $kc == 'none' || $kc == 'select-mc-answer';
}
// For each student and KC, Print out the model parameters.
// this was used to compare with Anirudh fits to logistic model.
if (false) {