int LogisticRegression::gradientAscent() { long double* deviations = new long double[sampleNum]; int iterations = 0; do { ++iterations; /* * How to handle the case that 'z' is either too big or too small??? */ // calculate deviations for all samples, one per sample. for(int i = 0; i < sampleNum; ++i) deviations[i] = categories[i] - rf(trainingSamples.getSample(i), parameters, featureNum); // adjust parameters for(int j = 0; j < featureNum; ++j) { long double factor = 0.0; for(int i = 0; i < sampleNum; ++i) factor += trainingSamples.getSample(i)[j] * deviations[i]; parameters[j] += alpha * factor; } } while(convergent(deviations, categoryRange) == false); delete[] deviations; return iterations; }
int main(void) { uint64_t count = 0; for(uint64_t n = 1; n < 10000000; ++n) { if(convergent(n) == 89) count++; } printf("%lu\n", count); }