Skip to content

Conversation

@SergeStinckwich
Copy link
Member

No description provided.

@SergeStinckwich SergeStinckwich added this to the v1.0.3 milestone Feb 23, 2021

aNumber2 > 0
ifFalse: [ self error: 'Illegal distribution parameters'].
ifFalse: [ self error: 'Illegal distribution parameters' ].
Copy link
Contributor

Choose a reason for hiding this comment

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

Here, for me, it would be clearer if we could invert the clause and say

number < 0 ifTrue: [...]

Copy link
Member Author

@SergeStinckwich SergeStinckwich Feb 23, 2021

Choose a reason for hiding this comment

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

It would be aNumber2 <=0 ifTrue: [...] I guess.

Copy link
Contributor

@hemalvarambhia hemalvarambhia left a comment

Choose a reason for hiding this comment

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

The build is red here. Do we need to add some missing programmer tests?

ifNil: [ [ v1 := Number random * 2 - 1.
v2 := Number random * 2 - 1.
w := v1 squared + v2 squared.
w > 1 ] whileTrue: [ ].
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you help me understand why the block is empty here?

Copy link
Member Author

Choose a reason for hiding this comment

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

I dunno, I can remove it.

].
^v1
NextRandom
ifNil: [ [ v1 := Number random * 2 - 1.
Copy link
Contributor

Choose a reason for hiding this comment

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

This part is a little hard for me to follow to be honest. If you could factor out this block to an intention revealing method to begin which, it would be very helpful.

Copy link
Member Author

Choose a reason for hiding this comment

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

I have no idea what the block is doing ...

Copy link
Contributor

Choose a reason for hiding this comment

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

What? It's well known Box-Muller algorithm for transforming a uniform distribution into a normal distribution.
See https://en.wikipedia.org/wiki/Box%E2%80%93Muller_transform

We need a pair (v1,v2) inside the unit circle.
If it's not, we have to redraw another pair.
Just replace whileTrue: [ ]. with whileTrue.

Copy link
Member Author

Choose a reason for hiding this comment

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

I replace whileTrue:[] with whileTrue. I add a comment for the moment to say that we are using the Box-Muller transform. Do you see a better way to be more intention revealing @hemalvarambhia ?

Copy link
Contributor

Choose a reason for hiding this comment

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

You could extract act boxMullerAlgorithm method

@SergeStinckwich
Copy link
Member Author

The build is red, because the coverage decreased I guess.

@SergeStinckwich
Copy link
Member Author

I do the extraction as boxMullerTransform.

Copy link
Contributor

@hemalvarambhia hemalvarambhia left a comment

Choose a reason for hiding this comment

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

Much better.

^v1

| v1 |
NextRandom
Copy link
Contributor

Choose a reason for hiding this comment

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

I wondered what kind of variable this is. It seems global. Is that right?

Copy link
Member Author

Choose a reason for hiding this comment

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

no this is a class variable.

}

{ #category : #information }
PMNormalDistribution class >> boxMullerTransform [
Copy link
Contributor

Choose a reason for hiding this comment

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

What's interesting is that this is a class method, rather than an instance one. I presume this choice was made because NextRandom is a class variable?

Copy link
Member Author

Choose a reason for hiding this comment

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

no because PMNormalDistribution class >> random is a class method.

@SergeStinckwich SergeStinckwich merged commit 482c790 into PolyMathOrg:master Feb 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants