Synthia
Generic and flexible data structure generator
ExplanationList2.java
Go to the documentation of this file.
1 /*
2  Synthia, a data structure generator
3  Copyright (C) 2019-2021 Laboratoire d'informatique formelle
4  Université du Québec à Chicoutimi, Canada
5 
6  This program is free software: you can redistribute it and/or modify
7  it under the terms of the GNU Lesser General Public License as published
8  by the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU Lesser General Public License for more details.
15 
16  You should have received a copy of the GNU Lesser General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 package examples.provenance;
20 
21 import java.util.List;
22 
23 import ca.uqac.lif.petitpoucet.ComposedPart;
24 import ca.uqac.lif.petitpoucet.PartNode;
25 import ca.uqac.lif.petitpoucet.function.LineageDotRenderer;
26 import ca.uqac.lif.petitpoucet.function.vector.NthElement;
34 import ca.uqac.lif.synthia.util.Freeze;
35 import ca.uqac.lif.synthia.util.Tick;
37 import examples.util.Utilities;
38 
39 /**
40  * A variation of {@link ExplanationList1} where a different explanation is
41  * requested, showing that fine-grained parts of the output can be tracked.
42  * <p>
43  * This example contains the same code as {@link ExplanationList1}, with the
44  * exception of the call to
45  * {@link Explanation#explain(ca.uqac.lif.petitpoucet.Part, ca.uqac.lif.synthia.Picker) Explanation.explain()}.
46  * This time, the part of the output for which an explanation is requested is
47  * the first coordinate of the second point inside the first list output by
48  * {@link ComposeList}. Given that the picker produces the list
49  * [[1,-1],[<b><u>2</u></b>,1],[3,0],[4,-1]], this corresponds to asking the
50  * provenance of number 2 (in bold).
51  *
52  * @ingroup Examples
53  */
54 public class ExplanationList2
55 {
56  @SuppressWarnings("unchecked")
57  public static void main(String[] args)
58  {
59  /* Step 1: create the pickers and connect them. These lines of code create
60  * exactly the pipeline shown in the picture above. */
61  RandomInteger r_int = new RandomInteger(1, 3);
62  r_int.setSeed(40002); // Modify this seed to make r_int pick another value
63  Freeze<Integer> fr_int = new Freeze<Integer>(r_int);
65  Tick t = new Tick(zero, fr_int);
66  Playback<Integer> pb = new Playback<Integer>(0, new Integer[] {0, -1, 1}).setLoop(true);
67  PrismPicker hp = new PrismPicker(t, pb);
68  PickIf<float[]> filter = new PickIf<float[]>(hp) {
69  protected boolean select(float[] p) { return p[0] != p[1]; }
70  };
72  ComposeList<float[]> list = new ComposeList<float[]>(filter, four);
73 
74  /* Step 2: ask for a first list out of ComposeList and display it */
75  List<float[]> l = list.pick();
76  Utilities.println(System.out, l);
77 
78  /* Step 3: request the explanation graph for the first element of
79  * the first list produced by ComposeList. */
80  PartNode tree = Explanation.explain(ComposedPart.compose(new NthElement(0), new NthElement(2), NthSuccessiveOutput.FIRST), list);
81  LineageDotRenderer renderer = new LineageDotRenderer(tree);
82  renderer.render(System.out);
83  }
84 }
ca.uqac.lif.synthia.explanation.NthSuccessiveOutput.FIRST
static final NthSuccessiveOutput FIRST
A static reference to an instance of the class with index = 0, thereby referring to the first output ...
Definition: NthSuccessiveOutput.java:42
ca.uqac.lif.synthia.util.Freeze
Picker that returns the first object fetched from another picker and repeats it endlessly.
Definition: Freeze.java:48
ca.uqac.lif.synthia.collection.ComposeList.pick
List< T > pick()
Picks an object.
Definition: ComposeList.java:94
examples.provenance.ExplanationList2
A variation of ExplanationList1 where a different explanation is requested, showing that fine-grained...
Definition: ExplanationList2.java:54
ca.uqac.lif.synthia.collection
Pickers generating and manipulating collections, such as lists and sets.
Definition: ComparableList.java:19
ca.uqac.lif.synthia.util
Miscellaneous pickers performing various functions.
Definition: ArrayPicker.java:19
ca.uqac.lif.synthia.vector.PrismPicker
Generates a vector by independently picking a value for each of its coordinates.
Definition: PrismPicker.java:38
ca.uqac.lif.synthia.explanation.Explanation.explain
static PartNode explain(Part part, Picker<?> picker)
Definition: Explanation.java:44
ca.uqac.lif.synthia.vector
Pickers generating multi-dimensional numerical vectors.
Definition: HyperspherePicker.java:19
ca.uqac.lif.synthia.sequence.Playback
Picker that returns values taken from a list.
Definition: Playback.java:61
ca.uqac
examples.util
Definition: package-info.java:1
ca.uqac.lif.synthia.random
Pickers that produce pseudo-random objects such as numbers.
Definition: AffineTransform.java:19
ca.uqac.lif.synthia
Definition: Bounded.java:19
ca.uqac.lif.synthia.util.Constant
Picker that returns the same object every time.
Definition: Constant.java:37
examples.util.Utilities.println
static void println(PrintStream ps, Object o)
Calls print(PrintStream, Object) and appends a new line.
Definition: Utilities.java:111
examples.util.Utilities
Object providing a few utility methods to simplify the examples in this project.
Definition: Utilities.java:30
ca.uqac.lif.synthia.explanation
Objects related to the explanation of results produced by pickers.
Definition: Explanation.java:19
ca.uqac.lif
ca.uqac.lif.synthia.random.RandomInteger.setSeed
RandomInteger setSeed(int seed)
Definition: RandomInteger.java:102
ca.uqac.lif.synthia.random.RandomInteger
Picks an integer uniformly in an interval.
Definition: RandomInteger.java:31
ca.uqac.lif.synthia.relative.PickIf
Returns object from a picker satisfying a condition.
Definition: PickIf.java:39
ca.uqac.lif.synthia.util.Tick
Generates a sequence of monotonically increasing numerical values.
Definition: Tick.java:51
ca
ca.uqac.lif.synthia.relative
Pickers that produce a value in relation to another value.
Definition: package-info.java:24
ca.uqac.lif.synthia.explanation.Explanation
Constructs an explanation graph for the output produced by a picker.
Definition: Explanation.java:42
examples
examples.provenance.ExplanationList2.main
static void main(String[] args)
Definition: ExplanationList2.java:57
ca.uqac.lif.synthia.collection.ComposeList
Definition: ComposeList.java:44
ca.uqac.lif.synthia.sequence
Pickers related to the generation of a sequence of values.
Definition: BehaviorTree.java:19
ca.uqac.lif.synthia.explanation.NthSuccessiveOutput
A Part pointing to the n-th output produced by a picker since its last call to reset().
Definition: NthSuccessiveOutput.java:36