Пример #1
0
 void context::display_subexprs_info(std::ostream & out, expr * n) const {
     ptr_buffer<expr> todo;
     todo.push_back(n);
     while (!todo.empty()) {
         expr * n = todo.back();
         todo.pop_back();
         out << "#";
         out.width(6);
         out << std::left << n->get_id();
         out << ", relevant: " << is_relevant(n);
         if (m_manager.is_bool(n)) {
             out << ", val: ";
             out.width(7);
             out << std::right;
             if (lit_internalized(n))
                 out << get_assignment(n);
             else
                 out << "l_undef";
         }
         if (e_internalized(n)) {
             enode * e = get_enode(n);
             out << ", root: #" << e->get_root()->get_owner_id();
         }
         out << "\n";
         if (is_app(n)) {
             for (unsigned i = 0; i < to_app(n)->get_num_args(); i++)
                 todo.push_back(to_app(n)->get_arg(i));
         }
     }
 }
Пример #2
0
 /**
    \brief Display enode definitions #n := (f #i_1 ... #i_n), where #i_k is the root
    of the k-th argument of the enode #n.
  */
 void context::display_normalized_enodes(std::ostream & out) const {
     out << "normalized enodes:\n";
     ptr_vector<enode>::const_iterator it  = m_enodes.begin();
     ptr_vector<enode>::const_iterator end = m_enodes.end();
     for (; it != end; ++it) {
         enode * n = *it;
         out << "#";
         out.width(5);
         out << std::left << n->get_owner_id() << " #";
         out.width(5);
         out << n->get_root()->get_owner_id() << " := " << std::right;
         unsigned num = n->get_owner()->get_num_args();
         if (num > 0)
             out << "(";
         out << n->get_decl()->get_name();
         if (!n->get_decl()->private_parameters())
             display_parameters(out, n->get_decl()->get_num_parameters(), n->get_decl()->get_parameters());
         for (unsigned i = 0; i < num; i++) {
             expr * arg = n->get_owner()->get_arg(i);
             if (e_internalized(arg)) {
                 enode * n = get_enode(arg)->get_root();
                 out << " #" << n->get_owner_id();
             }
             else {
                 out << " #" << arg->get_id();
             }
         }
         if (num > 0)
             out << ")";
         if (is_relevant(n))
             out << "\t*";
         out << "\n";
     }
 }
Пример #3
0
 void context::display_literal_info(std::ostream & out, literal l) const {
     l.display_compact(out, m_bool_var2expr.c_ptr());
     if (l.sign())
         out << "  (not " << mk_bounded_pp(bool_var2expr(l.var()), m_manager, 10) << ") ";
     else
         out << "  " << mk_bounded_pp(bool_var2expr(l.var()), m_manager, 10) << " ";
     out << "relevant: " << is_relevant(bool_var2expr(l.var())) << ", val: " << get_assignment(l) << "\n";
 }
Пример #4
0
 void context::display_assignment(std::ostream & out) const {
     if (!m_assigned_literals.empty()) {
         out << "current assignment:\n";
         for (literal lit : m_assigned_literals) {
             display_literal(out, lit);
             if (!is_relevant(lit)) out << " n ";
             out << ": ";
             display_verbose(out, m_manager, 1, &lit, m_bool_var2expr.c_ptr());
             out << "\n";
         }
     }
 }
Пример #5
0
 void context::display_eq_detail(std::ostream & out, enode * n) const {
     SASSERT(n->is_eq());
     out << "#" << n->get_owner_id()
         << ", root: #" << n->get_root()->get_owner_id()
         << ", cg: #" << n->m_cg->get_owner_id()
         << ", val: " << get_assignment(enode2bool_var(n))
         << ", lhs: #" << n->get_arg(0)->get_owner_id()
         << ", rhs: #" << n->get_arg(1)->get_owner_id()
         << ", lhs->root: #" << n->get_arg(0)->get_root()->get_owner_id()
         << ", rhs->root: #" << n->get_arg(1)->get_root()->get_owner_id()
         << ", is_marked: " << n->is_marked()
         << ", is_relevant: " << is_relevant(n)
         << ", iscope_lvl: " << n->get_iscope_lvl() << "\n";
 }
Пример #6
0
    /**
     *  Vertex update function.
     */
    void update(graphchi_vertex<VertexDataType, EdgeDataType> &vertex, graphchi_context &gcontext) {
        double objective = -0.5*sgd_lambda*latent_factors_inmem[vertex.id()].pvec.squaredNorm();

        // go over all user nodes
        if (vertex.num_outedges() > 1) { // can't compute with CLiMF if we have only 1 out edge!
            vec & U = latent_factors_inmem[vertex.id()].pvec;
            int Ni = vertex.num_edges();

            // precompute f_{ij} = <U_i,V_j> for j = 1..N_i
            std::vector<double> f(Ni);
            int num_relevant = 0;

            for (int j = 0; j < Ni; ++j) {
                if (is_relevant(vertex.edge(j))) {
                    const vec & Vj = latent_factors_inmem[vertex.edge(j)->vertex_id()].pvec;
                    f[j] = dot(U, Vj);
                    ++num_relevant;
                }
            }

            if (num_relevant < 2) {
                return;  // need at least 2 edges to compute updates with CLiMF!
                node_without_edges++;
            }

            // compute gradients
            vec dU = -sgd_lambda*U;

            for (int j = 0; j < Ni; ++j) {
                if (is_relevant(vertex.edge(j))) {
                    vec & Vj = latent_factors_inmem[vertex.edge(j)->vertex_id()].pvec;
                    vec dVj = g(-f[j])*ones(D) - sgd_lambda*Vj;

                    for (int k = 0; k < Ni; ++k) {
                        if (k != j && is_relevant(vertex.edge(k))) {
                            dVj += dg(f[j]-f[k])*(1.0/(1.0-g(f[k]-f[j]))-1.0/(1.0-g(f[j]-f[k])))*U;
                        }
                    }

                    Vj += sgd_gamma*dVj;  // not thread-safe
                    dU += g(-f[j])*Vj;

                    for (int k = 0; k < Ni; ++k) {
                        if (k != j && is_relevant(vertex.edge(k))) {
                            const vec & Vk = latent_factors_inmem[vertex.edge(k)->vertex_id()].pvec;
                            dU += (Vj-Vk)*dg(f[k]-f[j])/(1.0-g(f[k]-f[j]));
                        }
                    }
                }
            }

            U += sgd_gamma*dU;  // not thread-safe
            stat_vec[omp_get_thread_num()] += fabs(sgd_gamma*dU[0]);

            // compute smoothed MRR
            for(int j = 0; j < Ni; j++) {
                if (is_relevant(vertex.edge(j))) {
                    objective += std::log(g(f[j]));
                    for(int k = 0; k < Ni; k++) {
                        if (is_relevant(vertex.edge(k))) {
                            objective += std::log(1.0-g(f[k]-f[j]));
                        }
                    }
                }
            }
        }

        objective_vec[omp_get_thread_num()] += objective;
    }
Пример #7
0
/*
 * Locate and decode the FAST cookie in req, storing its contents in state for
 * later access by preauth modules.  If the cookie is expired, return
 * KRB5KDC_ERR_PREAUTH_EXPIRED if its contents are relevant to req, and ignore
 * it if they aren't.
 */
krb5_error_code
kdc_fast_read_cookie(krb5_context context, struct kdc_request_state *state,
                     krb5_kdc_req *req, krb5_db_entry *local_tgt)
{
    krb5_error_code ret;
    krb5_secure_cookie *cookie = NULL;
    krb5_timestamp now;
    krb5_keyblock *key = NULL;
    krb5_enc_data enc;
    krb5_pa_data *pa;
    krb5_kvno kvno;
    krb5_data plain = empty_data();

    pa = krb5int_find_pa_data(context, req->padata, KRB5_PADATA_FX_COOKIE);
    if (pa == NULL)
        return 0;

    /* If it's not an MIT version 1 cookie, ignore it.  It may be an empty
     * "MIT" cookie or a cookie generated by a different KDC implementation. */
    if (pa->length <= 8 || memcmp(pa->contents, "MIT1", 4) != 0)
        return 0;

    /* Extract the kvno and generate the corresponding cookie key. */
    kvno = load_32_be(pa->contents + 4);
    ret = get_cookie_key(context, local_tgt, kvno, req->client, &key, NULL);
    if (ret)
        goto cleanup;

    /* Decrypt and decode the cookie. */
    memset(&enc, 0, sizeof(enc));
    enc.enctype = key->enctype;
    enc.ciphertext = make_data(pa->contents + 8, pa->length - 8);
    ret = alloc_data(&plain, pa->length - 8);
    if (ret)
        goto cleanup;
    ret = krb5_c_decrypt(context, key, KRB5_KEYUSAGE_PA_FX_COOKIE, NULL, &enc,
                         &plain);
    if (ret)
        goto cleanup;
    ret = decode_krb5_secure_cookie(&plain, &cookie);
    if (ret)
        goto cleanup;

    /* Check if the cookie is expired. */
    ret = krb5_timeofday(context, &now);
    if (ret)
        goto cleanup;
    if (now - COOKIE_LIFETIME > cookie->time) {
        /* Don't accept the cookie contents.  Only return an error if the
         * cookie is relevant to the request. */
        if (is_relevant(cookie->data, req->padata))
            ret = KRB5KDC_ERR_PREAUTH_EXPIRED;
        goto cleanup;
    }

    /* Steal the pa-data list pointer from the cookie and store it in state. */
    state->in_cookie_padata = cookie->data;
    cookie->data = NULL;

cleanup:
    zapfree(plain.data, plain.length);
    krb5_free_keyblock(context, key);
    k5_free_secure_cookie(context, cookie);
    return 0;
}