Discriminator's loss of fake and real are same, and don't change - generative-adversarial-network

I'm training a GAN, and I use MSELoss as the GANLoss. But the discriminator's loss of fake and real inputs are totally same after several steps, loss_fake decreased to 0.25, loss_real increased to 0.25 at the same step. Then, they didn't change anymore. So, is my discriminator too strong or too weak?
As for the generator's loss, only SmoothL1Loss changed.

Related

Evaluate likelyhood state will happen based on factors for Finite State Machine

It is my first time programming a finite state machine for a boss fight in my game. I want the fight to feel dynamic, the evaluation is currently very simple and works like this:
Player within short range? > pick random within short range state
Player within medium range? > pick random within medium range state
My goal is to make this a bit more sophisticated, what I'd love to achieve is a value called StateLikelihood for each state that determines how likely a state can occur, and works like this:
StateLikelihood is 0% if player is outside range of state (or other
factors that can make it 0%)
StateLikelihood is reduced if state has already occurred recently (or other factors that reduces it)
Statelikelihood increases depending on various factors
Example:
Likelihood of state X is 70% if:
Player health is 60 (each healthpoint adds +1%)
Player is within medium range (Other ranges makes it 0%)
Player has attacked (adds +10% to likelihood)
State X occurred, State X likelihood is now 50% next evaluation
My questions is: Does anyone know a probability formula that could help me a achieve this, or is there a better approach than this? What trips me is that, sure this would be easy to do with a single state; but having multiple states it would be affecting the probability of all those other states being selected too.
First problem I see is that I cannot add flat likelihood percentage increases next evaluation, my idea is that the increases might have to be in relation to the max likelihood of the state.
If anyone has any recommendations or resources I'd be delighted.

Discretization simulation of a Wiener Process

I got some problems with this homework which I have totally no idea, never got into this field before and I really need some help.
First, we have a wiener process like
Which means the probability of the process drops beneath -3 within the time interval [0,1].
Now the thing is we have to simulate the process by discretize it.
1.Suppose we first discretize the process by 100 points and simulate 10,000 process in this way.
i.e., W(0.01), W(0.02), …., W(1.00).
Note that W(t) – W(t-0.01) ~ N(0,0.01) independently.
2.Using the data obtained at 1., we approximate
by
what is the relationship between this value and the real
(larger, equal to or smaller)?
3.Repeat 1. and 2. by cutting [0,1] into 10,000 points instead. Will the
resulting probability increases or decreases?

Cellular automaton with more then 2 states(more than just alive or dead)

I am making a roguelike where the setting is open world on a procedurally generated planet. I want the distribution of each biome to be organic. There are 5 different biomes. Is there a way to organically distribute them without a huge complicated algorithm? I want the amount of space each biome takes up to be nearly equal.
I have worked with cellular automata before when I was making the terrain generators for each biome. There were 2 different states for each tile there. Is there an efficient way to do 5?
I'm using python 2.5, although specific code isn't necessary. Programming theory on it is fine.
If the question is too open ended, are there any resources out there that I could look at for this kind of problem?
You can define a cellular automaton on any cell state space. Just formulate the cell update function as F:Q^n->Q where Q is your state space (here Q={0,1,2,3,4,5}) and n is the size of your neighborhood.
As a start, just write F as a majority rule, that is, 0 being the neutral state, F(c) should return the value in 1-5 with the highest count in the neighborhood, and 0 if none is present. In case of equality, you may pick one of the max at random.
As an initial state, start with a configuration with 5 relatively equidistant cells with the states 1-5 (you may build them deterministically through a fixed position that can be shifted/mirrored, or generate these points randomly).
When all cells have a value different than 0, you have your map.
Feel free to improve on the update function, for example by applying the rule with a given probability.

Create a key to generate random values from

Is is possible to somehow create a key or seed that you can initialize a random number generator with, and thereby ensuring that all the random numbers using this key will be identical.
Or is there another technique that i can use with similar results?
what i like to be able to do is create a random seed. then use this seed to initialize a random number generator, use this random number generator to build a tilemap or something else that requires alot of random numbers.
Then send the same seed to another client which will be able to generator the excact same map because the random numbers are the same?
Im just curious if something like this is possible, dont really care about platform etc.
As long as the random number generator you are using does nothing you don't tell it to, this will work. For example, if you seed c's RNG with a seed of "4", and then print 10 random numbers 100 times, those same 10 numbers will be printed 100 times. This is because the RNG only works based off of the seed, and does some algorithmic transformation on the seed to produce a set of values. If you give it the same seed each time, the same algorithmic process is repeat each time, leading to the same results.
I highlighted nothing because modern day RNGs may automatically use the time or some random system specs in the generation process without you knowing about it, such that for those whom do not desire the effect you desire do not get it.

Generate very very large random numbers

How would you generate a very very large random number? I am thinking on the order of 2^10^9 (one billion bits). Any programming language -- I assume the solution would translate to other languages.
I would like a uniform distribution on [1,N].
My initial thoughts:
--You could randomly generate each digit and concatenate. Problem: even very good pseudorandom generators are likely to develop patterns with millions of digits, right?
You could perhaps help create large random numbers by raising random numbers to random exponents. Problem: you must make the math work so that the resulting number is still random, and you should be able to compute it in a reasonable amount of time (say, an hour).
If it helps, you could try to generate a possibly non-uniform distribution on a possibly smaller range (using the real numbers, for instance) and transform. Problem: this might be equally difficult.
Any ideas?
Generate log2(N) random bits to get a number M,
where M may be up to twice as large as N.
Repeat until M is in the range [1;N].
Now to generate the random bits you could either use a source of true randomness, which is expensive.
Or you might use some cryptographically secure random number generator, for example AES with a random key encrypting a counter for subsequent blocks of bits. The cryptographically secure implies that there can be no noticeable patterns.
It depends on what you need the data for. For most purposes, a PRNG is fast and simple. But they are not perfect. For instance I remember hearing that Monte Carlos simulations of chaotic systems are really good at revealing the underlying pattern in a PRNG.
If that is the sort of thing that you are doing, though, there is a simple trick I learned in grad school for generating lots of random data. Take a large (preferably rapidly changing) file. (Some big data structures from the running kernel are good.) Compress it to increase the entropy. Throw away the headers. Then for good measure, encrypt the result. If you're planning to use this for cryptographic purposes (and you didn't have a perfect entropy data set to work with), then reverse it and encrypt again.
The underlying theory is simple. Information theory tells us that there is no difference between a signal with no redundancy and pure random data. So if we pick a big file (ie lots of signal), remove redundancy with compression, and strip the headers, we have a pretty good random signal. Encryption does a really good job at removing artifacts. However encryption algorithms tend to work forward in blocks. So if someone could, despite everything, guess what was happening at the start of the file, that data is more easily guessable. But then reversing the file and encrypting again means that they would need to know the whole file, and our encryption, to find any pattern in the data.
The reason to pick a rapidly changing piece of data is that if you run out of data and want to generate more, you can go back to the same source again. Even small changes will, after that process, turn into an essentially uncorrelated random data set.
NTL: A Library for doing Number Theory
This was recommended by my Coding Theory and Cryptography teacher... so I guess it does the work right, and it's pretty easy to use.
RandomBnd, RandomBits, RandomLen -- routines for generating pseudo-random numbers
ZZ RandomLen_ZZ(long l);
// ZZ = psuedo-random number with precisely l bits,
// or 0 of l <= 0.
If you have a random number generator that generates random numbers of X bits. And concatenated bits of [X1, X2, ... Xn ] create the number you want of N bits, as long as each X is random, I don't see why your large number wouldn't be random as well for all intents and purposes. And if standard C rand() method is not secure enough, I'm sure there's plenty of other libraries (like the ones mentioned in this thread) whose pseudo-random numbers are "more random".
even very good pseudorandom generators are likely to develop patterns with millions of digits, right?
From the wikipedia on pseudo-random number generation:
A PRNG can be started from an arbitrary starting state using a seed state. It will always produce the same sequence thereafter when initialized with that state. The maximum length of the sequence before it begins to repeat is determined by the size of the state, measured in bits. However, since the length of the maximum period potentially doubles with each bit of 'state' added, it is easy to build PRNGs with periods long enough for many practical applications.
You could perhaps help create large random numbers by raising random numbers to random exponents
I assume you're suggesting something like populating the values of a scientific notation with random values?
E.g.: 1.58901231 x 10^5819203489
The problem with this is that your distribution is going to be logarithmic (or is that exponential? :) - same difference, it isn't even). You will never get a value that has the millionth digit set, yet contains a digit in the one's column.
you could try to generate a possibly non-uniform distribution on a possibly smaller range (using the real numbers, for instance) and transform
Not sure I understand this. Sounds like the same thing as the exponential solution, with the same problems. If you're talking about multiplying by a constant, then you'll get a lumpy distribution instead of a logarithmic (exponential?) one.
Suggested Solution
If you just need really big pseudo-random values, with a good distribution, use a PRNG algorithm with a larger state. The Periodicity of a PRNG is often the square of the number of bits, so it doesn't take that many bits to fill even a really large number.
From there, you can use your first solution:
You could randomly generate each digit and concatenate
Although I'd suggest that you use the full range of values returned by your PRNG (possibly 2^31 or 2^32), and populate a byte array with those values, splitting it up as necessary. Otherwise you might be throwing away a lot of bits of randomness. Also, scaling your values to a range (or using modulo) can easily screw up your distribution, so there's another reason to try to keep the max number of bits your PRNG can return. Be careful to pack your byte array full of the bits returned, though, or you'll again introduce lumpiness to your distribution.
The problem with those solution, though, is how to fill that (larger than normal) seed state with random-enough values. You might be able to use standard-size seeds (populated via time or GUID-style population), and populate your big-PRNG state with values from the smaller-PRNG. This might work if it isn't mission critical how well distributed your numbers are.
If you need truly cryptographically secure random values, the only real way to do it is use a natural form of randomness, such as that at http://www.random.org/. The disadvantages of natural randomness are availability, and the fact that many natural-random devices take a while to generate new entropy, so generating large amounts of data might be really slow.
You can also use a hybrid and be safe - natural-random seeds only (to avoid the slowness of generation), and PRNG for the rest of it. Re-seed periodically.

Resources