silicium 0.0.2 → 0.0.14

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -3
  3. data/.travis.yml +14 -25
  4. data/Gemfile +0 -4
  5. data/README.md +0 -2
  6. data/Rakefile +0 -7
  7. data/lib/silicium/version.rb +1 -1
  8. data/lib/silicium.rb +1 -0
  9. data/silicium.gemspec +37 -39
  10. metadata +4 -92
  11. data/.codeclimate.yml +0 -4
  12. data/Makefile +0 -269
  13. data/docs/Object.html +0 -117
  14. data/docs/README_md.html +0 -142
  15. data/docs/Silicium/Combinatorics.html +0 -270
  16. data/docs/Silicium/Dice/Polyhedron.html +0 -315
  17. data/docs/Silicium/Dice/PolyhedronSet.html +0 -321
  18. data/docs/Silicium/Dice.html +0 -99
  19. data/docs/Silicium/Error.html +0 -106
  20. data/docs/Silicium/Geometry/Line2dCanon.html +0 -243
  21. data/docs/Silicium/Geometry/VariablesOrderException.html +0 -106
  22. data/docs/Silicium/Geometry.html +0 -940
  23. data/docs/Silicium/Graphs/GraphError.html +0 -106
  24. data/docs/Silicium/Graphs/OrientedGraph.html +0 -775
  25. data/docs/Silicium/Graphs/UnorientedGraph.html +0 -284
  26. data/docs/Silicium/Graphs.html +0 -164
  27. data/docs/Silicium/IntegralDoesntExistError.html +0 -106
  28. data/docs/Silicium/NumericalIntegration.html +0 -521
  29. data/docs/Silicium/Optimization.html +0 -639
  30. data/docs/Silicium/Plotter/Image.html +0 -297
  31. data/docs/Silicium/Plotter.html +0 -186
  32. data/docs/Silicium.html +0 -101
  33. data/docs/created.rid +0 -9
  34. data/docs/css/fonts.css +0 -167
  35. data/docs/css/rdoc.css +0 -619
  36. data/docs/fonts/Lato-Light.ttf +0 -0
  37. data/docs/fonts/Lato-LightItalic.ttf +0 -0
  38. data/docs/fonts/Lato-Regular.ttf +0 -0
  39. data/docs/fonts/Lato-RegularItalic.ttf +0 -0
  40. data/docs/fonts/SourceCodePro-Bold.ttf +0 -0
  41. data/docs/fonts/SourceCodePro-Regular.ttf +0 -0
  42. data/docs/images/add.png +0 -0
  43. data/docs/images/arrow_up.png +0 -0
  44. data/docs/images/brick.png +0 -0
  45. data/docs/images/brick_link.png +0 -0
  46. data/docs/images/bug.png +0 -0
  47. data/docs/images/bullet_black.png +0 -0
  48. data/docs/images/bullet_toggle_minus.png +0 -0
  49. data/docs/images/bullet_toggle_plus.png +0 -0
  50. data/docs/images/date.png +0 -0
  51. data/docs/images/delete.png +0 -0
  52. data/docs/images/find.png +0 -0
  53. data/docs/images/loadingAnimation.gif +0 -0
  54. data/docs/images/macFFBgHack.png +0 -0
  55. data/docs/images/package.png +0 -0
  56. data/docs/images/page_green.png +0 -0
  57. data/docs/images/page_white_text.png +0 -0
  58. data/docs/images/page_white_width.png +0 -0
  59. data/docs/images/plugin.png +0 -0
  60. data/docs/images/ruby.png +0 -0
  61. data/docs/images/tag_blue.png +0 -0
  62. data/docs/images/tag_green.png +0 -0
  63. data/docs/images/transparent.png +0 -0
  64. data/docs/images/wrench.png +0 -0
  65. data/docs/images/wrench_orange.png +0 -0
  66. data/docs/images/zoom.png +0 -0
  67. data/docs/index.html +0 -132
  68. data/docs/js/darkfish.js +0 -84
  69. data/docs/js/navigation.js +0 -105
  70. data/docs/js/navigation.js.gz +0 -0
  71. data/docs/js/search.js +0 -110
  72. data/docs/js/search_index.js +0 -1
  73. data/docs/js/search_index.js.gz +0 -0
  74. data/docs/js/searcher.js +0 -229
  75. data/docs/js/searcher.js.gz +0 -0
  76. data/docs/table_of_contents.html +0 -608
  77. data/lib/geometry.rb +0 -236
  78. data/lib/graph.rb +0 -164
  79. data/lib/numerical_integration.rb +0 -147
  80. data/lib/optimization.rb +0 -144
  81. data/lib/plotter.rb +0 -96
  82. data/lib/theory_of_probability.rb +0 -227
@@ -1,639 +0,0 @@
1
- <!DOCTYPE html>
2
-
3
- <html>
4
- <head>
5
- <meta charset="UTF-8">
6
-
7
- <title>module Silicium::Optimization - RDoc Documentation</title>
8
-
9
- <script type="text/javascript">
10
- var rdoc_rel_prefix = "../";
11
- var index_rel_prefix = "../";
12
- </script>
13
-
14
- <script src="../js/navigation.js" defer></script>
15
- <script src="../js/search.js" defer></script>
16
- <script src="../js/search_index.js" defer></script>
17
- <script src="../js/searcher.js" defer></script>
18
- <script src="../js/darkfish.js" defer></script>
19
-
20
- <link href="../css/fonts.css" rel="stylesheet">
21
- <link href="../css/rdoc.css" rel="stylesheet">
22
-
23
-
24
-
25
-
26
- <body id="top" role="document" class="module">
27
- <nav role="navigation">
28
- <div id="project-navigation">
29
- <div id="home-section" role="region" title="Quick navigation" class="nav-section">
30
- <h2>
31
- <a href="../index.html" rel="home">Home</a>
32
- </h2>
33
-
34
- <div id="table-of-contents-navigation">
35
- <a href="../table_of_contents.html#pages">Pages</a>
36
- <a href="../table_of_contents.html#classes">Classes</a>
37
- <a href="../table_of_contents.html#methods">Methods</a>
38
- </div>
39
- </div>
40
-
41
- <div id="search-section" role="search" class="project-section initially-hidden">
42
- <form action="#" method="get" accept-charset="utf-8">
43
- <div id="search-field-wrapper">
44
- <input id="search-field" role="combobox" aria-label="Search"
45
- aria-autocomplete="list" aria-controls="search-results"
46
- type="text" name="search" placeholder="Search" spellcheck="false"
47
- title="Type to search, Up and Down to navigate, Enter to load">
48
- </div>
49
-
50
- <ul id="search-results" aria-label="Search Results"
51
- aria-busy="false" aria-expanded="false"
52
- aria-atomic="false" class="initially-hidden"></ul>
53
- </form>
54
- </div>
55
-
56
- </div>
57
-
58
-
59
-
60
- <div id="class-metadata">
61
-
62
-
63
-
64
-
65
- <!-- Method Quickref -->
66
- <div id="method-list-section" class="nav-section">
67
- <h3>Methods</h3>
68
-
69
- <ul class="link-list" role="directory">
70
-
71
- <li ><a href="#method-i-accuracy">#accuracy</a>
72
-
73
- <li ><a href="#method-i-bogosort">#bogosort</a>
74
-
75
- <li ><a href="#method-i-bogosort-21">#bogosort!</a>
76
-
77
- <li ><a href="#method-i-half_division">#half_division</a>
78
-
79
- <li ><a href="#method-i-half_division_step">#half_division_step</a>
80
-
81
- <li ><a href="#method-i-hook_jeeves">#hook_jeeves</a>
82
-
83
- <li ><a href="#method-i-hook_jeeves_step">#hook_jeeves_step</a>
84
-
85
- <li ><a href="#method-i-integrating_Monte_Carlo_base">#integrating_Monte_Carlo_base</a>
86
-
87
- <li ><a href="#method-i-middle">#middle</a>
88
-
89
- <li ><a href="#method-i-re_lu">#re_lu</a>
90
-
91
- <li ><a href="#method-i-sigmoid">#sigmoid</a>
92
-
93
- <li ><a href="#method-i-sorted-3F">#sorted?</a>
94
-
95
- <li ><a href="#method-i-switch_step">#switch_step</a>
96
-
97
- </ul>
98
- </div>
99
-
100
- </div>
101
- </nav>
102
-
103
- <main role="main" aria-labelledby="module-Silicium::Optimization">
104
- <h1 id="module-Silicium::Optimization" class="module">
105
- module Silicium::Optimization
106
- </h1>
107
-
108
- <section class="description">
109
-
110
- </section>
111
-
112
-
113
- <section id="5Buntitled-5D" class="documentation-section">
114
-
115
-
116
-
117
-
118
-
119
-
120
-
121
-
122
-
123
- <section id="public-instance-5Buntitled-5D-method-details" class="method-section">
124
- <header>
125
- <h3>Public Instance Methods</h3>
126
- </header>
127
-
128
-
129
- <div id="method-i-accuracy" class="method-detail ">
130
-
131
- <div class="method-heading">
132
- <span class="method-name">accuracy</span><span
133
- class="method-args">(step)</span>
134
-
135
- <span class="method-click-advice">click to toggle source</span>
136
-
137
- </div>
138
-
139
-
140
- <div class="method-description">
141
-
142
- <p>calculate current accuracy in Hook - Jeeves method</p>
143
-
144
-
145
-
146
-
147
- <div class="method-source-code" id="accuracy-source">
148
- <pre><span class="ruby-comment"># File lib/optimization.rb, line 64</span>
149
- <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">accuracy</span>(<span class="ruby-identifier">step</span>)
150
- <span class="ruby-identifier">acc</span> = <span class="ruby-value">0</span>
151
- <span class="ruby-identifier">step</span>.<span class="ruby-identifier">each</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">a</span><span class="ruby-operator">|</span> <span class="ruby-identifier">acc</span> <span class="ruby-operator">+=</span> <span class="ruby-identifier">a</span> <span class="ruby-operator">*</span> <span class="ruby-identifier">a</span> }
152
- <span class="ruby-constant">Math</span>.<span class="ruby-identifier">sqrt</span>(<span class="ruby-identifier">acc</span>)
153
- <span class="ruby-keyword">end</span></pre>
154
- </div>
155
-
156
- </div>
157
-
158
-
159
-
160
-
161
- </div>
162
-
163
-
164
- <div id="method-i-bogosort" class="method-detail ">
165
-
166
- <div class="method-heading">
167
- <span class="method-name">bogosort</span><span
168
- class="method-args">(a)</span>
169
-
170
- <span class="method-click-advice">click to toggle source</span>
171
-
172
- </div>
173
-
174
-
175
- <div class="method-description">
176
-
177
- <p>fastest(but it is not exactly) sort</p>
178
-
179
-
180
-
181
-
182
- <div class="method-source-code" id="bogosort-source">
183
- <pre><span class="ruby-comment"># File lib/optimization.rb, line 52</span>
184
- <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">bogosort</span>(<span class="ruby-identifier">a</span>)
185
- <span class="ruby-keyword">if</span> (<span class="ruby-identifier">a</span>.<span class="ruby-identifier">nil?</span>)
186
- <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-string">&quot;Nil array in bogosort&quot;</span>
187
- <span class="ruby-keyword">end</span>
188
- <span class="ruby-identifier">crutch</span> = <span class="ruby-identifier">a</span>
189
- <span class="ruby-keyword">while</span> (<span class="ruby-operator">!</span><span class="ruby-identifier">sorted?</span>(<span class="ruby-identifier">crutch</span>))
190
- <span class="ruby-identifier">crutch</span> = <span class="ruby-identifier">a</span>.<span class="ruby-identifier">shuffle</span>
191
- <span class="ruby-keyword">end</span>
192
- <span class="ruby-identifier">crutch</span>
193
- <span class="ruby-keyword">end</span></pre>
194
- </div>
195
-
196
- </div>
197
-
198
-
199
-
200
-
201
- </div>
202
-
203
-
204
- <div id="method-i-bogosort-21" class="method-detail ">
205
-
206
- <div class="method-heading">
207
- <span class="method-name">bogosort!</span><span
208
- class="method-args">(a)</span>
209
-
210
- <span class="method-click-advice">click to toggle source</span>
211
-
212
- </div>
213
-
214
-
215
- <div class="method-description">
216
-
217
- <p>fastest(but it is not exactly) sort, modify sequance</p>
218
-
219
-
220
-
221
-
222
- <div class="method-source-code" id="bogosort-21-source">
223
- <pre><span class="ruby-comment"># File lib/optimization.rb, line 41</span>
224
- <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">bogosort!</span>(<span class="ruby-identifier">a</span>)
225
- <span class="ruby-keyword">if</span> (<span class="ruby-identifier">a</span>.<span class="ruby-identifier">nil?</span>)
226
- <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-string">&quot;Nil array in bogosort&quot;</span>
227
- <span class="ruby-keyword">end</span>
228
- <span class="ruby-keyword">while</span> (<span class="ruby-operator">!</span><span class="ruby-identifier">sorted?</span>(<span class="ruby-identifier">a</span>))
229
- <span class="ruby-identifier">a</span>.<span class="ruby-identifier">shuffle!</span>
230
- <span class="ruby-keyword">end</span>
231
- <span class="ruby-identifier">a</span>
232
- <span class="ruby-keyword">end</span></pre>
233
- </div>
234
-
235
- </div>
236
-
237
-
238
-
239
-
240
- </div>
241
-
242
-
243
- <div id="method-i-half_division" class="method-detail ">
244
-
245
- <div class="method-heading">
246
- <span class="method-name">half_division</span><span
247
- class="method-args">(a, b, eps = 0.001, &amp;block)</span>
248
-
249
- <span class="method-click-advice">click to toggle source</span>
250
-
251
- </div>
252
-
253
-
254
- <div class="method-description">
255
-
256
- <p>find root in [a, b], if he exist, if number of iterations &gt; iters -&gt; error</p>
257
-
258
-
259
-
260
-
261
- <div class="method-source-code" id="half_division-source">
262
- <pre><span class="ruby-comment"># File lib/optimization.rb, line 126</span>
263
- <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">half_division</span>(<span class="ruby-identifier">a</span>, <span class="ruby-identifier">b</span>, <span class="ruby-identifier">eps</span> = <span class="ruby-value">0.001</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
264
- <span class="ruby-identifier">iters</span> = <span class="ruby-value">1000000</span>
265
- <span class="ruby-identifier">c</span> = <span class="ruby-identifier">middle</span>(<span class="ruby-identifier">a</span>, <span class="ruby-identifier">b</span>)
266
- <span class="ruby-keyword">while</span> ((<span class="ruby-identifier">block</span>.<span class="ruby-identifier">call</span>(<span class="ruby-identifier">c</span>).<span class="ruby-identifier">abs</span>) <span class="ruby-operator">&gt;</span> <span class="ruby-identifier">eps</span>)
267
- <span class="ruby-identifier">tmp</span> = <span class="ruby-identifier">half_division_step</span>(<span class="ruby-identifier">a</span>, <span class="ruby-identifier">b</span>, <span class="ruby-identifier">c</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
268
- <span class="ruby-identifier">a</span> = <span class="ruby-identifier">tmp</span>[<span class="ruby-value">0</span>]
269
- <span class="ruby-identifier">b</span> = <span class="ruby-identifier">tmp</span>[<span class="ruby-value">1</span>]
270
- <span class="ruby-identifier">c</span> = <span class="ruby-identifier">tmp</span>[<span class="ruby-value">2</span>]
271
- <span class="ruby-identifier">iters</span> <span class="ruby-operator">-=</span> <span class="ruby-value">1</span>
272
- <span class="ruby-keyword">if</span> <span class="ruby-identifier">iters</span> <span class="ruby-operator">==</span> <span class="ruby-value">0</span>
273
- <span class="ruby-identifier">raise</span> <span class="ruby-constant">RuntimeError</span>, <span class="ruby-string">&quot;Root not found! Check does he exist, or change eps or iters&quot;</span>
274
- <span class="ruby-keyword">end</span>
275
- <span class="ruby-keyword">end</span>
276
- <span class="ruby-identifier">c</span>
277
- <span class="ruby-keyword">end</span></pre>
278
- </div>
279
-
280
- </div>
281
-
282
-
283
-
284
-
285
- </div>
286
-
287
-
288
- <div id="method-i-half_division_step" class="method-detail ">
289
-
290
- <div class="method-heading">
291
- <span class="method-name">half_division_step</span><span
292
- class="method-args">(a, b, c, &amp;block)</span>
293
-
294
- <span class="method-click-advice">click to toggle source</span>
295
-
296
- </div>
297
-
298
-
299
- <div class="method-description">
300
-
301
- <p>do one half division step</p>
302
-
303
-
304
-
305
-
306
- <div class="method-source-code" id="half_division_step-source">
307
- <pre><span class="ruby-comment"># File lib/optimization.rb, line 114</span>
308
- <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">half_division_step</span>(<span class="ruby-identifier">a</span>, <span class="ruby-identifier">b</span>, <span class="ruby-identifier">c</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
309
- <span class="ruby-keyword">if</span> (<span class="ruby-identifier">block</span>.<span class="ruby-identifier">call</span>(<span class="ruby-identifier">a</span>) <span class="ruby-operator">*</span> <span class="ruby-identifier">block</span>.<span class="ruby-identifier">call</span>(<span class="ruby-identifier">c</span>) <span class="ruby-operator">&lt;</span> <span class="ruby-value">0</span>)
310
- <span class="ruby-identifier">b</span> = <span class="ruby-identifier">c</span>
311
- <span class="ruby-identifier">c</span> = <span class="ruby-identifier">middle</span>(<span class="ruby-identifier">a</span>, <span class="ruby-identifier">c</span>)
312
- <span class="ruby-keyword">else</span>
313
- <span class="ruby-identifier">a</span> = <span class="ruby-identifier">c</span>
314
- <span class="ruby-identifier">c</span> = <span class="ruby-identifier">middle</span>(<span class="ruby-identifier">b</span>, <span class="ruby-identifier">c</span>)
315
- <span class="ruby-keyword">end</span>
316
- [<span class="ruby-identifier">a</span>, <span class="ruby-identifier">b</span>, <span class="ruby-identifier">c</span>]
317
- <span class="ruby-keyword">end</span></pre>
318
- </div>
319
-
320
- </div>
321
-
322
-
323
-
324
-
325
- </div>
326
-
327
-
328
- <div id="method-i-hook_jeeves" class="method-detail ">
329
-
330
- <div class="method-heading">
331
- <span class="method-name">hook_jeeves</span><span
332
- class="method-args">(x, step, eps = 0.1, &amp;block)</span>
333
-
334
- <span class="method-click-advice">click to toggle source</span>
335
-
336
- </div>
337
-
338
-
339
- <div class="method-description">
340
-
341
- <p>Hook - Jeeves method for find minimum point (x - array of start variables, step - step of one iteration, eps - allowable error, alfa - slowdown of step, block - function which takes array x, WAENING function doesn&#39;t control correctness of input</p>
342
-
343
-
344
-
345
-
346
- <div class="method-source-code" id="hook_jeeves-source">
347
- <pre><span class="ruby-comment"># File lib/optimization.rb, line 92</span>
348
- <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">hook_jeeves</span>(<span class="ruby-identifier">x</span>, <span class="ruby-identifier">step</span>, <span class="ruby-identifier">eps</span> = <span class="ruby-value">0.1</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
349
- <span class="ruby-identifier">prev_f</span> = <span class="ruby-identifier">block</span>.<span class="ruby-identifier">call</span>(<span class="ruby-identifier">x</span>)
350
- <span class="ruby-identifier">acc</span> = <span class="ruby-identifier">accuracy</span>(<span class="ruby-identifier">step</span>)
351
- <span class="ruby-keyword">while</span> (<span class="ruby-identifier">acc</span> <span class="ruby-operator">&gt;</span> <span class="ruby-identifier">eps</span>)
352
- <span class="ruby-keyword">for</span> <span class="ruby-identifier">i</span> <span class="ruby-keyword">in</span> <span class="ruby-value">0</span><span class="ruby-operator">..</span><span class="ruby-identifier">x</span>.<span class="ruby-identifier">length</span> <span class="ruby-operator">-</span> <span class="ruby-value">1</span>
353
- <span class="ruby-identifier">tmp</span> = <span class="ruby-identifier">hook_jeeves_step</span>(<span class="ruby-identifier">x</span>, <span class="ruby-identifier">i</span>, <span class="ruby-identifier">step</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
354
- <span class="ruby-identifier">cur_f</span> = <span class="ruby-identifier">tmp</span>[<span class="ruby-value">0</span>]
355
- <span class="ruby-identifier">x</span>[<span class="ruby-identifier">i</span>] = <span class="ruby-identifier">tmp</span>[<span class="ruby-value">1</span>]
356
- <span class="ruby-identifier">step</span>[<span class="ruby-identifier">i</span>] = <span class="ruby-identifier">switch_step</span>(<span class="ruby-identifier">cur_f</span>, <span class="ruby-identifier">prev_f</span>, <span class="ruby-identifier">step</span>, <span class="ruby-identifier">i</span>)
357
- <span class="ruby-identifier">prev_f</span> = <span class="ruby-identifier">cur_f</span>
358
- <span class="ruby-keyword">end</span>
359
- <span class="ruby-identifier">acc</span> = <span class="ruby-identifier">accuracy</span>(<span class="ruby-identifier">step</span>)
360
- <span class="ruby-keyword">end</span>
361
- <span class="ruby-identifier">x</span>
362
- <span class="ruby-keyword">end</span></pre>
363
- </div>
364
-
365
- </div>
366
-
367
-
368
-
369
-
370
- </div>
371
-
372
-
373
- <div id="method-i-hook_jeeves_step" class="method-detail ">
374
-
375
- <div class="method-heading">
376
- <span class="method-name">hook_jeeves_step</span><span
377
- class="method-args">(x, i, step, &amp;block)</span>
378
-
379
- <span class="method-click-advice">click to toggle source</span>
380
-
381
- </div>
382
-
383
-
384
- <div class="method-description">
385
-
386
- <p>do one Hook - Jeeves step</p>
387
-
388
-
389
-
390
-
391
- <div class="method-source-code" id="hook_jeeves_step-source">
392
- <pre><span class="ruby-comment"># File lib/optimization.rb, line 71</span>
393
- <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">hook_jeeves_step</span>(<span class="ruby-identifier">x</span>, <span class="ruby-identifier">i</span>, <span class="ruby-identifier">step</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
394
- <span class="ruby-identifier">x</span>[<span class="ruby-identifier">i</span>] <span class="ruby-operator">+=</span> <span class="ruby-identifier">step</span>[<span class="ruby-identifier">i</span>]
395
- <span class="ruby-identifier">tmp1</span> = <span class="ruby-identifier">block</span>.<span class="ruby-identifier">call</span>(<span class="ruby-identifier">x</span>)
396
- <span class="ruby-identifier">x</span>[<span class="ruby-identifier">i</span>] = <span class="ruby-identifier">x</span>[<span class="ruby-identifier">i</span>] <span class="ruby-operator">-</span> <span class="ruby-value">2</span> <span class="ruby-operator">*</span> <span class="ruby-identifier">step</span>[<span class="ruby-identifier">i</span>]
397
- <span class="ruby-identifier">tmp2</span> = <span class="ruby-identifier">block</span>.<span class="ruby-identifier">call</span>(<span class="ruby-identifier">x</span>)
398
- <span class="ruby-keyword">if</span> (<span class="ruby-identifier">tmp1</span> <span class="ruby-operator">&gt;</span> <span class="ruby-identifier">tmp2</span>)
399
- <span class="ruby-identifier">cur_f</span> = <span class="ruby-identifier">tmp2</span>
400
- <span class="ruby-keyword">else</span>
401
- <span class="ruby-identifier">x</span>[<span class="ruby-identifier">i</span>] = <span class="ruby-identifier">x</span>[<span class="ruby-identifier">i</span>] <span class="ruby-operator">+</span> <span class="ruby-identifier">step</span>[<span class="ruby-identifier">i</span>] <span class="ruby-operator">*</span> <span class="ruby-value">2</span>
402
- <span class="ruby-identifier">cur_f</span> = <span class="ruby-identifier">tmp1</span>
403
- <span class="ruby-keyword">end</span>
404
- [<span class="ruby-identifier">cur_f</span>, <span class="ruby-identifier">x</span>[<span class="ruby-identifier">i</span>]]
405
- <span class="ruby-keyword">end</span></pre>
406
- </div>
407
-
408
- </div>
409
-
410
-
411
-
412
-
413
- </div>
414
-
415
-
416
- <div id="method-i-integrating_Monte_Carlo_base" class="method-detail ">
417
-
418
- <div class="method-heading">
419
- <span class="method-name">integrating_Monte_Carlo_base</span><span
420
- class="method-args">(a, b, n = 100000, &amp;block)</span>
421
-
422
- <span class="method-click-advice">click to toggle source</span>
423
-
424
- </div>
425
-
426
-
427
- <div class="method-description">
428
-
429
- <p>integrating using method Monte Carlo (f - function, a, b - integrating limits, n - amount of random numbers)</p>
430
-
431
-
432
-
433
-
434
- <div class="method-source-code" id="integrating_Monte_Carlo_base-source">
435
- <pre><span class="ruby-comment"># File lib/optimization.rb, line 19</span>
436
- <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">integrating_Monte_Carlo_base</span>(<span class="ruby-identifier">a</span>, <span class="ruby-identifier">b</span>, <span class="ruby-identifier">n</span> = <span class="ruby-value">100000</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
437
- <span class="ruby-identifier">res</span> = <span class="ruby-value">0</span>
438
- <span class="ruby-identifier">range</span> = <span class="ruby-identifier">a</span><span class="ruby-operator">..</span><span class="ruby-identifier">b</span>.<span class="ruby-identifier">to_f</span>
439
- <span class="ruby-keyword">for</span> <span class="ruby-identifier">i</span> <span class="ruby-keyword">in</span> <span class="ruby-value">1</span><span class="ruby-operator">..</span>(<span class="ruby-identifier">n</span> <span class="ruby-operator">+</span> <span class="ruby-value">1</span>)
440
- <span class="ruby-identifier">x</span> = <span class="ruby-identifier">rand</span>(<span class="ruby-identifier">range</span>)
441
- <span class="ruby-identifier">res</span> <span class="ruby-operator">+=</span> (<span class="ruby-identifier">b</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">a</span>) <span class="ruby-operator">*</span> <span class="ruby-value">1.0</span> <span class="ruby-operator">/</span> <span class="ruby-identifier">n</span> <span class="ruby-operator">*</span> <span class="ruby-identifier">block</span>.<span class="ruby-identifier">call</span>(<span class="ruby-identifier">x</span>)
442
- <span class="ruby-keyword">end</span>
443
- <span class="ruby-identifier">res</span>
444
- <span class="ruby-keyword">end</span></pre>
445
- </div>
446
-
447
- </div>
448
-
449
-
450
-
451
-
452
- </div>
453
-
454
-
455
- <div id="method-i-middle" class="method-detail ">
456
-
457
- <div class="method-heading">
458
- <span class="method-name">middle</span><span
459
- class="method-args">(a, b)</span>
460
-
461
- <span class="method-click-advice">click to toggle source</span>
462
-
463
- </div>
464
-
465
-
466
- <div class="method-description">
467
-
468
- <p>find centr of interval</p>
469
-
470
-
471
-
472
-
473
- <div class="method-source-code" id="middle-source">
474
- <pre><span class="ruby-comment"># File lib/optimization.rb, line 109</span>
475
- <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">middle</span>(<span class="ruby-identifier">a</span>, <span class="ruby-identifier">b</span>)
476
- (<span class="ruby-identifier">a</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">b</span>) <span class="ruby-operator">/</span> <span class="ruby-value">2.0</span>
477
- <span class="ruby-keyword">end</span></pre>
478
- </div>
479
-
480
- </div>
481
-
482
-
483
-
484
-
485
- </div>
486
-
487
-
488
- <div id="method-i-re_lu" class="method-detail ">
489
-
490
- <div class="method-heading">
491
- <span class="method-name">re_lu</span><span
492
- class="method-args">(x)</span>
493
-
494
- <span class="method-click-advice">click to toggle source</span>
495
-
496
- </div>
497
-
498
-
499
- <div class="method-description">
500
-
501
- <p>reflector function</p>
502
-
503
-
504
-
505
-
506
- <div class="method-source-code" id="re_lu-source">
507
- <pre><span class="ruby-comment"># File lib/optimization.rb, line 9</span>
508
- <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">re_lu</span>(<span class="ruby-identifier">x</span>)
509
- <span class="ruby-identifier">x</span>.<span class="ruby-identifier">negative?</span> <span class="ruby-operator">?</span> <span class="ruby-value">0</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">x</span>
510
- <span class="ruby-keyword">end</span></pre>
511
- </div>
512
-
513
- </div>
514
-
515
-
516
-
517
-
518
- </div>
519
-
520
-
521
- <div id="method-i-sigmoid" class="method-detail ">
522
-
523
- <div class="method-heading">
524
- <span class="method-name">sigmoid</span><span
525
- class="method-args">(x)</span>
526
-
527
- <span class="method-click-advice">click to toggle source</span>
528
-
529
- </div>
530
-
531
-
532
- <div class="method-description">
533
-
534
- <p>sigmoid function</p>
535
-
536
-
537
-
538
-
539
- <div class="method-source-code" id="sigmoid-source">
540
- <pre><span class="ruby-comment"># File lib/optimization.rb, line 14</span>
541
- <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">sigmoid</span>(<span class="ruby-identifier">x</span>)
542
- <span class="ruby-value">1.0</span> <span class="ruby-operator">/</span> (<span class="ruby-value">1</span> <span class="ruby-operator">+</span> <span class="ruby-constant">Math</span>.<span class="ruby-identifier">exp</span>(<span class="ruby-operator">-</span><span class="ruby-identifier">x</span>))
543
- <span class="ruby-keyword">end</span></pre>
544
- </div>
545
-
546
- </div>
547
-
548
-
549
-
550
-
551
- </div>
552
-
553
-
554
- <div id="method-i-sorted-3F" class="method-detail ">
555
-
556
- <div class="method-heading">
557
- <span class="method-name">sorted?</span><span
558
- class="method-args">(a)</span>
559
-
560
- <span class="method-click-advice">click to toggle source</span>
561
-
562
- </div>
563
-
564
-
565
- <div class="method-description">
566
-
567
- <p>return true if array is sorted</p>
568
-
569
-
570
-
571
-
572
- <div class="method-source-code" id="sorted-3F-source">
573
- <pre><span class="ruby-comment"># File lib/optimization.rb, line 30</span>
574
- <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">sorted?</span>(<span class="ruby-identifier">a</span>)
575
- <span class="ruby-keyword">return</span> <span class="ruby-keyword">false</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">a</span>.<span class="ruby-identifier">nil?</span>
576
- <span class="ruby-keyword">for</span> <span class="ruby-identifier">i</span> <span class="ruby-keyword">in</span> <span class="ruby-value">0</span><span class="ruby-operator">..</span><span class="ruby-identifier">a</span>.<span class="ruby-identifier">length</span> <span class="ruby-operator">-</span> <span class="ruby-value">2</span>
577
- <span class="ruby-keyword">if</span> (<span class="ruby-identifier">a</span>[<span class="ruby-identifier">i</span> <span class="ruby-operator">+</span> <span class="ruby-value">1</span>] <span class="ruby-operator">&lt;</span> <span class="ruby-identifier">a</span>[<span class="ruby-identifier">i</span>])
578
- <span class="ruby-keyword">return</span> <span class="ruby-keyword">false</span>
579
- <span class="ruby-keyword">end</span>
580
- <span class="ruby-keyword">end</span>
581
- <span class="ruby-keyword">true</span>
582
- <span class="ruby-keyword">end</span></pre>
583
- </div>
584
-
585
- </div>
586
-
587
-
588
-
589
-
590
- </div>
591
-
592
-
593
- <div id="method-i-switch_step" class="method-detail ">
594
-
595
- <div class="method-heading">
596
- <span class="method-name">switch_step</span><span
597
- class="method-args">(cur_f, prev_f, step, i)</span>
598
-
599
- <span class="method-click-advice">click to toggle source</span>
600
-
601
- </div>
602
-
603
-
604
- <div class="method-description">
605
-
606
- <p>switch step if current func value &gt; previous func value</p>
607
-
608
-
609
-
610
-
611
- <div class="method-source-code" id="switch_step-source">
612
- <pre><span class="ruby-comment"># File lib/optimization.rb, line 86</span>
613
- <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">switch_step</span>(<span class="ruby-identifier">cur_f</span>, <span class="ruby-identifier">prev_f</span>, <span class="ruby-identifier">step</span>, <span class="ruby-identifier">i</span>)
614
- <span class="ruby-keyword">return</span> <span class="ruby-identifier">step</span>[<span class="ruby-identifier">i</span>] <span class="ruby-operator">/</span> <span class="ruby-value">2.0</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">cur_f</span> <span class="ruby-operator">&gt;=</span> <span class="ruby-identifier">prev_f</span> <span class="ruby-comment">#you can switch 2.0 on something else</span>
615
- <span class="ruby-identifier">step</span>[<span class="ruby-identifier">i</span>]
616
- <span class="ruby-keyword">end</span></pre>
617
- </div>
618
-
619
- </div>
620
-
621
-
622
-
623
-
624
- </div>
625
-
626
-
627
- </section>
628
-
629
- </section>
630
-
631
- </main>
632
-
633
-
634
- <footer id="validator-badges" role="contentinfo">
635
- <p><a href="https://validator.w3.org/check/referer">Validate</a>
636
- <p>Generated by <a href="https://ruby.github.io/rdoc/">RDoc</a> 6.2.0.
637
- <p>Based on <a href="http://deveiate.org/projects/Darkfish-RDoc/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.
638
- </footer>
639
-