SOURCE-COLLATED ARCHIVAL TRANSCRIPTION OF APPENDIX C Not a verified runnable program. No execution or semantic code repair is asserted. See original PDF pages175–192 and separate unresolved source errors register. SOURCE PDF PAGE 175 Appendix C: PHP scripts Functions.inc 15, '2' => 20, '3' => 47); // build case from given values function build_case($dsp=0, $optic=0, $mwave=0, $ntwrk=0, $satel=0, $prfm=0, $chrt=0) { return array( 'DSP' => $dsp, 'OPTIC' => $optic, 'MWAVE' => $mwave, 'NTWRK' => $ntwrk, 'SATEL' => $satel, 'PRFM' => $prfm, 'CHRT' => $chrt ); } // calculate the size of given case function case_size($case) { $sum = 0; foreach ($case as $value) { $sum += pow($value, 2); } SOURCE PDF PAGE 176 return sqrt($sum); } // multiply the corresponding pair and sum up the values function sumproduct($v1, $v2) { $sum = 0; foreach ($v1 as $key => $value) { $sum += $value * $v2[$key]; } return $sum; } // exhaustive search through the case base function found_new_solution(&$match,$pos,$id,$percent, $DSP, $OPTIC, $MWAVE, $NTWRK, $SATEL, $PRFM, $CHRT, $D1,$O2,$OM3,$M4,$NM5,$N6,$NS7,$S8) { for ($j=RANK_NUM; $j>$pos; $j--) { $match[$j] = $match[$j-1]; } $match[$pos] = array('id' => $id, 'percent' => $percent, 'DSP' => $DSP, 'OPTIC' => $OPTIC, 'MWAVE' => $MWAVE, 'NTWRK' => $NTWRK, 'SATEL' => $SATEL, 'PRFM' => $PRFM, 'CHRT' => $CHRT, 'D1' => $D1, 'O2' => $O2, 'OM3' => $OM3, 'M4' => $M4, 'NM5' => $NM5, 'N6' => $N6, 'NS7' => $NS7, 'S8' => $S8); } // display standard table header showing attributes function attr_tab_header() { SOURCE PDF PAGE 177 print "DSP"; print "OPTIC"; print "MWAVE"; print "NTWRK"; print "SATEL"; print "PRFM"; print "CHRT"; } // display standard table header showing solutions function solu_tab_header() { print "D1"; print "O2"; print "OM3"; print "M4"; print "NM5"; print "N6"; print "NS7"; print "S8"; } // display INT vector function show_interest($i) { print "" . $i['DSP'] . ""; print "" . $i['OPTIC'] . ""; print "" . $i['MWAVE'] . ""; print "" . $i['NTWRK'] . ""; print "" . $i['SATEL'] . ""; print "" . $i['PRFM'] . ""; print "" . $i['CHRT'] . ""; } SOURCE PDF PAGE 178 // display solutions in table function show_solution($s, $mode = "") { if (strlen($mode) > 0) { printf("%2.3f", $s['D1']); printf("%2.3f", $s['O2']); printf("%2.3f", $s['OM3']); printf("%2.3f", $s['M4']); printf("%2.3f", $s['NM5']); printf("%2.3f", $s['N6']); printf("%2.3f", $s['NS7']); printf("%2.3f", $s['S8']); } else { print "" . $s['D1'] . ""; print "" . $s['O2'] . ""; print "" . $s['OM3']. ""; print "" . $s['M4'] . ""; print "" . $s['NM5'] . ""; print "" . $s['N6']. ""; print "" . $s['NS7'] . ""; print "" . $s['S8']. ""; } } // initialize solution vectors function init_solu() { return array('D1' => 0, 'O2' => 0, 'OM3' => 0, 'M4' => 0, 'NM5' => 0, 'N6' => 0, 'NS7' => 0, 'S8' => 0); } // initialize advice vector SOURCE PDF PAGE 179 function init_advice() { return array( 'COUNT' => init_solu(), 'RANK_PCENT' => init_solu(), 'WEIGHT_SUM' => init_solu()); } // show ranked cases in table function process_ranked_cases($match) { print ""; attr_tab_header(); print ""; print ""; solu_tab_header(); print ""; $advice = init_advice(); for ($i=1; $i<=RANK_NUM; $i++) { print ""; show_interest($match[$i]); print ""; printf("", $match[$i]['percent']*100); show_solution($match[$i]); print ""; foreach ($advice['RANK_PCENT'] as $course => $rank_percentage) { // if this course is recommended, ie solution vector shows 1 if ($match[$i][$course] > 0) { $advice['COUNT'][$course]++; $advice['WEIGHT_SUM'][$course] += (2/75 + (RANK_NUM- $i+1)/75) * 100; if ($match[$i]['percent'] > $rank_percentage) { SOURCE PDF PAGE 180 $advice['RANK_PCENT'][$course] = $match[$i]['percent'] * 100; } } } } print "
casepercent
" . $match[$i]['id'] . "%2.3f

"; return $advice; } // show advice in table format function show_advice_table($advice, $prerequisites, $difficulties) { print ""; print ""; print ""; solu_tab_header(); print ""; print ""; print ""; show_solution($prerequisites); print ""; print ""; print ""; show_solution($difficulties); print ""; print ""; print ""; show_solution($advice['COUNT']); print ""; print ""; SOURCE PDF PAGE 181 print ""; show_solution($advice['RANK_PCENT'], "f"); print ""; print ""; print ""; show_solution($advice['WEIGHT_SUM'], "f"); print ""; print "
Description
Prequisite
Difficulty
Count
Ranked Percentage
Weighted Sum according to Counts

"; } // give out advice in plain English function give_advice($advice, $prerequisites, $difficulties, $performance) { $ordinal = 0; foreach ($advice['RANK_PCENT'] as $course => $rank_percentage) { $relevance = $advice['WEIGHT_SUM'][$course]; if ($prerequisites[$course] == 0) { $colour = "red"; $reason = "
This course is not available because its pre-requisites have not been fulfilled."; } elseif ($difficulties[$course] > $performance) { $colour = "orange"; $reason = "
This course is not recommended because its perceived difficulty is greater than the student's demonstrated academic performance."; } elseif ($ordinal < ENROL_COURSE_NUM) { $colour = "green"; $ordinal++; $reason = "
This is recommended as the choice # $ordinal."; } else { $colour = "blue"; $reason = ""; SOURCE PDF PAGE 182 } if ($rank_percentage > 0) { printf("

The course $course has a rating of %2.3f%% (matched with cases in the past) and a subrating of %2.3f%% (based on frequency of occurrances in ranked cases). %s", $rank_percentage, $relevance, $reason); } } } ?> Index.php CBR

Number of Different INT permutations out of 60 (5P3)

$value) { print "knowledge $value
"; } print "

Problem

\n"; print "
"; print "\n"; print "\n"; attr_tab_header(); SOURCE PDF PAGE 183 print "\n"; print "\n"; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; // display a list of predefined test cases in table $lines = file ('http://www.tanat.net/cbr/problems.txt'); foreach ($lines as $line_num => $line) { $problem = build_case(); list($problem['DSP'], $problem['OPTIC'],$problem['MWAVE'],$problem['NTWRK'],$problem['SATEL'],$problem['P RFM'],$problem['CHRT'])=explode("\t",$line); print "\n"; $query_str = "DSP=".$problem['DSP']."&OPTIC=".$problem['OPTIC']."&MWAVE=".$problem['MWAVE']. "&NTWRK=".$problem['NTWRK']."&SATEL=".$problem['SATEL']."&PRFM=".$problem['P RFM']."&CHRT=".$problem['CHRT']; $problem_id = strval($line_num+1); SOURCE PDF PAGE 184 ?> $value) { print ""; } print "\n"; } print "
idknowledge15knowledge20knowledge47
$problem_id - $value
\n"; print "
\n"; include("append.inc"); ?> SOURCE PDF PAGE 185 Knowledge.php Knowledge $knowledge_size"; $query = "SELECT * FROM knowledge$knowledge_size"; $result = mysql_query($query) or die ("Query failed"); print "\n"; print "\n"; attr_tab_header(); solu_tab_header(); print "\n"; while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { print "\n"; print "\n"; show_interest($row); show_solution($row); $case = build_case($row['DSP'], $row['OPTIC'], $row['MWAVE'], $row['NTWRK'], $row['SATEL'], $row['PRFM'], $row['CHRT']); printf ("\n",case_size($case)); print "\n"; } print "
idcase size
" . $row['id'] . "%2.3f

\n"; include("append.inc"); ?> SOURCE PDF PAGE 186 Match.php Problem (using Knowledge $knowledge_size)"; print ""; print ""; attr_tab_header(); print ""; print ""; // create a problem vector $problem = build_case($_GET['DSP'],$_GET['OPTIC'],$_GET['MWAVE'],$_GET['NTWRK'],$_GET['SA TEL'],$_GET['PRFM'],$_GET['CHRT']); print ""; show_interest($problem); printf ("",case_size($problem)); print ""; print "
problem size
%2.3f

"; /***************************************Correlaton & Diff of Means *****************************************/ for ($i=1; $i<=RANK_NUM; $i++) { $match[$i] = array('id'=>"0",'percent'=>0,'DSP'=>"0",'OPTIC'=>"0",'MWAVE'=>"0",'NTWRK'=>"0",'SATE L'=>"0",'PRFM'=>"0",'CHRT'=>"0",'D1'=>"0",'O2'=>"0",'OM3'=>"0",'M4'=>"0",'NM5'=>"0",' N6'=>"0",'NS7'=>"0",'S8'=>"0"); SOURCE PDF PAGE 187 } $query = "SELECT * FROM knowledge$knowledge_size"; $result = mysql_query($query) or die ("Query failed"); while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $case = build_case($row['DSP'], $row['OPTIC'], $row['MWAVE'], $row['NTWRK'], $row['SATEL'], $row['PRFM'], $row['CHRT']); $case_int = array_slice($case, 0, 5); $case_char = array_slice($case, 5); $problem_int = array_slice($problem, 0, 5); $problem_char = array_slice($problem, 5); $mean = $problem_char; foreach ($case_char as $key => $value) { $mean[$key] = ($value + $problem_char[$key]) / 2; } $diff = $problem_char; foreach ($problem_char as $key => $value) { $diff[$key] = $value - $mean[$key]; } // calculate matching percentage, using vector product divided by the product of both case sizes. Assign a weight of 5 out of 7 $match_percent = sumproduct($problem_int, $case_int) / case_size($problem_int) / case_size($case_int) * 5/7; $match_percent += (1- pow(case_size($diff) / case_size($problem_char), 2)) * 2/7; for ($j=1; $j<=RANK_NUM; $j++) { if ($match_percent > $match[$j]['percent']) { SOURCE PDF PAGE 188 found_new_solution($match, $j, $row['id'], $match_percent, $row['DSP'], $row['OPTIC'], $row['MWAVE'], $row['NTWRK'], $row['SATEL'], $row['PRFM'], $row['CHRT'], $row['D1'], $row['O2'], $row['OM3'], $row['M4'], $row['NM5'], $row['N6'], $row['NS7'], $row['S8']); break; } } } $difficulty = array('D1' => 1, 'O2' => 2, 'OM3' => 1, 'M4' => 3, 'NM5' => 2, 'N6' => 3, 'NS7' => 1,'S8'=>2); $prereq = array('D1' => 1, 'O2' => 1, 'OM3' => 0, 'M4' => 1, 'NM5' => 0, 'N6' => 1, 'NS7' => 0, 'S8' => 1); print "

Correlation of Interests (INT) and Difference of Means


"; $advice1 = process_ranked_cases($match); /***************************************distance of 2 vectors *****************************************/ for ($i=1; $i<=RANK_NUM; $i++) { $match[$i] = array('id'=>"0",'percent'=>0,'DSP'=>"0",'OPTIC'=>"0",'MWAVE'=>"0",'NTWRK'=>"0",'SATE L'=>"0",'PRFM'=>"0",'CHRT'=>"0",'D1'=>"0",'O2'=>"0",'OM3'=>"0",'M4'=>"0",'NM5'=>"0",' N6'=>"0",'NS7'=>"0",'S8'=>"0"); } $query = "SELECT * FROM knowledge$knowledge_size"; $result = mysql_query($query) or die ("Query failed"); while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { SOURCE PDF PAGE 189 $case = build_case($row['DSP'], $row['OPTIC'], $row['MWAVE'], $row['NTWRK'], $row['SATEL'], $row['PRFM'], $row['CHRT']); $diff = build_case(); foreach ($case as $key => $value) { $diff[$key] = $value - $problem[$key]; } // calculate matching percentage, the further the distance from the knowledge vector, the lower the matching percentage would be. $match_percent = 1- pow(case_size($diff) / case_size($problem), 2); for ($j=1; $j<=RANK_NUM; $j++) { if ($match_percent > $match[$j]['percent']) { found_new_solution($match, $j, $row['id'], $match_percent, $row['DSP'], $row['OPTIC'], $row['MWAVE'], $row['NTWRK'], $row['SATEL'], $row['PRFM'], $row['CHRT'], $row['D1'], $row['O2'], $row['OM3'], $row['M4'], $row['NM5'], $row['N6'], $row['NS7'], $row['S8']); break; } } } print "

Distance of 2 vectors


"; $advice2 = process_ranked_cases($match); /***************************************trivial IR *****************************************/ for ($i=1; $i<=RANK_NUM; $i++) { SOURCE PDF PAGE 190 $match[$i] = array('id'=>"0",'percent'=>0,'DSP'=>"0",'OPTIC'=>"0",'MWAVE'=>"0",'NTWRK'=>"0",'SATE L'=>"0",'PRFM'=>"0",'CHRT'=>"0",'D1'=>"0",'O2'=>"0",'OM3'=>"0",'M4'=>"0",'NM5'=>"0",' N6'=>"0",'NS7'=>"0",'S8'=>"0"); } $query = "SELECT * FROM knowledge$knowledge_size"; $result = mysql_query($query) or die ("Query failed"); while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $case = build_case($row['DSP'], $row['OPTIC'], $row['MWAVE'], $row['NTWRK'], $row['SATEL'], $row['PRFM'], $row['CHRT']); // matching percentage is calculated purely using trivial IR algorithm $match_percent = sumproduct($problem,$case) / case_size($problem) / case_size($case); for ($j=1; $j<=RANK_NUM; $j++) { if ($match_percent > $match[$j]['percent']) { found_new_solution($match, $j, $row['id'], $match_percent, $row['DSP'], $row['OPTIC'], $row['MWAVE'], $row['NTWRK'], $row['SATEL'], $row['PRFM'], $row['CHRT'], $row['D1'], $row['O2'], $row['OM3'], $row['M4'], $row['NM5'], $row['N6'], $row['NS7'], $row['S8']); break; } } } print "

Trivial IR algorithm


"; $advice3 = process_ranked_cases($match); /*******************************************************/ print "

Problem

"; SOURCE PDF PAGE 191 print ""; attr_tab_header(); print ""; print ""; show_interest($problem); print ""; print "

"; print "

Advice Table

"; print "

Correlation of Interests (INT) and Difference of Means


"; show_advice_table($advice1, $prereq, $difficulty); print "

Distance of 2 vectors


"; show_advice_table($advice2, $prereq, $difficulty); print "

Trivial IR algorithm


"; show_advice_table($advice3, $prereq, $difficulty); array_multisort( $advice1['RANK_PCENT'], SORT_NUMERIC, SORT_DESC,$advice3['WEIGHT_SUM'],SORT_NUMERIC, SORT_DESC); array_multisort( $advice2['RANK_PCENT'], SORT_NUMERIC, SORT_DESC,$advice3['WEIGHT_SUM'],SORT_NUMERIC, SORT_DESC); array_multisort( $advice3['RANK_PCENT'], SORT_NUMERIC, SORT_DESC,$advice3['WEIGHT_SUM'],SORT_NUMERIC, SORT_DESC); /*******************************************************/ print "

Problem

"; print ""; attr_tab_header(); print ""; print ""; show_interest($problem); SOURCE PDF PAGE 192 print ""; print "

"; print "

Advice with Reasons

"; print "

RED denotes courses that are blocked due to its unfulfilled pre-requisites
"; print "ORANGE denotes courses that are not recommended due to its perceived difficulty being greater than the student's demonstrated academic performance
"; print "GREEN denotes the recommended course with a ranked order
"; print "BLUE denotes other possible courses student may consider taking

"; print "

Correlation of Interests (INT) and Difference of Means


"; give_advice($advice1, $prereq, $difficulty, $problem['PRFM']); print "

Distance of 2 vectors


"; give_advice($advice2, $prereq, $difficulty, $problem['PRFM']); print "

Trivial IR algorithm


"; give_advice($advice3, $prereq, $difficulty, $problem['PRFM']); include("append.inc"); ?>