-
Notifications
You must be signed in to change notification settings - Fork 135
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
Conversation
Job Test qsubs falcon on 1f54de2 : invalidated by @mandd |
do we have a test that uses this modified twoPointsCrossovers method? |
I used Andrea's test, but I guess this one will take a long time, I can generate a simpler one. |
@@ -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)) |
There was a problem hiding this comment.
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?
Job Test qsubs falcon on 7c3deff : invalidated by @Jimmy-INL |
Job Test qsubs sawtooth on 7c3deff : invalidated by @Jimmy-INL |
Job Test qsubs falcon on 7c3deff : invalidated by @Jimmy-INL |
1 similar comment
Job Test qsubs falcon on 7c3deff : invalidated by @Jimmy-INL |
@wangcj05 : this PR is good to me. Can I merge it into devel? |
@mandd Sure, when all the checklists are satisfied, you are free to merge any PR. |
@Jimmy-INL : let me see if i can do it before the end of today |
There was a problem hiding this 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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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)) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
index = int(matrixOperation[2*i,0]) | ||
else: | ||
index = int(matrixOperation[i+1,0]) | ||
index = int(matrixOperation[2*i+1,0]) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
change MaxwoReplacement to MaxwoReplacementTwoPointsCrossover
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch fixed
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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> |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
increase indent here
There was a problem hiding this comment.
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> |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
couple of questions here:
- why the con_objective is not changing?
- Will this test converge to the analytical solution? I saw you have marked the test as analytic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- 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.)
- The analytic solution is 1,2,3,4,5,6 and objective is 91, which is exactly the solution.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
@Jimmy-INL : I have addressed all comments except the one you are discussing with @wangcj05. |
Job Test qsubs falcon on ddc8479 : invalidated by @mandd |
2 similar comments
Job Test qsubs falcon on ddc8479 : invalidated by @mandd |
Job Test qsubs falcon on ddc8479 : invalidated by @mandd |
There was a problem hiding this 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.
<convergence> | ||
<objective>-1</objective> | ||
</convergence> |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this 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.
PR checklist is satisfied, and PR can be merged into devel |
@Jimmy-INL @mandd I have approved and merged your PR. Thanks for your contributions. |
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.
<internalParallel>
to True.raven/tests/framework/user_guide
andraven/docs/workshop
) have been changed, the associated documentation must be reviewed and assured the text matches the example.