Das hatte ich erst auch überlegt, aber ändert das nicht die Verteilung? Mein Hirn ist heute schon abgeraucht.abs() ?
Japp. Wird dann die "Half-normal distribution".aber ändert das nicht die Verteilung?
Ich brauch die Zahlen später für eine Lorenz-Kurve und für den Gini-Koeffizient. Da bekomme ich mit negativen Zahlen Probleme.Was spricht dagegen, so lange Zufallswerte zu erzeugen, bis sie im gewünschten Bereich liegen?
Welchen Bereich? Die Zufallszahlen gehen theoretisch von -infty bis +infty.Was spricht dagegen, den Bereich mit +1 ins Positive zu verschieben?
Welchen Bereich? Die Zufallszahlen gehen theoretisch von -infty bis +infty.
the next pseudorandom, Gaussian ("normally") distributed double value with mean 0.0 and standard deviation 1.0 from this random number generator's sequence
Man kann das Intervall aber beliebig groß wählen, man wird nie 100 % erreichen.
Moment mal, der Wertebereich ist wirklich nicht [-1.0, +1.0]? Ich hatte das auch so verstanden.Ich hatte das so interpretiert, dass der Wertebereich von -1.0 bis + 1.0 geht.
import java.util.Random;
public class Gaussian {
public static void main(String[] args) {
Random rand = new Random(1L);
int count = 0;
do {
double value;
do {
value = rand.nextGaussian();
} while (Math.abs(value) <= 1.0);
System.out.println(value);
count++;
} while (count < 10);
}
}
1.561581040188955
-1.0912278829447088
-1.1182832102556484
-1.6583217791337177
-1.8821643777572246
-1.160868794354026
2.8307323206471837
-1.3604870442090895
-1.1629624729268742
-1.3049338775280348
public static double ng(double a, double b) {
double eps = 0.001;
if (!(a + eps < b)) {
throw new IllegalArgumentException("a must be lower than b");
}
Random r = new Random();
double g = r.nextGaussian();
while (g < a || g > b) {
g = r.nextGaussian();
}
return g;
}
public static void main(String[] args) {
for (int i = 0; i < 20; i++) {
System.out.println(ng(0.10, 0.11));
}
}
ng(10, 11)
hält es allerdings nicht an...Aber was wäre damit
Die Wahrscheinlichkeit, dass Du eine Zufallsvariable > 4,09 erhältst, ist nahezu 0. Siehe https://de.wikipedia.org/wiki/Standardnormalverteilungstabelle.Being(10, 11)
hält es allerdings nicht an...
So sehe ich das auch. Wenn man nur eine Seite abschneidet, dürfte sich der Erwartungswert verschieben. Wenn man sich überlegt, dass es fast unmöglich ist, Werte jenseits +/- 5 zu erhalten, spielt das für Erwartungswerte > 5 praktisch keine Rolle.Sollte aber klappen, den Erwartungswert in die Mitte des gewünschten Intervalls zu "schieben" und die Standardabweichung anzupassen (zB 1/6 der Interfvallgröße). Wenn man alles außerhalb liegende abschneidet, verliert man ein paar Promille (je nach Standardabweichung), aber nutzen lassen sollte es sich trotzdem.
function retval = incomings(n,m,s)
X=zeros(n,1);
for i = 1:n
do
v = randn()*s+m;
until (v >= 0)
X(i) = round(v);
endfor
retval = X;
endfunction
I=incomings(10000, 1500, 500);
X=sort(I);
total=sum(X)
C=cumsum(X)/total;
Y=[0;accumarray(ceil((1:rows(C)) / 1000)(:), C)];
I=abs(randn(10000,1))*500+1500;
X=sort(I);
total=sum(X)
C=cumsum(X)/total;
Z=[0;accumarray(ceil((1:rows(C)) / 1000)(:), C)];
hf = figure()
hold on
plot(0:0.1:1, Y/max(Y), "markersize", 10, "o-")
plot(0:0.1:1, Z/max(Z), "markersize", 10, "xr-")
hold off
print(hf, "lorenz.png", "-dpng")
import java.util.*;
public class NormalVerteilung {
private final double from;
private final double to;
private final Random random = new Random();
public NormalVerteilung(final double from, final double to) {
this.from = from;
this.to = to;
}
public double next() {
final double expectation = from + (to - from) / 2;
final double stdDev = (to - from) / 6; //knapp 2‰ liegen dann außerhalb, uU anpassen
double result;
do {
result = random.nextGaussian() * stdDev + expectation;
} while (result < from || result > to);
return result;
}
public static void main(String[] args) {
final NormalVerteilung normalVerteilung = new NormalVerteilung(5, 10);
for (int i = 0; i < 1000; i++) {
System.out.println(normalVerteilung.next());
}
}
}
Weniger als gar nicht gibt es also doch?!?Ich kenne mich anscheinend noch weniger gut als mihe7 damit aus...
Etwa so sollte das klappen:
Achtung Mathematik-DAU: Wofür ist nochmal das "stdDev" nötig?
Man hat einen Erwartungswert und die Standardabweichung. Ca. 69 % der normalverteilten Werte liegen im Bereich des Erwartungswerts +/- Standardabweichung. Verdoppelt man die Standardabweichung, liegen etwa 95 % der Werte in dem sich ergebenden Bereich. Man kann das Intervall aber beliebig groß wählen, man wird nie 100 % erreichen.
Wenn das hier so weiter geht, können wir ein Mathe-DAU-Forum aufziehen mit dem Untertitel "Wir haben kein Wissen, davon aber besonders viel"Achtung, auch Mathematik-DAU:
public static double ng(double a, double b) {
double eps = 0.001;
if (!(a + eps < b)) {
throw new IllegalArgumentException("a must be lower than b");
}
double c = -(b - a) / 2;
double d = +(b - a) / 2;
Random r = new Random();
double g = r.nextGaussian();
while (g < c || g > d) {
g = r.nextGaussian();
}
return g + d + a;
}
public static void main(String[] args) {
double d = 0;
for (int i = 0; i < 10000; i++) {
d += ng(0.10, 0.11) / 10000;
}
System.out.println(d);
d = 0;
for (int i = 0; i < 10000; i++) {
d += ng(10, 11) / 10000;
}
System.out.println(d);
d = 0;
for (int i = 0; i < 10000; i++) {
d += ng(-11, -10) / 10000;
}
System.out.println(d);
}
0.10501...
10.502...
-10.497...
Ist allerdings je nach Intervall nicht mehr als Normalverteilung erkennbar, da immer eine Standardabweichung von 1Juhu, fertig![]()
Da ist keine Abweichung um 1
https://docs.oracle.com/javase/8/docs/api/java/util/Random.html#nextGaussian() hat gesagt.:Returns the next pseudorandom, Gaussian ("normally") distributed double value with mean 0.0 and standard deviation 1.0 from this random number generator's sequence.
Wie das?Mit einem 0.5-Faktor ist der weg.
Hm , ich weiß nicht was er mit Verschiebung um 1 meint.Wie das?
double[] d = new double[11];
for (int i = 0; i < 1000; i++) {
int e = (int) Math.round(ng(-5, +5)) + 5;
d[e] += 1.0 / 1000.0;
}
for (int i = 0; i < d.length; i++) {
double e = d[i];
System.out.println(((i - 5) + " " + (e)));
}
-5 0.0
-4 0.001
-3 0.009 (Nullen entfernt)
-2 0.067
-1 0.237
0 0.379
1 0.231
2 0.073
3 0.003
4 0.0
5 0.0
Das hab ich nicht in Zweifel gezogenDas entspricht fast schon dieser Normalverteilung...