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

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

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

Variables.getListOfVariables介绍

暂无

代码示例

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

/**
 * 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

/**
 * 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

/**
 * tests if the attributes passed as an argument in the constructor are suitable for this classifier
 * @return boolean value with the result of the test.
 */
@Override
public boolean isValidConfiguration(){
  boolean isValid = true;
  if(!vars.getListOfVariables().stream()
      .map( v -> v.getStateSpaceTypeEnum().equals(StateSpaceTypeEnum.REAL))
      .reduce((n1,n2) -> n1 && n2).get().booleanValue()){
    isValid = false;
    System.err.println("Invalid configuration: all the variables must be real");
  }
  return  isValid;
}

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

/**
 * tests if the attributes passed as an argument in the constructor are suitable for this classifier
 * @return boolean value with the result of the test.
 */
@Override
public boolean isValidConfiguration(){
  boolean isValid = true;
  if(!vars.getListOfVariables().stream()
      .map( v -> v.getStateSpaceTypeEnum().equals(StateSpaceTypeEnum.REAL))
      .reduce((n1,n2) -> n1 && n2).get().booleanValue()){
    isValid = false;
    System.err.println("Invalid configuration: all the variables must be real");
  }
  return  isValid;
}

代码示例来源: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 Stream<DataInstance> stream() {
  return this.stream().map(a -> new DataInstanceFromAssignment(a, this.atts, this.variables.getListOfVariables()));
}

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

/**
 * Builds the DAG over the set of variables given with the structure of the model
 */
@Override
protected void buildDAG() {
  dag = new DAG(vars);
  // add the links between the attributes (features)
  List<Variable> attrVars = vars.getListOfVariables();
  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

@Override
public boolean isValidConfiguration() {
  boolean isValid = true;
  long numFinite = vars.getListOfVariables().stream()
      .filter( v -> v.getStateSpaceTypeEnum().equals(StateSpaceTypeEnum.FINITE_SET))
      .count();
  if(numFinite <2) {
    isValid = false;
    String errorMsg = "Invalid configuration: There should be at least 2 discrete variables (root and class)";
    this.setErrorMessage(errorMsg);
  }
  return  isValid;
}

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

@Override
public boolean isValidConfiguration() {
  boolean isValid = true;
  long numFinite = vars.getListOfVariables().stream()
      .filter( v -> v.getStateSpaceTypeEnum().equals(StateSpaceTypeEnum.FINITE_SET))
      .count();
  long numReal = vars.getListOfVariables().stream()
      .filter( v -> v.getStateSpaceTypeEnum().equals(StateSpaceTypeEnum.REAL))
      .count();
  if(numFinite > 1 && numReal > 0) {
    isValid = false;
    String errorMsg = "Invalid configuration: There should be at least 2 discrete variables (root and class)";
    this.setErrorMessage(errorMsg);
  }
  return  isValid;
}

代码示例来源: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(v -> v.getStateSpaceTypeEnum().equals(StateSpaceTypeEnum.REAL));
  if(!isValid) {
    setErrorMessage("All the variables must be REAL");
  }
  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

/**
 * tests if the attributes passed as an argument in the constructor are suitable for this classifier
 * @return boolean value with the result of the test.
 */
@Override
public boolean isValidConfiguration(){
  boolean isValid = true;
  long numFinite = vars.getListOfVariables().stream()
      .filter( v -> v.getStateSpaceTypeEnum().equals(StateSpaceTypeEnum.FINITE_SET))
      .count();
  if(numFinite == 0) {
    isValid = false;
    String errorMsg = "It should contain at least 1 discrete variable and the rest shoud be real";
    this.setErrorMessage(errorMsg);
  }
  return  isValid;
}

代码示例来源: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 DataStreamFromStreamOfAssignments(Variables variables, Stream<Assignment> stream){
  this.variables = variables;
  this.stream = stream;
  List<Attribute> list = this.variables.getListOfVariables().stream()
      .map(var -> new Attribute(var.getVarID(), var.getName(), var.getStateSpaceType())).collect(Collectors.toList());
  this.atts= new Attributes(list);
}

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

/**
 * Builds the DAG of the model.
 */
@Override
protected void buildDAG() {
  dag = new DAG(vars);
  //arcs from the features to the class
  vars.getListOfVariables().stream()
      .filter(v -> !v.equals(classVar))
      .forEach(v -> dag.getParentSet(classVar).addParent(v));
  // if it is not diagonal add the links between the attributes (features)
  if(!isDiagonal()) {
    List<Variable> attrVars = vars.getListOfVariables().stream().filter(v -> !v.equals(classVar)).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 DAG over the set of variables given with the naive Bayes structure
 */
@Override
protected void buildDAG() {
  //We create a standard naive Bayes
  dag = new DAG(vars);
  dag.getParentSets().stream().filter(w -> !w.getMainVar().equals(classVar)).forEach(w -> w.addParent(classVar));
  // if it is not diagonal add the links between the attributes (features)
  if(!isDiagonal()) {
    List<Variable> attrVars = vars.getListOfVariables().stream().filter(v -> !v.equals(classVar)).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 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

@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

@Override
public void mapPartition(Iterable<DynamicDataInstance> values, Collector<DynamicDataInstance> out) throws Exception {
  values.forEach(d -> {
    HashMapAssignment pastAssignment = new HashMapAssignment();
    for (Attribute att : d.getAttributes().getListOfNonSpecialAttributes()){
      pastAssignment.setValue(bn.getVariables().getVariableByName(att.getName()+ DynamicVariables.INTERFACE_SUFFIX),d.getValue(att));
    }
    Assignment assignment = sample(bn, causalOrder, random, pastAssignment);
    hiddenVars.keySet().stream().forEach(var -> assignment.setValue(bn.getVariables().getVariableByName(var.getName()),Utils.missingValue()));
    marVars.entrySet().forEach(e -> {
      if (random.nextDouble()<e.getValue())
        assignment.setValue(bn.getVariables().getVariableByName(e.getKey().getName()),Utils.missingValue());
    });
    DataInstance dataInstanceNew = new DataStreamFromStreamOfAssignments.DataInstanceFromAssignment(assignment,attributes, bn.getVariables().getListOfVariables());
    DynamicDataInstanceWrapper wrapper = new DynamicDataInstanceWrapper(dataInstanceNew,attributes,d.getSequenceID(), d.getTimeID()+1);
    out.collect(wrapper);
  });
}

相关文章