Package unbbayes.prs.mebn.compiler.exception

Examples of unbbayes.prs.mebn.compiler.exception.InvalidProbabilityRangeException


      INestedIfElseClauseContainer currentIfContainer = this.currentHeader;
      // if there is a nested if, this if should be the upper clause (set currentHeader as upper clause).
      statement(currentIfContainer);
    } catch (TableFunctionMalformedException e) {
      // Debug.println("->" + getNode());e.printStackTrace();
      throw new InvalidProbabilityRangeException("["+this.getNode().getName()+"]",e);
    }
   
   
   
    // Debug.println("LOOKING FOR ELSE STATEMENT");
View Full Code Here


        if (!(getNode() instanceof ContinuousResidentNode)) {
          // ignore continuous nodes, because sum may not be 1
          if (!this.currentHeader.isSumEquals1()) {
            // Debug.println("Testing cell's probability value's sum: " + currentHeader.getProbCellSum());
            if (!Float.isNaN(this.currentHeader.getProbCellSum())) {
              throw new InvalidProbabilityRangeException();
            } else {
              // Debug.println("=>NaN found!!!");
            }
          }
        }
View Full Code Here

        // if it is not parsable, then it is unknown
        float retValueFloat = Float.parseFloat(retValue);
        // consistency check C09
        // a single state shall never have prob range out from [0,1]
        if ( (retValueFloat < 0.0) || (1.0 < retValueFloat)) {
          throw new InvalidProbabilityRangeException();
        }
      } catch (InvalidProbabilityRangeException e) {
        // InvalidProbabilityRangeException may become a subclass of NumberFormatException in a future.
        // this is to guarantee that InvalidProbabilityRangeException is thrown even in such case.
        throw e;
      } catch (NumberFormatException e) {
        hasUnknownValue = true;
      }
    }
   
    // add cell to header
    currentCell.setProbability(ret);
    if (currentCell.getPossibleValue() != null   // this is an assignment ::= state = probability
//        || (isAssigningToNoState && (possibleStates == null || possibleStates.isEmpty()))) {  // this is an expression, and node has no possible state
        || isAssigningToNoState ) {  // this is an expression (not an assignment)
      this.currentHeader.addCell(currentCell);
      // if node has no possible value, add current cell, although it has no related entity (state)
    }
    // Debug.println("Adding cell: " + currentCell.getPossibleValue().name + " = " + ret.toString());
   
   
    // LOOK FOR , (OPTIONAL)
    if (look == ',') {
      match(',');
      AProbabilityValue temp = assignment(declaredStates, possibleStates);
      String tempValue = temp.getValue();
      hasUnknownValue = hasUnknownValue || (tempValue== null);
      if (hasUnknownValue) {
        // TODO we are returning null, but if a combining rule must be applied for assignments, then it should return an string expression...
        retValue = null;
      } else {
        try {
          retValue = String.valueOf(Float.parseFloat(retValue) + Float.parseFloat(temp.getValue()));
        } catch (NumberFormatException e) {
          retValue = null;
        }
      }
    } else {
      // this is the last assignment. If there are undeclared states, force their values to 0%.
      // obtain undeclared states = possibleStates - declaredStates
      Collection<Entity> undeclaredStates = new HashSet<Entity>(possibleStates);
      undeclaredStates.removeAll(declaredStates);
      for (Entity entity : undeclaredStates) {
        if (entity != null) {
          if (isAssigningToNoState) {
            // if node has state and this is an expression (not an assignment), then all states will have the current expression as its value
            // do not add again, because previous "this.currentHeader.addCell(currentCell);" (line 1038) is adding a cell with no entity
            // so that a cell with no entity represents a non-assignment
//            this.currentHeader.addCell(new TempTableProbabilityCell(entity, ret));
          } else {
            // add assignment: <undeclared state> = 0.0,
            this.currentHeader.addCell(new TempTableProbabilityCell(entity, new SimpleProbabilityValue(0.0f)));
          }
          declaredStates.add(entity);
        }
        // we do not need to update retValue (the total probability),
        // because it would be something like retValue += 0.0 (that is, it will not be altered at all);
      }
    }
   
    Float retValueFloat = Float.NaN;
    try {
      if (retValue != null) {
        retValueFloat = Float.parseFloat(retValue);
      }
    } catch (NumberFormatException e) {
      // in this case, retValueFloat = Float.NaN;
    }

    // Debug.println("Returned expression value = " + retValue);
    if (!Float.isNaN(retValueFloat) && (retValueFloat < 0)) {
      throw new InvalidProbabilityRangeException();
    }
   
    return new SimpleProbabilityValue(retValueFloat);
  }
View Full Code Here

TOP

Related Classes of unbbayes.prs.mebn.compiler.exception.InvalidProbabilityRangeException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.