Skip to main content
29 votes
Accepted

Removing neighbors in a point cloud

1. Introduction It is not a good plan to leave code running for 30 hours. Until you have analyzed the code, and have figured out how its runtime varies according to the size of the input, then you ...
Gareth Rees's user avatar
  • 49.6k
26 votes

Finding the closest point to a list of points

All your code could be rewritten as: ...
arekolek's user avatar
  • 401
10 votes

K-Means image segmentation algorithm

I'm not familiar with image processing at all, so I cannot give you any advice about your algorithm implementation. However, there are quite a few things I'd like to say about good practices and code ...
Ben Steffan's user avatar
  • 5,228
10 votes

Removing neighbors in a point cloud

Gareth provided some excellent ideas, for which I will suggest a very similar solution, only using scipy instead of rtree. I ...
Aaron's user avatar
  • 233
7 votes

K-Means image segmentation algorithm

I want to reinforce a point that Ben Steffan made in his answer: This part is really bad: std::vector<Pixel*> m_pixels; This would be much, much better: <...
Cris Luengo's user avatar
  • 6,217
7 votes

Closest Pair algorithm implementation in C++

Your code can be improved in regard to its efficiency and its readability. But first of all, don't write that using namespace std. Efficiency You create a lot of ...
papagaga's user avatar
  • 5,757
6 votes

Finding the closest point to a list of points

By using a kd-tree computing the distance between all points it's not needed for this type of query. It's also built in into scipy and can speed up these types of programs enormously going from O(n^2) ...
vidstige's user avatar
  • 273
6 votes
Accepted

K-means clustering implemented in Python 3

import numpy as np class kmeans(): Use a PEP 8 checker such as pycodestyle or flake8. Integrate it into your file editor or IDE, if you're not doing it already. ...
Quentin Pradet's user avatar
5 votes

Given a collection of points on a 2D plane, find the pair that is closest to each other

Comments out of sync with code ...
Jerry Coffin's user avatar
  • 33.6k
4 votes
Accepted

Clustering 16 million records in parallel

Hard to tell without sample data, but lets start with a cleaned up version as there's soo much duplicated code here and the formatting is inconsistent. The require ...
ferada's user avatar
  • 11.1k
4 votes
Accepted

KNN algorithm implemented in Python

First a style nitpick: Python has an official style-guide, PEP8, which recommends using lower_case_with_underscores for variable and function names instead of ...
Graipher's user avatar
  • 41k
4 votes
Accepted

Cosine similarity of one vector with many

I'm using Microsoft R (with Intel MKL) which makes matrix multiplications faster, but for fair comparison I set it to be single threaded. setMKLthreads(1) In my ...
Andrey Shabalin's user avatar
4 votes
Accepted

Simple natural language classifier

Welcome to Code Review! This is an interesting program; thanks for sharing! To help you maintain it ... baseDict appears to be unused, and can be removed. Ditto ...
AJNeufeld's user avatar
  • 33.9k
4 votes
Accepted

Implementation of K-means

Unnecessary type checking In update_h_params, you write ...
Brian61354270's user avatar
4 votes
Accepted

Calculation of the Distance Matrix in the K-Means Algorithm in MATLAB

Your Distance Matrix Calculation You wrote the code (I summarize it for the Distance Matrix): ...
Royi's user avatar
  • 582
3 votes
Accepted

Pole (Hackerrank)

This is my code, but the complexity is very high. How high? Python has standard formatting conventions, known as PEP8. There are free tools to lint code to those standards (e.g. this online checker, ...
Peter Taylor's user avatar
  • 24.1k
3 votes
Accepted

Given a collection of points on a 2D plane, find the pair that is closest to each other

Consider using range-based for loop If you don't need information about index of element, then you can iterate over the vector of points with following code: <...
adasikow's user avatar
  • 121
3 votes
Accepted

Selecting kids for a Christmas play with similar heights

Time is mostly spent in I/O I played with your program and found that most of the time was spent doing I/O. However, from your comments, it appears you already improved your I/O so that your best ...
JS1's user avatar
  • 28.5k
3 votes

Finding closest pair of 2D points, using divide-and-conquer

Here are some observations that may help you improve your code. Use all required #includes The code uses std::vector which ...
Edward's user avatar
  • 66.5k
3 votes
Accepted

Zip code reduce function

An alternative ...
mdfst13's user avatar
  • 21.7k
3 votes
Accepted

Clustering nodes with Hamming distance < 3

Generic comments Your spacing is very odd and inconsistent, which makes reading the code a bit harder. 2 blank lines before function definition, spaces around operators, and after a coma is what is ...
301_Moved_Permanently's user avatar
3 votes
Accepted

Predict new ratings for each user based on their pearson correlation with other users

You have incorrect indexing in the loop. Better version with mapply and correct indexing: ...
m0nhawk's user avatar
  • 366
3 votes
Accepted

"Similar Destinations" challenge

I've managed to solve the problem after a bit of selective profiling. It would seem that my initial hunch was right. The problem had less to do with the algorithm and more towards the data structures ...
cottonman's user avatar
  • 171
3 votes
Accepted

A Simple Cluster Generator v0.2

This code looks pretty good, but here are some things that may help you further improve it. Separate interface from implementation The interface goes into the .h ...
Edward's user avatar
  • 66.5k
3 votes
Accepted

A Simple Cluster Generator v0.3

#include <fstream> #include <vector> #include <string> It's really nice to see that you are only #includeing ...
Justin's user avatar
  • 3,295
3 votes

DBSCAN "region query" too slow; implement a tree?

You don't provide much information, which is unfortunate, since this kind of optimization problem relies on knowing how to "skew" the code in order to get better performance. For example, are your ...
aghast's user avatar
  • 12.4k
3 votes
Accepted

K-Nearest Neighbors in pure Python

Assumption: k << N, where N = len(points) There is no need to sort the entire list of points! Instead, take the first k points, and determine their distance ...
AJNeufeld's user avatar
  • 33.9k
3 votes

k-means using numpy

The code looks good, I wouldn't suggest anything as needing to be changed. In line with your question about possible ways to use Numpy better, I'll offer a few things you could try: You can pass low/...
scnerd's user avatar
  • 2,030
3 votes
Accepted

Efficiently determining maximum allowed euclidean distance between lists of colors

As @vnp says, a solution involving an octree would a more efficient way to find neighboring points. Before you implement one, though, there are some huge time savings you can get by making some ...
200_success's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible