Skip to content

Commit

Permalink
forget the single var scenario when dealing with the VectorizedDistri…
Browse files Browse the repository at this point in the history
…bution #289
  • Loading branch information
walterxie committed Dec 12, 2023
1 parent 68bb587 commit 216531d
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions lphy/src/main/java/lphy/core/parser/LPhyListenerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -276,17 +276,23 @@ public Value visitStoch_relation(Stoch_relationContext ctx) {
Var var = (Var)visit(ctx.getChild(0));
RandomVariable variable = null;

if (genDist instanceof VectorizedDistribution<?> vectDist &&
DataClampingUtils.isDataClamping(var, parserDictionary)) {
if (DataClampingUtils.isDataClamping(var, parserDictionary)) {
// data clamping
Object valueVal = Objects.requireNonNull(parserDictionary.getDataDictionary().get(var.getId())).value();

// when the generator is VectorizedDistribution,
// data clamping requires to wrap the list of component RandomVariable into VectorizedRandomVariable,
// so that the equation and narrative can be generated properly
Object array = Objects.requireNonNull(parserDictionary.getDataDictionary().get(var.getId())).value();
if (array.getClass().isArray()) {
variable = DataClampingUtils.getDataClampedVectorizedRandomVariable(var.getId(), vectDist, (Object[]) array);
LoggerUtils.log.info("Data clamping: the value of " + var.getId() +
" in the 'model' block is replaced by the value of " + var.getId() + " in the 'data' block .");
if (genDist instanceof VectorizedDistribution<?> vectDist && valueVal.getClass().isArray()) {
variable = DataClampingUtils.getDataClampedVectorizedRandomVariable(
var.getId(), vectDist, (Object[]) valueVal);
} else {
// singe var
variable = new RandomVariable(var.getId(), valueVal, genDist);
variable.setClamped(true);
}
LoggerUtils.log.info("Data clamping: the value of " + var.getId() +
" in the 'model' block is replaced by the value of " + var.getId() + " in the 'data' block .");

} else {
variable = genDist.sample(var.getId());
Expand Down

0 comments on commit 216531d

Please sign in to comment.