net.sf.tweety.logics.pl.util

## Class SyntacticRandomSampler

• All Implemented Interfaces:
java.util.Iterator<PlBeliefSet>, BeliefSetIterator<PropositionalFormula,PlBeliefSet>

```public class SyntacticRandomSampler
extends BeliefSetSampler<PropositionalFormula,PlBeliefSet>```

This sampler implements a random generation algorithm for generating formulas, based on the syntax tree of propositional formulas. Consider the following BNF for a propositional logic formula:

F ::== !F | F && F | F || F | A

with propositions A. The algorithm for constructing formulas takes four parameters:

• probneg: the probability to generate a negation
• probconj: the probability to generate a conjunction
• probdisj: the probability to generate a disjunction
• recDecrease: a value in (0,1) by which the above probabilities are multiplied in each recursive step to increase likelihood of termination.
From these parameters the probability to generate a proposition "probprop" is computed via probprop=1-probneg-probconj-probdisj (the actual proposition is selected with a uniform distribution). Then a formula is generated by randomly selecting which rule in the above BNF is followed wrt. these probabilities. Note that the algorithm is not guaranteed to terminate.

Author:
Matthias Thimm
• ### Field Summary

Fields
Modifier and Type Field and Description
`private static byte` `CONJ`
`private static byte` `DISJ`
`private static byte` `NEG`
`private ProbabilityFunction<java.lang.Byte>` `prob`
The probability function modeling the random decisions.
`private ProbabilityFunction<Proposition>` `probProp`
The probability function used to sample propositions
`private static byte` `PROP`
`private java.util.Random` `rand`
`private double` `recDecrease`
• ### Fields inherited from class net.sf.tweety.commons.BeliefSetSampler

`DEFAULT_MAXIMUM_BELIEFBASE_LENGTH, DEFAULT_MINIMUM_BELIEFBASE_LENGTH`
• ### Constructor Summary

Constructors
Constructor and Description
```SyntacticRandomSampler(Signature signature, Probability probneg, Probability probconj, Probability probdisj, double recDecrease)```
Creates a new sampler.
```SyntacticRandomSampler(Signature signature, Probability probneg, Probability probconj, Probability probdisj, double recDecrease, int minLength, int maxLength)```
Creates a new sampler.
• ### Method Summary

All Methods
Modifier and Type Method and Description
`private ProbabilityFunction<java.lang.Byte>` ```decrease(ProbabilityFunction<java.lang.Byte> prob, double value)```
Adapts the given probability function by decreasing the probabilities of NEG, CONJ and DISJ.
`PlBeliefSet` `next()`
`PropositionalFormula` `sampleFormula(ProbabilityFunction<java.lang.Byte> prob)`
Samples a single formula.
• ### Methods inherited from class net.sf.tweety.commons.BeliefSetSampler

`getMaxLength, getMinLength, getSignature, hasNext`
• ### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`
• ### Methods inherited from interface java.util.Iterator

`forEachRemaining, remove`
• ### Field Detail

• #### prob

`private ProbabilityFunction<java.lang.Byte> prob`
The probability function modeling the random decisions.
• #### probProp

`private ProbabilityFunction<Proposition> probProp`
The probability function used to sample propositions
• #### recDecrease

`private double recDecrease`
• #### CONJ

`private static final byte CONJ`
Constant Field Values
• #### DISJ

`private static final byte DISJ`
Constant Field Values
• #### PROP

`private static final byte PROP`
Constant Field Values
• #### rand

`private java.util.Random rand`
• ### Constructor Detail

• #### SyntacticRandomSampler

```public SyntacticRandomSampler(Signature signature,
Probability probneg,
Probability probconj,
Probability probdisj,
double recDecrease)```
Creates a new sampler.
Parameters:
`signature` - some set of propositions
`probneg` - the probability to generate a negation
`probconj` - the probability to generate a conjunction
`probdisj` - the probability to generate a disjunction
`recDecrease` - a value in (0,1) by which the above probabilities are multiplied in each recursive step to increase likelihood of termination.
• #### SyntacticRandomSampler

```public SyntacticRandomSampler(Signature signature,
Probability probneg,
Probability probconj,
Probability probdisj,
double recDecrease,
int minLength,
int maxLength)```
Creates a new sampler.
Parameters:
`signature` - some set of propositions
`probneg` - the probability to generate a negation
`probconj` - the probability to generate a conjunction
`probdisj` - the probability to generate a disjunction
`recDecrease` - a value in (0,1) by which the above probabilities are multiplied in each recursive step to increase likelihood of termination.
`minLength` - the minimum length of knowledge bases
`maxLength` - the maximum length of knowledge bases
• ### Method Detail

• #### decrease

```private ProbabilityFunction<java.lang.Byte> decrease(ProbabilityFunction<java.lang.Byte> prob,
double value)```
Adapts the given probability function by decreasing the probabilities of NEG, CONJ and DISJ.
Parameters:
`prob` - a probability function.
`value` - some value in (0,1)
Returns:
the modified probability function.
• #### sampleFormula

`public PropositionalFormula sampleFormula(ProbabilityFunction<java.lang.Byte> prob)`
Samples a single formula.
Returns:
a single formula.
• #### next

`public PlBeliefSet next()`
Specified by:
`next` in interface `java.util.Iterator<PlBeliefSet>`
Specified by:
`next` in interface `BeliefSetIterator<PropositionalFormula,PlBeliefSet>`
Specified by:
`next` in class `BeliefSetSampler<PropositionalFormula,PlBeliefSet>`
Returns: