Maths.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. /**
  3. * Artificial Neural Network - Version 2.2
  4. *
  5. * For updates and changes visit the project page at http://ann.thwien.de/
  6. *
  7. *
  8. *
  9. * <b>LICENCE</b>
  10. *
  11. * The BSD 2-Clause License
  12. *
  13. * http://opensource.org/licenses/bsd-license.php
  14. *
  15. * Copyright (c) 2002, Eddy Young
  16. * Copyright (c) 2007 - 2012, Thomas Wien
  17. * All rights reserved.
  18. *
  19. * Redistribution and use in source and binary forms, with or without
  20. * modification, are permitted provided that the following conditions
  21. * are met:
  22. *
  23. * 1. Redistributions of source code must retain the above copyright
  24. * notice, this list of conditions and the following disclaimer.
  25. *
  26. * 2. Redistributions in binary form must reproduce the above copyright
  27. * notice, this list of conditions and the following disclaimer in the
  28. * documentation and/or other materials provided with the distribution.
  29. *
  30. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  31. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  32. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  33. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  34. * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  35. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  36. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  37. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  38. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  39. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  40. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  41. * POSSIBILITY OF SUCH DAMAGE.
  42. *
  43. * @author Eddy Young <jeyoung_at_priscimon_dot_com>
  44. * @author Thomas Wien <info_at_thwien_dot_de>
  45. * @version ANN Version 1.0 by Eddy Young
  46. * @version ANN Version 2.2 by Thomas Wien
  47. * @copyright Copyright (c) 2002 by Eddy Young
  48. * @copyright Copyright (c) 2007-2012 by Thomas Wien
  49. * @package ANN
  50. */
  51. namespace ANN;
  52. /**
  53. * @package ANN
  54. * @access private
  55. */
  56. class Maths
  57. {
  58. /**
  59. * @param float $floatValue
  60. * @return float (between near 0 and near 1)
  61. */
  62. public static function sigmoid($floatValue)
  63. {
  64. return 1 / (1 + exp(-1 * $floatValue));
  65. }
  66. /**
  67. * @param float $floatValue
  68. * @return integer (0 or 1)
  69. */
  70. public static function threshold($floatValue)
  71. {
  72. return ($floatValue > 0.5) ? 1 : 0;
  73. }
  74. /**
  75. * @return float
  76. */
  77. public static function randomDelta()
  78. {
  79. return mt_rand(-999, 999) / 1000;
  80. }
  81. /**
  82. * @return float
  83. */
  84. public static function randomWeight()
  85. {
  86. return mt_rand(-2000, 2000) / 1000;
  87. }
  88. }