Example #1
0
Blob compare(Blob& A, Blob& B) {
    assert(A.get_N() == B.get_N());
    Blob out(A.size());
    for (int i = 0; i < A.get_N(); ++i) {
        out[i] = conv_to<cube>::from(A[i] == B[i]);
    }
    return out;
}
Example #2
0
Blob operator/(Blob& A, double num) {
    Blob out(A.size());
    int N = A.get_N();
    for (int i = 0; i < N; ++i) {
        out[i] = A[i] / num;
    }
    return out;
}
Example #3
0
Blob operator*(double num, Blob& A) {
    Blob out(A.size());
    int N = A.get_N();
    for (int i = 0; i < N; ++i) {
        out[i] = A[i] * num;
    }
    return out;
}
Example #4
0
Blob sqrt(Blob& A) {
    Blob out(A.size());
    int N = A.get_N();
    for (int i = 0; i < N; ++i) {
        out[i] = arma::sqrt(A[i]);
    }
    return out;
}
Example #5
0
Blob operator*(Blob& A, Blob& B) {
    vector<int> sz_A = A.size();
    vector<int> sz_B = B.size();
    for (int i = 0; i < 4; ++i) {
        assert(sz_A[i] == sz_B[i]);
    }
    Blob out(A.size());
    int N = A.get_N();
    for (int i = 0; i < N; ++i) {
        out[i] = A[i] % B[i];
    }
    return out;
}
Example #6
0
double prob(Blob& Y, Blob& p) {
    assert(Y.get_N() == p.get_N());
    assert(Y.get_C() == p.get_C());
    assert(Y.get_H() == p.get_H());
    assert(Y.get_W() == p.get_W());

    double ret = 0;
    int N = Y.get_N();
    int C = Y.get_C();
    vector<int> pp(N, -1);
    vector<int> yy(N, -2);
    mat mpp = p.reshape();
    mat myy = Y.reshape();
    
    for (int i = 0; i < N; ++i) {
        int idx_p = 0, idx_y = 0;
        double max_p = mpp(i,0), max_y = myy(i,0);
        for (int j = 1; j < C; ++j) {
            if (mpp(i, j) > max_p) {
                max_p = mpp(i, j);
                idx_p = j;
            }
            if (myy(i, j) > max_y) {
                max_y = myy(i, j);
                idx_y = j;
            }
        }
        pp[i] = idx_p;
        yy[i] = idx_y;
    }
    int cnt = 0;
    for (int i = 0; i < N; ++i) {
        if (pp[i] == yy[i])
            cnt++;
    }
    ret = (double)cnt / (double)N;
    return ret;
}