本文整理了Java中eu.amidst.core.variables.Variables.<init>()
方法的一些代码示例,展示了Variables.<init>()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Variables.<init>()
方法的具体详情如下:
包路径:eu.amidst.core.variables.Variables
类名称:Variables
方法名:<init>
暂无
代码示例来源: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
/**
* Returns the class variable.
* @param modelContext a {@link moa.core.InstancesHeader} object.
* @param atts a set of of {@link Attributes}.
* @return a {@link Variable} object that represents the class variable.
*/
public static Variable getClassVariable(InstancesHeader modelContext, Attributes atts){
Variables variables = new Variables(atts);
String className = modelContext.classAttribute().name();
return variables.getVariableByName(className);
}
代码示例来源:origin: amidst/toolbox
public Model(Attributes attributes) {
this.atts = attributes;
vars = new Variables(attributes);
if(!this.isValidConfiguration()) {
throw new WrongConfigurationException(getErrorMessage());
}
}
代码示例来源: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
Variables variables = new Variables();
代码示例来源: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
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
Variables variables = new Variables();
word = variables.newSparseMultionomialVariable(attributes.getAttributeByName(wordDocumentName));
代码示例来源:origin: amidst/toolbox
Variables variables = new Variables();
word = variables.newSparseMultionomialVariable(attributes.getAttributeByName(wordDocumentName));
代码示例来源:origin: amidst/toolbox
public static DAG getHiddenNaiveBayesStructure(DataFlink<DataInstance> dataStream) {
Variables modelHeader = new Variables(dataStream.getAttributes());
代码示例来源: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
/**
* 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
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
Variables variables = new Variables();
代码示例来源:origin: amidst/toolbox
Variables variables = new Variables();
代码示例来源: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
/**
* {@inheritDoc}
*/
@Override
public void initLearning() {
super.initLearning();
truncatedExpVar = new Variables().newTruncatedExponential("TruncatedExponentialVar");
this.ef_TExpP = truncatedExpVar.getDistributionType().newEFUnivariateDistribution(this.getDelta());
prior = this.plateuStructure.getPlateauNaturalParameterPrior();
int size = prior.getNumberOfBaseVectors();
this.ef_TExpQ = new EF_TruncatedExponential[size];
for (int i = 0; i < size; i++) {
this.ef_TExpQ[i] = truncatedExpVar.getDistributionType().newEFUnivariateDistribution(this.getDelta());
}
firstBatch=true;
}
代码示例来源:origin: amidst/toolbox
/**
* {@inheritDoc}
*/
@Override
public void initLearning() {
super.initLearning();
truncatedExpVar = new Variables().newTruncatedExponential("TruncatedExponentialVar");
this.ef_TExpP = truncatedExpVar.getDistributionType().newEFUnivariateDistribution(this.getDelta());
prior = this.plateuStructure.getPlateauNaturalParameterPrior();
for (Variable variable : this.plateuStructure.getNonReplicatedVariables()) {
if (variable.getNumberOfStates()>maxsize)
maxsize=variable.getNumberOfStates();
}
this.ef_TExpQ = new EF_TruncatedExponential[prior.getNumberOfBaseVectors()][maxsize];
for (int i = 0; i < this.ef_TExpQ.length; i++) {
for (int j = 0; j < this.ef_TExpQ[i].length; j++) {
this.ef_TExpQ[i][j] = truncatedExpVar.getDistributionType().newEFUnivariateDistribution(this.getDelta());
}
}
firstBatch=true;
}
代码示例来源: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
public static BayesianNetwork createFireDetectorModel(double tempMean) {
Variables variables = new Variables();
内容来源于网络,如有侵权,请联系作者删除!