Skip to content

Commit

Permalink
add the disappearing sample function
Browse files Browse the repository at this point in the history
  • Loading branch information
SevgiAkten committed Aug 12, 2024
1 parent 0e35dee commit c60f89d
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,28 @@ def generate_probability_vector(mins: List[float], maxs: List[float], ntries: in

return probvector

def sample(probvector: List[float]) -> List[int]:
"""
Sample a vector based on the provided probability vector.
Parameters
----------
probvector : List[float]
Probability vector for sampling.
Returns
-------
List[int]
Sampled binary vector.
"""
n = len(probvector)
newvector = [0] * n

for i in range(n):
if random.random() < probvector[i]:
newvector[i] = 1

return newvector



6 comments on commit c60f89d

@jbytecode
Copy link
Collaborator

@jbytecode jbytecode commented on c60f89d Aug 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SevgiAkten - Why are you adding the deleted function again? Does it have any use? If so, who uses, is there sample(... function call anywhere?

If it is substantial, why tests still pass even tough it is absent?

@SevgiAkten
Copy link
Owner Author

@SevgiAkten SevgiAkten commented on c60f89d Aug 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, the sample(...) function call is present here, and before I started reviewing the code, it was causing an error in the optimizer.py file because the function was not defined. I thought it might have been accidentally deleted.

`# Evaluate the final solution sampled from the probability vector

best_byte_ch = byte_operators.bits_to_floats(sample(vector))
best_byte_result = problem.f(best_byte_ch)`

@jbytecode
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so, the tests are not written properly, right? One can not run each single file after a change, so tests should satisfy the robustness of the package.

I have been changing things and observing the test results, all of my changes pass tests, but now I can see it is not the point and I might have broken something.

This is a sign of a poor design.

@jbytecode
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please look at that, https://github.com/SevgiAkten/pycellga/actions, everything is in green but it seems I have broken at least one thing.

@SevgiAkten
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're absolutely right. I will now write comprehensive tests for each part of the optimizer separately. This oversight is entirely my fault, and I will make sure to address it.

@jbytecode
Copy link
Collaborator

@jbytecode jbytecode commented on c60f89d Aug 12, 2024 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.