Synthia
Generic and flexible data structure generator
BiasedRandomFloat.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 ca.uqac.lif.synthia.random;
20 
21 /**
22  * Generates pseudo-random floating-point numbers in the interval [0,1],
23  * but according to a probability distribution that is not uniform.
24  * Concretely, a value is first picked uniformly, and is then multiplied
25  * by a factor &beta; called the bias. The resulting value is then
26  * replaced by 0 or 1 if it lies outside the interval. Setting
27  * &beta; &lt; 1 results in a picker that favors values closer to 0, while
28  * setting &beta; &gt; 1 results in a picker that favors values closer to 1.
29  *
30  * @author Sylvain Hallé
31  *
32  */
33 public class BiasedRandomFloat extends RandomFloat
34 {
35  /**
36  * The bias parameter &beta;.
37  */
38  protected float m_beta;
39 
40  /**
41  * Creates a new instance of the biased random float picker.
42  * @param beta The bias parameter &beta;
43  */
44  public BiasedRandomFloat(float beta)
45  {
46  super();
47  m_beta = beta;
48  }
49 
50  @Override
51  public Float pick()
52  {
53  float f = super.pick();
54  float biased_f = f * m_beta;
55  if (biased_f < 0)
56  {
57  return 0f;
58  }
59  if (biased_f > 1)
60  {
61  return 1f - 0.000001f;
62  }
63  return biased_f;
64  }
65 
66  @Override
67  public BiasedRandomFloat duplicate(boolean with_state)
68  {
69  return new BiasedRandomFloat(m_beta);
70  }
71 }
ca.uqac.lif.synthia.random.BiasedRandomFloat.pick
Float pick()
Picks a random float in the specified interval.
Definition: BiasedRandomFloat.java:51
ca.uqac.lif.synthia.random.BiasedRandomFloat
Generates pseudo-random floating-point numbers in the interval [0,1], but according to a probability ...
Definition: BiasedRandomFloat.java:33
ca.uqac.lif.synthia.random.BiasedRandomFloat.BiasedRandomFloat
BiasedRandomFloat(float beta)
Creates a new instance of the biased random float picker.
Definition: BiasedRandomFloat.java:44
ca.uqac.lif.synthia.random.BiasedRandomFloat.duplicate
BiasedRandomFloat duplicate(boolean with_state)
Creates a copy of the RandomIntervalFloat picker.
Definition: BiasedRandomFloat.java:67
ca.uqac.lif.synthia.random.BiasedRandomFloat.m_beta
float m_beta
The bias parameter β.
Definition: BiasedRandomFloat.java:38
ca.uqac.lif.synthia.random.RandomFloat
Picks a floating point number uniformly in an interval.
Definition: RandomFloat.java:30