| 
									
										
										
										
											2012-12-12 15:16:30 +00:00
										 |  |  | /* Learn distribution for school database. */ | 
					
						
							| 
									
										
										
										
											2009-02-16 12:23:29 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-12 15:16:30 +00:00
										 |  |  | /* We do not consider aggregates yet.      */ | 
					
						
							| 
									
										
										
										
											2009-02-16 12:23:29 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | :- [pos:train]. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-13 19:00:28 +00:00
										 |  |  | :- ['../../examples/School/school_32']. | 
					
						
							| 
									
										
										
										
											2009-02-16 12:23:29 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-11 00:16:56 +00:00
										 |  |  | :- use_module(library(clpbn/learning/em)). | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-10 23:04:17 +00:00
										 |  |  | %:- set_em_solver(ve). | 
					
						
							| 
									
										
										
										
											2012-12-17 21:19:47 +00:00
										 |  |  | %:- set_em_solver(hve). | 
					
						
							|  |  |  | %:- set_em_solver(bdd). | 
					
						
							|  |  |  | %:- set_em_solver(bp). | 
					
						
							|  |  |  | %:- set_em_solver(cbp). | 
					
						
							| 
									
										
										
										
											2009-10-21 00:05:23 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | timed_main :- | 
					
						
							|  |  |  | 	statistics(runtime, _), | 
					
						
							| 
									
										
										
										
											2013-01-11 00:16:56 +00:00
										 |  |  | 	findall(X, goal(X), L), | 
					
						
							|  |  |  | 	em(L, 0.01, 10, _, Lik), | 
					
						
							| 
									
										
										
										
											2009-10-21 00:05:23 +01:00
										 |  |  | 	statistics(runtime, [T,_]), | 
					
						
							|  |  |  | 	format('Took ~d msec and Lik ~3f~n',[T,Lik]). | 
					
						
							| 
									
										
										
										
											2009-02-16 12:23:29 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | main :- | 
					
						
							| 
									
										
										
										
											2012-12-12 15:16:30 +00:00
										 |  |  | 	findall(X,goal(X),L), | 
					
						
							| 
									
										
										
										
											2013-01-11 00:16:56 +00:00
										 |  |  | 	em(L, 0.01, 10, CPTs, Lik), | 
					
						
							| 
									
										
										
										
											2012-12-12 15:16:30 +00:00
										 |  |  | 	writeln(Lik:CPTs). | 
					
						
							| 
									
										
										
										
											2009-02-16 12:23:29 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | % | 
					
						
							| 
									
										
										
										
											2012-12-12 15:36:38 +00:00
										 |  |  | % Change to 0.0, 0.1, 0.2 to make things simpler/harder | 
					
						
							| 
									
										
										
										
											2012-12-12 16:28:18 +00:00
										 |  |  | % | 
					
						
							| 
									
										
										
										
											2012-08-15 16:01:45 -05:00
										 |  |  | missing(0.2). | 
					
						
							| 
									
										
										
										
											2009-02-16 12:23:29 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | goal(professor_ability(P,V)) :- | 
					
						
							| 
									
										
										
										
											2012-12-12 15:16:30 +00:00
										 |  |  | 	pos:professor_ability(P,V1), | 
					
						
							| 
									
										
										
										
											2009-02-16 12:23:29 +00:00
										 |  |  | 	missing(X), | 
					
						
							| 
									
										
										
										
											2012-12-12 15:16:30 +00:00
										 |  |  | 	( random > X -> V = V1 ; true). | 
					
						
							| 
									
										
										
										
											2012-12-12 15:36:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-02-16 12:23:29 +00:00
										 |  |  | goal(professor_popularity(P,V)) :- | 
					
						
							| 
									
										
										
										
											2012-12-12 15:16:30 +00:00
										 |  |  | 	pos:professor_popularity(P,V1), | 
					
						
							| 
									
										
										
										
											2009-02-16 12:23:29 +00:00
										 |  |  | 	missing(X), | 
					
						
							| 
									
										
										
										
											2012-12-12 15:16:30 +00:00
										 |  |  | 	( random > X -> V = V1 ; true). | 
					
						
							| 
									
										
										
										
											2012-12-12 15:36:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-02-16 12:23:29 +00:00
										 |  |  | goal(registration_grade(P,V)) :- | 
					
						
							| 
									
										
										
										
											2012-12-12 15:16:30 +00:00
										 |  |  | 	pos:registration_grade(P,V1), | 
					
						
							| 
									
										
										
										
											2009-02-16 12:23:29 +00:00
										 |  |  | 	missing(X), | 
					
						
							| 
									
										
										
										
											2012-12-12 15:16:30 +00:00
										 |  |  | 	( random > X -> V = V1 ; true). | 
					
						
							| 
									
										
										
										
											2012-12-12 15:36:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-02-16 12:23:29 +00:00
										 |  |  | goal(student_intelligence(P,V)) :- | 
					
						
							| 
									
										
										
										
											2012-12-12 15:16:30 +00:00
										 |  |  | 	pos:student_intelligence(P,V1), | 
					
						
							| 
									
										
										
										
											2009-02-16 12:23:29 +00:00
										 |  |  | 	missing(X), | 
					
						
							| 
									
										
										
										
											2012-12-12 15:16:30 +00:00
										 |  |  | 	( random > X -> V = V1 ; true). | 
					
						
							| 
									
										
										
										
											2012-12-12 15:36:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-02-16 12:23:29 +00:00
										 |  |  | goal(course_difficulty(P,V)) :- | 
					
						
							| 
									
										
										
										
											2012-12-12 15:16:30 +00:00
										 |  |  | 	pos:course_difficulty(P,V1), | 
					
						
							| 
									
										
										
										
											2009-02-16 12:23:29 +00:00
										 |  |  | 	missing(X), | 
					
						
							| 
									
										
										
										
											2012-12-12 15:16:30 +00:00
										 |  |  | 	( random > X -> V = V1 ; true). | 
					
						
							| 
									
										
										
										
											2012-12-12 15:36:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-02-16 12:23:29 +00:00
										 |  |  | goal(registration_satisfaction(P,V)) :- | 
					
						
							| 
									
										
										
										
											2012-12-12 15:16:30 +00:00
										 |  |  | 	pos:registration_satisfaction(P,V1), | 
					
						
							| 
									
										
										
										
											2009-02-16 12:23:29 +00:00
										 |  |  | 	missing(X), | 
					
						
							| 
									
										
										
										
											2012-12-12 15:16:30 +00:00
										 |  |  | 	( random > X -> V = V1 ; true). | 
					
						
							|  |  |  | 
 |