import pandas as pd
import jpype
import jpype.imports
from jpype.types import *
from jpype import java
classpath = "lib/bayesserver-10.8.jar"
jpype.startJVM(classpath=[classpath])
import data_frame_utils as dfu
from com.bayesserver import *
from com.bayesserver.inference import *
from com.bayesserver.data import *
from com.bayesserver.data.discovery import *
d = {'A': [3.0, 10.0, 14.3, 12.2], 'B': [16, 12, 3, 6], 'C': ['A', 'B', 'A', 'B'], 'D': ['X', 'Y', 'X', 'X']}
df = pd.DataFrame(data=d)
dt = dfu.to_data_table(df)
network = Network()
data_reader_command = DataTableDataReaderCommand(dt)
options = VariableGeneratorOptions()
variable_defs = [
VariableDefinition('A', 'A', VariableValueType.CONTINUOUS),
VariableDefinition('B', 'B', VariableValueType.CONTINUOUS),
VariableDefinition('C', 'C', VariableValueType.DISCRETE),
VariableDefinition('D', 'D', VariableValueType.DISCRETE)
]
variable_infos = VariableGenerator.generate(
data_reader_command,
java.util.Arrays.asList(variable_defs),
options)
print(network.getVariables().size())
for vi in variable_infos:
variable = vi.getVariable()
network.getNodes().add(Node(variable))
print(network.getVariables().size())