Closed launerbie closed 9 years ago
its caused by the algorithm generating less than the requested number of stars iin some cases - I have a fix: https://github.com/ipelupessy/amuse/tree/fractalcluster_nsmax_fix which I make into a pull request - it may need some backend coding to either try again automatically when calling new_fractal_cluster (or at least warn the user about the problem...
@ipelupessy : I'd like to confirm 500dc59e1a67399536fe4ba84c383e574dab1c30 indeed fixes it for me.
I don't know what to make of your comment on backend coding though...
well, I mean it fixes the error in the code, but the fractal cluster may now return with less particles than requested, which you may still consider unsatisfactor..the new_fractal_cluster_model function could be adapted to catch this and give an error or try again with a different seed and generate a valid model, what do you think?
I have added an option, match_N [=True by default] to exactly match the requested number of particles..
[...] but the fractal cluster may now return with less particles than requested
I suppose this is inherent to how the fractal generation algorithm works?
I think calling new_fractal_cluster_model(N=100)
should always return 100 particles, you seem to have fixed this with the match_N
option. And if I understand correctly, what match_N=True
does, is call the fractal generation code again with a different seed until a fractal is made with the required number of particles.
It sounds as if we now don't have the guarantee that if I call new_fractal_cluster_model(N=100, random_seed=s, match_N=True)
with S different seeds, I will get back S unique fractals due to possible seed reuse? (Btw, even if this is so, I still think it's quite acceptable)
if it needs to retry, new_fractal_cluster_model continues with the same generator, continuing its internal random sequence (so it will duplicate some other model, but not trivially)..have you tested the new code?
Yes, it (bc84494f59baf49804224d97ceec78a31aae29bd) works as advertised.
#makefractals3.py
from amuse.ic.fractalcluster import new_fractal_cluster_model
modelsA = []
modelsB = []
for i in range(2000):
modelsA.append(new_fractal_cluster_model(N=100, random_seed=i, match_N=True))
for i in range(2000):
modelsB.append(new_fractal_cluster_model(N=100, random_seed=i, match_N=False))
hundredsA = [len(i) for i in modelsA].count(100)
hundredsB = [len(i) for i in modelsB].count(100)
print(hundredsA, hundredsB)
laub @ F036961: ~% am makefractals3.py
(2000, 1993)
/home/laub/githubs/amuse/src/amuse/support/literature.py:78: AmuseWarning:
You have used the following codes, which contain literature references:
"FractalClusterInterface"
Simon Goodwin & Ant Whitworth (2004, A&A, 413, 929)
"AMUSE"
** Portegies Zwart, S. et al., 2013, Multi-physics Simulations Using a Hierarchical Interchangeable Software Interface, Computer Physics Communications 183, 456-468 [2013CoPhC.183..456P]
** Pelupessy, F. I. et al., 2013, The Astrophysical Multipurpose Software Environment, Astronomy and Astrophysics 557, 84 [2013A&A...557A..84P]
Portegies Zwart, S. et al., 2009, A multiphysics and multiscale software environment for modeling astrophysical systems, *New Astronomy*, **Volume 14**, **Issue 4**, 369-378 [2009NewA...14..369P]
warnings.warn(prefix + self.all_literature_references_string(), exceptions.AmuseWarning)
ok, will merge
I'm trying to create 100 fractal clusters with new_fractal_cluster_model(), with the following piece of code (makefractals.py).
but running makefractals.py however, throws the following exception:
I've also tried randomizing the seeds like so (makefractals2.py):
This will throw the same exception after 164 models.
Can anybody confirm/reproduce this behaviour of new_fractal_cluster_model?