//training step //the raw data has the form {x1, x2, t} //convert to form x={x0, x1, x2} and t=t double updateWeights(Neuron* neuron, const double* rawData) { int t = rawData[N]; //desired class (-1, +1) double x[DIM]; //actual input vector x[0] = 1; //dummy input for w0 for (int i = 1; i <= N; i++) { x[i] = rawData[i - 1]; //copy feature vector from from rawData } //perceptron update step: w(k+1) = w(k) + eta*x*t //memcpy(neuron->w, sumVec(neuron->w, multiplyVec(multiplyVec(x, t), neuron->eta)), DIM*sizeof(double)); //neuron update step: delta rule (w(k+1) = w(k) + (error*w(k) * (fdx(w(k)*in) * in) double out = f(neuron, x); double e = error(out, t); double f_dx = fdx(neuron, &x); double* a = vectorProd(multiplyVec(neuron->w, e, N), multiplyVec(neuron->w, f_dx, N), N); memcpy(neuron->w, sumVec(neuron->w, (a), N) , DIM*sizeof(double)); return e; }
bool insideTriangle(int x, int y, Vec3i t0, Vec3i t1, Vec3i t2) { Vec2i a(t0.x - x, t0.y - y), b(t1.x - x, t1.y - y), c(t2.x - x, t2.y - y); return vectorProd(a, b) * vectorProd(b, c) >= 0 && vectorProd(b, c) * vectorProd(c, a) >= 0 && vectorProd(c, a) * vectorProd(a, b) >= 0; }