Closed HarryLynas closed 10 years ago
A copy of the full source code I am using can be found below:
package dk.bayes.infer
import org.junit._
import Assert._
import dk.bayes.model.clustergraph.factor._
import dk.bayes.model.clustergraph.GenericClusterGraph
import dk.bayes.testutil.AssertUtil._
class BayTesting_MediumNetwork {
val loops: Int = 1000
var loopyBP: LoopyBP = _
var clusterGraph: GenericClusterGraph = _
var alcoholism: Var = _
var alcoholismFac: Factor = _
var vh_amn: Var = _
var vh_amnFac: Factor = _
var hepatotoxic: Var = _
var hepatotoxicFac: Factor = _
var THepatitis: Var = _
var THepatitisFac: Factor = _
var hospital: Var = _
var hospitalFac: Factor = _
var surgery: Var = _
var surgeryFac: Factor = _
var gallstones: Var = _
var gallstonesFac: Factor = _
var choledocholithotomy: Var = _
var choledocholithotomyFac: Factor = _
var injections: Var = _
var injectionsFac: Factor = _
var transfusion: Var = _
var transfusionFac: Factor = _
var ChHepatitis: Var = _
var ChHepatitisFac: Factor = _
var sex: Var = _
var sexFac: Factor = _
var age: Var = _
var ageFac: Factor = _
var PBC: Var = _
var PBCFac: Factor = _
var fibrosis: Var = _
var fibrosisFac: Factor = _
var diabetes: Var = _
var diabetesFac: Factor = _
var obesity: Var = _
var obesityFac: Factor = _
var Steatosis: Var = _
var SteatosisFac: Factor = _
var Cirrhosis: Var = _
var CirrhosisFac: Factor = _
var Hyperbilirubinemia: Var = _
var HyperbilirubinemiaFac: Factor = _
var triglycerides: Var = _
var triglyceridesFac: Factor = _
var RHepatitis: Var = _
var RHepatitisFac: Factor = _
var fatigue: Var = _
var fatigueFac: Factor = _
var bilirubin: Var = _
var bilirubinFac: Factor = _
var itching: Var = _
var itchingFac: Factor = _
var upper_pain: Var = _
var upper_painFac: Factor = _
var fat: Var = _
var fatFac: Factor = _
var pain_ruq: Var = _
var pain_ruqFac: Factor = _
var pressure_ruq: Var = _
var pressure_ruqFac: Factor = _
var phosphatase: Var = _
var phosphataseFac: Factor = _
var skin: Var = _
var skinFac: Factor = _
var ama: Var = _
var amaFac: Factor = _
var le_cells: Var = _
var le_cellsFac: Factor = _
var joints: Var = _
var jointsFac: Factor = _
var pain: Var = _
var painFac: Factor = _
var proteins: Var = _
var proteinsFac: Factor = _
var edema: Var = _
var edemaFac: Factor = _
var platelet: Var = _
var plateletFac: Factor = _
var inr: Var = _
var inrFac: Factor = _
var bleeding: Var = _
var bleedingFac: Factor = _
var flatulence: Var = _
var flatulenceFac: Factor = _
var alcohol: Var = _
var alcoholFac: Factor = _
var encephalopathy: Var = _
var encephalopathyFac: Factor = _
var urea: Var = _
var ureaFac: Factor = _
var ascites: Var = _
var ascitesFac: Factor = _
var hepatomegaly: Var = _
var hepatomegalyFac: Factor = _
var hepatalgia: Var = _
var hepatalgiaFac: Factor = _
var density: Var = _
var densityFac: Factor = _
var ESR: Var = _
var ESRFac: Factor = _
var alt: Var = _
var altFac: Factor = _
var ast: Var = _
var astFac: Factor = _
var amylase: Var = _
var amylaseFac: Factor = _
var ggtp: Var = _
var ggtpFac: Factor = _
var cholesterol: Var = _
var cholesterolFac: Factor = _
var hbsag: Var = _
var hbsagFac: Factor = _
var hbsag_anti: Var = _
var hbsag_antiFac: Factor = _
var anorexia: Var = _
var anorexiaFac: Factor = _
var nausea: Var = _
var nauseaFac: Factor = _
var spleen: Var = _
var spleenFac: Factor = _
var consciousness: Var = _
var consciousnessFac: Factor = _
var spiders: Var = _
var spidersFac: Factor = _
var jaundice: Var = _
var jaundiceFac: Factor = _
var albumin: Var = _
var albuminFac: Factor = _
var edge: Var = _
var edgeFac: Factor = _
var irregular_liver: Var = _
var irregular_liverFac: Factor = _
var hbc_anti: Var = _
var hbc_antiFac: Factor = _
var hcv_anti: Var = _
var hcv_antiFac: Factor = _
var palms: Var = _
var palmsFac: Factor = _
var hbeag: Var = _
var hbeagFac: Factor = _
var carcinoma: Var = _
var carcinomaFac: Factor = _
/*@Before*/ def loadNetwork() {
//Create variables
alcoholism = Var(1, 2)
vh_amn = Var(2, 2)
hepatotoxic = Var(3, 2)
THepatitis = Var(4, 2)
hospital = Var(5, 2)
surgery = Var(6, 2)
gallstones = Var(7, 2)
choledocholithotomy = Var(8, 2)
injections = Var(9, 2)
transfusion = Var(10, 2)
ChHepatitis = Var(11, 3)
sex = Var(12, 2)
age = Var(13, 4)
PBC = Var(14, 2)
fibrosis = Var(15, 2)
diabetes = Var(16, 2)
obesity = Var(17, 2)
Steatosis = Var(18, 2)
Cirrhosis = Var(19, 3)
Hyperbilirubinemia = Var(20, 2)
triglycerides = Var(21, 3)
RHepatitis = Var(22, 2)
fatigue = Var(23, 2)
bilirubin = Var(24, 4)
itching = Var(25, 2)
upper_pain = Var(26, 2)
fat = Var(27, 2)
pain_ruq = Var(28, 2)
pressure_ruq = Var(29, 2)
phosphatase = Var(30, 3)
skin = Var(31, 2)
ama = Var(32, 2)
le_cells = Var(33, 2)
joints = Var(34, 2)
pain = Var(35, 2)
proteins = Var(36, 2)
edema = Var(37, 2)
platelet = Var(38, 4)
inr = Var(39, 3)
bleeding = Var(40, 2)
flatulence = Var(41, 2)
alcohol = Var(42, 2)
encephalopathy = Var(43, 2)
urea = Var(44, 3)
ascites = Var(45, 2)
hepatomegaly = Var(46, 2)
hepatalgia = Var(47, 2)
density = Var(48, 2)
ESR = Var(49, 3)
alt = Var(50, 4)
ast = Var(51, 4)
amylase = Var(52, 3)
ggtp = Var(53, 4)
cholesterol = Var(54, 3)
hbsag = Var(55, 2)
hbsag_anti = Var(56, 2)
anorexia = Var(57, 2)
nausea = Var(58, 2)
spleen = Var(59, 2)
consciousness = Var(60, 2)
spiders = Var(61, 2)
jaundice = Var(62, 2)
albumin = Var(63, 3)
edge = Var(64, 2)
irregular_liver = Var(65, 2)
hbc_anti = Var(66, 2)
hcv_anti = Var(67, 2)
palms = Var(68, 2)
hbeag = Var(69, 2)
carcinoma = Var(70, 2)
//Create Factors
alcoholismFac = Factor(Array(alcoholism), Array(0.13590844, 0.86409156))
vh_amnFac = Factor(Array(vh_amn), Array(0.17310443, 0.82689557))
hepatotoxicFac = Factor(Array(hepatotoxic), Array(0.08154506, 0.91845494))
THepatitisFac = Factor(Array(hepatotoxic, alcoholism, THepatitis), Array(0.0326087, 0.9673913, 0.08888889, 0.91111111, 0.00191939, 0.99808061, 0.2, 0.8))
hospitalFac = Factor(Array(hospital), Array(0.53505007, 0.46494993))
surgeryFac = Factor(Array(surgery), Array(0.42346209, 0.57653791))
gallstonesFac = Factor(Array(gallstones), Array(0.15307582, 0.84692418))
choledocholithotomyFac = Factor(Array(gallstones, choledocholithotomy), Array(0.03716216, 0.96283784, 0.71028037, 0.28971963))
injectionsFac = Factor(Array(hospital, surgery, choledocholithotomy, injections), Array(0.0647482, 0.9352518, 0.01098901, 0.98901099, 0.23333333, 0.76666667, 0.375, 0.625, 0.48181818, 0.51818182, 0.83333333, 0.16666667, 0.71584699, 0.28415301, 0.8, 0.2))
transfusionFac = Factor(Array(hospital, surgery, choledocholithotomy, transfusion), Array(0.01079137, 0.98920863, 0.01098901, 0.98901099, 0.3, 0.7, 0.125, 0.875, 0.11818182, 0.88181818, 0.16666667, 0.83333333, 0.28961749, 0.71038251, 0.33333333, 0.66666667))
updateValuesSmall(Array(transfusion, ChHepatitis, injections, vh_amn), Array(0.13095238, 0.05357143, 0.07692308, 0.00591716, 0.24, 0.14, 0.15384615, 0.05128205, 0.13043478, 0.04347826, 0.06, 0.06, 0.46153846, 0.30769231, 0.20942408, 0.0052356))
ChHepatitisFac = Factor(Array(transfusion, ChHepatitis, injections, vh_amn), Array(0.13095238, 0.05357143, 0.07692308, 0.00591716, 0.24, 0.14, 0.15384615, 0.05128205, 0.13043478, 0.04347826, 0.06, 0.06, 0.46153846, 0.30769231, 0.20942408, 0.0052356))
sexFac = Factor(Array(sex), Array(0.59799714, 0.40200286))
ageFac = Factor(Array(age), Array(0.07725322, 0.38769671))
PBCFac = Factor(Array(sex, age, PBC), Array(0.00156006, 0.99843994, 0.06730769, 0.93269231, 0.08510638, 0.91489362, 0.36842105, 0.63157895, 0.125, 0.875, 0.61494253, 0.38505747, 0.70056497, 0.29943503, 0.65714286, 0.34285714))
fibrosisFac = Factor(Array(ChHepatitis, fibrosis), Array(0.001, 0.999, 0.05, 0.95, 0.3, 0.7))
diabetesFac = Factor(Array(diabetes), Array(0.03576538, 0.96423462))
obesityFac = Factor(Array(diabetes, obesity), Array(0.06231454, 0.93768546, 0.24, 0.76))
SteatosisFac = Factor(Array(obesity, alcoholism, Steatosis), Array(0.06349206, 0.93650794, 0.23809524, 0.76190476, 0.18918919, 0.81081081, 0.36363636, 0.63636364))
CirrhosisFac = Factor(Array(fibrosis, Steatosis, Cirrhosis), Array(0.001, 0.001, 0.35, 0.15, 0.49, 0.21, 0.56, 0.24))
HyperbilirubinemiaFac = Factor(Array(age, sex, Hyperbilirubinemia), Array(0.453125, 0.546875, 0.21875, 0.78125, 0.07692308, 0.92307692, 0.04597701, 0.95402299, 0.0212766, 0.9787234, 0.01129944, 0.98870056, 0.0052356, 0.9947644, 0.002849, 0.997151))
triglyceridesFac = Factor(Array(Steatosis, triglycerides), Array(0.02373418, 0.03164557, 0.17910448, 0.1641791))
RHepatitisFac = Factor(Array(hepatotoxic, RHepatitis), Array(0.02492212, 0.97507788, 0.01754386, 0.98245614))
fatigueFac = Factor(Array(ChHepatitis, THepatitis, RHepatitis, fatigue), Array(0.53598485, 0.46401515, 0.70588235, 0.29411765, 0.66666667, 0.33333333, 0.61538462, 0.38461538, 0.52777778, 0.47222222, 0.58928571, 0.41071429, 0.59322034, 0.40677966, 0.60714286, 0.39285714, 0.6043956, 0.3956044, 0.62365591, 0.37634409, 0.625, 0.375, 0.63636364, 0.36363636))
bilirubinFac = Factor(Array(Hyperbilirubinemia, PBC, Cirrhosis, gallstones, ChHepatitis, bilirubin), Array(7.0872E-4, 0.02126152, 0.00284091, 0.00284091, 0.01234568, 0.02469136, 0.01587302, 0.01587302, 0.07692308, 0.07692308, 0.00980392, 0.00980392, 0.03448276, 0.03448276, 0.01694915, 0.01694915, 0.01818182, 0.01818182, 0.04545455, 0.04545455, 0.00621118, 0.0621118, 0.00321543, 0.09646302, 0.01886792, 0.13207547, 0.01282051, 0.07692308, 0.01449275, 0.07246377, 0.01923077, 0.19230769, 0.01818182, 0.16363636, 0.02830189, 0.16037736, 0.03030303, 0.16666667, 0.02926829, 0.14634146, 0.03910615, 0.15083799, 0.08536585, 0.24390244, 0.05555556, 0.19444444, 0.04477612, 0.1641791, 0.02824859, 0.14124294, 0.0234375, 0.1328125, 0.032, 0.136, 0.07042254, 0.22535211, 0.05084746, 0.20338983, 0.04255319, 0.17021277, 0.02590674, 0.15025907, 0.02173913, 0.13768116, 0.03030303, 0.14393939, 0.07692308, 0.23076923, 0.06818182, 0.20454545, 0.04081633, 0.14285714, 0.00181159, 0.00181159, 0.00127877, 0.00127877, 0.00146843, 0.01468429, 0.07692308, 0.07692308, 0.0049505, 0.0049505, 0.00255102, 0.00255102, 0.00144509, 0.00144509, 0.00174825, 0.00174825, 0.00178253, 0.01782531, 0.01388889, 0.01388889, 0.00892857, 0.00892857, 0.00311526, 0.03115265, 0.00114811, 0.05740528, 0.00144718, 0.04341534, 0.00151286, 0.04538578, 0.00662252, 0.13245033, 0.00398406, 0.11952191, 0.01449275, 0.11594203, 0.02061856, 0.12371134, 0.02158273, 0.11510791, 0.03030303, 0.12121212, 0.07575758, 0.22727273, 0.06, 0.2, 0.04225352, 0.15492958, 0.02362205, 0.11811024, 0.01941748, 0.10679612, 0.02020202, 0.11111111, 0.07692308, 0.23076923, 0.05882353, 0.20588235, 0.03571429, 0.16071429, 0.02189781, 0.12408759, 0.01818182, 0.11818182, 0.01923077, 0.11538462, 0.07894737, 0.23684211, 0.07407407, 0.22222222, 0.04347826, 0.2173913))
itchingFac = Factor(Array(bilirubin, itching), Array(0.33333333, 0.66666667, 0.54773869, 0.45226131, 0.68656716, 0.31343284, 0.875, 0.125))
upper_painFac = Factor(Array(gallstones, upper_pain), Array(0.38682432, 0.61317568, 0.41121495, 0.58878505))
fatFac = Factor(Array(gallstones, fat), Array(0.28040541, 0.71959459, 0.17757009, 0.82242991))
pain_ruqFac = Factor(Array(Steatosis, Hyperbilirubinemia, pain_ruq), Array(0.421875, 0.578125, 0.28571429, 0.71428571, 0.47761194, 0.52238806, 0.39344262, 0.60655738))
pressure_ruqFac = Factor(Array(gallstones, PBC, ChHepatitis, pressure_ruq), Array(0.45323741, 0.54676259, 0.42857143, 0.57142857, 0.4691358, 0.5308642, 0.29292929, 0.70707071, 0.32275132, 0.67724868, 0.34246575, 0.65753425, 0.28571429, 0.71428571, 0.09090909, 0.90909091, 0.4, 0.6, 0.32926829, 0.67073171, 0.328125, 0.671875, 0.33333333, 0.66666667))
phosphataseFac = Factor(Array(RHepatitis, THepatitis, Cirrhosis, ChHepatitis, phosphatase), Array(0.2118451, 0.33940774, 0.02777778, 0.19444444, 0.03296703, 0.21978022, 0.06451613, 0.38709677, 0.03896104, 0.31168831, 0.04494382, 0.33707865, 0.06896552, 0.48275862, 0.04494382, 0.33707865, 0.04597701, 0.29885057, 0.07407407, 0.14814815, 0.04054054, 0.2027027, 0.04651163, 0.22093023, 0.05357143, 0.26785714, 0.03703704, 0.25925926, 0.04166667, 0.27777778, 0.05555556, 0.34722222, 0.04918033, 0.31147541, 0.04761905, 0.28571429, 0.00584795, 0.23391813, 0.015625, 0.234375, 0.02597403, 0.24675325, 0.02083333, 0.3125, 0.02040816, 0.28571429, 0.02985075, 0.29850746, 0.04545455, 0.37878788, 0.03389831, 0.3220339, 0.02898551, 0.28985507, 0.02325581, 0.18604651, 0.02272727, 0.20454545, 0.03571429, 0.21428571, 0.02702703, 0.27027027, 0.025, 0.25, 0.03773585, 0.26415094, 0.04166667, 0.33333333, 0.04347826, 0.30434783, 0.04166667, 0.29166667))
skinFac = Factor(Array(bilirubin, skin), Array(0.1822542, 0.8177458, 0.70351759, 0.29648241, 0.89552239, 0.10447761, 0.99378882, 0.00621118))
amaFac = Factor(Array(PBC, ama), Array(0.01193317, 0.98806683, 0.56785714, 0.43214286))
le_cellsFac = Factor(Array(PBC, le_cells), Array(0.04057279, 0.95942721, 0.12142857, 0.87857143))
jointsFac = Factor(Array(PBC, joints), Array(0.10023866, 0.89976134, 0.12857143, 0.87142857))
painFac = Factor(Array(PBC, joints, pain), Array(0.18302387, 0.81697613, 0.80952381, 0.19047619, 0.14754098, 0.85245902, 0.38888889, 0.61111111))
proteinsFac = Factor(Array(Cirrhosis, proteins), Array(0.98032787, 0.01967213, 0.99678457, 0.00321543, 0.99827883, 0.00172117))
edemaFac = Factor(Array(Cirrhosis, edema), Array(0.13114754, 0.86885246, 0.06451613, 0.93548387, 0.34482759, 0.65517241))
plateletFac = Factor(Array(Cirrhosis, PBC, platelet), Array(0.09393939, 0.73636364, 0.06428571, 0.67142857, 0.06451613, 0.64516129, 0.06557377, 0.63934426, 0.06896552, 0.46551724, 0.06547619, 0.63690476))
inrFac = Factor(Array(ChHepatitis, Cirrhosis, THepatitis, Hyperbilirubinemia, inr), Array(0.065, 0.875, 0.05357143, 0.89285714, 0.03703704, 0.92592593, 0.03508772, 0.84210526, 0.00321543, 0.67524116, 0.02816901, 0.8028169, 0.01785714, 0.78571429, 0.01785714, 0.76785714, 0.00172117, 0.60240964, 0.02173913, 0.75, 0.01428571, 0.75714286, 0.03448276, 0.81034483, 0.08333333, 0.88888889, 0.05333333, 0.90666667, 0.05, 0.9, 0.05084746, 0.88135593, 0.03333333, 0.83333333, 0.03571429, 0.85714286, 0.04081633, 0.83673469, 0.03508772, 0.8245614, 0.02469136, 0.75308642, 0.02898551, 0.79710145, 0.03225806, 0.79032258, 0.03030303, 0.84848485, 0.02197802, 0.9010989, 0.024, 0.904, 0.01923077, 0.90384615, 0.02197802, 0.89010989, 0.01960784, 0.85294118, 0.02409639, 0.86746988, 0.01333333, 0.86666667, 0.025, 0.85, 0.01666667, 0.8, 0.02150538, 0.8172043, 0.01298701, 0.81818182, 0.01754386, 0.84210526))
bleedingFac = Factor(Array(platelet, inr, bleeding), Array(0.66666667, 0.33333333, 0.25581395, 0.74418605, 0.5, 0.5, 0.25, 0.75, 0.13333333, 0.86666667, 0.2, 0.8, 0.425, 0.575, 0.1373494, 0.8626506, 0.13043478, 0.86956522, 0.09090909, 0.90909091, 0.10638298, 0.89361702, 0.14285714, 0.85714286))
flatulenceFac = Factor(Array(gallstones, flatulence), Array(0.43074324, 0.56925676, 0.39252336, 0.60747664))
alcoholFac = Factor(Array(Cirrhosis, alcohol), Array(0.11147541, 0.88852459, 0.22580645, 0.77419355, 0.20689655, 0.79310345))
encephalopathyFac = Factor(Array(Cirrhosis, PBC, encephalopathy), Array(0.01515152, 0.98484848, 0.05357143, 0.94642857, 0.00321543, 0.99678457, 0.04891304, 0.95108696, 0.05172414, 0.94827586, 0.05325444, 0.94674556))
ureaFac = Factor(Array(encephalopathy, urea), Array(0.03550296, 0.06508876, 0.2173913, 0.13043478))
ascitesFac = Factor(Array(proteins, ascites), Array(0.58333333, 0.41666667, 0.12809316, 0.87190684))
hepatomegalyFac = Factor(Array(RHepatitis, THepatitis, Steatosis, Hyperbilirubinemia, hepatomegaly), Array(0.69736842, 0.30263158, 0.375, 0.625, 0.68656716, 0.31343284, 0.58666667, 0.41333333, 0.77777778, 0.22222222, 0.58974359, 0.41025641, 0.67567568, 0.32432432, 0.6, 0.4, 0.70588235, 0.29411765, 0.55555556, 0.44444444, 0.65277778, 0.34722222, 0.59016393, 0.40983607, 0.67391304, 0.32608696, 0.59183673, 0.40816327, 0.68, 0.32, 0.6097561, 0.3902439))
hepatalgiaFac = Factor(Array(hepatomegaly, hepatalgia), Array(0.03070175, 0.96929825, 0.31422505, 0.68577495))
densityFac = Factor(Array(encephalopathy, density), Array(0.37721893, 0.62278107, 0.73913043, 0.26086957))
ESRFac = Factor(Array(PBC, ChHepatitis, Steatosis, Hyperbilirubinemia, ESR), Array(0.04733728, 0.05325444, 0.01785714, 0.07142857, 0.13432836, 0.05970149, 0.07594937, 0.06329114, 0.05555556, 0.05555556, 0.05434783, 0.07608696, 0.08602151, 0.08602151, 0.06024096, 0.12048193, 0.03296703, 0.21978022, 0.10457516, 0.16339869, 0.175, 0.1625, 0.26829268, 0.17682927, 0.43214286, 0.21071429, 0.36363636, 0.18181818, 0.36298932, 0.17793594, 0.34259259, 0.1712963, 0.368, 0.184, 0.33333333, 0.17204301, 0.3315508, 0.17112299, 0.30939227, 0.17679558, 0.32055749, 0.20557491, 0.29411765, 0.19117647, 0.2972973, 0.18378378, 0.2704918, 0.17213115))
altFac = Factor(Array(ChHepatitis, RHepatitis, THepatitis, Steatosis, Cirrhosis, alt), Array(0.04569892, 0.17473118, 0.03225806, 0.19354839, 0.06896552, 0.12068966, 0.00149031, 0.08941878, 0.01176471, 0.10588235, 0.02666667, 0.09333333, 0.00369004, 0.07380074, 0.01470588, 0.11764706, 0.025, 0.1, 0.00131406, 0.09198423, 0.00172117, 0.10327022, 0.01818182, 0.10909091, 0.00584795, 0.23391813, 0.01724138, 0.15517241, 0.02816901, 0.12676056, 0.00144718, 0.11577424, 0.00178253, 0.12477718, 0.01666667, 0.11666667, 0.0023753, 0.14251781, 0.00249377, 0.14962594, 0.02, 0.12, 0.00191939, 0.11516315, 0.00212314, 0.12738854, 0.02, 0.12, 0.02777778, 0.13888889, 0.02631579, 0.13157895, 0.03409091, 0.11363636, 0.01190476, 0.10714286, 0.01492537, 0.11940299, 0.02777778, 0.11111111, 0.01818182, 0.10909091, 0.02040816, 0.12244898, 0.01724138, 0.10344828, 0.00166389, 0.09983361, 0.00191939, 0.11516315, 0.01724138, 0.12068966, 0.02083333, 0.16666667, 0.02272727, 0.15909091, 0.01886792, 0.13207547, 0.00181488, 0.12704174, 0.002079, 0.12474012, 0.01923077, 0.11538462, 0.00262467, 0.1312336, 0.00269542, 0.13477089, 0.02272727, 0.11363636, 0.0021692, 0.10845987, 0.02173913, 0.13043478, 0.05172414, 0.15517241, 0.12087912, 0.23076923, 0.08661417, 0.19685039, 0.08148148, 0.17777778, 0.064, 0.168, 0.0625, 0.16666667, 0.06862745, 0.16666667, 0.08333333, 0.1875, 0.07792208, 0.18181818, 0.06976744, 0.1627907, 0.05882353, 0.15294118, 0.05479452, 0.16438356, 0.0617284, 0.17283951, 0.08988764, 0.2247191, 0.08333333, 0.20833333, 0.075, 0.1875, 0.0625, 0.175, 0.05882353, 0.17647059, 0.06849315, 0.16438356, 0.07936508, 0.19047619, 0.07017544, 0.19298246, 0.06451613, 0.17741935, 0.04761905, 0.15873016, 0.05454545, 0.16363636, 0.05882353, 0.15686275))
astFac = Factor(Array(ChHepatitis, RHepatitis, THepatitis, Steatosis, Cirrhosis, ast), Array(0.01075269, 0.22580645, 0.03225806, 0.06451613, 0.01724138, 0.13793103, 0.00149031, 0.07451565, 0.00116144, 0.08130081, 0.00133156, 0.09320905, 0.00369004, 0.07380074, 0.00149031, 0.07451565, 0.00126422, 0.08849558, 0.00133156, 0.0665779, 0.00172117, 0.06884682, 0.00181488, 0.0907441, 0.00584795, 0.11695906, 0.00172117, 0.10327022, 0.00140647, 0.11251758, 0.00142653, 0.08559201, 0.00175131, 0.08756567, 0.00166389, 0.09983361, 0.00243309, 0.0729927, 0.00249377, 0.07481297, 0.00199601, 0.0998004, 0.00191939, 0.07677543, 0.00212314, 0.08492569, 0.00199601, 0.0998004, 0.02777778, 0.11111111, 0.01315789, 0.09210526, 0.01136364, 0.10227273, 0.00120337, 0.08423586, 0.00149031, 0.08941878, 0.00142653, 0.09985735, 0.00181488, 0.0907441, 0.00203666, 0.0814664, 0.00172117, 0.10327022, 0.00166389, 0.08319468, 0.00191939, 0.07677543, 0.00172117, 0.10327022, 0.00212314, 0.10615711, 0.00226757, 0.09070295, 0.00184843, 0.11090573, 0.00181488, 0.0907441, 0.00203666, 0.0814664, 0.00191939, 0.09596929, 0.00269542, 0.08086253, 0.00269542, 0.08086253, 0.00221729, 0.11086475, 0.00212314, 0.08492569, 0.00221729, 0.0886918, 0.01754386, 0.14035088, 0.05494505, 0.23076923, 0.03937008, 0.18110236, 0.03676471, 0.17647059, 0.03174603, 0.15873016, 0.03125, 0.15625, 0.02912621, 0.16504854, 0.03125, 0.1875, 0.02597403, 0.16883117, 0.02352941, 0.16470588, 0.02380952, 0.14285714, 0.02739726, 0.1369863, 0.02469136, 0.16049383, 0.03370787, 0.20224719, 0.02777778, 0.18055556, 0.025, 0.175, 0.02531646, 0.15189873, 0.02941176, 0.14705882, 0.02777778, 0.15277778, 0.03225806, 0.17741935, 0.01818182, 0.16363636, 0.01612903, 0.16129032, 0.01612903, 0.14516129, 0.01818182, 0.12727273, 0.01960784, 0.1372549))
amylaseFac = Factor(Array(gallstones, amylase), Array(0.01013514, 0.01689189, 0.01869159, 0.04672897))
ggtpFac = Factor(Array(PBC, THepatitis, RHepatitis, Steatosis, ChHepatitis, Hyperbilirubinemia, ggtp), Array(0.08, 0.096, 0.00177936, 0.00177936, 0.00277008, 0.05540166, 0.04395604, 0.07692308, 0.08791209, 0.14285714, 0.05660377, 0.06603774, 0.07462687, 0.02985075, 0.03703704, 0.02777778, 0.04210526, 0.04210526, 0.04444444, 0.04444444, 0.07692308, 0.08547009, 0.06493506, 0.06493506, 0.11695906, 0.00584795, 0.03076923, 0.01538462, 0.03448276, 0.03448276, 0.04545455, 0.04545455, 0.07692308, 0.08791209, 0.06410256, 0.05128205, 0.06756757, 0.01351351, 0.04615385, 0.01538462, 0.05, 0.03333333, 0.0483871, 0.03225806, 0.07594937, 0.07594937, 0.06349206, 0.04761905, 0.07380074, 0.00369004, 0.02702703, 0.01351351, 0.03030303, 0.03030303, 0.04166667, 0.04166667, 0.07070707, 0.08080808, 0.06024096, 0.04819277, 0.0617284, 0.01234568, 0.04285714, 0.01428571, 0.04615385, 0.03076923, 0.04545455, 0.03030303, 0.07142857, 0.07142857, 0.05714286, 0.04285714, 0.06651885, 0.00221729, 0.04338395, 0.0021692, 0.04761905, 0.02380952, 0.04166667, 0.02083333, 0.078125, 0.078125, 0.06557377, 0.04918033, 0.07393715, 0.00184843, 0.05649718, 0.00188324, 0.06122449, 0.02040816, 0.05555556, 0.03703704, 0.10526316, 0.09210526, 0.1509434, 0.14150943, 0.23928571, 0.225, 0.1986755, 0.19205298, 0.20074349, 0.19702602, 0.18468468, 0.18468468, 0.19397993, 0.19397993, 0.1826087, 0.17826087, 0.19776119, 0.17910448, 0.18229167, 0.16145833, 0.18435754, 0.16759777, 0.16981132, 0.1572327, 0.1804878, 0.17560976, 0.17877095, 0.17318436, 0.22077922, 0.1991342, 0.19642857, 0.17857143, 0.19871795, 0.18589744, 0.17857143, 0.17142857, 0.18994413, 0.18994413, 0.17763158, 0.17105263, 0.19393939, 0.16969697, 0.17647059, 0.15441176, 0.17829457, 0.1627907, 0.16666667, 0.15, 0.18, 0.16666667, 0.17567568, 0.16216216, 0.21428571, 0.19327731, 0.19186047, 0.1744186, 0.19375, 0.18125, 0.17482517, 0.16783217, 0.18579235, 0.18579235, 0.17419355, 0.16774194, 0.18934911, 0.16568047, 0.17266187, 0.15107914, 0.17424242, 0.15909091, 0.16528926, 0.14876033, 0.17687075, 0.16326531, 0.16666667, 0.15909091, 0.21088435, 0.18367347, 0.18852459, 0.16393443, 0.19130435, 0.17391304, 0.17592593, 0.15740741, 0.18320611, 0.17557252, 0.16949153, 0.16101695, 0.18548387, 0.16129032, 0.16666667, 0.14814815, 0.17307692, 0.15384615, 0.15463918, 0.1443299, 0.16964286, 0.16071429, 0.15909091, 0.14772727))
cholesterolFac = Factor(Array(PBC, Steatosis, ChHepatitis, cholesterol), Array(4.4425E-4, 0.09773434, 0.00277008, 0.02770083, 0.03296703, 0.06593407, 0.04477612, 0.2238806, 0.06918239, 0.23899371, 0.09174312, 0.27981651, 0.125, 0.36428571, 0.10509554, 0.31528662, 0.1015873, 0.3047619, 0.10344828, 0.3256705, 0.09659091, 0.30113636, 0.08965517, 0.28275862))
hbsagFac = Factor(Array(vh_amn, ChHepatitis, hbsag), Array(0.04674797, 0.95325203, 0.04347826, 0.95652174, 0.19047619, 0.80952381, 0.1125, 0.8875, 0.46153846, 0.53846154, 0.5, 0.5))
hbsag_antiFac = Factor(Array(vh_amn, ChHepatitis, hbsag, hbsag_anti), Array(0.01492537, 0.98507463, 0.004329, 0.995671, 0.00452489, 0.99547511, 0.09090909, 0.90909091, 0.00195695, 0.99804305, 0.08333333, 0.91666667, 0.04225352, 0.95774648, 0.01098901, 0.98901099, 0.01408451, 0.98591549, 0.01639344, 0.98360656, 0.07142857, 0.92857143, 0.0070922, 0.9929078))
anorexiaFac = Factor(Array(RHepatitis, THepatitis, anorexia), Array(0.28091603, 0.71908397, 0.22222222, 0.77777778, 0.11764706, 0.88235294, 0.18181818, 0.81818182))
nauseaFac = Factor(Array(RHepatitis, THepatitis, nausea), Array(0.28549618, 0.71450382, 0.37037037, 0.62962963, 0.35294118, 0.64705882, 0.36363636, 0.63636364))
spleenFac = Factor(Array(Cirrhosis, RHepatitis, THepatitis, spleen), Array(0.10070671, 0.89929329, 0.11111111, 0.88888889, 0.11764706, 0.88235294, 0.16216216, 0.83783784, 0.25806452, 0.74193548, 0.21568627, 0.78431373, 0.24444444, 0.75555556, 0.30232558, 0.69767442, 0.48275862, 0.51724138, 0.36231884, 0.63768116, 0.37037037, 0.62962963, 0.32352941, 0.67647059))
consciousnessFac = Factor(Array(encephalopathy, consciousness), Array(0.01627219, 0.98372781, 0.30434783, 0.69565217))
spidersFac = Factor(Array(Cirrhosis, spiders), Array(0.18360656, 0.81639344, 0.48387097, 0.51612903, 0.60344828, 0.39655172))
jaundiceFac = Factor(Array(bilirubin, jaundice), Array(0.1942446, 0.8057554, 0.34673367, 0.65326633, 0.56716418, 0.43283582, 0.75, 0.25))
albuminFac = Factor(Array(Cirrhosis, albumin), Array(0.73934426, 0.14262295, 0.96463023, 0.00321543, 0.91222031, 0.08605852))
edgeFac = Factor(Array(Cirrhosis, edge), Array(0.23442623, 0.76557377, 0.4516129, 0.5483871, 0.75862069, 0.24137931))
irregular_liverFac = Factor(Array(Cirrhosis, irregular_liver), Array(0.10655738, 0.89344262, 0.35483871, 0.64516129, 0.60344828, 0.39655172))
hbc_antiFac = Factor(Array(vh_amn, ChHepatitis, hbc_anti), Array(0.10162602, 0.89837398, 0.13043478, 0.86956522, 0.07936508, 0.92063492, 0.0875, 0.9125, 0.00763359, 0.99236641, 0.00355872, 0.99644128))
hcv_antiFac = Factor(Array(vh_amn, ChHepatitis, hcv_anti), Array(0.00203252, 0.99796748, 0.004329, 0.995671, 0.00158479, 0.99841521, 0.00124844, 0.99875156, 0.00763359, 0.99236641, 0.00355872, 0.99644128))
palmsFac = Factor(Array(Cirrhosis, palms), Array(0.14098361, 0.85901639, 0.29032258, 0.70967742, 0.5, 0.5))
hbeagFac = Factor(Array(vh_amn, ChHepatitis, hbeag), Array(0.00203252, 0.99796748, 0.04347826, 0.95652174, 0.00158479, 0.99841521, 0.00124844, 0.99875156, 0.00763359, 0.99236641, 0.00355872, 0.99644128))
carcinomaFac = Factor(Array(Cirrhosis, PBC, carcinoma), Array(0.01, 0.99, 0.1, 0.9, 0.2, 0.8, 0.27272727, 0.72727273, 0.3, 0.7, 0.36363636, 0.63636364))
//Create ClusterGraph
clusterGraph = GenericClusterGraph()
clusterGraph.addCluster(1, alcoholismFac)
clusterGraph.addCluster(2, vh_amnFac)
clusterGraph.addCluster(3, hepatotoxicFac)
clusterGraph.addCluster(4, THepatitisFac)
clusterGraph.addCluster(5, hospitalFac)
clusterGraph.addCluster(6, surgeryFac)
clusterGraph.addCluster(7, gallstonesFac)
clusterGraph.addCluster(8, choledocholithotomyFac)
clusterGraph.addCluster(9, injectionsFac)
clusterGraph.addCluster(10, transfusionFac)
clusterGraph.addCluster(11, ChHepatitisFac)
clusterGraph.addCluster(12, sexFac)
clusterGraph.addCluster(13, ageFac)
clusterGraph.addCluster(14, PBCFac)
clusterGraph.addCluster(15, fibrosisFac)
clusterGraph.addCluster(16, diabetesFac)
clusterGraph.addCluster(17, obesityFac)
clusterGraph.addCluster(18, SteatosisFac)
clusterGraph.addCluster(19, CirrhosisFac)
clusterGraph.addCluster(20, HyperbilirubinemiaFac)
clusterGraph.addCluster(21, triglyceridesFac)
clusterGraph.addCluster(22, RHepatitisFac)
clusterGraph.addCluster(23, fatigueFac)
clusterGraph.addCluster(24, bilirubinFac)
clusterGraph.addCluster(25, itchingFac)
clusterGraph.addCluster(26, upper_painFac)
clusterGraph.addCluster(27, fatFac)
clusterGraph.addCluster(28, pain_ruqFac)
clusterGraph.addCluster(29, pressure_ruqFac)
clusterGraph.addCluster(30, phosphataseFac)
clusterGraph.addCluster(31, skinFac)
clusterGraph.addCluster(32, amaFac)
clusterGraph.addCluster(33, le_cellsFac)
clusterGraph.addCluster(34, jointsFac)
clusterGraph.addCluster(35, painFac)
clusterGraph.addCluster(36, proteinsFac)
clusterGraph.addCluster(37, edemaFac)
clusterGraph.addCluster(38, plateletFac)
clusterGraph.addCluster(39, inrFac)
clusterGraph.addCluster(40, bleedingFac)
clusterGraph.addCluster(41, flatulenceFac)
clusterGraph.addCluster(42, alcoholFac)
clusterGraph.addCluster(43, encephalopathyFac)
clusterGraph.addCluster(44, ureaFac)
clusterGraph.addCluster(45, ascitesFac)
clusterGraph.addCluster(46, hepatomegalyFac)
clusterGraph.addCluster(47, hepatalgiaFac)
clusterGraph.addCluster(48, densityFac)
clusterGraph.addCluster(49, ESRFac)
clusterGraph.addCluster(50, altFac)
clusterGraph.addCluster(51, astFac)
clusterGraph.addCluster(52, amylaseFac)
clusterGraph.addCluster(53, ggtpFac)
clusterGraph.addCluster(54, cholesterolFac)
clusterGraph.addCluster(55, hbsagFac)
clusterGraph.addCluster(56, hbsag_antiFac)
clusterGraph.addCluster(57, anorexiaFac)
clusterGraph.addCluster(58, nauseaFac)
clusterGraph.addCluster(59, spleenFac)
clusterGraph.addCluster(60, consciousnessFac)
clusterGraph.addCluster(61, spidersFac)
clusterGraph.addCluster(62, jaundiceFac)
clusterGraph.addCluster(63, albuminFac)
clusterGraph.addCluster(64, edgeFac)
clusterGraph.addCluster(65, irregular_liverFac)
clusterGraph.addCluster(66, hbc_antiFac)
clusterGraph.addCluster(67, hcv_antiFac)
clusterGraph.addCluster(68, palmsFac)
clusterGraph.addCluster(69, hbeagFac)
clusterGraph.addCluster(70, carcinomaFac)
//Add edges between clusters in a cluster graph
clusterGraph.addEdges((3, 4), (1, 4), (7, 8), (5, 9), (6, 9), (8, 9), (5, 10), (6, 10), (8, 10), (10, 11), (2, 11), (9, 11), (12, 14), (13, 14), (11, 15), (16, 17), (17, 18), (1, 18), (15, 19), (18, 19), (13, 20), (12, 20), (18, 21), (3, 22), (11, 23), (4, 23), (22, 23), (20, 24), (14, 24), (19, 24), (7, 24), (11, 24), (24, 25), (7, 26), (7, 27), (18, 28), (20, 28), (7, 29), (14, 29), (11, 29), (22, 30), (4, 30), (19, 30), (11, 30), (24, 31), (14, 32), (14, 33), (14, 34), (14, 35), (34, 35), (19, 36), (19, 37), (19, 38), (14, 38), (11, 39), (19, 39), (4, 39), (20, 39), (38, 40), (39, 40), (7, 41), (19, 42), (19, 43), (14, 43), (43, 44), (36, 45), (22, 46), (4, 46), (18, 46), (20, 46), (46, 47), (43, 48), (14, 49), (11, 49), (18, 49), (20, 49), (11, 50), (22, 50), (4, 50), (18, 50), (19, 50), (11, 51), (22, 51), (4, 51), (18, 51), (19, 51), (7, 52), (14, 53), (4, 53), (22, 53), (18, 53), (11, 53), (20, 53), (14, 54), (18, 54), (11, 54), (2, 55), (11, 55), (2, 56), (11, 56), (55, 56), (22, 57), (4, 57), (22, 58), (4, 58), (19, 59), (22, 59), (4, 59), (43, 60), (19, 61), (24, 62), (19, 63), (19, 64), (19, 65), (2, 66), (11, 66), (2, 67), (11, 67), (19, 68), (2, 69), (11, 69), (19, 70), (14, 70))
//Calibrate cluster graph
loopyBP = LoopyBP(clusterGraph)
loopyBP.calibrate()
}
@Test def loadNetworkSmall {
var time: Long = 0
for (i <- 1 to loops) {
var now = System.nanoTime()
loadNetwork()
time += (System.nanoTime() - now)
}
time /= loops
println("Loading medium network took " + time + " ns")
}
/*@Test*/ def updateValuesSmall(variables: Array[Var], values: Array[Double]) {
val stepSizes: Array[Int] = calcStepSizes(variables)
val dimProduct = stepSizes(0) * variables(0).dim
require(dimProduct == values.size, "Number of potential values must equal to a product of variable dimensions")
def getVariables(): Array[Var] = variables
def getValues(): Array[Double] = values
}
def calcStepSizes(variables: Array[Var]): Array[Int] = { // Pass in all variables, returns array
val varNum = variables.size // number of vars
val stepSizes = new Array[Int](varNum) // return value equal to size of above
if (varNum == 1) stepSizes(0) = 1 // if only 1 variable, set return value to 1
else { // else
var i = varNum - 1 // i = number of vars - 1
var product = 1 // p = 1
while (i >= 0) { // while i >= 0, looping through vars backwards
stepSizes(i) = product // return value (i) = p
product *= variables(i).dim // p = p * (number of states inside variable(i))
i -= 1 // i = i - 1
}
}
stepSizes
}
@Test def updateEvidenceSmall {
}
@Test def getValuesSmall {
}
}
Can you send me your full code, which generates this error?
Guessing that in the 'ChHepatitisFac = Factor(Array(transfusion, ChHepatitis, injections, vh_amn), Array(0.13095238...'
the size of Array with potentials doesn't much the product of dimensions of all variables, e.g. if all four variables in a factor have dimensions of 2, then the number of potentials should be 4*2 = 16, simply all the possible combinations of factor variables.
which in your case is 24, but you have just 16 potential values
It seems I have made a silly mistake my side when converting the data. :) Thanks for the quick response.
Hi there,
I'm currently trying to create a few Bayesian networks for some benchmarking I am doing. However I have run into an issue that I have been unable to resolve. My setup is described below.
I create my variables like so:
Then create the factors:
Create a cluster graph:
Then finally add the edges and propagate the values with the calibrate function:
However when creating the factors there is an issue I am having that I do not understand.
When I create this Factor:
I get the error "java.lang.IllegalArgumentException: requirement failed: Number of potential values must equal to a product of variable dimensions".
So I traced through the code to find where this issue is coming from. Copying the same code to a local version for debugging, I ended up with this:
From what I understand a value is produced based on the number of variables and it tries to match the amount of data with this value produced multiplied by the number of states in the first Variable passed into the Factor.
However I do not understand why this code happens. What is it validating? The network I am trying to create in Bayes-Scala is taken from an example given in GenIe (Heplar II), and already converted and tested in multiple other programs so I know the data and variables should match up. When I test a smaller and simpler network (Asia) this works fine.
If I do not change the number of variables and do not change the amount of data, then the only other two possible changes are to change the number of states (which I may have misunderstood as to what that value is) and to change which is the first variable passed into the factor.
I have tried passing in each variable as the first into the factor and none succeed.
I am saying the number of states is the data like: "Present, Absent".
If you can advise on what I may be doing wrong or if there is a limitation with Bayes-Scala that would be great. I was unsure where the best place to post about this issue would be.
Thanks, Harry