Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

minor changes to twoPointsCrossovers #1723

Merged
merged 15 commits into from
Dec 9, 2021
Merged

Conversation

Jimmy-INL
Copy link
Collaborator

@Jimmy-INL Jimmy-INL commented Nov 29, 2021


Pull Request Description

What issue does this change request address? (Use "#" before the issue to link it, i.e., #42.)

This PR Closes #1724

What are the significant changes in functionality due to this change request?

TwoPointsCrossOver will not error out.


For Change Control Board: Change Request Review

The following review must be completed by an authorized member of the Change Control Board.

  • 1. Review all computer code.
  • 2. If any changes occur to the input syntax, there must be an accompanying change to the user manual and xsd schema. If the input syntax change deprecates existing input files, a conversion script needs to be added (see Conversion Scripts).
  • 3. Make sure the Python code and commenting standards are respected (camelBack, etc.) - See on the wiki for details.
  • 4. Automated Tests should pass, including run_tests, pylint, manual building and xsd tests. If there are changes to Simulation.py or JobHandler.py the qsub tests must pass.
  • 5. If significant functionality is added, there must be tests added to check this. Tests should cover all possible options. Multiple short tests are preferred over one large test. If new development on the internal JobHandler parallel system is performed, a cluster test must be added setting, in XML block, the node <internalParallel> to True.
  • 6. If the change modifies or adds a requirement or a requirement based test case, the Change Control Board's Chair or designee also needs to approve the change. The requirements and the requirements test shall be in sync.
  • 7. The merge request must reference an issue. If the issue is closed, the issue close checklist shall be done.
  • 8. If an analytic test is changed/added is the the analytic documentation updated/added?
  • 9. If any test used as a basis for documentation examples (currently found in raven/tests/framework/user_guide and raven/docs/workshop) have been changed, the associated documentation must be reviewed and assured the text matches the example.

@Jimmy-INL Jimmy-INL added defect RAVENv2.2 for RAVENv2.2 Release labels Nov 29, 2021
@Jimmy-INL Jimmy-INL requested a review from mandd November 29, 2021 20:24
@Jimmy-INL Jimmy-INL self-assigned this Nov 29, 2021
@moosebuild
Copy link

Job Test qsubs falcon on 1f54de2 : invalidated by @mandd

@mandd
Copy link
Collaborator

mandd commented Nov 30, 2021

do we have a test that uses this modified twoPointsCrossovers method?

@Jimmy-INL
Copy link
Collaborator Author

I used Andrea's test, but I guess this one will take a long time, I can generate a simpler one.

@Jimmy-INL Jimmy-INL requested a review from mandd November 30, 2021 07:29
@@ -130,22 +129,29 @@ def twoPointsCrossover(parents, parentIndexes,**kwargs):
coords={'chromosome': np.arange(int(2*comb(nParents,2))),
'Gene':parents.coords['Gene'].values})
index = 0
for couples in parentIndexes:
parentPairs = list(combinations(parents,2))
Copy link
Collaborator

Choose a reason for hiding this comment

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

should we control here the total number of pairs to be considered?

@moosebuild
Copy link

Job Test qsubs falcon on 7c3deff : invalidated by @Jimmy-INL

@moosebuild
Copy link

Job Test qsubs sawtooth on 7c3deff : invalidated by @Jimmy-INL

@moosebuild
Copy link

Job Test qsubs falcon on 7c3deff : invalidated by @Jimmy-INL

1 similar comment
@moosebuild
Copy link

Job Test qsubs falcon on 7c3deff : invalidated by @Jimmy-INL

@mandd
Copy link
Collaborator

mandd commented Dec 6, 2021

@wangcj05 : this PR is good to me. Can I merge it into devel?

@Jimmy-INL
Copy link
Collaborator Author

@mandd @wangcj05. I was wishing that Diego adds the missing unit tests if he has time. I also made other changes to keep the elite parents which seem to help with the tough optimization problem our private citizen has. PR will be posted soon.

@wangcj05
Copy link
Collaborator

wangcj05 commented Dec 6, 2021

@mandd Sure, when all the checklists are satisfied, you are free to merge any PR.

@mandd
Copy link
Collaborator

mandd commented Dec 6, 2021

@Jimmy-INL : let me see if i can do it before the end of today

Copy link
Collaborator

@wangcj05 wangcj05 left a comment

Choose a reason for hiding this comment

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

Hi @Jimmy-INL @mandd,

Thanks for your contributions. I have couple of comments for your consideration. Please let me know if you have any question about my comments.

if loc1 == loc2:
if loc1 == len(locRangeList)-2:
locU = loc1
locL = loc1 - 2
Copy link
Collaborator

Choose a reason for hiding this comment

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

This indicates the locRangList need to be larger than 4, i.e. locL >= 1 ==> len(locRangeList) >= 5. Is it always true?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I have restructured the method and it should be more clear

locL=loc2
locU=loc1
elif loc1<loc2:
if loc1 == loc2:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Instead to check the equality here, I would suggest to check the equality of indices directly, i.e., check if index1 == index2? Another suggestion is when index1 == index2, I think you can regenerate index2

Copy link
Collaborator

Choose a reason for hiding this comment

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

see above, note also that I have added a check on the number of genes which should be >=3

@@ -130,22 +129,29 @@ def twoPointsCrossover(parents, parentIndexes,**kwargs):
coords={'chromosome': np.arange(int(2*comb(nParents,2))),
'Gene':parents.coords['Gene'].values})
index = 0
for couples in parentIndexes:
parentPairs = list(combinations(parents,2))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Here, you are using combinations which assume the first dim of parents is the parentIndexes, please add more details in the docstring to make it more clear, i.e., to indicate the first dim is the parent index

Copy link
Collaborator

Choose a reason for hiding this comment

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

Note that parentIndexes is not used anymore, the docstring indicates how parents is supposed to be structured

Comment on lines +127 to +129
index = int(matrixOperation[2*i,0])
else:
index = int(matrixOperation[i+1,0])
index = int(matrixOperation[2*i+1,0])
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you explain the changes from i to 2i, and i+1 to 2i+1?

Copy link
Collaborator

Choose a reason for hiding this comment

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

this was a bug, we are filling the population 2 children at a time, hence we need to populate it using the 2i and 2i+1 indexes

<?xml version="1.0" ?>
<Simulation verbosity="debug">
<TestInfo>
<name>framework/Optimizers/GA.MaxwoReplacement</name>
Copy link
Collaborator

Choose a reason for hiding this comment

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

change MaxwoReplacement to MaxwoReplacementTwoPointsCrossover

Copy link
Collaborator

Choose a reason for hiding this comment

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

good catch fixed

Comment on lines +9 to +12
This test assesses the Genetic algorithm using the weighted sum found in myLocalSum.py function.
The nominal dimensionality of the test problem is 3.
The objective variable is ans. The problem in unconstrained, it is a maximization problem, and the sampling is from discrete variables without replacement.
The cross over mechanism used is the twoPointsCrossover algorithm
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you update the description to reflect the fix proposed in this PR?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The fix in this PR is to make TwoPointsCrossover work, as it wasn't working before, and this ios the first test on it that's why the last line is added. Can you suggest what should I update the description to?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm looking for the explanation about failure, and the modifications for the fix @Jimmy-INL

<Optimizer class="Optimizers" type="GeneticAlgorithm">GAopt</Optimizer>
<SolutionExport class="DataObjects" type="PointSet">opt_export</SolutionExport>
<Output class="DataObjects" type="PointSet">optOut</Output>
<Output class="OutStreams" type="Print">opt_export</Output>
Copy link
Collaborator

Choose a reason for hiding this comment

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

This line can be removed since you are using IOStep to Print the info.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Fixed


<objective>ans</objective>
<TargetEvaluation class="DataObjects" type="PointSet">optOut</TargetEvaluation>
<Sampler class="Samplers" type="MonteCarlo">MC_samp</Sampler>
Copy link
Collaborator

Choose a reason for hiding this comment

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

increase indent here

Copy link
Collaborator

Choose a reason for hiding this comment

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

Fixed


<Models>
<ExternalModel ModuleToLoad="../../../../../AnalyticModels/optimizing/myLocalSum.py" name="myLocalSum" subType="">
<variables>x1,x2,x3,x4,x5,x6,ans</variables>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Use inputs and outputs instead of variables

Copy link
Collaborator

Choose a reason for hiding this comment

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

Fixed

4.0,2.0,1.0,3.0,6.0,5.0,83.0,9.0,20.0,166.0,19.0,accepted,0.0
4.0,2.0,3.0,5.0,6.0,1.0,73.0,9.0,20.0,146.0,19.0,accepted,0.0
3.0,1.0,2.0,4.0,5.0,6.0,88.0,9.0,20.0,176.0,19.0,accepted,0.0
1.0,2.0,3.0,4.0,5.0,6.0,91.0,10.0,20.0,182.0,19.0,final,0.0
Copy link
Collaborator

Choose a reason for hiding this comment

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

couple of questions here:

  1. why the con_objective is not changing?
  2. Will this test converge to the analytical solution? I saw you have marked the test as analytic.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

  1. Conv_objective is a boolean that is tro when objective value converges to a user given value which is not the case here that's why it is false. (I think it should be False not zero, but this is the case in most optimizers.)
  2. The analytic solution is 1,2,3,4,5,6 and objective is 91, which is exactly the solution.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I see in the test the target objective value is '-1', does it mean when the objective value converge to '-1', the con_objective will become True? Another question is, in the test, the type of optimization is assigned to 'max' (see below), but why the objective value is '-1'. @Jimmy-INL

image

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

When I know that the objective is a positive value and I select conv_obj = -1, this is just to force the algorithm to continue till the iteration limit is reached. I can remove this from this test if it causes confusion.

@mandd
Copy link
Collaborator

mandd commented Dec 7, 2021

@Jimmy-INL : I have addressed all comments except the one you are discussing with @wangcj05.

@moosebuild
Copy link

Job Test qsubs falcon on ddc8479 : invalidated by @mandd

2 similar comments
@moosebuild
Copy link

Job Test qsubs falcon on ddc8479 : invalidated by @mandd

@moosebuild
Copy link

Job Test qsubs falcon on ddc8479 : invalidated by @mandd

Copy link
Collaborator

@wangcj05 wangcj05 left a comment

Choose a reason for hiding this comment

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

additional comment for objective node.

Comment on lines +81 to +83
<convergence>
<objective>-1</objective>
</convergence>
Copy link
Collaborator

Choose a reason for hiding this comment

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

I have checked several definitions in the user manual, for GA (see attached picture), it seems to me the value should be always positive, in addition, we should use InputData to check it. @Jimmy-INL @mandd

image

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@wangcj05, that's what I am saying. The algorithm will converge when $Objective = \epsilon^{obj}$. If I don't want to use the objective convergence and want the algorithm to carry on till it reaches the iteration limit, I select $\epsilon^{obj}$ to be something impossible. For this problem, the obj is always positive, so I picked -1 so that conv_obj is always False (0). If I couldn't explain myself, let's discuss this face to face. Thanks.

Copy link
Collaborator

Choose a reason for hiding this comment

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

As discussed, the convergence on objective is not consistent across different optimizations, and it can be confusing, a new issue has been opened #1729

Copy link
Collaborator

@wangcj05 wangcj05 left a comment

Choose a reason for hiding this comment

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

Modifications in this PR are good.

@wangcj05
Copy link
Collaborator

wangcj05 commented Dec 9, 2021

PR checklist is satisfied, and PR can be merged into devel

@wangcj05 wangcj05 merged commit 63d933b into devel Dec 9, 2021
@wangcj05 wangcj05 deleted the Jimmy-Fixing-TwoPointsCrossovers branch December 9, 2021 16:28
@wangcj05
Copy link
Collaborator

wangcj05 commented Dec 9, 2021

@Jimmy-INL @mandd I have approved and merged your PR. Thanks for your contributions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
defect RAVENv2.2 for RAVENv2.2 Release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[DEFECT] Two Points Crossover doesn't work
4 participants