logprob_type logprob_buffer(Iterator first, Iterator last, void* buffer) const { matrix_type input(reinterpret_cast<parameter_type*>(buffer), dimension_embedding_ * (order_ - 1), 1); if (last - first < order_) { size_type i = 0; for (/**/; i < order_ - (last - first); ++ i) input.block(dimension_embedding_ * i, 0, dimension_embedding_, 1) = embedding_input_().col(id_eps_); for (/**/; first != last - 1; ++ first, ++ i) input.block(dimension_embedding_ * i, 0, dimension_embedding_, 1) = embedding_input_().col(*first); } else { size_type i = 0; for (/**/; first != last - 1; ++ first, ++ i) input.block(dimension_embedding_ * i, 0, dimension_embedding_, 1) = embedding_input_().col(*first); } if (normalize_) { matrix_type hidden(reinterpret_cast<parameter_type*>(buffer) + dimension_embedding_ * (order_ - 1), dimension_embedding_, 1); hidden = (Wh_() * (Wc_() * input + bc_()).array().unaryExpr(hinge()).matrix() + bh_()).array().unaryExpr(hinge()); double logsum = - std::numeric_limits<double>::infinity(); double logprob = 0.0; const word_type word = *(last - 1); for (id_type id = 0; id != embedding_size_; ++ id) if (id != id_bos_ && id != id_eps_) { const double lp = (embedding_output_().col(id).block(0, 0, dimension_embedding_, 1).transpose() * hidden + embedding_output_().col(id).block(dimension_embedding_, 0, 1, 1))(0, 0); logsum = utils::mathop::logsum(logsum, lp); if (id == word.id()) logprob = lp; } return logprob - logsum; } else return (embedding_output_().col(*(last - 1)).block(0, 0, dimension_embedding_, 1).transpose() * (Wh_() * (Wc_() * input + bc_()).array().unaryExpr(hinge()).matrix() + bh_()).array().unaryExpr(hinge()).matrix() + embedding_output_().col(*(last - 1)).block(dimension_embedding_, 0, 1, 1))(0, 0); }
bool CarSuspension::Load( const PTree & cfg_wheel, CarSuspension *& suspension, std::ostream & error_output) { CarSuspensionInfo info; std::vector<btScalar> p(3); if (!cfg_wheel.get("position", p, error_output)) return false; if (!cfg_wheel.get("camber", info.camber, error_output)) return false; if (!cfg_wheel.get("caster", info.caster, error_output)) return false; if (!cfg_wheel.get("toe", info.toe, error_output)) return false; cfg_wheel.get("steering", info.steering_angle); cfg_wheel.get("ackermann", info.ackermann); info.position.setValue(p[0], p[1], p[2]); const PTree * cfg_coil; if (!cfg_wheel.get("coilover", cfg_coil, error_output)) return false; if (!LoadCoilover(*cfg_coil, info, error_output)) return false; const PTree * cfg_susp; if (cfg_wheel.get("macpherson-strut", cfg_susp)) { std::vector<btScalar> strut_top(3), strut_end(3), hinge(3); if (!cfg_susp->get("hinge", hinge, error_output)) return false; if (!cfg_susp->get("strut-top", strut_top, error_output)) return false; if (!cfg_susp->get("strut-end", strut_end, error_output)) return false; MacPhersonSuspension * mps = new MacPhersonSuspension(); mps->Init(info, strut_top, strut_end, hinge); suspension = mps; } /* else if (cfg_wheel.get("double-wishbone", cfg_susp)) { std::vector<btScalar> up_ch0(3), up_ch1(3), lo_ch0(3), lo_ch1(3), up_hub(3), lo_hub(3); if (!cfg_susp->get("upper-chassis-front", up_ch0, error_output)) return false; if (!cfg_susp->get("upper-chassis-rear", up_ch1, error_output)) return false; if (!cfg_susp->get("lower-chassis-front", lo_ch0, error_output)) return false; if (!cfg_susp->get("lower-chassis-rear", lo_ch1, error_output)) return false; if (!cfg_susp->get("upper-hub", up_hub, error_output)) return false; if (!cfg_susp->get("lower-hub", lo_hub, error_output)) return false; WishboneSuspension * wbs = new WishboneSuspension(); wbs->Init(info, up_ch0, up_ch1, lo_ch0, lo_ch1, up_hub, lo_hub); suspension = wbs; }*/ else { std::vector<btScalar> ch(3, 0), wh(3, 0); if (!cfg_wheel.get("hinge", cfg_susp, error_output)) return false; if (!cfg_susp->get("chassis", ch, error_output)) return false; if (!cfg_susp->get("wheel", wh, error_output)) return false; BasicSuspension * bs = new BasicSuspension(); bs->Init(info, ch, wh); suspension = bs; } return true; }