Hoa central
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
Hoa\Math\Sampler\Sampler Class Reference
Inheritance diagram for Hoa\Math\Sampler\Sampler:

Public Member Functions

 __construct (Array $parameters=[])
 
 construct ()
 
 getParameters ()
 
 getInteger ($lower=null, $upper=null, Array &$exclude=null)
 
 getFloat ($lower=null, $upper=null)
 
 getExcludeSet ()
 

Protected Member Functions

 _getInteger ($lower, $upper)
 
 _getFloat ($lower, $upper)
 

Protected Attributes

 $_parameters = null
 

Detailed Description

Class .

Generic sampler.

Definition at line 50 of file Sampler.php.

Constructor & Destructor Documentation

Hoa\Math\Sampler\Sampler::__construct ( Array  $parameters = [])

Construct an abstract sampler.

Parameters
array$parametersParameters.
Returns
void

Definition at line 67 of file Sampler.php.

68  {
69  $this->_parameters = new Core\Parameter(
70  __CLASS__,
71  [],
72  [
73  'integer.min' => -16,
74  'integer.max' => 15,
75  'float.min' => -128.0,
76  'float.max' => 127.0
77  ]
78  );
79  $this->_parameters->setParameters($parameters);
80 
81  if (null === $this->_parameters->getParameter('integer.min')) {
82  $this->_parameters->setParameter('integer.min', PHP_INT_MIN);
83  }
84 
85  if (null === $this->_parameters->getParameter('integer.max')) {
86  $this->_parameters->setParameter('integer.max', PHP_INT_MAX);
87  }
88 
89  if (null === $this->_parameters->getParameter('float.min')) {
90  $this->_parameters->setParameter('float.min', PHP_INT_MIN);
91  }
92 
93  if (null === $this->_parameters->getParameter('float.max')) {
94  $this->_parameters->setParameter('float.max', PHP_INT_MAX);
95  }
96 
97  $this->construct();
98 
99  return;
100  }

Here is the call graph for this function:

Member Function Documentation

Hoa\Math\Sampler\Sampler::_getFloat (   $lower,
  $upper 
)
abstractprotected

Generate a continuous uniform distribution.

Parameters
float$lowerLower bound value.
float$upperUpper bound value.
Returns
float

Here is the caller graph for this function:

Hoa\Math\Sampler\Sampler::_getInteger (   $lower,
  $upper 
)
abstractprotected

Generate a discrete uniform distribution.

Parameters
int$lowerLower bound value.
int$upperUpper bound value.
Returns
int

Here is the caller graph for this function:

Hoa\Math\Sampler\Sampler::construct ( )

Construct.

Returns
void

Definition at line 107 of file Sampler.php.

108  {
109  return;
110  }

Here is the caller graph for this function:

Hoa\Math\Sampler\Sampler::getExcludeSet ( )

Get an exclude set.

Returns
array

Definition at line 240 of file Sampler.php.

241  {
242  return [];
243  }
Hoa\Math\Sampler\Sampler::getFloat (   $lower = null,
  $upper = null 
)

Generate a continuous uniform distribution.

Parameters
float$lowerLower bound value.
float$upperUpper bound value.
Returns
float

Definition at line 197 of file Sampler.php.

198  {
199  if (null === $lower) {
200  $lower = $this->_parameters->getParameter('float.min');
201  }
202  /*
203  $lower = true === S_32\BITS
204  ? -3.4028235e38 + 1
205  : -1.7976931348623157e308 + 1;
206  */
207 
208  if (null === $upper) {
209  $upper = $this->_parameters->getParameter('float.max');
210  }
211  /*
212  $upper = true === S_32\BITS
213  ? 3.4028235e38 - 1
214  : 1.7976931348623157e308 - 1;
215  */
216 
217  if ($lower > $upper) {
218  throw new Math\Exception(
219  'Unexpected values, float %f should be lower than %f',
220  2, [$lower, $upper]);
221  }
222 
223  return $this->_getFloat($lower, $upper);
224  }
_getFloat($lower, $upper)

Here is the call graph for this function:

Hoa\Math\Sampler\Sampler::getInteger (   $lower = null,
  $upper = null,
Array &  $exclude = null 
)

Generate a discrete uniform distribution.

Parameters
int$lowerLower bound value.
int$upperUpper bound value.
array&$excludeExcluded values.
Returns
int

Definition at line 130 of file Sampler.php.

134  {
135  if (null === $lower) {
136  $lower = $this->_parameters->getParameter('integer.min');
137  }
138 
139  if (null === $upper) {
140  $upper = $this->_parameters->getParameter('integer.max');
141  }
142 
143  if (null === $exclude) {
144  if ($lower > $upper) {
145  throw new Math\Exception(
146  'Unexpected values, integer %d should be lower than %d',
147  0,
148  [$lower, $upper]
149  );
150  }
151 
152  return $this->_getInteger($lower, $upper);
153  }
154 
155 
156  sort($exclude);
157 
158  $upper -= count($exclude);
159 
160  if ($lower > $upper) {
161  throw new Math\Exception(
162  'Unexpected values, integer %d should be lower than %d',
163  1,
164  [$lower, $upper]
165  );
166  }
167 
168  $sampled = $this->_getInteger($lower, $upper);
169 
170  foreach ($exclude as $e) {
171  if ($sampled >= $e) {
172  ++$sampled;
173  } else {
174  break;
175  }
176  }
177 
178  return $sampled;
179  }
_getInteger($lower, $upper)

Here is the call graph for this function:

Hoa\Math\Sampler\Sampler::getParameters ( )

Get parameters.

Returns

Implements Hoa\Core\Parameter\Parameterizable.

Definition at line 117 of file Sampler.php.

118  {
119  return $this->_parameters;
120  }

Member Data Documentation

Hoa\Math\Sampler\Sampler::$_parameters = null
protected

Definition at line 57 of file Sampler.php.


The documentation for this class was generated from the following file: