double get_radius_of_gyration(const ParticlesTemp& ps) { IMP_USAGE_CHECK(ps.size() > 0, "No particles provided"); bool mass = Mass::get_is_setup(ps[0]); bool radii = core::XYZR::get_is_setup(ps[0]); algebra::Vector3D cm(0, 0, 0); double total = 0; for (unsigned int i = 0; i < ps.size(); ++i) { double weight = get_weight(mass, radii, ps[i]); total += weight; cm += core::XYZ(ps[i]).get_coordinates() * weight; } cm /= total; double ret = 0; for (unsigned int i = 0; i < ps.size(); ++i) { double c; if (radii) { c = .6 * square(core::XYZR(ps[i]).get_radius()); } else { c = 0; } double d = get_squared_distance(core::XYZ(ps[i]).get_coordinates(), cm); ret += get_weight(mass, radii, ps[i]) * (d + c); } return std::sqrt(ret / total); }
float Grid_2D :: get_edge(pair<uint32_t, uint32_t> start, cell_adjacent neighbor) { pair<uint32_t, uint32_t> neighbor_node = neighbor_to_pair(start, neighbor); if(!is_valid_node(start) || !is_neighbor(start, neighbor_node)) { return INFINITY; } uint8_t start_weight = get_weight(start); uint8_t neighbor_weight = get_weight(get_neighbor(start, neighbor)); if(start_weight == INF || neighbor_weight == INF) { return INFINITY; } float edge = start_weight + neighbor_weight; edge /= 2; if(neighbor == TOP_LEFT || neighbor == TOP_RIGHT || neighbor == BOTTOM_LEFT || neighbor == BOTTOM_RIGHT) { edge *= sqrt(2); } return edge; }
static void rn_ntwk_init(struct layer *layer_p) { if((data_p=malloc(ntwk_info.input_dim*sizeof(double)))==NULL) /* allocate space for data vector */ fprintf(stderr,"\nerror allocating data_p"); /* initialize the weights for matrix of struct unit_train */ for(count_l=0;count_l<ntwk_info.layers;count_l++) { if(count_l==0) { for(count_u=0;count_u<layer_p->units;count_u++) { for(count_w=0;count_w<=ntwk_info.input_dim;count_w++) { *(*(layer_p->weights+count_u)+count_w)=get_weight(); /* experimented with removing what appear to be unnec. () */ } } } if(count_l!=0) { for(count_u=0;count_u<(layer_p+count_l)->units;count_u++) { for(count_w=0;count_w<=(layer_p+count_l-1)->units;count_w++) { *(*((layer_p+count_l)->weights+count_u)+count_w)=get_weight(); /* experimented with removing () */ } } } } }
expr defeq_canonizer::canonize_core(expr const & e) { if (auto it = m_state.m_C.find(e)) { expr e1 = *it; if (e1 == e) return e; expr e2 = canonize_core(e1); if (e2 != e1) { replace_C(e, e2); } return e2; } expr e_type = m_ctx.infer(e); optional<name> h = get_head_symbol(e_type); if (!h) { /* canonization is not support for type of e */ insert_C(e, e); return e; } else if (optional<expr> new_e = find_defeq(*h, e)) { if (get_weight(e) < get_weight(*new_e) && locals_subset(e, *new_e)) { replace_C(*new_e, e); replace_M(*h, *new_e, e); insert_C(e, e); return e; } else { insert_C(e, *new_e); return *new_e; } } else { insert_C(e, e); insert_M(*h, e); return e; } }
bool is_lt(expr const & a, expr const & b, bool use_hash) { if (is_eqp(a, b)) return false; unsigned wa = get_weight(a); unsigned wb = get_weight(b); if (wa < wb) return true; if (wa > wb) return false; if (a.kind() != b.kind()) return a.kind() < b.kind(); if (use_hash) { if (a.hash() < b.hash()) return true; if (a.hash() > b.hash()) return false; } if (a == b) return false; switch (a.kind()) { case expr_kind::Var: return var_idx(a) < var_idx(b); case expr_kind::Constant: if (const_name(a) != const_name(b)) return const_name(a) < const_name(b); else return is_lt(const_levels(a), const_levels(b), use_hash); case expr_kind::App: if (app_fn(a) != app_fn(b)) return is_lt(app_fn(a), app_fn(b), use_hash); else return is_lt(app_arg(a), app_arg(b), use_hash); case expr_kind::Lambda: case expr_kind::Pi: if (binding_domain(a) != binding_domain(b)) return is_lt(binding_domain(a), binding_domain(b), use_hash); else return is_lt(binding_body(a), binding_body(b), use_hash); case expr_kind::Let: if (let_type(a) != let_type(b)) return is_lt(let_type(a), let_type(b), use_hash); else if (let_value(a) != let_value(b)) return is_lt(let_value(a), let_value(b), use_hash); else return is_lt(let_body(a), let_body(b), use_hash); case expr_kind::Sort: return is_lt(sort_level(a), sort_level(b), use_hash); case expr_kind::Local: case expr_kind::Meta: if (mlocal_name(a) != mlocal_name(b)) return mlocal_name(a) < mlocal_name(b); else return is_lt(mlocal_type(a), mlocal_type(b), use_hash); case expr_kind::Macro: if (macro_def(a) != macro_def(b)) return macro_def(a) < macro_def(b); if (macro_num_args(a) != macro_num_args(b)) return macro_num_args(a) < macro_num_args(b); for (unsigned i = 0; i < macro_num_args(a); i++) { if (macro_arg(a, i) != macro_arg(b, i)) return is_lt(macro_arg(a, i), macro_arg(b, i), use_hash); } return false; } lean_unreachable(); // LCOV_EXCL_LINE }
/* * Dijkstra最短路径。 * 即,统计图(G)中"顶点vs"到其它各个顶点的最短路径。 * * 参数说明: * G -- 图 * vs -- 起始顶点(start vertex)。即计算"顶点vs"到其它顶点的最短路径。 * prev -- 前驱顶点数组。即,prev[i]的值是"顶点vs"到"顶点i"的最短路径所经历的全部顶点中,位于"顶点i"之前的那个顶点。 * dist -- 长度数组。即,dist[i]是"顶点vs"到"顶点i"的最短路径的长度。 */ void dijkstra(LGraph G, int vs, int prev[], int dist[]) { int i,j,k; int min; int tmp; int flag[MAX]; // flag[i]=1表示"顶点vs"到"顶点i"的最短路径已成功获取。 // 初始化 for (i = 0; i < G.vexnum; i++) { flag[i] = 0; // 顶点i的最短路径还没获取到。 prev[i] = 0; // 顶点i的前驱顶点为0。 dist[i] = get_weight(G, vs, i); // 顶点i的最短路径为"顶点vs"到"顶点i"的权。 } // 对"顶点vs"自身进行初始化 flag[vs] = 1; dist[vs] = 0; // 遍历G.vexnum-1次;每次找出一个顶点的最短路径。 for (i = 1; i < G.vexnum; i++) { // 寻找当前最小的路径; // 即,在未获取最短路径的顶点中,找到离vs最近的顶点(k)。 min = INF; for (j = 0; j < G.vexnum; j++) { if (flag[j]==0 && dist[j]<min) { min = dist[j]; k = j; } } // 标记"顶点k"为已经获取到最短路径 flag[k] = 1; // 修正当前最短路径和前驱顶点 // 即,当已经"顶点k的最短路径"之后,更新"未获取最短路径的顶点的最短路径和前驱顶点"。 for (j = 0; j < G.vexnum; j++) { tmp = get_weight(G, k, j); tmp = (tmp==INF ? INF : (min + tmp)); // 防止溢出 if (flag[j] == 0 && (tmp < dist[j]) ) { dist[j] = tmp; prev[j] = k; } } } // 打印dijkstra最短路径的结果 printf("dijkstra(%c): \n", G.vexs[vs].data); for (i = 0; i < G.vexnum; i++) printf(" shortest(%c, %c)=%d\n", G.vexs[vs].data, G.vexs[i].data, dist[i]); }
expr_app::expr_app(expr const & fn, expr const & arg, tag g): expr_composite(expr_kind::App, ::lean::hash(fn.hash(), arg.hash()), fn.has_expr_metavar() || arg.has_expr_metavar(), fn.has_univ_metavar() || arg.has_univ_metavar(), fn.has_local() || arg.has_local(), fn.has_param_univ() || arg.has_param_univ(), inc_weight(add_weight(get_weight(fn), get_weight(arg))), std::max(get_free_var_range(fn), get_free_var_range(arg)), g), m_fn(fn), m_arg(arg) { m_hash = ::lean::hash(m_hash, m_weight); }
expr_let::expr_let(name const & n, expr const & t, expr const & v, expr const & b, tag g): expr_composite(expr_kind::Let, ::lean::hash(::lean::hash(t.hash(), v.hash()), b.hash()), t.has_expr_metavar() || v.has_expr_metavar() || b.has_expr_metavar(), t.has_univ_metavar() || v.has_univ_metavar() || b.has_univ_metavar(), t.has_local() || v.has_local() || b.has_local(), t.has_param_univ() || v.has_param_univ() || b.has_param_univ(), inc_weight(add_weight(add_weight(get_weight(t), get_weight(v)), get_weight(b))), std::max(std::max(get_free_var_range(t), get_free_var_range(v)), dec(get_free_var_range(b))), g), m_name(n), m_type(t), m_value(v), m_body(b) { m_hash = ::lean::hash(m_hash, m_weight); }
/** * \copydoc Detector::notify_action_command_pressed */ bool Destructible::notify_action_command_pressed() { KeysEffect::ActionKeyEffect effect = get_keys_effect().get_action_key_effect(); if ((effect == KeysEffect::ACTION_KEY_LIFT || effect == KeysEffect::ACTION_KEY_LOOK) && get_weight() != -1 && !is_being_cut && !is_waiting_for_regeneration() && !is_regenerating) { if (get_equipment().has_ability(Ability::LIFT, get_weight())) { uint32_t explosion_date = get_can_explode() ? System::now() + 6000 : 0; get_hero().start_lifting(std::make_shared<CarriedItem>( get_hero(), *this, get_animation_set_id(), get_destruction_sound(), get_damage_on_enemies(), explosion_date) ); // Play the sound. Sound::play("lift"); // Create the pickable treasure. create_treasure(); if (!get_can_regenerate()) { // Remove this destructible from the map. remove_from_map(); } else { // The item can actually regenerate. play_destroy_animation(); } // Notify Lua. get_lua_context().destructible_on_lifting(*this); } else { // Cannot lift the object. get_hero().start_grabbing(); get_lua_context().destructible_on_looked(*this); } return true; } return false; }
bool is_lt_no_level_params(expr const & a, expr const & b) { if (is_eqp(a, b)) return false; unsigned wa = get_weight(a); unsigned wb = get_weight(b); if (wa < wb) return true; if (wa > wb) return false; if (a.kind() != b.kind()) return a.kind() < b.kind(); switch (a.kind()) { case expr_kind::Var: return var_idx(a) < var_idx(b); case expr_kind::Constant: if (const_name(a) != const_name(b)) return const_name(a) < const_name(b); else return is_lt_no_level_params(const_levels(a), const_levels(b)); case expr_kind::App: if (is_lt_no_level_params(app_fn(a), app_fn(b))) return true; else if (is_lt_no_level_params(app_fn(b), app_fn(a))) return false; else return is_lt_no_level_params(app_arg(a), app_arg(b)); case expr_kind::Lambda: case expr_kind::Pi: if (is_lt_no_level_params(binding_domain(a), binding_domain(b))) return true; else if (is_lt_no_level_params(binding_domain(b), binding_domain(a))) return false; else return is_lt_no_level_params(binding_body(a), binding_body(b)); case expr_kind::Sort: return is_lt_no_level_params(sort_level(a), sort_level(b)); case expr_kind::Local: case expr_kind::Meta: if (mlocal_name(a) != mlocal_name(b)) return mlocal_name(a) < mlocal_name(b); else return is_lt_no_level_params(mlocal_type(a), mlocal_type(b)); case expr_kind::Macro: if (macro_def(a) != macro_def(b)) return macro_def(a) < macro_def(b); if (macro_num_args(a) != macro_num_args(b)) return macro_num_args(a) < macro_num_args(b); for (unsigned i = 0; i < macro_num_args(a); i++) { if (is_lt_no_level_params(macro_arg(a, i), macro_arg(b, i))) return true; else if (is_lt_no_level_params(macro_arg(b, i), macro_arg(a, i))) return false; } return false; } lean_unreachable(); }
expr_binding::expr_binding(expr_kind k, name const & n, expr const & t, expr const & b, binder_info const & i, tag g): expr_composite(k, ::lean::hash(t.hash(), b.hash()), t.has_expr_metavar() || b.has_expr_metavar(), t.has_univ_metavar() || b.has_univ_metavar(), t.has_local() || b.has_local(), t.has_param_univ() || b.has_param_univ(), inc_weight(add_weight(get_weight(t), get_weight(b))), std::max(get_free_var_range(t), dec(get_free_var_range(b))), g), m_binder(n, t, i), m_body(b) { m_hash = ::lean::hash(m_hash, m_weight); lean_assert(k == expr_kind::Lambda || k == expr_kind::Pi); }
int get_average(int n) { int i; int val; val = get_weight(); for(i = 0; i < n; i++) { val += get_weight(); val = val >> 1; Delayms(1); } return val; }
void Patches::normalize_weights() { float total = 0; for (int i = 0; i < size(); i++) { total += get_weight(i); } for (int i = 0; i < size(); i++) { set_weight(i, get_weight(i) / total); } }
int main(int argc, char* argv[]) { int input_size = 10; int dense_size1 = 5; int dense_size2 = 3; Container model; model.add(Dense(dense_size1, input_size)); model.add(Dense(dense_size2)); auto layer = model.get_layer(); for (unsigned int i = 0; i < layer.size(); ++i) { auto dense = layer[i]; printf("layer : %d\tdense_size : %d\t prev_dense_size : %d\n", i, dense.dense_size(), dense.get_cell(0).edge_size()); for(unsigned int j = 0; j < dense.dense_size(); ++j) { auto cell = dense.get_cell(j); auto weight = cell.get_weight(); auto bias = cell.get_bias(); for(unsigned int k = 0; k < weight.size(); ++k) { printf("(%d,%d) : %lf\t%lf\n", j, k, weight[k], bias); } } } return 0; }
/*! the relative size of a quad Min( J, 1/J ), where J is determinant of weighted Jacobian matrix */ C_FUNC_DEF VERDICT_REAL v_quad_relative_size_squared( int /*num_nodes*/, VERDICT_REAL coordinates[][3] ) { double quad_area = v_quad_area (4, coordinates); double rel_size = 0; v_set_quad_size( quad_area ); double w11,w21,w12,w22; get_weight(w11,w21,w12,w22); double avg_area = determinant(w11,w21,w12,w22); if ( avg_area > VERDICT_DBL_MIN ) { w11 = quad_area / avg_area; if ( w11 > VERDICT_DBL_MIN ) { rel_size = VERDICT_MIN( w11, 1/w11 ); rel_size *= rel_size; } } if( rel_size > 0 ) return (VERDICT_REAL) VERDICT_MIN( rel_size, VERDICT_DBL_MAX ); return (VERDICT_REAL) VERDICT_MAX( rel_size, -VERDICT_DBL_MAX ); }
//! Get all weights algebra::VectorKD Weight::get_weights() { algebra::VectorKD ww = algebra::get_zero_vector_kd(get_number_of_states()); for (int i = 0; i < get_number_of_states(); ++i) { ww[i] = get_weight(i); } return ww; }
int main(void) { // Declare variables double weight = 0.0, height = 0.0, bmi = 0.0; WeightStatus status = 0; // Ask for and save the value for weight. weight = get_weight(); // Ask for and save the value for height. height = get_height(); // Bail out if we have an invalid weight. if (validate_weight(weight) == 0) { printf("\n!!! Invalid weight. Exiting...\n"); return 0; } // Bail out if we have an invalid height. if (validate_height(height) == 0) { printf("\n!!! Invalid height. Exiting...\n"); return 0; } // Calculate and print the BMI. bmi = get_bmi(weight, height); print_bmi(bmi); // Decide and print the weight status. status = get_weight_status(bmi); print_status(status); return 0; }
/** * \brief This function is called when this entity detects a collision with the hero. * \param hero the hero * \param collision_mode the collision mode that detected the collision */ void Destructible::notify_collision_with_hero(Hero& hero, CollisionMode /* collision_mode */) { if (get_weight() != -1 && !is_being_cut && !is_waiting_for_regeneration() && !is_regenerating && get_keys_effect().get_action_key_effect() == KeysEffect::ACTION_KEY_NONE && hero.is_free()) { if (get_equipment().has_ability(Ability::LIFT, get_weight())) { get_keys_effect().set_action_key_effect(KeysEffect::ACTION_KEY_LIFT); } else { get_keys_effect().set_action_key_effect(KeysEffect::ACTION_KEY_LOOK); } } }
char* create_xlfd(font_family* family, font_style* style, uint32 flag) { char buf[100]; sprintf(buf, "-TTFont-%s-%s-%c-normal--0-0-0-0-%c-0-%s", *family, get_weight(style), get_slant(style), get_spacing(flag), get_encoding(family)); char* xlfd = (char*) calloc(strlen(buf) + 1, sizeof(char)); strcpy(xlfd, buf); return xlfd; }
// A*を用いてstartからgoalまでの経路導出 Path(const Field& _field ,const ItemCollection& _item ,const int _start, const int _goal) : start (_start), goal (_goal), load_weight(get_weight(_item, _goal)), route (a_star(_field, get_pos(_field, _item, _start), get_pos(_field, _item, _goal))) { }
void make_refgrps(t_pull *pull,matrix box,t_mdatoms *md) { int ngrps,i,ii,j,k,m; static bool bFirst = TRUE; real dr,mass; real truemass; rvec test; ngrps = pull->pull.n; if (bFirst) { snew(pull->dyna.ngx,ngrps); snew(pull->dyna.idx,ngrps); snew(pull->dyna.weights,ngrps); for (i=0;i<ngrps;i++) { snew(pull->dyna.idx[i],pull->ref.ngx[0]); /* more than nessary */ snew(pull->dyna.weights[i],pull->ref.ngx[0]); } bFirst = FALSE; } /* loop over all groups to make a reference group for each*/ for (i=0;i<ngrps;i++) { k=0; truemass=0; pull->dyna.tmass[i] = 0; pull->dyna.ngx[i] = 0; /* loop over all atoms in the main ref group */ for (j=0;j<pull->ref.ngx[0];j++) { ii = pull->ref.idx[0][j]; /* get_distance takes pbc into account */ dr = get_cylinder_distance(pull->ref.x0[0][j],pull->pull.x_unc[i],box); if (dr < pull->rc) { /* add to index, to sum of COM, to weight array */ mass = md->massT[ii]; truemass += mass; pull->dyna.ngx[i]++; pull->dyna.weights[i][k] = get_weight(dr,pull->r,pull->rc); pull->dyna.idx[i][k] = ii; for (m=0;m<DIM;m++) pull->dyna.x_unc[i][m] += mass*pull->dyna.weights[i][k]* pull->ref.x0[0][j][m]; pull->dyna.tmass[i] += mass*pull->dyna.weights[i][k]; k++; } } /* normalize the new 'x_unc' */ svmul(1/pull->dyna.tmass[i],pull->dyna.x_unc[i],pull->dyna.x_unc[i]); if (pull->bVerbose) fprintf(stderr,"Made group %d:%8.3f%8.3f%8.3f wm:%8.3f m:%8.3f\n", i,pull->dyna.x_unc[i][0],pull->dyna.x_unc[i][1], pull->dyna.x_unc[i][2],pull->dyna.tmass[i],truemass); } }
/** * Pretty print the graph */ void pretty_print (int source) const { assert(M>source); for (int index = begin (source); index < end (source); ++index) { int target = get_target (index); double weight = get_weight (index); std::cout << source << " " << target << " " << weight << std::endl; } }
unsigned light_lt_manager::get_weight_core(expr const & e) { switch (e.kind()) { case expr_kind::Var: case expr_kind::Constant: case expr_kind::Sort: case expr_kind::Meta: case expr_kind::Local: return 1; case expr_kind::Lambda: case expr_kind::Pi: return safe_add(1, safe_add(get_weight(binding_domain(e)), get_weight(binding_body(e)))); case expr_kind::Macro: return safe_add(1, add_weight(macro_num_args(e), macro_args(e))); case expr_kind::App: buffer<expr> args; expr fn = get_app_args(e, args); if (is_constant(fn)) { unsigned const * light_arg = m_lrs.find(const_name(fn)); if (light_arg && args.size() > *light_arg) return get_weight(args[*light_arg]); } return safe_add(1, safe_add(get_weight(app_fn(e)), get_weight(app_arg(e)))); } lean_unreachable(); // LCOV_EXCL_LINE }
/** * Pretty print the graph */ void pretty_print () const { for (int source = 0; source < N; ++source) { for (int target_index = begin (source); target_index < end (source); ++target_index) { std::cout << source << " ---> " << get_target (target_index) << " (weight=" << get_weight (target_index) << ")" << std::endl; } } }
void fill_glass(int sel) { disable_joystick(); // Disable user input LCD_Clear(); LCD_DrawString(2, 8, (u8*)"Filling...", 10); LCD_DrawString(4, 8, (u8*)drink[sel], strlen(drink[sel]));; set_all_valves(0); // Safety check; close all valves int empty_weight = get_weight(); switch(sel) { case 0: // Tequila Sunrise; 30.75% Tequila, 61.5% Orange Juice, 7.75% Grenadine LCD_DrawChar(0, 0, '1'); fill_liquid(TEQUILA, (empty_weight + 0.3075*MAX_WEIGHT)); LCD_DrawChar(0, 0, '2'); fill_liquid(ORANGE, (empty_weight + 0.9225*MAX_WEIGHT)); LCD_DrawChar(0, 0, '3'); fill_liquid(GRENADINE, (empty_weight + MAX_WEIGHT)); break; case 1: // The Gilbert; 58% Vodka, 30% Soda, 12% Orange Juice LCD_DrawChar(0, 0, '1'); fill_liquid(VODKA, (empty_weight + 0.58*MAX_WEIGHT)); LCD_DrawChar(0, 0, '2'); fill_liquid(SODA, (empty_weight + 0.88*MAX_WEIGHT)); LCD_DrawChar(0, 0, '3'); fill_liquid(ORANGE, (empty_weight + MAX_WEIGHT)); break; case 2: // Pink Polar Bear; 58% Vodka, 42% Grenadine LCD_DrawChar(0, 0, '1'); fill_liquid(VODKA, (empty_weight + 0.58*MAX_WEIGHT)); LCD_DrawChar(0, 0, '2'); fill_liquid(GRENADINE, (empty_weight + MAX_WEIGHT)); break; case 3: // Screwdriver; 48% Vodka, 52% Orange Juice LCD_DrawChar(0, 0, '1'); fill_liquid(VODKA, (empty_weight + 0.48*MAX_WEIGHT)); LCD_DrawChar(0, 15*8, '2'); fill_liquid(ORANGE, (empty_weight + MAX_WEIGHT)); break; default: break; } set_all_valves(0); // Safety check; close all valves LCD_Clear(); LCD_DrawString(1, 8, (u8*)"Enjoy...", 8); LCD_DrawString(3, 8, (u8*)"Press Joystick", 14); LCD_DrawString(5, 8, (u8*)"for new drink", 13); enable_joystick(); // Enable user input }
static void parse_weightsystem_keyvalue(void *_ws, const char *key, const char *value) { weightsystem_t *ws = _ws; if (!strcmp(key, "weight")) { ws->weight = get_weight(value); return; } /* This is handled by the "get_utf8()" */ if (!strcmp(key, "description")) return; report_error("Unknown weightsystem key/value pair (%s/%s)", key, value); }
// Given a hidden neuron vector, return the probability of a visible unit i double visible_probability(rbm* r, unsigned int i, std::vector<int> hidden) { if (!(i < r->nv && hidden.size() == r->nh)) { return -1.; } double s = get_weight_hidden_bias(r, i); for (unsigned int j=0; j < r->nh; j++) { s+= get_weight(r, i, j) * hidden[j]; } return sigmoid(s); }
// Given an input vector, return the probability of a hidden unit j double hidden_probability(rbm* r, unsigned int j, std::vector<int> visible) { if (!(j < r->nh && visible.size() == r->nv)) { return -1.; } double s = get_weight_visible_bias(r, j); for (unsigned int i=0; i < r->nv; i++) { s+= get_weight(r, i, j) * visible[i]; } return sigmoid(s); }
vertex_id reach_dijkstra::iterate() { if (q_.size() > max_heap_size_) max_heap_size_ = q_.size(); while (pout_->count(q_.top().id) != 0) { if (iterations_counter % 100000 == 0) cout << "Heap size: " << q_.size() << endl; ++iterations_counter; q_.pop(); } heap_vertex hv = q_.top(); q_.pop(); const path_vertex &pv = unordered_safe_find_const(border_, hv.id); (*pout_)[hv.id] = pv; const vertex &v = pgraph_->get_vertex(hv.id); for (vertex::adj_iterator it = v.out_begin(); it != v.out_end(); ++it) { const vertex_id &adj_vid = (*it).v; const vertex &adj_v = pgraph_->get_vertex(adj_vid); const edge_id &eid = (*it).e; const edge &e = pgraph_->get_edge(eid); if (pout_->count (adj_vid) > 0) continue; path_vertex pv2 (adj_vid, pv.d + get_weight(e), eid, hv.id); heap_vertex hv2 (adj_vid, pv2.d); if (border_.count(adj_vid) == 0 || unordered_safe_find_const(border_, adj_vid).d > pv2.d) { q_.push(hv2); border_[adj_vid] = pv2; } } border_.erase(hv.id); return hv.id; }
decltype(auto) dropout_wrapper_test() { //std::random_device rd; //std::mt19937 rand(rd()); std::mt19937 rand(0); // fixed initial vector auto input_dim = 2u; auto output_dim = 1u; auto batch_size = 4u; std::vector<neu::cpu_vector> cpu_input = { {0.f, 0.f}, {1.f, 0.f}, {0.f, 1.f}, {1.f, 1.f} }; std::vector<neu::cpu_vector> cpu_teach = { {0.f}, {1.f}, {1.f}, {0.f} }; neu::gpu_vector input; for(auto const& cpui : cpu_input) { input.insert(input.end(), cpui.begin(), cpui.end()); } neu::gpu_vector teach; for(auto const& cput : cpu_teach) { teach.insert(teach.end(), cput.begin(), cput.end()); } auto fc = neu::make_full_connected_layer( input_dim, output_dim, batch_size, neu::rectifier()); fc.init_weight_randomly( [&rand, bin=std::uniform_real_distribution<>(0.f, 1.f)]() mutable { return bin(rand); }); std::cout << "weight "; neu::print(fc.get_weight()); std::cout << std::endl; auto dfc = neu::make_dropout_wrapper(fc, 0.9f, rand); std::cout << "weight "; neu::print(dfc.get_layer().get_weight()); std::cout << std::endl; neu::layer_calc_u_and_y(dfc, input); auto y = neu::layer_get_y(dfc); std::cout << "y "; neu::print(y); neu::gpu_vector errors(y.size()); boost::compute::transform(y.begin(), y.end(), teach.begin(), errors.begin(), boost::compute::minus<neu::scalar>()); neu::layer_calc_delta(dfc, errors); neu::layer_update_delta_weight(dfc, input); neu::layer_update_weight(dfc); auto weight = neu::layer_get_weight(dfc.get_layer()); std::cout << "updated weight"; neu::print(weight); }