Skip to content

Commit

Permalink
simplified some comprehensions and fixed some possible memory contigu…
Browse files Browse the repository at this point in the history
…ity issues
  • Loading branch information
jmason42 committed Mar 16, 2018
1 parent 830184c commit 3793b5a
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions optimize.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,24 +171,22 @@ def build_perturbation_vectors(naive = False):
# a given 'standard' parameter does not influence the value of any
# other 'standard' parameter.

perturbation_vectors = [
vector
for vector in np.linalg.pinv(structure.standard_parameter_matrix).T
]
perturbation_vectors = list(
np.linalg.pinv(structure.standard_parameter_matrix).T.copy()
)

# TODO: assert perturbations are simple

else:
perturbation_vectors = [
vector
for vector in la.bilevel_elementwise_pseudoinverse(
perturbation_vectors = list(
la.bilevel_elementwise_pseudoinverse(
np.concatenate([
structure.activity_matrix,
np.identity(structure.n_parameters),
]),
structure.activity_matrix
).T
]
).T.copy()
)

# Many of the basic parameter perturbation vectors end up being
# identical to the 'activity matrix' perturbation vectors, so I detect
Expand Down Expand Up @@ -310,6 +308,7 @@ def estimate_parameters(
# TODO: pass initial parameters, bounds, perturbation vectors
# TODO: pass metaparameters
# TODO: more results/options/callbacks
# TODO: logging as callbacks

print 'Initializing optimization.'

Expand Down Expand Up @@ -385,7 +384,7 @@ def estimate_parameters(
perturbation_vectors = build_perturbation_vectors(naive)
n_perturb = len(perturbation_vectors)

ibm_v = [v.copy() for v in inverse_bounds_matrix.T] # Copy needed to enforce memory-contiguity
ibm_v = inverse_bounds_matrix.T.copy() # Copy needed to enforce memory-contiguity

for (epoch, disequ_weight) in enumerate(DISEQU_WEIGHTS):
history_best_objective = []
Expand Down

0 comments on commit 3793b5a

Please sign in to comment.