eu.amidst.core.variables.Variables.getNumberOfVars()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(5.3k)|赞(0)|评价(0)|浏览(103)

本文整理了Java中eu.amidst.core.variables.Variables.getNumberOfVars()方法的一些代码示例,展示了Variables.getNumberOfVars()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Variables.getNumberOfVars()方法的具体详情如下:
包路径:eu.amidst.core.variables.Variables
类名称:Variables
方法名:getNumberOfVars

Variables.getNumberOfVars介绍

暂无

代码示例

代码示例来源: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

/**
 * Constructor of a classifier which is initialized with the default arguments:
 * the last variable in attributes is the class variable and importance sampling
 * is the inference algorithm for making the predictions.
 * @param attributes list of attributes of the classifier (i.e. its variables)
 * @throws WrongConfigurationException is thrown when the attributes passed are not suitable
 * for such classifier
 */
protected Classifier(Attributes attributes) throws WrongConfigurationException {
  super(attributes);
  classVar = vars.getListOfVariables().get(vars.getNumberOfVars()-1);
  inferenceAlgoPredict = new ImportanceSampling();
}

代码示例来源:origin: amidst/toolbox

@Override
public boolean isValidConfiguration(){
  boolean isValid = true;
  long numReal = vars.getListOfVariables().stream()
      .filter( v -> v.getStateSpaceTypeEnum().equals(StateSpaceTypeEnum.REAL))
      .count();
  long numFinite = vars.getListOfVariables().stream()
      .filter( v -> v.getStateSpaceTypeEnum().equals(StateSpaceTypeEnum.FINITE_SET))
      .count();
  if(numFinite != 1 || numReal != vars.getNumberOfVars()-1) {
    isValid = false;
    String errorMsg = "Invalid configuration: wrong number types of variables domains. It should contain 1 discrete variable and the rest shoud be real";
    this.setErrorMessage(errorMsg);
  }
  return  isValid;
}

代码示例来源:origin: amidst/toolbox

public boolean isValidConfiguration(){
  boolean isValid = true;
  long numReal = vars.getListOfVariables().stream()
      .filter( v -> v.getStateSpaceTypeEnum().equals(StateSpaceTypeEnum.REAL))
      .count();
  long numFinite = vars.getListOfVariables().stream()
      .filter( v -> v.getStateSpaceTypeEnum().equals(StateSpaceTypeEnum.FINITE_SET))
      .count();
  if(numFinite != 1 || numReal != vars.getNumberOfVars()-1) {
    isValid = false;
    String errorMsg = "Invalid configuration: wrong number types of variables domains. It should contain 1 discrete variable and the rest shoud be real";
    this.setErrorMessage(errorMsg);
  }
  return  isValid;
}

代码示例来源:origin: amidst/toolbox

public static void main(String[] args) throws Exception {

  // load the true Bayesian network
  BayesianNetwork originalBnet = BayesianNetworkLoader.loadFromFile(args[0]);

  System.out.println("\n Network \n " + args[0]);
  System.out.println("\n Number of variables \n " + originalBnet.getDAG().getVariables().getNumberOfVars());

  //Sampling from the input BN
  BayesianNetworkSampler sampler = new BayesianNetworkSampler(originalBnet);
  sampler.setSeed(0);

  // Defines the size of the data to be generated from the input BN
  int sizeData = Integer.parseInt(args[1]);

  System.out.println("\n Sampling and saving the data... \n ");
  
  DataStream<DataInstance> data = sampler.sampleToDataStream(sizeData);

  DataStreamWriter.writeDataToFile(data, "./data.arff");
}

代码示例来源:origin: amidst/toolbox

public static void main(String[] args) throws Exception {
  final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
  DataFlink<DataInstance> dataFlink = DataFlinkLoader.loadDataFromFile(env, "./data.arff", false);
  DAG dag = SetBNwithHidden.getHiddenNaiveBayesStructure(dataFlink);
  BayesianNetwork bnet = new BayesianNetwork(dag);
  System.out.println("\n Number of variables \n " + bnet.getDAG().getVariables().getNumberOfVars());
  System.out.println(dag.toString());
  BayesianNetworkWriter.save(bnet, "./BNHiddenExample.bn");
}

代码示例来源:origin: amidst/toolbox

System.out.println("\n Number of variables \n " + bn.getDAG().getVariables().getNumberOfVars());
System.out.println(dag.toString());

代码示例来源:origin: amidst/toolbox

@Override
protected void buildDAG() {
  int numPredictiveAtts = vars.getNumberOfVars()-1;

代码示例来源:origin: amidst/toolbox

/**
 * Sets the Hugin nodes from the AMIDST variables.
 * @param amidstBN the Bayesian network model in AMIDST format.
 * @throws ExceptionHugin
 */
private void setNodes(BayesianNetwork amidstBN) throws ExceptionHugin {
  Variables amidstVars = amidstBN.getVariables();
  int size = amidstVars.getNumberOfVars();
  //Hugin always inserts variables at position 0, i.e, for an order A,B,C, it stores C,B,A
  //A reverse order of the variables is needed instead.
  for(int i=1;i<=size;i++){
    Variable amidstVar = amidstVars.getVariableById(size-i);
    if(amidstVar.isMultinomial()){
      LabelledDCNode n = new LabelledDCNode(this.huginBN);
      n.setName(amidstVar.getName());
      n.setNumberOfStates(amidstVar.getNumberOfStates());
      n.setLabel(amidstVar.getName());
      for (int j=0;j<n.getNumberOfStates();j++){
        String stateName = ((FiniteStateSpace)amidstVar.getStateSpaceType()).getStatesName(j);
        n.setStateLabel(j, stateName);
      }
    } else if (amidstVar.isNormal()) {
      ContinuousChanceNode c = new ContinuousChanceNode(this.huginBN);
      c.setName(amidstVar.getName());
    } else {
      throw new IllegalArgumentException("Unrecognized DistributionType:" + amidstVar.getDistributionTypeEnum().toString());
    }
  }
}

相关文章