本文整理了Java中eu.amidst.core.variables.Variables.newMultinomialVariable()
方法的一些代码示例,展示了Variables.newMultinomialVariable()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Variables.newMultinomialVariable()
方法的具体详情如下:
包路径:eu.amidst.core.variables.Variables
类名称:Variables
方法名:newMultinomialVariable
暂无
代码示例来源: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 DAG over the set of variables given with the structure of the model
*/
@Override
protected void buildDAG() {
hiddenVar = vars.newMultinomialVariable("HiddenVar",numStatesHiddenVar);
//We create a standard naive Bayes
dag = new DAG(vars);
dag.getParentSets().stream().filter(w -> !w.getMainVar().equals(hiddenVar)).forEach(w -> w.addParent(hiddenVar));
// if it is not diagonal add the links between the attributes (features)
if(!isDiagonal()) {
List<Variable> attrVars = vars.getListOfVariables().stream().filter(v -> !v.equals(hiddenVar)).collect(Collectors.toList());
for (int i=0; i<attrVars.size()-1; i++){
for(int j=i+1; j<attrVars.size(); j++) {
// Add the links
dag.getParentSet(attrVars.get(i)).addParent(attrVars.get(j));
}
}
}
}
代码示例来源: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));
}
}
代码示例来源: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
/**
* 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.newMultinomialVariable(groupedClassName + "_t" + Integer.toString(mergedClassVarIndex), nStatesMAPVariable);
});
代码示例来源:origin: amidst/toolbox
@Override
protected void buildDAG() {
Variable superParentVar = vars.newMultinomialVariable("superParentVar",getNumStates());
dag = new DAG(vars);
dag.getParentSets()
.stream()
.filter(w -> !w.getMainVar().equals(classVar))
.filter(w -> !w.getMainVar().equals(superParentVar))
.forEach(w -> {
w.addParent(classVar);
w.addParent(superParentVar);
});
dag.getParentSet(superParentVar).addParent(classVar);
}
代码示例来源: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
topicIndicator = variables.newMultinomialVariable("TopicIndicator", nTopics);
代码示例来源:origin: amidst/toolbox
topicIndicator = variables.newMultinomialVariable("TopicIndicator", nTopics);
代码示例来源:origin: amidst/toolbox
Variable globalHiddenDiscrete = modelHeader.newMultinomialVariable("globalHiddenDiscrete", 2);
代码示例来源:origin: amidst/toolbox
Variable globalHiddenVar = modelHeader.newMultinomialVariable("GlobalHidden", 2);
代码示例来源:origin: amidst/toolbox
.forEach(i -> variables.newMultinomialVariable("DiscreteVar" + i, getNumStates()));
Variable classVar = variables.newMultinomialVariable("ClassVar", getNumStates());
Variable discreteHiddenVar = variables.newMultinomialVariable("DiscreteSPVar", getNumStatesHiddenDiscVars());
代码示例来源:origin: amidst/toolbox
.forEach(i -> variables.newMultinomialVariable("DiscreteVar" + i, getNumStates()));
Variable classVar = variables.newMultinomialVariable("ClassVar", getNumStates());
Variable discreteHiddenVar = variables.newMultinomialVariable("DiscreteSPVar", getNumStatesHiddenDiscVars());
代码示例来源: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
@Override
public void buildClusterer(Instances data) throws Exception {
attributes_ = Converter.convertAttributes(data.enumerateAttributes());
Variables modelHeader = new Variables(attributes_);
clusterVar_ = modelHeader.newMultinomialVariable("clusterVar", this.numberOfClusters());
inferenceAlgorithm_ = new ImportanceSampling();
inferenceAlgorithm_.setSeed(this.getSeed());
dag = new DAG(modelHeader);
/* Set DAG structure. */
/* Add the hidden cluster variable as a parent of all the predictive attributes. */
dag.getParentSets().stream()
.filter(w -> w.getMainVar().getVarID() != clusterVar_.getVarID())
.filter(w -> w.getMainVar().isObservable())
.forEach(w -> w.addParent(clusterVar_));
System.out.println(dag.toString());
parameterLearningAlgorithm_ = new SVB();
parameterLearningAlgorithm_.setDAG(dag);
DataOnMemoryListContainer<DataInstance> batch_ = new DataOnMemoryListContainer(attributes_);
data.stream().forEach(instance ->
batch_.add(new DataInstanceFromDataRow(new DataRowWeka(instance, this.attributes_)))
);
parameterLearningAlgorithm_.setDataStream(batch_);
parameterLearningAlgorithm_.initLearning();
parameterLearningAlgorithm_.runLearning();
bnModel_ = parameterLearningAlgorithm_.getLearntBayesianNetwork();
System.out.println(bnModel_);
inferenceAlgorithm_.setModel(bnModel_);
}
代码示例来源:origin: amidst/toolbox
clusterVar_ = modelHeader.newMultinomialVariable("clusterVar", getNumClusters());
代码示例来源:origin: amidst/toolbox
/**
* Define the Fire Dectector Model's DAG.
* @param attributes
* @return
*/
public static DAG creatFireDectectorModel(Attributes attributes){
/********** Model Definition ************/
//Create the object handling the random variables of the model
Variables variables = new Variables();
//Create the random variables of the model. Some of them are associated to one attribute to retrieve its observed values from the data set.
Variable fire = variables.newMultinomialVariable(attributes.getAttributeByName("Fire"));
Variable temperature = variables.newGaussianVariable("Temperature");
Variable smoke = variables.newMultinomialVariable("Smoke",2);
Variable sensorT1 = variables.newGaussianVariable(attributes.getAttributeByName("SensorTemp1"));
Variable sensorT2 = variables.newGaussianVariable(attributes.getAttributeByName("SensorTemp2"));
Variable sensorSmoke = variables.newGaussianVariable(attributes.getAttributeByName("SensorSmoke"));
//Create the directed acyclic graph object encoding the conditional independe relaionship among the variables of the model.
DAG dag = new DAG(variables);
//Define the parent set for each random variable
dag.getParentSet(sensorT1).addParent(temperature);
dag.getParentSet(sensorT2).addParent(temperature);
dag.getParentSet(sensorSmoke).addParent(smoke);
dag.getParentSet(temperature).addParent(fire);
dag.getParentSet(smoke).addParent(fire);
return dag;
}
代码示例来源:origin: amidst/toolbox
Variable fire = variables.newMultinomialVariable("Fire", 2);
Variable temperature = variables.newGaussianVariable("Temperature");
Variable smoke = variables.newMultinomialVariable("Smoke", 2);
Variable sensorT1 = variables.newGaussianVariable("SensorTemp1");
Variable sensorT2 = variables.newGaussianVariable("SensorTemp2");
代码示例来源:origin: amidst/toolbox
Variable fire = variables.newMultinomialVariable("Fire", 2);
Variable temperature = variables.newGaussianVariable("Temperature");
Variable smoke = variables.newMultinomialVariable("Smoke", 2);
Variable sensorT1 = variables.newGaussianVariable("SensorTemp1");
Variable sensorT2 = variables.newGaussianVariable("SensorTemp2");
内容来源于网络,如有侵权,请联系作者删除!