Skip to content

Commit

Permalink
added a function to calc popn
Browse files Browse the repository at this point in the history
  • Loading branch information
PRAVEEN-mnl committed Nov 3, 2023
1 parent 06e5bf2 commit 25ef9b4
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions pycbc/live/snr_optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,23 @@ def normalize_initial_point(initial_point, bounds):
return (initial_point - bounds[:,0]) / (bounds[:,1] - bounds[:,0])


def init_population_array(init, parameter_count):
# Make sure you're using a float array
popn = numpy.asarray(init, dtype=numpy.float64)

if (numpy.size(popn, 0) < 5 or
popn.shape[1] != parameter_count or
len(popn.shape) != 2):
raise ValueError("The population supplied needs to have shape (S, len(x)), where S > 4.")

# Scale values to be between 0 and 1
population = (popn - popn.min(axis=0)) / (popn.max(axis=0) - popn.min(axis=0))
num_population_members = numpy.size(population, 0)
population_shape = (num_population_members, parameter_count)

return population, num_population_members, population_shape


def optimize_di(bounds, cli_args, extra_args, initial_point):
bounds = numpy.array([
bounds['mchirp'],
Expand All @@ -190,9 +207,9 @@ def optimize_di(bounds, cli_args, extra_args, initial_point):
])

# Currently only implemented for random seed initial array
rng = numpy.random.mtrand._rand
population_shape = (int(cli_args.snr_opt_di_popsize), 4)
population = rng.uniform(size=population_shape)
init = numpy.random.rand(cli_args.di_popsize, 4)
population, num_population_members, population_shape = init_population_array(init, 4)

if cli_args.snr_opt_include_candidate:
# Re-normalize the initial point into the correct range
point_init = normalize_initial_point(initial_point, bounds)
Expand Down

0 comments on commit 25ef9b4

Please sign in to comment.