New answers tagged

1

All your output statements are of the form: std::cout << (" Layer[" + std::to_string(i) + "] = \n {\n"); that is very weird. Why are you using to_string and concatenating the strings for the output, rather than just using << normally? That is: cout << " Layer[" << i << "] = \n {\n&...


2

Write only one statement per line For some reason you decided to make all the activation functions and their derivatives one-liners. This results in some very long lines, requiring sideways scrolling. I recommend you just use one statement per line. Make constants static constexpr The constants a (in lrelu::deriv_t), as well as learningRate and ...


2

There are certainly things you could improve This use of global is quite confusing: you are using eta, model_w and model_b as a local variables to the for eta in np.arange(.1, 2.0, .1), not as a global state. A cleaner way to do that would be to pass them as parameters to update_weights. The way j is used outside of the loop is not very clear (even if it ...


2

Loops You criminally underuse the range-based for. JDlogusz already mentioned this, but it cannot be said enough. Avoid index variables whenever possible. Memory management char* content = new char[file.tellg()]; //... delete[] content; new and delete are code smells. The only acceptable times for manual memory management in C++ are when you are writing ...


2

#include <math.h> Prefer to include <cmath>. That's better, as it declares its identifiers in the std namespace. We'll need to change exp() to std::exp(), but OTOH, std::tanh() becomes correct. We're missing <cstring>, for std::memcpy() <iterator>, for std::ostream_iterator std::size_t is misspelt in several places. template<...


5

#define WEIGHT_RANDOM_RANGE .1 Don't use #define to make your constants. Use constexpr. In your CSV parser: scalar value = scalar(std::stof(line.substr(0, found))); line = line.substr(found + 1, line.size()); That's grossly inefficient. The string::substr creates a new string and copies data. Then you shorten the input by using substr again and ...


2

The only thing I would change in your code is about the Comparator you are using below: processedPoints.sort( (a, b) -> Double.compare( a.doubleValue(), b.doubleValue())); You could use the Comparator#comparingDouble that is the specific comparator for comparing doubles: processedPoints.sort(...


1

Tests Unit tests are better than printing to the console. One example: @Test public void testReturn0WhenEquidistantPoints() { ClusternessMeasure cm = new ClusternessMeasure(); List<Double> points = List.of(1.0, 2.0, 3.0, 4.0, 5.0); double expected = 0.0; double delta = 0.0; double actual = cm.computeClusternessMeasure(points); ...


4

First, some Python improvements. You do repeated lookups of the kind cluster_dict[cluster]. If you were to directly iterate over cluster_dict.values() these would all be not needed. Also, list comprehensions are usually faster than building a simple list with a for loop. And finally, docstrings go inside the function: def update_center(self, cluster_dict): ...


Top 50 recent answers are included