/**
 * Description of the Alarm network
 * as a class to be linked with EJavaBayes.
 * Author: Fabio G. Cozman (fgcozman@usp.br).
 */

import BayesianNetworks.*;

class Alarm extends BayesNet {

public Alarm() {
name = "Alarm";

// PROBABILITY VARIABLES.

DiscreteVariable hypovolemia = new DiscreteVariable("Hypovolemia",
	DiscreteVariable.CHANCE, new String[] {  "True" , "False" });

DiscreteVariable strokeVolume = new DiscreteVariable("StrokeVolume",
	DiscreteVariable.CHANCE, new String[] {  "Low" , "Normal" , "High" });

DiscreteVariable lvFailure = new DiscreteVariable("LVFailure",
	DiscreteVariable.CHANCE, new String[] {  "True" , "False" });

DiscreteVariable lvedVolume = new DiscreteVariable("LVEDVolume",
	DiscreteVariable.CHANCE, new String[] {  "Low" , "Normal" , "High" });

DiscreteVariable pcwp = new DiscreteVariable("PCWP",
	DiscreteVariable.CHANCE, new String[] {  "Low" , "Normal" , "High" });

DiscreteVariable cvp = new DiscreteVariable("CVP",
	DiscreteVariable.CHANCE, new String[] {  "Low" , "Normal" , "High" });

DiscreteVariable history = new DiscreteVariable("History",
	DiscreteVariable.CHANCE, new String[] {  "True" , "False" });

DiscreteVariable minVolSet = new DiscreteVariable("MinVolSet",
	DiscreteVariable.CHANCE, new String[] {  "Low" , "Normal" , "High" });

DiscreteVariable ventMach = new DiscreteVariable("VentMach",
	DiscreteVariable.CHANCE, new String[] {  "Zero" , "Low" , "Normal" , "High" });

DiscreteVariable  disconnect = new DiscreteVariable("Disconnect",
	DiscreteVariable.CHANCE, new String[] {  "True" , "False" });

DiscreteVariable  ventTube = new DiscreteVariable("VentTube",
	DiscreteVariable.CHANCE, new String[] {  "Zero" , "Low" , "Normal" , "High" });

DiscreteVariable  kinkedTube = new DiscreteVariable("KinkedTube",
	DiscreteVariable.CHANCE, new String[] {  "True" , "False" });

DiscreteVariable  press = new DiscreteVariable("Press",
	DiscreteVariable.CHANCE, new String[] {  "Zero" , "Low" , "Normal" , "High" });

DiscreteVariable errLowOutput = new DiscreteVariable("ErrLowOutput",
	DiscreteVariable.CHANCE, new String[] {  "True" , "False" });

DiscreteVariable hrbp = new DiscreteVariable("HRBP",
	DiscreteVariable.CHANCE, new String[]  {  "Low" , "Normal" , "High" });

DiscreteVariable errCauter = new DiscreteVariable("ErrCauter",
	DiscreteVariable.CHANCE, new String[] {  "True" , "False" });

DiscreteVariable hrekg = new DiscreteVariable("HREKG",
	DiscreteVariable.CHANCE, new String[] {  "Low" , "Normal" , "High" });

DiscreteVariable hrSat = new DiscreteVariable("HRSat",
	DiscreteVariable.CHANCE, new String[] {  "Low" , "Normal" , "High" });

DiscreteVariable bp = new DiscreteVariable("BP",
	DiscreteVariable.CHANCE, new String[] {  "Low" , "Normal" , "High" });

DiscreteVariable co = new DiscreteVariable("CO",
	DiscreteVariable.CHANCE, new String[] {  "Low" , "Normal" , "High" });

DiscreteVariable hr = new DiscreteVariable("HR",
	DiscreteVariable.CHANCE, new String[]  {  "Low" , "Normal" , "High" });

DiscreteVariable tpr = new DiscreteVariable("TPR",
	DiscreteVariable.CHANCE, new String[] {  "Low" , "Normal" , "High" });

DiscreteVariable anaphylaxis = new DiscreteVariable("Anaphylaxis",
	DiscreteVariable.CHANCE, new String[] {  "True" , "False" });

DiscreteVariable insuffAnesth = new DiscreteVariable("InsuffAnesth",
	DiscreteVariable.CHANCE, new String[] {  "True" , "False" });

DiscreteVariable pap = new DiscreteVariable("PAP",
	DiscreteVariable.CHANCE, new String[]  {  "Low" , "Normal" , "High" });

DiscreteVariable pulmEmbolus = new DiscreteVariable("PulmEmbolus",
	DiscreteVariable.CHANCE, new String[] {  "True" , "False" });

DiscreteVariable fiO2 = new DiscreteVariable("FiO2",
	DiscreteVariable.CHANCE, new String[] {  "Low" , "Normal" });

DiscreteVariable catechol = new DiscreteVariable("Catechol",
	DiscreteVariable.CHANCE, new String[] {  "Normal" , "High" });

DiscreteVariable saO2 = new DiscreteVariable("SaO2",
	DiscreteVariable.CHANCE, new String[] {  "Low" , "Normal" , "High" });

DiscreteVariable shunt = new DiscreteVariable("Shunt",
	DiscreteVariable.CHANCE, new String[] {  "Normal" , "High" });

DiscreteVariable pvSat = new DiscreteVariable("PVSat",
	DiscreteVariable.CHANCE, new String[] {  "Low" , "Normal" , "High" });

DiscreteVariable minVol = new DiscreteVariable("MinVol",
	DiscreteVariable.CHANCE, new String[] {  "Zero" , "Low" , "Normal" , "High" });

DiscreteVariable expCO2 = new DiscreteVariable("ExpCO2",
	DiscreteVariable.CHANCE, new String[] {  "Zero" , "Low" , "Normal" , "High" });

DiscreteVariable artCO2 = new DiscreteVariable("ArtCO2",
	DiscreteVariable.CHANCE, new String[] {  "Low" , "Normal" , "High" });

DiscreteVariable ventAlv = new DiscreteVariable("VentAlv",
	DiscreteVariable.CHANCE, new String[] {  "Zero" , "Low" , "Normal" , "High" });

DiscreteVariable ventLung = new DiscreteVariable("VentLung",
	DiscreteVariable.CHANCE, new String[] {  "Zero" , "Low" , "Normal" , "High" });

DiscreteVariable intubation = new DiscreteVariable("Intubation",
	DiscreteVariable.CHANCE, new String[] {  "Normal" , "Esophageal" , "OneSided" });

// PROBABILITY FUNCTIONS.

DiscreteFunction p1 = new DiscreteFunction(
                new DiscreteVariable[] { hypovolemia },
                new DiscreteVariable[] {},
                new double[] { 0.2 , 0.8 });

DiscreteFunction p2 = new DiscreteFunction(
                new DiscreteVariable[] { strokeVolume },
                new DiscreteVariable[] { lvFailure, hypovolemia },
	            new double[] { 0.98 , 0.5 , 0.95 , 0.05 , 0.01 , 0.49 , 0.04 , 0.9 , 0.01 , 0.01 , 0.01 , 0.05 });

DiscreteFunction p3 = new DiscreteFunction(
                new DiscreteVariable[] { lvFailure },
                new DiscreteVariable[] {},
            	new double[] { 0.05 , 0.95 });

DiscreteFunction p4 = new DiscreteFunction(
                new DiscreteVariable[] { lvedVolume },
                new DiscreteVariable[] { hypovolemia, lvFailure },
	            new double[] { 0.95 , 0.98 , 0.01 , 0.05 , 0.04 , 0.01 , 0.09 , 0.9 , 0.01 , 0.01 , 0.9 , 0.05});

DiscreteFunction p5 = new DiscreteFunction(
                new DiscreteVariable[] { pcwp },
                new DiscreteVariable[] { lvedVolume },
            	new double[] { 0.95 , 0.04 , 0.01 , 0.04 , 0.95 , 0.04 , 0.01 , 0.01 , 0.95 });

DiscreteFunction p6 = new DiscreteFunction(
                new DiscreteVariable[] { cvp },
                new DiscreteVariable[] { lvedVolume },
            	new double[] { 0.95 , 0.04 , 0.01 , 0.04 , 0.95 , 0.29 , 0.01 , 0.01 , 0.7 });

DiscreteFunction p7 = new DiscreteFunction(
                new DiscreteVariable[] { history },
                new DiscreteVariable[] { lvFailure },
	            new double[] { 0.9 , 0.01 , 0.1 , 0.99 });

DiscreteFunction p8 = new DiscreteFunction(
                new DiscreteVariable[] { minVolSet },
                new DiscreteVariable[] {},
                new double[] { 0.01 , 0.98 , 0.01 });

DiscreteFunction p9 = new DiscreteFunction(
                new DiscreteVariable[] { ventMach },
                new DiscreteVariable[] { minVolSet },
            	new double[] { 0.01 , 0.01 , 0.01 , 0.97 , 0.01 , 0.01 , 0.01 , 0.97 , 0.01 , 0.01 , 0.01 , 0.97 });

DiscreteFunction p10 = new DiscreteFunction(
                new DiscreteVariable[] { disconnect },
                new DiscreteVariable[] { },
            	new double[] { 0.05 , 0.95 });

DiscreteFunction p11 = new DiscreteFunction(
                new DiscreteVariable[] { ventTube },
                new DiscreteVariable[] { disconnect },
            	new double[] { 0.97 , 0.97 , 0.97 , 0.01 , 0.97 , 0.01 , 0.97 , 0.01 , 0.01 , 0.01 , 0.01 , 0.97 , 0.01 , 0.01 , 0.01 , 0.01 , 0.01 , 0.01 , 0.01 , 0.01 , 0.01 , 0.97 , 0.01 , 0.01 , 0.01 , 0.01 , 0.01 , 0.01 , 0.01 , 0.01 , 0.01 , 0.97 });

DiscreteFunction p12 = new DiscreteFunction(
                new DiscreteVariable[] { kinkedTube },
                new DiscreteVariable[] { },
            	new double[] { 0.04 , 0.96 });

DiscreteFunction p13 = new DiscreteFunction(
                new DiscreteVariable[] { press },
                new DiscreteVariable[] { kinkedTube, intubation, ventTube },
            	new double[] { 0.97 , 0.01 , 0.01 , 0.01 , 0.97 , 0.1 , 0.05 , 0.01 , 0.97 , 0.01 , 0.01 , 0.01 , 0.97 , 0.01 , 0.01 , 0.01 , 0.97 , 0.4 , 0.2 , 0.2 , 0.97 , 0.01 , 0.01 , 0.01 , 0.01 , 0.49 , 0.01 , 0.01 , 0.01 , 0.84 , 0.25 , 0.15 , 0.01 , 0.29 , 0.01 , 0.01 , 0.01 , 0.97 , 0.01 , 0.01 , 0.01 , 0.58 , 0.75 , 0.7 , 0.01 , 0.9 , 0.01 , 0.01 , 0.01 , 0.3 , 0.08 , 0.01 , 0.01 , 0.05 , 0.25 , 0.25 , 0.01 , 0.3 , 0.08 , 0.01 , 0.01 , 0.01 , 0.97 , 0.01 , 0.01 , 0.01 , 0.04 , 0.09 , 0.01 , 0.08 , 0.38 , 0.01 , 0.01 , 0.2 , 0.9 , 0.97 , 0.01 , 0.01 , 0.45 , 0.59 , 0.01 , 0.4 , 0.9 , 0.97 , 0.01 , 0.01 , 0.01 , 0.97 , 0.01 , 0.01 , 0.01 , 0.01 , 0.01 , 0.01 , 0.6 , 0.97 });

DiscreteFunction p14 = new DiscreteFunction(
                new DiscreteVariable[] { errLowOutput },
                new DiscreteVariable[] { },
            	new double[] { 0.05 , 0.95 });

DiscreteFunction p15 = new DiscreteFunction(
                new DiscreteVariable[] { hrbp },
                new DiscreteVariable[] { errLowOutput, hr },
            	new double[] { 0.98 , 0.4 , 0.3 , 0.98 , 0.01 , 0.01 , 0.01 , 0.59 , 0.4 , 0.01 , 0.98 , 0.01 , 0.01 , 0.01 , 0.3 , 0.01 , 0.01 , 0.98 });

DiscreteFunction p16 = new DiscreteFunction(
                new DiscreteVariable[] { errCauter },
                new DiscreteVariable[] { },
            	new double[] { 0.1 , 0.9 });

DiscreteFunction p17 = new DiscreteFunction(
                new DiscreteVariable[] { hrekg },
                new DiscreteVariable[] { hr, errCauter },
            	new double[] { 0.333333 , 0.98 , 0.333333 , 0.01 , 0.333333 , 0.01 , 0.333333 , 0.01 , 0.333333 , 0.98 , 0.333333 , 0.01 , 0.333333 , 0.01 , 0.333333 , 0.01 , 0.333333 , 0.98 });

DiscreteFunction p18 = new DiscreteFunction(
                new DiscreteVariable[] { hrSat },
                new DiscreteVariable[] { hr, errCauter },
	            new double[] { 0.333333 , 0.98 , 0.333333 , 0.01 , 0.333333 , 0.01 , 0.333333 , 0.01 , 0.333333 , 0.98 , 0.333333 , 0.01 , 0.333333 , 0.01 , 0.333333 , 0.01 , 0.333333 , 0.98 });

DiscreteFunction p19 = new DiscreteFunction(
                new DiscreteVariable[] { bp },
                new DiscreteVariable[] { co, tpr },
                new double[] { 0.98 , 0.98 , 0.3 , 0.98 , 0.1 , 0.05 , 0.9 , 0.05 , 0.01 , 0.01 , 0.01 , 0.6 , 0.01 , 0.85 , 0.4 , 0.09 , 0.2 , 0.09 , 0.01 , 0.01 , 0.1 , 0.01 , 0.05 , 0.55 , 0.01 , 0.75 , 0.9 });

DiscreteFunction p20 = new DiscreteFunction(
                new DiscreteVariable[] { co },
                new DiscreteVariable[] { hr, strokeVolume },
            	new double[] { 0.98 , 0.95 , 0.3 , 0.95 , 0.04 , 0.01 , 0.8 , 0.01 , 0.01 , 0.01 , 0.04 , 0.69 , 0.04 , 0.95 , 0.3 , 0.19 , 0.04 , 0.01 , 0.01 , 0.01 , 0.01 , 0.01 , 0.01 , 0.69 , 0.01 , 0.95 , 0.98 });

DiscreteFunction p21 = new DiscreteFunction(
                new DiscreteVariable[] { hr },
                new DiscreteVariable[] { catechol },
                new double[] { 0.1 , 0.01 , 0.89 , 0.09 , 0.01 , 0.9 });

DiscreteFunction p22 = new DiscreteFunction(
                new DiscreteVariable[] { tpr },
                new DiscreteVariable[] { anaphylaxis },
            	new double[] { 0.98 , 0.3 , 0.01 , 0.4 , 0.01 , 0.3 });

DiscreteFunction p23 = new DiscreteFunction(
                new DiscreteVariable[] { anaphylaxis },
                new DiscreteVariable[] { },
            	new double[] { 0.01 , 0.99 });

DiscreteFunction p24 = new DiscreteFunction(
                new DiscreteVariable[] { insuffAnesth },
                new DiscreteVariable[] { },
            	new double[] { 0.2 , 0.8 });

DiscreteFunction p25 = new DiscreteFunction(
                new DiscreteVariable[] { pap },
                new DiscreteVariable[] { pulmEmbolus },
            	new double[] { 0.01 , 0.05 , 0.19 , 0.9 , 0.8 , 0.05 });

DiscreteFunction p26 = new DiscreteFunction(
                new DiscreteVariable[] { pulmEmbolus },
                new DiscreteVariable[] { },
            	new double[] { 0.01 , 0.99 });

DiscreteFunction p27 = new DiscreteFunction(
                new DiscreteVariable[] { fiO2 },
                new DiscreteVariable[] { },
            	new double[] { 0.01 , 0.99 });

DiscreteFunction p28 = new DiscreteFunction(
                new DiscreteVariable[] { catechol },
                new DiscreteVariable[] { insuffAnesth, saO2, tpr, artCO2 },
            	new double[] { 0.01 , 0.01 , 0.01 , 0.01 , 0.01 , 0.01 , 0.01 , 0.01 , 0.01 , 0.01 , 0.01 , 0.01 , 0.01 , 0.01 , 0.01 , 0.05 , 0.05 , 0.01 , 0.01 , 0.01 , 0.01 , 0.05 , 0.05 , 0.01 , 0.05 , 0.05 , 0.01 , 0.05 , 0.05 , 0.01 , 0.05 , 0.05 , 0.01 , 0.05 , 0.05 , 0.01 , 0.1 , 0.1 , 0.1 , 0.95 , 0.95 , 0.3 , 0.95 , 0.95 , 0.3 , 0.95 , 0.95 , 0.3 , 0.99 , 0.99 , 0.99 , 0.95 , 0.99 , 0.3 , 0.99 , 0.99 , 0.99 , 0.99 , 0.99 , 0.99 , 0.99 , 0.99 , 0.99 , 0.99 , 0.99 , 0.99 , 0.99 , 0.99 , 0.99 , 0.95 , 0.95 , 0.99 , 0.99 , 0.99 , 0.99 , 0.95 , 0.95 , 0.99 , 0.95 , 0.95 , 0.99 , 0.95 , 0.95 , 0.99 , 0.95 , 0.95 , 0.99 , 0.95 , 0.95 , 0.99 , 0.9 , 0.9 , 0.9 , 0.05 , 0.05 , 0.7 , 0.05 , 0.05 , 0.7 , 0.05 , 0.05 , 0.7 , 0.01 , 0.01 , 0.01 , 0.05 , 0.01 , 0.7 });

DiscreteFunction p29 = new DiscreteFunction(
                new DiscreteVariable[] { saO2 },
                new DiscreteVariable[] { shunt, pvSat },
            	new double[] { 0.98 , 0.01 , 0.01 , 0.98 , 0.98 , 0.69 , 0.01 , 0.98 , 0.01 , 0.01 , 0.01 , 0.3 , 0.01 , 0.01 , 0.98 , 0.01 , 0.01 , 0.01 });

DiscreteFunction p30 = new DiscreteFunction(
                new DiscreteVariable[] { shunt },
                new DiscreteVariable[] { pulmEmbolus, intubation },
            	new double[] { 0.1 , 0.1 , 0.01 , 0.95 , 0.95 , 0.05 , 0.9 , 0.9 , 0.99 , 0.05 , 0.05 , 0.95 });

DiscreteFunction p31 = new DiscreteFunction(
                new DiscreteVariable[] { pvSat },
                new DiscreteVariable[] { ventAlv, fiO2 },
            	new double[] { 0.98 , 0.98 , 0.98 , 0.98 , 0.95 , 0.01 , 0.95 , 0.01 , 0.01 , 0.01 , 0.01 , 0.01 , 0.04 , 0.95 , 0.04 , 0.01 , 0.01 , 0.01 , 0.01 , 0.01 , 0.01 , 0.04 , 0.01 , 0.98 });

DiscreteFunction p32 = new DiscreteFunction(
                new DiscreteVariable[] { minVol },
                new DiscreteVariable[] { ventLung, intubation },
            	new double[] { 0.97 , 0.97 , 0.97 , 0.01 , 0.6 , 0.01 , 0.01 , 0.5 , 0.01 , 0.01 , 0.5 , 0.01 , 0.01 , 0.01 , 0.01 , 0.97 , 0.38 , 0.97 , 0.01 , 0.48 , 0.01 , 0.01 , 0.48 , 0.01 , 0.01 , 0.01 , 0.01 , 0.01 , 0.01 , 0.01 , 0.97 , 0.01 , 0.97 , 0.01 , 0.01 , 0.01 , 0.01 , 0.01 , 0.01 , 0.01 , 0.01 , 0.01 , 0.01 , 0.01 , 0.01 , 0.97 , 0.01 , 0.97 });

DiscreteFunction p33 = new DiscreteFunction(
                new DiscreteVariable[] { expCO2 },
                new DiscreteVariable[] { artCO2, ventLung },
            	new double[] { 0.97 , 0.01 , 0.01 , 0.01 , 0.97 , 0.01 , 0.01 , 0.01 , 0.97 , 0.01 , 0.01 , 0.01 , 0.01 , 0.97 , 0.97 , 0.97 , 0.01 , 0.01 , 0.01 , 0.01 , 0.01 , 0.01 , 0.01 , 0.01 , 0.01 , 0.01 , 0.01 , 0.01 , 0.01 , 0.97 , 0.97 , 0.97 , 0.01 , 0.01 , 0.01 , 0.01 , 0.01 , 0.01 , 0.01 , 0.01 , 0.01 , 0.01 , 0.01 , 0.01 , 0.01 , 0.97 , 0.97 , 0.97 });

DiscreteFunction p34 = new DiscreteFunction(
                new DiscreteVariable[] { artCO2 },
                new DiscreteVariable[] { ventAlv },
            	new double[] { 0.01 , 0.01 , 0.04 , 0.9 , 0.01 , 0.01 , 0.92 , 0.09 , 0.98 , 0.98 , 0.04 , 0.01 });

DiscreteFunction p35 = new DiscreteFunction(
                new DiscreteVariable[] { ventAlv },
                new DiscreteVariable[] { intubation, ventLung },
            	new double[] { 0.97 , 0.01 , 0.01 , 0.01 , 0.97 , 0.01 , 0.01 , 0.01 , 0.97 , 0.03 , 0.01 , 0.01 , 0.01 , 0.97 , 0.01 , 0.01 , 0.01 , 0.97 , 0.01 , 0.01 , 0.01 , 0.95 , 0.94 , 0.88 , 0.01 , 0.01 , 0.97 , 0.01 , 0.01 , 0.01 , 0.97 , 0.01 , 0.01 , 0.01 , 0.04 , 0.1 , 0.01 , 0.01 , 0.01 , 0.97 , 0.01 , 0.01 , 0.01 , 0.97 , 0.01 , 0.01 , 0.01 , 0.01 });

DiscreteFunction p36 = new DiscreteFunction(
                new DiscreteVariable[] { ventLung },
                new DiscreteVariable[] { kinkedTube, ventTube, intubation },
            	new double[] { 0.97 , 0.97 , 0.97 , 0.95 , 0.97 , 0.95 , 0.4 , 0.97 , 0.5 , 0.3 , 0.97 , 0.3 , 0.97 , 0.97 , 0.97 , 0.01 , 0.97 , 0.01 , 0.01 , 0.97 , 0.01 , 0.01 , 0.97 , 0.01 , 0.01 , 0.01 , 0.01 , 0.03 , 0.01 , 0.03 , 0.58 , 0.01 , 0.48 , 0.68 , 0.01 , 0.68 , 0.01 , 0.01 , 0.01 , 0.97 , 0.01 , 0.97 , 0.01 , 0.01 , 0.01 , 0.01 , 0.01 , 0.01 , 0.01 , 0.01 , 0.01 , 0.01 , 0.01 , 0.01 , 0.01 , 0.01 , 0.01 , 0.01 , 0.01 , 0.01 , 0.01 , 0.01 , 0.01 , 0.01 , 0.01 , 0.01 , 0.97 , 0.01 , 0.97 , 0.01 , 0.01 , 0.01 , 0.01 , 0.01 , 0.01 , 0.01 , 0.01 , 0.01 , 0.01 , 0.01 , 0.01 , 0.01 , 0.01 , 0.01 , 0.01 , 0.01 , 0.01 , 0.01 , 0.01 , 0.01 , 0.01 , 0.01 , 0.01 , 0.97 , 0.01 , 0.97 });

DiscreteFunction p37 = new DiscreteFunction(
                new DiscreteVariable[] { intubation },
                new DiscreteVariable[] { },
            	new double[] { 0.92 , 0.03 , 0.05 });

add( new DiscreteVariable[]
    { hypovolemia, strokeVolume, lvFailure, lvedVolume,
      pcwp, cvp, history, minVolSet, ventMach, disconnect,
      ventTube, kinkedTube, press, errLowOutput, hrbp,
      errCauter, hrekg, hrSat, bp, co, hr, tpr, anaphylaxis,
      insuffAnesth, pap, pulmEmbolus, fiO2, catechol, saO2,
      shunt, pvSat, minVol, expCO2, artCO2, ventAlv, ventLung,
      intubation });

add( new DiscreteFunction[] {
        p1, p2, p3, p4, p5,  p6, p7, p8, p9, p10,
        p11, p12, p13, p14, p15,  p16, p17, p18, p19, p20,
        p21, p22, p23, p24, p25,  p26, p27, p28, p29, p30,
        p31, p32, p33, p34, p35,  p36, p37 } );
}
}
