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

Code changes for Manhattan, Euclidean and Minkowski distance calculation #35

Merged
merged 7 commits into from
Oct 28, 2017

Conversation

MishraShivendra
Copy link
Contributor

These changes would introduce functions to calculate Manhattan, Euclidean and Minkowski distance. Plus, I have done a bit of code reformatting in the old code.
Please take a look.
-Shivendra

@MishraShivendra
Copy link
Contributor Author

MishraShivendra commented Oct 23, 2017

@montanaflynn
Hi Montana,
Any input in these changes? Are we planing to merge these?

-Shivendra

@@ -0,0 +1,99 @@
//
Copy link
Owner

Choose a reason for hiding this comment

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

Can you remove these comments, they show up in the generated documentation:

https://godoc.org/github.com/montanaflynn/stats

The commit history and contribution is stored in the .git and GitHub.

)

// Validate data for distance calculation
func ValidateData(dataPointX, dataPointY []float64) error {
Copy link
Owner

Choose a reason for hiding this comment

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

Let's make this a private function since it's only meant to be used internally. To do so just change the function name to validateData, Golang exposes uppercase functions, methods and variables.

var err error
dataPointX := []float64{2, 3, 4, 5, 6, 7, 8}
dataPointY := []float64{8, 7, 6, 5, 4, 3, 2}
_, err = ChebyshevDistance(dataPointX, dataPointY)
Copy link
Owner

Choose a reason for hiding this comment

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

Can we also check the result to be what is expected?

cd, err = ChebyshevDistance(dataPointX, dataPointY)
if err != nil {
	t.Errorf("Failed to compute Chebyshev distance.")
}
if cd != 6 {
	t.Errorf("ChebyshevDistance(%v, %v) => %.1f != %.1f", dataPointX, dataPointX, cd, 6)
}

dataPointY := []float64{8, 7, 6, 5, 4, 3, 2}
_, err = ChebyshevDistance(dataPointX, dataPointY)
if err != nil {
t.Errorf("Failed to compute Chebyshev disatance.")
Copy link
Owner

Choose a reason for hiding this comment

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

Typo disatance


func TestDataSetDistances(t *testing.T) {
var err error
dataPointX := []float64{2, 3, 4, 5, 6, 7, 8}
Copy link
Owner

Choose a reason for hiding this comment

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

Since I want to check the output as well it might be easier if you adopt the table driven test pattern:

https://github.com/golang/go/wiki/TableDrivenTests

examples/main.go Outdated
d, _ = stats.ChebyshevDistance([]float64{2, 3, 4, 5, 6, 7, 8}, []float64{8, 7, 6, 5, 4, 3, 2})
fmt.Println(d) // Should yield 6
d, _ = stats.ManhattanDistance([]float64{2, 3, 4, 5, 6, 7, 8}, []float64{8, 7, 6, 5, 4, 3, 2})
fmt.Println(d) // Should yield 24
Copy link
Owner

Choose a reason for hiding this comment

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

Can we add some new lines between the functions to mimic the rest of the file?

d, _ = stats.ChebyshevDistance([]float64{2, 3, 4, 5, 6, 7, 8}, []float64{8, 7, 6, 5, 4, 3, 2})
fmt.Println(d) // Should yield 6

d, _ = stats.ManhattanDistance([]float64{2, 3, 4, 5, 6, 7, 8}, []float64{8, 7, 6, 5, 4, 3, 2})
fmt.Println(d) // Should yield 24

@montanaflynn
Copy link
Owner

Hey @MishraShivendra,

Sorry I was busy over the weekend. I added comments in a review.

Thanks for your contributions!

@MishraShivendra
Copy link
Contributor Author

Thanks for those inputs. I'll push those changes in a while.

-Shivendra

@MishraShivendra
Copy link
Contributor Author

@montanaflynn
Pushed the suggested changes.

@montanaflynn montanaflynn merged commit 72625ec into montanaflynn:master Oct 28, 2017
@montanaflynn
Copy link
Owner

@MishraShivendra LGTM (looks good to me) and thanks for all your hard work and contributions!

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.

2 participants