Synthia
Generic and flexible data structure generator
Variation3.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.hypersphere;
20 
23 import ca.uqac.lif.synthia.util.Choice;
24 import ca.uqac.lif.synthia.util.Freeze;
26 import examples.util.Utilities;
27 
28 /**
29  * Generates two-dimensional points producing a spiral pattern.
30  * The points are generated by composing pickers as in the following diagram:
31  * <p>
32  * <img src="./doc-files/hypersphere/Variation3.png" alt="Diagram">
33  * <p>
34  * This variation shows the use of the {@link Tick} picker. The radius of the
35  * first point is either 0 or 1, and each successive radius increments by a
36  * fixed amount of &pi;/6. On its side, the starting angle is randomly selected
37  * between four values, and each successive angle is incremented by a fixed
38  * amount of &pi;/6. This results in a spiral pattern with slight variations.
39  *
40  * @ingroup Examples
41  */
42 public class Variation3
43 {
44 
45  @SuppressWarnings("unchecked")
46  public static void main(String[] args)
47  {
48  RandomFloat r_float1 = new RandomFloat().setSeed(42);
49  RandomFloat r_float2 = new RandomFloat().setSeed(40);
50  AffineTransformFloat af = new AffineTransformFloat(r_float1, 2, 1);
51  Freeze<Float> radius = new Freeze<Float>(af);
52  Choice<Double> angle = new Choice<Double>(r_float2)
53  .add(0d, 0.25).add(Math.PI / 2, 0.25).add(Math.PI, 0.25).add(3 * Math.PI / 2, 0.25);
54  HyperspherePicker hp = new HyperspherePicker(radius, angle);
55  for (int i = 0; i < 100; i++)
56  {
57  Utilities.print(System.out, hp.pick());
58  }
59  }
60 
61 }
ca.uqac.lif.synthia.random.AffineTransform.AffineTransformFloat
Affine transform producing floats.
Definition: AffineTransform.java:132
ca.uqac.lif.synthia.util.Freeze
Picker that returns the first object fetched from another picker and repeats it endlessly.
Definition: Freeze.java:48
examples.hypersphere.Variation3
Generates two-dimensional points producing a spiral pattern.
Definition: Variation3.java:42
ca.uqac.lif.synthia.util
Miscellaneous pickers performing various functions.
Definition: ArrayPicker.java:19
ca.uqac.lif.synthia.vector.HyperspherePicker.pick
float[] pick()
Picks an object.
Definition: HyperspherePicker.java:97
ca.uqac.lif.synthia.vector
Pickers generating multi-dimensional numerical vectors.
Definition: HyperspherePicker.java:19
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.vector.HyperspherePicker
Generates n-dimensional vectors with a given modulus.
Definition: HyperspherePicker.java:42
ca.uqac.lif.synthia.random.AffineTransform
Applies an affine transform to a value produced by another picker.
Definition: AffineTransform.java:38
examples.util.Utilities
Object providing a few utility methods to simplify the examples in this project.
Definition: Utilities.java:30
ca.uqac.lif.synthia.random.RandomFloat.setSeed
RandomFloat setSeed(int seed)
Definition: RandomFloat.java:85
ca.uqac.lif
ca.uqac.lif.synthia.util.Choice.add
Choice< T > add(ProbabilityChoice< T > pc)
Adds an object-probability association.
Definition: Choice.java:72
ca
examples.hypersphere.Variation3.main
static void main(String[] args)
Definition: Variation3.java:46
examples
ca.uqac.lif.synthia.random.RandomFloat
Picks a floating point number uniformly in an interval.
Definition: RandomFloat.java:30
ca.uqac.lif.synthia.util.Choice
Picks an element from a collection, where the probability of picking each element can be user-defined...
Definition: Choice.java:44
examples.util.Utilities.print
static void print(PrintStream ps, Object o)
Prints an object to a print stream.
Definition: Utilities.java:37