本文整理了Java中eu.amidst.core.variables.Variables
类的一些代码示例,展示了Variables
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Variables
类的具体详情如下:
包路径:eu.amidst.core.variables.Variables
类名称:Variables
暂无
代码示例来源:origin: amidst/toolbox
public static BayesianNetwork createBN(int nVars) throws Exception {
Variables dynamicVariables = new Variables();
Variable classVar = dynamicVariables.newMultinomialVariable("C", 2);
for (int i = 0; i < nVars; i++) {
dynamicVariables.newGaussianVariable("A" + i);
}
DAG dag = new DAG(dynamicVariables);
for (int i = 0; i < nVars; i++) {
dag.getParentSet(dynamicVariables.getVariableByName("A" + i)).addParent(classVar);
}
dag.setName("dbn1");
BayesianNetwork bn = new BayesianNetwork(dag);
bn.randomInitialization(new Random(1));
return bn;
}
代码示例来源:origin: amidst/toolbox
/**
* This method contains the code needed to build the NaiveBayes DAG with a global hidden variable modelling
* concept drift.
* @return A poperly created {@link DAG} object.
* @throws Exception if an error occurs while reading the file.
*/
public static DAG modelBuilding() throws Exception {
//We load the data for one month
DataStream<DataInstance> instances = DataStreamLoader.open("./datasets/bnaic2015/BCC/Month0.arff");
//Define the variables. By default, a random variable is created for each attribute
Variables variables = new Variables(instances.getAttributes());
//We create a new global hidden Gaussian variable
Variable hiddenGaussian = variables.newGaussianVariable("HiddenGaussian");
//We get the variable Default
Variable defaultVariable = variables.getVariableByName("default");
//We define the DAG
DAG dag = new DAG(variables);
//We add the links of the DAG
dag.getVariables()
.getListOfVariables()
.stream()
.filter(var -> var != defaultVariable)
.filter(var -> var != hiddenGaussian)
.forEach(var -> {
dag.getParentSet(var).addParent(defaultVariable);
dag.getParentSet(var).addParent(hiddenGaussian);
});
return dag;
}
代码示例来源:origin: amidst/toolbox
/**
* This method returns a DAG object with naive Bayes structure for the attributes of the passed data stream.
* @param dataStream object of the class DataStream<DataInstance>
* @param classIndex integer value indicating the position of the class
* @return object of the class DAG
*/
public static DAG getNaiveBayesStructure(DataStream<DataInstance> dataStream, int classIndex){
//We create a Variables object from the attributes of the data stream
Variables modelHeader = new Variables(dataStream.getAttributes());
//We define the predicitive class variable
Variable classVar = modelHeader.getVariableById(classIndex);
//Then, we create a DAG object with the defined model header
DAG dag = new DAG(modelHeader);
//We set the linkds of the DAG.
dag.getParentSets().stream().filter(w -> w.getMainVar() != classVar).forEach(w -> w.addParent(classVar));
return dag;
}
代码示例来源:origin: amidst/toolbox
/**
* Constructor from a list of attributes.
* The default parameters are used: the class variable is the last one and the
* diagonal flag is set to false (predictive variables are NOT independent).
* @param attributes list of attributes of the classifier (i.e. its variables)
* @throws WrongConfigurationException
*/
public BayesianLinearRegression(Attributes attributes) throws WrongConfigurationException {
super(attributes);
classVar = vars.getListOfVariables().get(vars.getNumberOfVars()-1);
this.diagonal = false;
}
代码示例来源:origin: amidst/toolbox
/**
* Returns the class variable.
* @param modelContext a {@link weka.core.Instances} object.
* @param atts a set of of {@link Attributes}.
* @return a {@link Variable} object that represents the class variable.
*/
public static Variable getClassVariable(Instances modelContext, Attributes atts){
Variables variables = new Variables(atts);
String className = modelContext.classAttribute().name();
return variables.getVariableByName(className);
}
代码示例来源:origin: amidst/toolbox
public static void main(String[] args) throws Exception {
//We first create an empty Variables object
Variables variables = new Variables();
//We invoke the "new" methods of the object Variables to create new variables.
//Now we create a Gaussian variables
Variable gaussianVar = variables.newGaussianVariable("Gaussian");
//Now we create a Multinomial variable with two states
Variable multinomialVar = variables.newMultinomialVariable("Multinomial", 2);
//Now we create a Multinomial variable with two states: TRUE and FALSE
Variable multinomialVar2 = variables.newMultinomialVariable("Multinomial2", Arrays.asList("TRUE, FALSE"));
//For Multinomial variables we can iterate over their different states
FiniteStateSpace states = multinomialVar2.getStateSpaceType();
states.getStatesNames().forEach(System.out::println);
//Variable objects can also be used, for example, to know if one variable can be set as parent of some other variable
System.out.println("Can a Gaussian variable be parent of Multinomial variable? " +
(multinomialVar.getDistributionType().isParentCompatible(gaussianVar)));
System.out.println("Can a Multinomial variable be parent of Gaussian variable? " +
(gaussianVar.getDistributionType().isParentCompatible(multinomialVar)));
}
}
代码示例来源:origin: amidst/toolbox
/**
* Method to set the class variable.
* @param className String with the name of the class variable
*/
public BayesianLinearRegression setClassName(String className){
setClassVar(vars.getVariableByName(className));
return this;
}
代码示例来源:origin: amidst/toolbox
Variables modelHeader = new Variables(attributes);
Variable globalHiddenVar = modelHeader.newMultinomialVariable("GlobalHidden", 2);
Variable globalHiddenGaussian = modelHeader.newGaussianVariable("globalHiddenGaussian");
Variable classVar = modelHeader.getVariableById(0);
代码示例来源:origin: amidst/toolbox
Variables variables = new Variables();
.forEach(i -> variables.newMultinomialVariable("DiscreteVar" + i, getNumStates()));
.forEach(i -> variables.newGaussianVariable("GaussianVar" + i));
Variable classVar = variables.newMultinomialVariable("ClassVar", getNumStates());
System.out.println("\n Number of variables \n " + bn.getDAG().getVariables().getNumberOfVars());
System.out.println(dag.toString());
代码示例来源:origin: amidst/toolbox
/**
* Builds the DAG structure of a Naive Bayes classifier with a global hidden Gaussian variable.
*/
private void buildGlobalDAG(){
Variables variables = new Variables(attributes);
String className = attributes.getFullListOfAttributes().get(classIndex).getName();
hiddenVars = new ArrayList<Variable>();
for (int i = 0; i < this.numberOfGlobalVars ; i++) {
hiddenVars.add(variables.newGaussianVariable("GlobalHidden_"+i));
}
Variable classVariable = variables.getVariableByName(className);
this.globalDAG = new DAG(variables);
for (Attribute att : attributes.getListOfNonSpecialAttributes()) {
if (att.getName().equals(className))
continue;
Variable variable = variables.getVariableByName(att.getName());
globalDAG.getParentSet(variable).addParent(classVariable);
for (int i = 0; i < this.numberOfGlobalVars ; i++) {
globalDAG.getParentSet(variable).addParent(hiddenVars.get(i));
}
}
System.out.println(globalDAG.toString());
}
代码示例来源:origin: amidst/toolbox
@Override
protected void buildDAG() {
/** Create a set of variables from the given attributes**/
Variables variables = new Variables(attributes);
/** Create a hidden variable with two hidden states*/
Variable hiddenVar = variables.newMultinomialVariable("HiddenVar",2);
//We create a standard naive Bayes
DAG dag = new DAG(variables);
for (Variable variable: variables){
if (variable==hiddenVar)
continue;
dag.getParentSet(variable).addParent(hiddenVar);
}
//This is needed to maintain coherence in the Model class.
this.dag=dag;
this.vars = variables;
}
代码示例来源:origin: amidst/toolbox
Variables modelHeader = new Variables(dataStream.getAttributes());
this.targetVar = modelHeader.getVariableByName(this.nameTarget);
DAG dag = new DAG(modelHeader);
BayesianNetwork bn = new BayesianNetwork(dag);
Variable var = bn.getDAG().getVariables().getVariableById(i);
Node n = nodeList.get(i);
try {
dagLearned = (BNConverterToAMIDST.convertToAmidst(huginNetwork)).getDAG();
dagLearned.getVariables().setAttributes(dataStream.getAttributes());
} catch (ExceptionHugin exceptionHugin) {
System.out.println("ParallelTan LearnDAG Error 6");
代码示例来源:origin: amidst/toolbox
Set<Variable> dynAssigVariables = dynamicAssignment.getVariables();
for (Variable dynVariable : dynAssigVariables) {
Variable staticVariable = unfoldedStaticModel.getVariables().getVariableByName(dynVariable.getName() + "_t" + Integer.toString(time));
double varValue = dynamicAssignment.getValue(dynVariable);
staticEvidence.setValue(staticVariable, varValue);
((ImportanceSamplingRobust)staticModelInference).setVariablesAPosteriori(unfoldedStaticModel.getVariables().getListOfVariables().stream().filter(variable -> variable.getName().contains(MAPvarName)).collect(Collectors.toList()));
Variables variables = Serialization.deepCopy(this.unfoldedStaticModel.getVariables());
Variable currentVar;
if (variables.getVariableByName(MAPvarName + "_t" + Integer.toString(t))!=null) {
currentVar = variables.getVariableByName(MAPvarName + "_t" + Integer.toString(t));
currentVar = variables.newMultinomialVariable(MAPvarName + "_t" + Integer.toString(t), MAPvariable.getNumberOfStates());
代码示例来源:origin: amidst/toolbox
/**
* tests if the attributes passed as an argument in the constructor are suitable
* @return boolean value with the result of the test.
*/
@Override
public boolean isValidConfiguration() {
boolean isValid = vars.getListOfVariables().stream()
.allMatch(Variable::isNormal);
if(!isValid) {
String errorMsg = "Invalid configuration: All variables must be real";
this.setErrorMessage(errorMsg);
}
return isValid;
}
代码示例来源:origin: amidst/toolbox
Variables variables = new Variables();
word = variables.newSparseMultionomialVariable(attributes.getAttributeByName(wordDocumentName));
topicIndicator = variables.newMultinomialVariable("TopicIndicator", nTopics);
代码示例来源:origin: amidst/toolbox
/**
* Builds the DAG over the set of variables given with the naive Bayes structure
*/
@Override
protected void buildDAG() {
//Obtain the predictive attributes
List<Variable> attrVars = vars.getListOfVariables().stream()
.filter(v -> !v.equals(classVar)).collect(Collectors.toList());
//Create the hidden variabels
hiddenMultinomial = vars.newMultinomialVariable("M", numStatesHidden);
contHiddenList = new ArrayList<Variable>();
for(int i=0; i<numContinuousHidden; i++) {
contHiddenList.add(vars.newGaussianVariable("Z"+Integer.toString(i)));
}
dag = new DAG(vars);
//arcs from the class to the hidden variables
dag.getParentSet(hiddenMultinomial).addParent(classVar);
contHiddenList.stream().forEach(z -> dag.getParentSet(z).addParent(classVar));
//arcs from the hidden vars to each attribute
attrVars.stream().forEach(x->dag.getParentSet(x).addParent(hiddenMultinomial));
for (Variable z : contHiddenList) {
attrVars.stream().forEach(x->dag.getParentSet(x).addParent(z));
}
}
/*
代码示例来源:origin: amidst/toolbox
Variables variables = new Variables();
variables.newMultinomialVariable(groupedClassName + "_t" + Integer.toString(mergedClassVarIndex), nStatesMAPVariable);
});
VariableBuilder aux = dynVar.getVariableBuilder();
aux.setName(dynVar.getName() + "_t" + Integer.toString(i));
variables.newVariable(aux);
})
);
代码示例来源:origin: amidst/toolbox
/**
* Builds the DAG
*/
@Override
protected void buildDAG() {
List<Variable> observableVariables = new ArrayList<>();
List<Variable> latentVariables = new ArrayList<>();
vars.forEach(observableVariables::add);
IntStream.range(0,numberOfLatentVariables).forEach(i -> {
Variable latentVar = vars.newGaussianVariable("LatentVar" + i);
latentVariables.add(latentVar);
});
dag = new DAG(vars);
for (Variable variable : observableVariables) {
latentVariables.forEach(latentVariable -> dag.getParentSet(variable).addParent(latentVariable));
}
IntStream.range(0,numberOfLatentVariables).forEach(i -> {
Variable latentVarChildren = vars.getVariableByName("LatentVar" + i);
IntStream.range(0,i).forEach(j -> {
Variable latentVarParent = vars.getVariableByName("LatentVar" + j);
dag.getParentSet(latentVarChildren).addParent(latentVarParent);
});
});
}
代码示例来源:origin: amidst/toolbox
@Override
protected void buildDAG() {
//Obtain the predictive attributes
List<Variable> attrVars = vars.getListOfVariables().stream()
.filter(v -> !v.equals(classVar)).collect(Collectors.toList());
int numAttr = attrVars.size();
/** Create a hidden variable with two hidden states */
Variable globalHiddenVar = vars.newMultinomialVariable("globalHiddenVar",2);
/** Create a list of local hidden variables */
List<Variable> localHidden = new ArrayList<Variable>();
for(int i= 0; i< numAttr; i++) {
localHidden.add(vars.newMultinomialVariable("locallHiddenVar_"+i,2));
}
/** We create a standard naive Bayes */
DAG dag = new DAG(vars);
/** Add the links */
for (int i=0; i<numAttr; i++) {
dag.getParentSet(attrVars.get(i)).addParent(localHidden.get(i));
dag.getParentSet(attrVars.get(i)).addParent(globalHiddenVar);
dag.getParentSet(attrVars.get(i)).addParent(classVar);
}
//This is needed to maintain coherence in the Model class.
this.dag=dag;
}
代码示例来源:origin: amidst/toolbox
/**
* Builds the graph
*/
@Override
protected void buildDAG() {
List<Variable> observableVariables = new ArrayList<>();
List<Variable> latentVariables = new ArrayList<>();
vars.forEach(observableVariables::add);
Variable discreteLatentVar = vars.newMultinomialVariable("DiscreteLatentVar",numberOfStatesLatentDiscreteVar);
IntStream.range(0,numberOfLatentVariables).forEach(i -> {
Variable latentVar = vars.newGaussianVariable("LatentVar" + i);
latentVariables.add(latentVar);
});
dag = new DAG(vars);
for (Variable variable : observableVariables) {
dag.getParentSet(variable).addParent(discreteLatentVar);
latentVariables.forEach(latentVariable -> dag.getParentSet(variable).addParent(latentVariable));
}
}
内容来源于网络,如有侵权,请联系作者删除!