void testSimpleVectorScalarProduct() { SimpleVector v1 = createSimpleVector(3); SimpleVector v2 = createSimpleVector(3); // [0,1,2] * [0,1,2] = 5 BOOST_CHECK( v1.scalarProduct(v2) == 5 ); }
void testSimpleVectorScalarProductInequalSize() { SimpleVector v1 = createSimpleVector(2); SimpleVector v2 = createSimpleVector(3); try { v1.scalarProduct(v2); BOOST_ERROR( "Exception should have been thrown!" ); } catch (const char* e) { } }
void testSimpleVectorMinus() { SimpleVector v1 = createSimpleVector(3); SimpleVector v2 = createSimpleVector(3); // [0,1,2] - [0,1,2] = [0,0,0] v1.minus(v2); BOOST_CHECK( v1.getElement(0) == 0 ); BOOST_CHECK( v1.getElement(1) == 0 ); BOOST_CHECK( v1.getElement(2) == 0 ); }
void testSimpleVectorPlus() { SimpleVector v1 = createSimpleVector(3); SimpleVector v2 = createSimpleVector(3); // [0,1,2] + [0,1,2] = [0,2,4] v1.plus(v2); BOOST_CHECK( v1.getElement(0) == 0 ); BOOST_CHECK( v1.getElement(1) == 2 ); BOOST_CHECK( v1.getElement(2) == 4 ); }
void testSimpleVectorDataAccess() { SimpleVector v = createSimpleVector(3); BOOST_CHECK( v.getElement(0) == 0 ); BOOST_CHECK( v.getElement(1) == 1 ); BOOST_CHECK( v.getElement(2) == 2 ); }
float* LeastSquareFilter::computeLinearFunc(std::vector<float> Y) { int n = Y.size(); float res[2]; res[0] = 0.0; res[1] = 0.0; if (n > 0) { std::vector<float> X = createSimpleVector(n); float meanX = mean(X); std::vector<float> x_minus_meanx = addScalar(X, -meanX); std::vector<float> x_minus_meanx_square = product(x_minus_meanx, x_minus_meanx); float SSxx = sum(x_minus_meanx_square); // float sumY = sum(Y); float sumX = n * (n-1) / 2.0; std::vector<float> x_product_y = product(X, Y); float SSxy = sum(x_product_y) - sumX * sumY / n; // float b1 = 0.0; if (SSxx != 0.0) { b1 = SSxy / SSxx; } float b0 = sumY / n - b1 * sumX / n; res[0] = b0; res[1] = b1; } return res; }
void testSimpleVectorMultiply() { SimpleVector v = createSimpleVector(3); // [0,1,2] * 3 = [0,3,6] v.multiply(3); BOOST_CHECK( v.getElement(0) == 0 ); BOOST_CHECK( v.getElement(1) == 3 ); BOOST_CHECK( v.getElement(2) == 6 ); }
void testSimpleVectorClone() { SimpleVector v = createSimpleVector(3); Vector* c = v.clone(); v.setElement(0, 7); v.setElement(1, 7); v.setElement(2, 7); BOOST_CHECK( c->getElement(0) == 0 ); BOOST_CHECK( c->getElement(1) == 1 ); BOOST_CHECK( c->getElement(2) == 2 ); }
float LeastSquareFilter::apply(std::vector<float> Y, int idx) { // Compute linear function parameter int n = Y.size(); float func[2]; std::vector<float> X = createSimpleVector(n); genericComputeLinearFunc(func, X, Y); printf("func %.2f\n",func[0]); // Use idx + 1 to simulate "future" return func[0] + func[1] * (idx+1); }
void testSimpleMatrixMultiplyInequalSize() { SimpleVector v = createSimpleVector(3); SimpleMatrix m = createSimpleMatrix(2, 2); try { m.multiplyLeft(v); BOOST_ERROR( "Exception should have been thrown!" ); } catch (const char* e) { } try { m.multiplyRight(v); BOOST_ERROR( "Exception should have been thrown!" ); } catch (const char* e) { } }
void testSimpleVectorSize() { SimpleVector v = createSimpleVector(5); BOOST_CHECK( v.size() == 5 ); }