Proccessing, nextGaussian isn't between -1 and 1? - processing

I was working on a little Processing project to visualize gaussian random numbers, and I have a problem where the numbers produced are not between -1 and 1, which throws my whole thing off. What numbers do I have to scale the number by to scale it to the -1 to 1 range?
Program
import java.util.*;
Random generator;
void setup()
{
size(600,600);
generator = new Random();
background(255);
}
void draw()
{
generatenewdot();
}
void generatenewdot()
{
float xnum = (float)generator.nextGaussian();
float sd = 60;
float xmean = width/2;
float x = sd * xnum + xmean;
float ynum = (float)generator.nextGaussian();
float ymean = height/2;
float y = sd * ynum + ymean;
//Bigger when closer, smaller when farther
//get distance from center
float distance = sqrt(pow(sd*xnum,2) + pow(sd*ynum,2));
float size = (1 - (distance/sd)) * 10;
println("X: " + xnum + " | Y: " + ynum);
noStroke();
fill(0, 50);
ellipse(x, y, size, size);
}
Output
X: -1.2560346 | Y: 0.43913
X: 1.6684186 | Y: -1.0307527
X: -0.20982298 | Y: -0.22280085
X: -0.5874519 | Y: -2.3560321
X: -1.6996952 | Y: -0.6252706
X: -0.3767569 | Y: 0.8847021
X: 2.16339 | Y: 0.84067136
X: 0.9579867 | Y: -1.5785545
X: 0.39750758 | Y: -1.4931071
X: -0.43088776 | Y: 0.75665843
X: 1.0801688 | Y: -2.6318247
X: -1.1454289 | Y: -0.95125073
X: 1.4965589 | Y: 1.0736477
X: -0.39217913 | Y: -0.34573647
X: 0.0060171164 | Y: 1.0194058
X: -2.482392 | Y: -0.37381676
X: -0.120092504 | Y: -1.3072939
X: -0.79035485 | Y: -0.33741793
X: -1.0654978 | Y: -1.3986521
X: 0.30195275 | Y: -0.09365952
X: -1.3775821 | Y: -0.91224575
X: 0.15109988 | Y: -1.5025057
X: -0.9888884 | Y: 0.5061488
X: 1.7362484 | Y: -0.3089954
X: -0.48933098 | Y: -1.0289067
X: 0.54819685 | Y: 1.915066
X: -0.89757615 | Y: -0.5725651
X: -1.1072423 | Y: 0.1549204
X: -0.05344215 | Y: 0.044364702
X: -0.047609538 | Y: 0.7296939
X: 0.62724686 | Y: 0.30536157
X: 1.6744004 | Y: 0.13948894
X: 0.8259148 | Y: 1.3571945
X: 0.93188906 | Y: 0.89352655
X: -0.62066746 | Y: -0.2791857
X: 0.45208132 | Y: 0.7484442
X: 1.4533566 | Y: 0.15946567
X: -0.26117975 | Y: -0.9406836
X: 0.14579183 | Y: -0.6735571
X: -0.11575534 | Y: 0.24251445
X: -0.71969754 | Y: 1.2312696
X: -0.33103114 | Y: -0.3679331
X: -0.87640345 | Y: 0.18695408
X: 1.4733391 | Y: -1.717308
X: -0.47379303 | Y: 0.94097525
X: -1.2317376 | Y: -0.44845966
X: -1.9225131 | Y: 0.33214918
X: 0.6805828 | Y: -0.82625526
X: 2.0353675 | Y: -0.56851065
X: 0.43589613 | Y: -0.059929434
X: -0.53751755 | Y: 0.85414284
X: 2.2904902 | Y: -0.369723
X: -0.12156449 | Y: -1.0917004
X: -0.889154 | Y: 0.64644057
X: -0.22776474 | Y: 1.4512538
X: -0.7672019 | Y: -0.42612842
X: -0.410998 | Y: -1.1754745
X: 0.9694859 | Y: -0.32890838
X: 0.38745773 | Y: -0.7073066
X: -0.41483563 | Y: 0.3499609
X: 0.0570873 | Y: 1.0256606
X: 0.5236664 | Y: -1.6412264
X: -1.1053294 | Y: -0.06714651
X: 0.77513236 | Y: -0.36635277
X: 0.40660658 | Y: 0.72002655
X: -0.2413241 | Y: 0.10751419
X: -0.5079167 | Y: 0.2544589
X: 0.0738618 | Y: -0.46861497
X: 0.36933857 | Y: 3.282707
X: -0.38261575 | Y: -1.2680397
X: 0.26502755 | Y: -1.4085288
X: -1.0758035 | Y: 0.48999637
X: -1.0022781 | Y: 0.18629716
X: 1.089121 | Y: 0.22576475
X: -0.1774196 | Y: 1.1405197
X: -0.75939226 | Y: -1.246858
X: 2.0534744 | Y: -0.027038628
X: 1.2573285 | Y: -0.2153611
X: 0.91109043 | Y: -0.9592889
X: 1.1948314 | Y: 0.8129871
X: -0.2642877 | Y: -2.1204646
X: 0.76492834 | Y: 1.0202236
X: -0.19996478 | Y: -0.25985986
X: 0.305574 | Y: -0.15428662
X: -0.5793801 | Y: 0.05751243
X: -1.1586995 | Y: -1.354029
X: -2.0605218 | Y: 0.15988825
X: 0.13619052 | Y: 0.688434
X: -0.28077507 | Y: -1.5288342
X: -0.382878 | Y: -0.37027964
X: 0.7066691 | Y: -0.71114177
X: 0.3983471 | Y: 0.52614754
X: -0.7913421 | Y: 1.4425266
X: 0.12273746 | Y: 1.081629
X: -0.13688068 | Y: -1.1057968
X: 0.60105777 | Y: -0.93368775
X: -1.3000423 | Y: -0.061667506
X: 0.12970658 | Y: -0.82605433
X: 0.29501432 | Y: -0.52549535
X: 0.39391693 | Y: 0.8624781
X: 2.4755092 | Y: -1.0342329
X: -0.22210532 | Y: -0.6144739
X: -0.3413467 | Y: -0.19307336
X: -0.5308936 | Y: 0.30849203
X: 1.1740618 | Y: 1.2144334
X: 0.1827944 | Y: -0.17112117
X: 1.1925478 | Y: -0.3520857
X: -1.2051786 | Y: 0.15042834
X: 3.0183444 | Y: -0.90113115
X: -1.0622096 | Y: -0.30049986
X: 1.8420129 | Y: 1.2509897
X: -2.297314 | Y: -2.0725875
X: 1.0673923 | Y: -2.5084429
X: 0.3134048 | Y: -0.052358847
X: 0.16638549 | Y: 0.5592031
X: -0.067902535 | Y: -1.420417
X: -0.016045086 | Y: -1.0686399
X: -0.6912575 | Y: -0.9322265
X: 1.0217631 | Y: 0.5885641
X: -0.77907616 | Y: 0.5000267
X: 0.01890201 | Y: -0.11718043
X: -0.958193 | Y: -1.3351127
X: -0.3736327 | Y: 1.9608271
X: -0.7962202 | Y: 0.7476578
X: 0.25758967 | Y: -0.77497977
X: -0.48639807 | Y: -0.7017801
X: -0.82916087 | Y: 0.8303733
X: -1.707152 | Y: -1.3296013
X: -1.7046789 | Y: -0.24234797
X: -1.0117844 | Y: 0.45633218
X: -0.08127227 | Y: 0.48397893
X: 0.82085145 | Y: 2.2481968
X: 1.3258406 | Y: 2.198357
X: 0.2562196 | Y: 0.3340968
X: 0.60788757 | Y: 0.24063592
X: -0.031290732 | Y: -0.14278243
X: -1.2028422 | Y: 0.6705914
X: -0.7122825 | Y: 0.33648172
X: -1.3599969 | Y: -0.6731673
X: -0.5936929 | Y: -0.34959924
X: 1.964009 | Y: 0.8512692
X: -0.68523324 | Y: -0.4050971
X: 0.60271347 | Y: -0.09168337
X: 0.02265682 | Y: -0.8994877
X: 0.5623386 | Y: -1.1070106
X: -1.4453007 | Y: -0.31628308
X: -0.062762 | Y: 1.5903912
X: -0.3273365 | Y: 0.11271362
X: -0.011844525 | Y: -0.97879356
X: -0.21651044 | Y: -1.488296
X: 1.7444072 | Y: -0.6698305
X: 0.07018017 | Y: 0.052752882
X: 0.33038074 | Y: -0.51466936
X: -0.3488621 | Y: 0.6184827
X: 0.049165536 | Y: 0.7268606
X: 0.38889283 | Y: 0.22207315
X: 1.1190308 | Y: 0.18530433
X: -0.5596919 | Y: 0.038130693
X: 2.2971296 | Y: 0.08598893
X: 0.48901424 | Y: -0.6340521
X: -0.34295475 | Y: 2.4535484
X: 0.7059389 | Y: -0.060639072
X: -0.9430291 | Y: -0.030210787
X: 0.14106135 | Y: 0.3733378
X: 0.23838589 | Y: -0.11811932
X: -0.14800806 | Y: 0.02691031
X: -0.4372808 | Y: -0.912786
X: -1.2872834 | Y: -0.16293962
X: 1.9569577 | Y: -0.2684084
X: 1.4659501 | Y: 0.79093254
X: 1.1387724 | Y: 1.4153944
X: -0.9614859 | Y: 1.2193747
X: -0.24685526 | Y: 1.1087464
X: 0.25005496 | Y: -0.18707326
X: -0.08282836 | Y: 0.16380334
X: -0.890932 | Y: -0.01911562
X: -1.3180755 | Y: -1.7750782
X: -1.9738325 | Y: 0.4650801
X: 0.11823471 | Y: -0.7086047
X: 0.7637192 | Y: 3.0014162
X: 1.0746229 | Y: 0.5347033
X: -0.57545507 | Y: 1.2818112
X: 1.2836952 | Y: 1.0796871
X: -0.26668364 | Y: 0.19159853
X: -2.1289194 | Y: -1.8146951
X: 1.4087044 | Y: 0.266897
X: -0.12748817 | Y: 1.4472772
X: 1.0245978 | Y: 0.17778511
X: -1.416702 | Y: -1.1412634
X: -1.5589409 | Y: 0.095859885
X: 1.1145445 | Y: -0.32158515
X: -2.2714367 | Y: -1.032223
X: 1.2649084 | Y: -1.9037691
X: -0.33965677 | Y: 0.81614226
X: -0.12146729 | Y: 0.4777388
X: -0.4253145 | Y: 1.5192709
X: -0.20069526 | Y: 0.0266705
X: 0.7794582 | Y: 0.20600611
X: 0.068017714 | Y: -0.7936217
X: -0.8899986 | Y: -0.5964193
X: -0.18383493 | Y: -0.92586005
X: -0.7818783 | Y: -0.4391756
X: 2.9518538 | Y: 0.51974326
X: -0.30460843 | Y: 1.4595356
X: -0.76000154 | Y: -0.6935336
X: 1.2247328 | Y: -1.9350185
X: -0.17959218 | Y: 0.52692646
X: -1.1845113 | Y: -0.7372843
X: 0.7145226 | Y: 0.97987723
X: 0.294313 | Y: 0.42491102
X: 0.69715863 | Y: 1.0249106
X: 0.61984223 | Y: 1.9051309
X: 0.10692853 | Y: -0.7397708
X: -1.6503758 | Y: -0.56400114
X: -0.619303 | Y: -0.50828993
X: -1.0103049 | Y: 1.5179138
X: -0.6610786 | Y: -0.23466662
X: 1.47647 | Y: -0.7518148
X: 1.8461105 | Y: -0.89638317
X: -1.0333326 | Y: 0.5272911
X: 0.32953307 | Y: -2.068906
X: -0.3369011 | Y: 1.1342978
X: 0.26832464 | Y: 0.35111254
X: -1.1943347 | Y: 1.5756301
X: -0.2821439 | Y: -0.21851084
X: 0.045426905 | Y: 0.43564394
X: -0.08327247 | Y: 0.17497726
X: 0.26342446 | Y: 0.8225831
X: 0.51339006 | Y: -0.70085526
X: 0.6015727 | Y: 1.4097772
X: -0.87026924 | Y: -1.2695398
X: 0.9147027 | Y: -0.54681355
X: -0.25914836 | Y: 0.14173253
X: 0.79905576 | Y: -0.78842294
X: -0.122037366 | Y: 1.9061232
X: 0.031827897 | Y: 9.054022E-5
X: 0.8216564 | Y: 1.1695337
X: -0.3981461 | Y: 1.6214145
X: -0.6744849 | Y: 0.16823441
X: 0.1994377 | Y: 1.041054
X: -0.9688934 | Y: 0.5749102
X: 0.52517 | Y: 0.3087776
X: -0.31726742 | Y: 1.0651228
X: 0.5944692 | Y: -0.39537027
X: -0.14272667 | Y: 0.15524986
X: 1.0194787 | Y: -0.17233147
X: -0.3691948 | Y: 0.62380767
X: 1.2492002 | Y: -0.024808018
X: 1.0656878 | Y: -0.6394374
X: 1.8846616 | Y: 1.1887405
X: 2.2143235 | Y: -0.9957973
X: 1.1480668 | Y: -2.0087852
X: -0.7856953 | Y: 0.17126346
X: 1.4994434 | Y: 0.42100754
X: 0.61520094 | Y: 0.4594768
X: -1.8998433 | Y: 0.81686187
X: -0.59870094 | Y: 0.16190825
X: 0.7568211 | Y: 0.1445908
X: 0.068865344 | Y: -0.11507618
X: -0.13646689 | Y: -0.71280926
X: -0.42065284 | Y: 1.6816016
X: -0.8548044 | Y: -0.23868565
X: 0.44674578 | Y: -0.08002255
X: 0.15143052 | Y: 0.9913837
X: -0.24043444 | Y: -0.4339675
X: -0.07372746 | Y: -1.4390934
X: -2.0154748 | Y: -0.6124442
X: 2.336962 | Y: 0.09206108
X: 0.12995008 | Y: 0.6019416
X: -0.14780447 | Y: -0.9132321
X: 0.8062503 | Y: 0.1129237
X: 0.12131127 | Y: -1.5861236
X: 0.4869577 | Y: -0.67768985
X: -1.1218196 | Y: 1.184578
X: 0.7874171 | Y: -0.045187805
X: -0.67828524 | Y: -0.5735016
X: -0.994444 | Y: 0.28350237
X: 2.633789 | Y: 0.54614604
X: -0.08738608 | Y: 1.5393788
X: -0.1632809 | Y: 1.0571663
X: -0.9038875 | Y: 0.30314434
X: 1.3459784 | Y: 0.38406494
X: -0.638972 | Y: -0.21715638
X: 1.401298 | Y: 0.2867331
X: -0.92279404 | Y: 0.9176272
X: -0.041815635 | Y: -1.5927134
X: 0.14853486 | Y: -0.5005275
X: -0.12517829 | Y: 0.9995699
X: 0.30420595 | Y: -0.7695801
X: -1.1811762 | Y: -1.1573164
X: 0.3598652 | Y: 0.18536983
X: 0.92923003 | Y: -0.045854274
X: 1.0242708 | Y: -0.6519265
X: -0.15148447 | Y: -1.6188399
X: -0.5767954 | Y: -0.7759711
X: 1.691366 | Y: 2.0550196
X: -2.4651797 | Y: -0.532277
X: -0.38202325 | Y: 2.7200665
X: -0.026308075 | Y: -0.41392756
X: -0.54529566 | Y: 1.0306138
X: -0.2474008 | Y: -0.8410272
X: -0.8878296 | Y: 0.6692659
X: -1.0749551 | Y: -0.05105501
X: -1.4509034 | Y: -0.40763706
X: 0.63799614 | Y: 0.5781374
X: -0.15311946 | Y: 0.9867796
X: 1.0860987 | Y: 2.2270775
X: -1.8498964 | Y: -0.15837035
X: 0.5712155 | Y: 0.6274683
X: 0.10293772 | Y: -0.2556146
X: 0.70576346 | Y: -0.60659826
X: 0.40139621 | Y: 0.17961529
X: -1.8881758 | Y: 0.017092947
X: -2.8272333 | Y: -0.9225435
X: -0.10255992 | Y: -0.5627598
X: -1.5514668 | Y: 1.090334
X: 0.8607706 | Y: 0.44446054

The Gaussian probability distribution extends to infinity, but you can scale it so that samples are in (-1, 1) with 95%, 99%, or higher probability. But some samples will always be outside of (-1, 1).
For example generator.nextGaussian()/1.69 will be in (-1, 1) with 95% probability, and outside with 5% probability.

Related

Fibonacci sequence in Ruby

def fibonacci(n)
n <= 1 ? n : fibonacci( n - 1 ) + fibonacci( n - 2 )
end
puts fibonacci( 6)
Can somebody explain how this code works. I realise that it works due to recursion but i cannot figure it out gradually. Will be gratefull for step by step explanation.
Does this help you visualise it?:
def fibonacci(n, level = 0)
puts ('| ' * level) + 'n: ' + n.to_s
res = n <= 1 ? n : fibonacci(n - 1, level + 1) + fibonacci(n - 2, level + 1)
puts ('| ' * level) + 'res: ' + res.to_s
res
end
irb(main):038:0> fibonacci(6)
n: 6
| n: 5
| | n: 4
| | | n: 3
| | | | n: 2
| | | | | n: 1
| | | | | res: 1
| | | | | n: 0
| | | | | res: 0
| | | | res: 1
| | | | n: 1
| | | | res: 1
| | | res: 2
| | | n: 2
| | | | n: 1
| | | | res: 1
| | | | n: 0
| | | | res: 0
| | | res: 1
| | res: 3
| | n: 3
| | | n: 2
| | | | n: 1
| | | | res: 1
| | | | n: 0
| | | | res: 0
| | | res: 1
| | | n: 1
| | | res: 1
| | res: 2
| res: 5
| n: 4
| | n: 3
| | | n: 2
| | | | n: 1
| | | | res: 1
| | | | n: 0
| | | | res: 0
| | | res: 1
| | | n: 1
| | | res: 1
| | res: 2
| | n: 2
| | | n: 1
| | | res: 1
| | | n: 0
| | | res: 0
| | res: 1
| res: 3
res: 8
=> 8

Change 'References' dialog width?

I want to give the Reference popup tool window a wider default width to show more information. I've done this before on another machine but I don't know how. Is it a registry hack?
Thanks in advance because it's very annoying that this toolwindow can't be resized. It obscures certain information which cannot be viewed otherwise.
(Since the other answer doesn't actually describe what to do - I've copied it here in case the external link goes dead).
A process to do this is described in the following article, excerpted here:
(from https://visualstudiomagazine.com/articles/2010/03/02/redesign-ide-dialogs.aspx)
Redesign IDE Dialogs
By Karl E. Peterson 03/02/2010
...Well, there's a tool you can use to do modify these sorts of
settings to your heart's content. Resource Hacker is a freeware
utility to view, modify, rename, add, delete and extract resources in
32-bit Windows executables and resource files.
ResHacker offers a dialog tool that's extremely similar to Classic
VB's -- you just drag the dialog elements around, resizing them to
suit. Or you can edit the raw resource script, and watch the changes
play out in the dialog designer. Simply open the "Dialog" node in the
treeview, find the dialog you want to edit, and go to town. When
you're happy with the new design, press the "Compile Script" button,
then just do a File | Save to write the changes to disk. (Be sure to
make a backup of the original file, first...)
To modify the Classic VB Project-References dialog, open the
VB6IDE.DLL (or VB5IDE.DLL) file in ResHacker, find Dialog #4040 and
get to work.
The article also included two resource scripts - the modified, wider version, and also the original as a reference / backup.
Modified:
4040 DIALOG 0, 0, 455, 305
STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
CAPTION "References"
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
FONT 8, "Tahoma"
{
CONTROL "&Available References:", -1, STATIC, SS_LEFTNOWORDWRAP | WS_CHILD | WS_VISIBLE, 7, 7, 73, 8
CONTROL "", 5050, LISTBOX, LBS_NOTIFY | LBS_MULTIPLESEL | LBS_OWNERDRAWFIXED | LBS_HASSTRINGS | LBS_NOINTEGRALHEIGHT | WS_CHILD | WS_VISIBLE | WS_BORDER | WS_VSCROLL | WS_HSCROLL | WS_GROUP | WS_TABSTOP, 7, 19, 382, 235
CONTROL "OK", 1, BUTTON, BS_DEFPUSHBUTTON | WS_CHILD | WS_VISIBLE | WS_GROUP | WS_TABSTOP, 398, 18, 50, 14
CONTROL "Cancel", 2, BUTTON, BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 398, 40, 50, 14
CONTROL "&Browse...", 5051, BUTTON, BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 398, 61, 50, 14
CONTROL "&Help", 5052, BUTTON, BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 398, 240, 50, 14
CONTROL "Result", 5055, BUTTON, BS_GROUPBOX | WS_CHILD | WS_VISIBLE, 8, 260, 442, 37
CONTROL "Location:", -1, STATIC, SS_LEFT | WS_CHILD | WS_VISIBLE, 14, 271, 32, 8
CONTROL "", 5053, STATIC, SS_LEFTNOWORDWRAP | SS_NOPREFIX | WS_CHILD | WS_VISIBLE, 52, 271, 390, 8
CONTROL "Language:", -1, STATIC, SS_LEFT | WS_CHILD | WS_VISIBLE, 14, 282, 36, 8
CONTROL "", 5054, STATIC, SS_LEFTNOWORDWRAP | SS_NOPREFIX | WS_CHILD | WS_VISIBLE, 52, 282, 390, 8
CONTROL "&U", 4528, BUTTON, BS_OWNERDRAW | WS_CHILD | WS_VISIBLE | WS_GROUP | WS_TABSTOP, 416, 122, 14, 14
CONTROL "&D", 4529, BUTTON, BS_OWNERDRAW | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 416, 149, 14, 14
CONTROL "Priority", -1, STATIC, SS_LEFTNOWORDWRAP | SS_NOPREFIX | WS_CHILD | WS_VISIBLE, 411, 139, 24, 8
}
Original:
4040 DIALOG 0, 0, 295, 204
STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
CAPTION "References"
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
FONT 8, "Tahoma"
{
CONTROL "&Available References:", -1, STATIC, SS_LEFTNOWORDWRAP | WS_CHILD | WS_VISIBLE, 7, 7, 73, 8
CONTROL "", 5050, LISTBOX, LBS_NOTIFY | LBS_MULTIPLESEL | LBS_OWNERDRAWFIXED | LBS_HASSTRINGS | LBS_NOINTEGRALHEIGHT | WS_CHILD | WS_VISIBLE | WS_BORDER | WS_VSCROLL | WS_HSCROLL | WS_GROUP | WS_TABSTOP, 7, 24, 193, 123
CONTROL "OK", 1, BUTTON, BS_DEFPUSHBUTTON | WS_CHILD | WS_VISIBLE | WS_GROUP | WS_TABSTOP, 238, 6, 50, 14
CONTROL "Cancel", 2, BUTTON, BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 238, 23, 50, 14
CONTROL "&Browse...", 5051, BUTTON, BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 238, 45, 50, 14
CONTROL "&Help", 5052, BUTTON, BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 238, 84, 50, 14
CONTROL "Result", 5055, BUTTON, BS_GROUPBOX | WS_CHILD | WS_VISIBLE, 7, 154, 281, 43
CONTROL "Location:", -1, STATIC, SS_LEFT | WS_CHILD | WS_VISIBLE, 35, 168, 32, 8
CONTROL "", 5053, STATIC, SS_LEFTNOWORDWRAP | SS_NOPREFIX | WS_CHILD | WS_VISIBLE, 75, 168, 198, 8
CONTROL "Language:", -1, STATIC, SS_LEFT | WS_CHILD | WS_VISIBLE, 35, 180, 36, 8
CONTROL "", 5054, STATIC, SS_LEFTNOWORDWRAP | SS_NOPREFIX | WS_CHILD | WS_VISIBLE, 77, 180, 196, 8
CONTROL "&U", 4528, BUTTON, BS_OWNERDRAW | WS_CHILD | WS_VISIBLE | WS_GROUP | WS_TABSTOP, 211, 62, 14, 14
CONTROL "&D", 4529, BUTTON, BS_OWNERDRAW | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 211, 96, 14, 14
CONTROL "Priority", -1, STATIC, SS_LEFTNOWORDWRAP | SS_NOPREFIX | WS_CHILD | WS_VISIBLE, 206, 82, 24, 8
}
I've just tried this and it worked correctly. (Using VB6 Enterprise Edition + SP6.)
The tool (Resource Hacker) works very well and not only for VB6 ;-).
Thanks Brian !
Question closed.

Oracle ROUND HALF EVEN [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
Is there any Oracle function to perform the ROUND HALF EVEN?
I've found this post MySQL round half however I couldn't make it work in Oracle
CREATE FUNCTION roundHalfEven (numberToRound IN NUMBER, roundPrecision IN NUMBER)
RETURN NUMBER
IS roundedNumber NUMBER;
BEGIN
DECLARE digitEvenOdd NUMBER;
DECLARE digitPosition NUMBER;
DECLARE digitToRound NUMBER;
DECLARE roundedNumber DECIMAL(20,6) DEFAULT 0;
SET digitPosition = INSTR(numberToRound, '.');
IF (roundingPrecision < 1) THEN
SET digitPosition = digitPosition + roundingPrecision;
ELSE
SET digitPosition = digitPosition + roundingPrecision + 1;
END IF;
IF (digitPosition > 0 AND digitPosition <= CHAR_LENGTH(numberToRound)) THEN
SET digitToRound = CAST(SUBSTR(numberToRound, digitPosition, 1) AS UNSIGNED);
SET digitPosition = digitPosition - 1;
IF (digitPosition > 0 AND digitPosition <= CHAR_LENGTH(numberToRound)) THEN
SET digitEvenOdd = CAST(SUBSTR(numberToRound, digitPosition, 1) AS UNSIGNED);
END IF;
END IF;
IF (digitToRound > -1) THEN
IF (digitToRound >= 5 AND digitEvenOdd IN (1,3,5,7,9)) THEN
SET roundedNumber = ROUND(numberToRound, roundingPrecision);
ELSE
SET roundedNumber = TRUNCATE(numberToRound, roundingPrecision);
END IF;
ELSE IF (roundingPrecision > 0) THEN
SET roundedNumber = numberToRound;
END IF;
RETURN(roundedNumber);
END;
/
SQL Fiddle
Oracle 11g R2 Schema Setup:
CREATE TABLE test_data( value ) AS
SELECT (LEVEL -11)/2 FROM DUAL CONNECT BY LEVEL <= 21;
Query 1:
SELECT value,
ROUND( value ),
CASE
WHEN MOD( ABS( value ), 2 ) = 0.5
THEN TRUNC( value )
ELSE ROUND( value )
END AS round_half_even
FROM test_data
Results:
| VALUE | ROUND(VALUE) | ROUND_HALF_EVEN |
|-------|--------------|-----------------|
| -5 | -5 | -5 |
| -4.5 | -5 | -4 |
| -4 | -4 | -4 |
| -3.5 | -4 | -4 |
| -3 | -3 | -3 |
| -2.5 | -3 | -2 |
| -2 | -2 | -2 |
| -1.5 | -2 | -2 |
| -1 | -1 | -1 |
| -0.5 | -1 | 0 |
| 0 | 0 | 0 |
| 0.5 | 1 | 0 |
| 1 | 1 | 1 |
| 1.5 | 2 | 2 |
| 2 | 2 | 2 |
| 2.5 | 3 | 2 |
| 3 | 3 | 3 |
| 3.5 | 4 | 4 |
| 4 | 4 | 4 |
| 4.5 | 5 | 4 |
| 5 | 5 | 5 |
Or as a function:
SQL Fiddle
Oracle 11g R2 Schema Setup:
CREATE TABLE test_data( value ) AS
SELECT (LEVEL -11)/20 FROM DUAL CONNECT BY LEVEL <= 21
/
CREATE FUNCTION round_half_even(
value NUMBER,
prec INTEGER DEFAULT 0
) RETURN NUMBER
IS
whole NUMBER := POWER( 10, -prec );
BEGIN
RETURN CASE
WHEN ABS( MOD( value, 2*whole ) ) = 0.5*whole
THEN TRUNC( value, prec )
ELSE ROUND( value, prec )
END;
END;
/
Query 1:
SELECT value,
ROUND( value , 1),
round_half_even( value, 1 )
FROM test_data
Results:
| VALUE | ROUND(VALUE,1) | ROUND_HALF_EVEN(VALUE,1) |
|-------|----------------|--------------------------|
| -0.5 | -0.5 | -0.5 |
| -0.45 | -0.5 | -0.4 |
| -0.4 | -0.4 | -0.4 |
| -0.35 | -0.4 | -0.4 |
| -0.3 | -0.3 | -0.3 |
| -0.25 | -0.3 | -0.2 |
| -0.2 | -0.2 | -0.2 |
| -0.15 | -0.2 | -0.2 |
| -0.1 | -0.1 | -0.1 |
| -0.05 | -0.1 | 0 |
| 0 | 0 | 0 |
| 0.05 | 0.1 | 0 |
| 0.1 | 0.1 | 0.1 |
| 0.15 | 0.2 | 0.2 |
| 0.2 | 0.2 | 0.2 |
| 0.25 | 0.3 | 0.2 |
| 0.3 | 0.3 | 0.3 |
| 0.35 | 0.4 | 0.4 |
| 0.4 | 0.4 | 0.4 |
| 0.45 | 0.5 | 0.4 |
| 0.5 | 0.5 | 0.5 |

Selecting rows in DataFrame by/after grouping using DataFramesMeta in Julia

I am trying to select certain data rows in a DataFrame using #linq macros:
using DataFrames, DataFramesMeta
df=DataFrame(x = ["a", "a", "a", "b", "b", "b"],
y = [1, 2, 3, 2, 3, 4],
z = [100, 200, 300, 456, 345, 234])
| Row | x | y | z |
|-----|-----|---|-----|
| 1 | "a" | 1 | 100 |
| 2 | "a" | 2 | 200 |
| 3 | "a" | 3 | 300 |
| 4 | "b" | 2 | 456 |
| 5 | "b" | 3 | 345 |
| 6 | "b" | 4 | 234 |
I am trying to select those rows that have the maximum y for a given type of x, that is
| Row | x | y | z |
|-----|-----|---|-----|
| 1 | "a" | 3 | 300 |
| 2 | "b" | 4 | 234 |
So, I am grouping by column x and adding a column with the maxima
#linq df |> #by(:x, maxY = maximum(:y))
which gives
| Row | x | maxY |
|-----|-----|------|
| 1 | "a" | 3 |
| 2 | "b" | 4 |
but I don't see how to put the corresponding z entries back in. Probably, it would be join but I don't see how to do that or get the result in another, simple way.
You can do it in one line joining on=[:x,:y] but for this to work you need to name the maximum(:y) column y not maxY:
df2 = #linq df |> by(:x, y=maximum(:y)) |> join(df, on=[:x, :y])
You can later rename that column to the intended maxY:
rename!(df2, :y, :maxY)

Extracting path in A* search

I'm trying to implement A* search with the following code:
void Map::findPath(Robot robot, Model target, vector<Node> nodeList) {
Node targetNode = target.getCurrentNode();
Node startNode = robot.getCurrentNode();
vector<Node> openList;
vector<Node> closedList;
openList.push_back(startNode);
while (!openList.empty()) {
Node curNode = nodeWithLowestFScore(openList);
if (curNode.equal(targetNode)) {
/*cout << "WTF" << endl;
Node *p = curNode.getParent();
int i = 0;
while (!p->equal(startNode)) {
cout << p->getX() << " " << p->getY() << endl;
p = p->getParent();
cout << i++ << endl;
}*/
break;
}
closedList.push_back(curNode);
removeFromVector(openList, curNode);
vector<Node> adjNodes;
curNode.getWalkableAdjacentNodes(nodeList, adjNodes);
for (int i = 0; i < adjNodes.size(); i++) {
if (inVector(closedList, adjNodes[i])) {
continue;
}
if (!inVector(closedList, adjNodes[i])) {
adjNodes[i].setParent(&curNode);
cout << "Child: " <<adjNodes[i].getX() << " " << adjNodes[i].getY() << endl;
cout << "Parent: " << adjNodes[i].getParent()->getX()
<< " " << adjNodes[i].getParent()->getY() << endl;
adjNodes[i].setG(curNode.getG() + 1);
adjNodes[i].setH(adjNodes[i].getDistance(targetNode, 'm'));
adjNodes[i].setF();
openList.push_back(adjNodes[i]);
}
if (inVector(closedList, adjNodes[i])) {
if (curNode.getG() + 1 < adjNodes[i].getG()) {
adjNodes[i].setParent(&curNode);
adjNodes[i].setG(curNode.getG() + 1);
adjNodes[i].setF();
}
}
}
}
}
Here's the console output of this code(StartP = [x:-7, y:6], EndP = [x:0, y:-2]:
Child: -1 -2
Parent: 0 -2
Child: 1 -2
Parent: 0 -2
Child: -2 -2
Parent: -1 -2
Child: -1 -3
Parent: -1 -2
Child: -3 -2
Parent: -2 -2
Child: -3 -1
Parent: -3 -2
Child: -3 0
Parent: -3 -1
Child: -3 1
Parent: -3 0
Child: -4 0
Parent: -3 0
Child: -5 0
Parent: -4 0
Child: -5 1
Parent: -5 0
Child: -5 -1
Parent: -5 0
Child: -5 2
Parent: -5 1
Child: -5 3
Parent: -5 2
Child: -5 4
Parent: -5 3
Child: -5 5
Parent: -5 4
Child: -6 4
Parent: -5 4
Child: -4 4
Parent: -5 4
Child: -7 4
Parent: -6 4
Child: -8 4
Parent: -7 4
Child: -5 6
Parent: -5 5
Child: -5 7
Parent: -5 6
Child: -4 6
Parent: -5 6
Child: -3 2
Parent: -3 1
Child: -3 3
Parent: -3 2
Child: -2 2
Parent: -3 2
Child: -3 4
Parent: -3 3
Child: -4 4
Parent: -3 4
Child: -2 4
Parent: -3 4
Child: -1 4
Parent: -2 4
Child: -1 2
Parent: -2 2
Child: -3 6
Parent: -4 6
Child: -5 8
Parent: -5 7
Child: -9 4
Parent: -8 4
Child: -5 -2
Parent: -5 -1
Child: -1 -4
Parent: -1 -3
Child: 2 -2
Parent: 1 -2
Child: 3 -2
Parent: 2 -2
Child: 2 -3
Parent: 2 -2
Child: -2 -4
Parent: -1 -4
Child: -3 -4
Parent: -2 -4
Child: -3 -5
Parent: -3 -4
Child: -5 -3
Parent: -5 -2
Child: -9 5
Parent: -9 4
Child: -9 6
Parent: -9 5
Child: -8 6
Parent: -9 6
Child: -7 6
Parent: -8 6
It's a bit messy but I followed it. It reaches the starting point. (-7, 6)-> (-8, 6) -> (-9, 6) ... (-1, -2)->(0, -2).
However, if I uncomment the line that starts with "WTF" and want to back trace it it just gets into an infinite loop that prints (-7, 6) which is my EndP.
Any help is much appreciated.
Okay problematic line was this: adjNodes[i].setParent(&curNode); I just had to reallocate a new Node, copy the contents of curNode to it and set that one as parent. Algorithm was fine.

Resources