示例#1
0
inline
void
subview_field<oT>::operator= (const field<oT>& x)
  {
  arma_extra_debug_sigprint();
  
  subview_field<oT>& t = *this;
  
  arma_debug_check( (t.n_rows != x.n_rows) || (t.n_cols != x.n_cols) || (t.n_slices != x.n_slices), "incompatible field dimensions");
  
  if(t.n_slices == 1)
    {
    for(uword col=0; col < t.n_cols; ++col)
    for(uword row=0; row < t.n_rows; ++row)
      {
      t.at(row,col) = x.at(row,col);
      }
    }
  else
    {
    for(uword slice=0; slice < t.n_slices; ++slice)
    for(uword col=0;   col   < t.n_cols;   ++col  )
    for(uword row=0;   row   < t.n_rows;   ++row  )
      {
      t.at(row,col,slice) = x.at(row,col,slice);
      }
    }
  }
示例#2
0
void oarchive_json::printFieldName(const field& att)
{
	if ( !this->_compact)
		this->_data << this->_tab << "\"" << att.name() << "\": ";
    else
        this->_data << "\"" << att.name() << "\":";
}
示例#3
0
arma::vec log_longF_svft(const field<vec>& y, const field<vec>& eta,
                         const CharacterVector& fams, const CharacterVector& links,
                         const List& sigmas, const field<uvec>& id, const int& n) {
    int n_outcomes = y.size();
    vec out(n, fill::zeros);
    for (int i = 0; i < n_outcomes; ++i) {
        uvec id_i = id.at(i);
        vec y_i = y.at(i);
        vec eta_i = eta.at(i);
        if (fams[i] == "gaussian") {
            double sigma_i = as<double>(sigmas[i]);
            vec log_dens = - 0.5 * pow((y_i - eta_i) / sigma_i, 2);
            out += rowsum_svft(log_dens, id_i);
        } else if (fams[i] == "binomial") {
            if (links[i] == "logit") {
                vec pr = exp(eta_i) / (1 + exp(eta_i));
                vec log_dens = y_i % log(pr) + (1 - y_i) % log(1 - pr);
                out += rowsum_svft(log_dens, id_i);
            } else if (links[i] == "probit") {
                vec pr = Vpnorm_svft(eta_i);
                vec log_dens = y_i % log(pr) + (1 - y_i) % log(1 - pr);
                out += rowsum_svft(log_dens, id_i);
            } else if (links[i] == "cloglog") {
                vec pr = - exp(- exp(eta_i)) + 1;
                vec log_dens = y_i % log(pr) + (1 - y_i) % log(1 - pr);
                out += rowsum_svft(log_dens, id_i);
            }
        } else if (fams[i] == "poisson") {
            vec mu = exp(eta_i);
            vec log_dens = y_i % log(mu) - mu;
            out += rowsum_svft(log_dens, id_i);
        }
    }
    return(out);
}
示例#4
0
void draw_game::draw_Field(int x, int y, const field& object) const
{
	typedef enum GameObject::field::ERASE_CHK FLAG;
	auto field_size = object.get_size();
	x += offset.x;
	y += offset.y;
	//背景描画
	//DrawBox(x - frame_tickness, y - frame_tickness, x + (frame_tickness + block_size_.x) * field_size.x, y + (frame_tickness + block_size_.y) * field_size.y, GetColor(50, 50, 150), true);
	DrawGraph(x - frame_tickness, y - frame_tickness, *res[RES::FIELD], true);
	for (int i = 0; i < field_size.y; ++i)
	{
		for (int j = 0; j < field_size.x; ++j)
		{
			switch (object.get_flag(j, i))
			{
			case FLAG::WALLCONNECT:
			{
				util::scoped_dx_blendmode d(DX_BLENDMODE_ADD, 100);
				DrawBox(
					x + j * (block_size_.x + frame_tickness), y + i * (block_size_.y + frame_tickness),
					x + (j + 1) * (block_size_.x + frame_tickness) - frame_tickness, y + (i + 1) * (block_size_.y + frame_tickness) - frame_tickness,
					GetColor(255, 255, 255), true
					);
			}
				draw_Block(x + j * (block_size_.x + frame_tickness), y + i * (block_size_.y + frame_tickness), object.get_block_const(j, i), true);
				/*DxLib::SetDrawBlendMode(DX_BLENDMODE_ALPHA, 128);
				DrawBox(
					x + j * (block_size_.x + frame_tickness), y + i * (block_size_.y + frame_tickness),
					x + (j + 1) * (block_size_.x + frame_tickness) - frame_tickness, y + (i + 1) * (block_size_.y + frame_tickness) - frame_tickness,
					GetColor(255, 0, 255), true
					);*/
				break;
			case FLAG::ERASING:
				draw_Block(x + j * (block_size_.x + frame_tickness), y + i * (block_size_.y + frame_tickness), object.get_block_const(j, i), true);
				if (object.get_block_const(j, i).get_block_type() != GameObject::WALL)
				{
					util::scoped_dx_blendmode d(DX_BLENDMODE_ALPHA, 255 - object.get_block_const(j, i).get_eraseframe() / 2);
					DrawBox(
					x + j * (block_size_.x + frame_tickness), y + i * (block_size_.y + frame_tickness),
					x + (j + 1) * (block_size_.x + frame_tickness) - frame_tickness, y + (i + 1) * (block_size_.y + frame_tickness) - frame_tickness,
					GetColor(255, 255, 0), true
					);
				}
				break;
			
			default:
				draw_Block(x + j * (block_size_.x + frame_tickness), y + i * (block_size_.y + frame_tickness), object.get_block_const(j, i), false);
			
				break;
			}
		}
	}
	//スコアの描画
	DrawFormatStringToHandle
		(x + ((block_size_.x + frame_tickness) * field_size.x) / 2,
		y + (block_size_.y + frame_tickness) * field_size.y + 5,
		GetColor(0, 0, 0), *res[FONT], "%d", object.get_score()
		);
}
示例#5
0
文件: field_meat.hpp 项目: iirob/wire
inline
void
field_aux::reset_objects(field<oT>& x)
  {
  arma_extra_debug_sigprint();
  
  x.delete_objects();
  x.create_objects();
  }
示例#6
0
文件: message.hpp 项目: sbunce/p2p
	//must be called for all fields in derived when derived object instantiated
	void _add_field(field & F, const bool check_unique)
	{
		std::pair<std::map<boost::uint64_t, field *>::iterator, bool >
			p = Field.insert(std::make_pair(F.ID(), &F));
		if(check_unique && !p.second){
			LOG << "non-unique field ID " << F.ID();
			exit(1);
		}
	}
示例#7
0
arma::field<arma::vec> lin_predF_svft(const field<vec>& Xbetas, const field<mat>& Z,
                                      const mat& b, const field<uvec>& RE_inds,
                                      const field<uvec>& id) {
    signed int n_field = Xbetas.size();
    field<vec> out(n_field);
    for (int i = 0; i < n_field; ++i) {
        mat bb = b.cols(RE_inds.at(i));
        vec Zb = sum(Z.at(i) % bb.rows(id.at(i)), 1);
        out.at(i) = Xbetas.at(i) + Zb;
    }
    return(out);
}
示例#8
0
void draw_game::draw_Flags(int x, int y, const field& object) const
{
	auto field_size = object.get_size();
	typedef enum GameObject::field::ERASE_CHK FLAG;
	x += offset.x;
	y += offset.y;
	for (int i = 0; i < field_size.y; ++i)
	{
		for (int j = 0; j < field_size.x; ++j)
		{
			int flag = object.get_flag(j, i);
			std::string str;
			int color = 0;
			int color2 = object.connectnum[i * field_size.x + j] != 0 ? GetColor(255, 0, 0) : GetColor(255, 255, 255);
			switch (flag)
			{
			case FLAG::ERASE:
				str = "Er";
				color = GetColor(255, 0, 0);
				break;
			case FLAG::ERASING:
				str = "Eg";
				color = GetColor(255, 0, 0);
				break;
			case FLAG::WALLCONNECT:
				str = "Wc";
				color = GetColor(0, 255, 255);
				break;
			case FLAG::WALL_COOL_DOWN:
				str = "Cd";
				color = GetColor(255, 0, 255);
				break;
			default:
				str = "No";
				break;
			}
			if (object.get_block_const(j, i).is_new())
			{
				str = "Nw";
			}
			DrawString(3 + x + j * (block_size + frame_tickness), y + i * (block_size + frame_tickness), str.c_str(), color);
			DrawFormatString(3 + x + j * (block_size + frame_tickness), 20 + y + i * (block_size + frame_tickness), GetColor(255, 0, 255), "%d", object.connectnum[i * field_size.x + j]);
			DrawFormatString(3 + x + j * (block_size + frame_tickness), 40 + y + i * (block_size + frame_tickness), GetColor(255, 0, 255), "%d", object.get_block_const(j, i).get_eraseframe());

			//(j * (block_size_.x + 5), i * (block_size_.y + 5), object.get_block(j, i));
		}
	}
}
示例#9
0
    gsl::vector force(gsl::vector &position, gsl::vector &momentum, double time, int charge)
    {
        //values
        double momentum_squared=momentum.sum_of_squares();
        double momentum_magnitude=sqrt(momentum_squared);
        double G=gamma(momentum_squared);
        double inverse_gamma=1.0/G;

        //electric field
        gsl::vector force=charge*E_field->get(position, time);

        //magnetic field
        gsl::vector B=charge*B_field->get(position, time);
        force[0]+=inverse_gamma*(momentum[1]*B[2]-momentum[2]*B[1]);
        force[1]+=inverse_gamma*(momentum[2]*B[0]-momentum[0]*B[2]);
        force[2]+=inverse_gamma*(momentum[0]*B[1]-momentum[1]*B[0]);

        //ionization friction
        double friction=-1;
        if(charge==-1)
        {
            if(remove_moller==0 or remove_moller==1) //if not removing moller losses, or constant min_energy
            {
                friction=electron_table.electron_lookup(momentum_squared);
            }
            else if(remove_moller==2) //variable min energy
            {
                friction=electron_table.electron_lookup_variable_RML(momentum_squared, min_energy);
            }
        }
        else
        {
            throw gen_exception("positrons not implemented");
            ////positrons not implemented
            //friction=ionization.positron_lookup(momentum_squared);
        }

        //friction*=0.2;

        if(friction>0) //don't want weird stuff
        {
            force[0]-=friction*momentum[0]/momentum_magnitude;
            force[1]-=friction*momentum[1]/momentum_magnitude;
            force[2]-=friction*momentum[2]/momentum_magnitude;
        }

        return force;
    }
void readBridgeHeaderVector(Bottle &rf, string name, field &groups, int size)
{
    groups.clear();
    if ( rf.check( name.c_str() ) )
    {
        Bottle &grp = rf.findGroup(name.c_str());
        for ( int i = 0; i < size; i++)
        {
            groups.push_back({grp.get(1+i).asString().c_str(),""});
        }
    }
    else
    {
        cout << "Could not find parameters for " << name << ". "
            << "Setting everything to null by default" << endl;
    }
}
示例#11
0
 //! Read value of a class field
 void iarchive_xml::readField (const field& f, const std::string& fieldName, any& object)
 {
const descriptor& fd = f.desc();
token t;
any a;

    // READ ATTRIBUTES
    this->readAttributes(object);

    // End of section
    t = std::move(this->read_token(XML::TOKEN_SLASH_SUPERIOR, XML::TOKEN_SUPERIOR));

    if (t._token_id == XML::TOKEN_SLASH_SUPERIOR)
        return;

    // read type format
    if (this->read_custom_field_format(f, object))
    {
        this->readEndOfField(f, fieldName);
        return; 
    }



    if (fd.has(descriptor::Flags::FIELDS))
    {
        assert(false);
    }
    else
    {
        std::string content = this->_tokenizer.readUntil("<", false);
        this->readEndOfField(f, fieldName);
        f.set(object, content);
        return;

    }
    // normal execution
 }
inline
void
arma_ostream::print(std::ostream& o, const field<oT>& x)
  {
  arma_extra_debug_sigprint();
  
  const arma_ostream_state stream_state(o);
  
  const std::streamsize cell_width = o.width();
  
  const uword x_n_rows = x.n_rows;
  const uword x_n_cols = x.n_cols;
  
  if(x.is_empty() == false)
    {
    for(uword col=0; col<x_n_cols; ++col)
      {
      o << "[field column " << col << ']' << '\n'; 
      
      for(uword row=0; row<x_n_rows; ++row)
        {
        o.width(cell_width);
        o << x.at(row,col) << '\n';
        }
      
      o << '\n';
      }
    }
  else
    {
    o << "[field size: " << x_n_rows << 'x' << x_n_cols <<  "]\n";
    }
  
  o.flush();
  stream_state.restore(o);
  }
inline
void
subview_field<oT>::operator= (const field<oT>& x)
  {
  arma_extra_debug_sigprint();
  
  subview_field<oT>& t = *this;
  
  arma_debug_check( (t.n_rows != x.n_rows) || (t.n_cols != x.n_cols), "incompatible field dimensions");
  
  for(u32 col=0; col<t.n_cols; ++col)
    {
    for(u32 row=0; row<t.n_rows; ++row)
      {
      t.at(row,col) = x.at(row,col);
      }
    }
  }
示例#14
0
文件: field_meat.hpp 项目: iirob/wire
inline
void
field<oT>::init(const field<oT>& x)
  {
  arma_extra_debug_sigprint();
  
  if(this != &x)
    {
    init(x.n_rows, x.n_cols);
    
    field& t = *this;
    
    for(uword col=0; col<x.n_cols; ++col)
    for(uword row=0; row<x.n_rows; ++row)
      {
      t.at(row,col) = x.at(row,col);
      }
    }
  
  }
inline
void
field<oT>::init(const field<oT>& x)
  {
  arma_extra_debug_sigprint();
  
  if(this != &x)
    {
    const uword x_n_rows = x.n_rows;
    const uword x_n_cols = x.n_cols;
    
    init(x_n_rows, x_n_cols);
    
    field& t = *this;
    
    for(uword ucol=0; ucol < x_n_cols; ++ucol)
    for(uword urow=0; urow < x_n_rows; ++urow)
      {
      t.at(urow,ucol) = x.at(urow,ucol);
      }
    }
  
  }
示例#16
0
bool snake::tick(field &field_){
    lastMove_ = direction_;
    std::pair<int, int> p = blocks_.front();
    switch (direction_) {
    case LEFT:
    p.first--;
        break;
    case UP:
    p.second--;
        break;
    case RIGHT:
    p.first++;
        break;
    case DOWN:
    p.second++;
        break;
    }
    if(p.first<0 || p.first >= field::WIDTH ||
       p.second<0 || p.second >= field::HEIGHT)
        return false;
    if (field_.block(p.first, p.second) == 
      field::SNAKE_BLOCK)
        return false;
    blocks_.push_front(p);
  if (field_.block(p.first, p.second) != 
      field::FRUIT)
  {
    field_.setBlock(field::SNAKE_BLOCK, p.first, p.second);
    std::pair<int, int> p = blocks_.back();
    field_.setBlock(field::EMPTY, p.first, p.second);
    blocks_.pop_back();
  }
  else
  {
    field_.setBlock(field::SNAKE_BLOCK, p.first, p.second);
    field_.newFruit();
  }
  if (blocks_.size() >= field::WIDTH * field::HEIGHT - 1)
    return false;
  return true; 
}
示例#17
0
文件: field.hpp 项目: sushi1986/MAS
inline bool operator==(const field<Columns, Rows>& lhs,
                       const field<Columns, Rows>& rhs) {
    return equal(lhs.begin(), lhs.end(), rhs.begin());
}
示例#18
0
arma::mat lin_pred_matF_svft(const field<vec>& Xbetas, const field<mat>& Z,
                             const mat& b, const field<mat>& U,
                             const field<uvec>& RE_inds, const field<uvec>& id,
                             const field<uvec>& col_inds, const uvec& row_inds,
                             const int& nrows, const int& ncols,
                             const CharacterVector& trans_Funs) {
    int n_field = Xbetas.size();
    mat out = mat(nrows, ncols, fill::zeros);
    for (int i = 0; i < n_field; ++i) {
        mat bb = b.cols(RE_inds.at(i));
        vec Zb = sum(Z.at(i) % bb.rows(id.at(i)), 1);
        if (trans_Funs[i] == "identity") {
            out.submat(row_inds, col_inds.at(i)) = U.at(i).each_col() % (Xbetas.at(i) + Zb);
        } else if (trans_Funs[i] == "expit") {
            vec exp_eta = exp(Xbetas.at(i) + Zb);
            out.submat(row_inds, col_inds.at(i)) = U.at(i).each_col() % (exp_eta / (1 + exp_eta));
        } else if (trans_Funs[i] == "exp") {
            out.submat(row_inds, col_inds.at(i)) = U.at(i).each_col() % exp(Xbetas.at(i) + Zb);
        } else if (trans_Funs[i] == "log") {
            out.submat(row_inds, col_inds.at(i)) = U.at(i).each_col() % log(Xbetas.at(i) + Zb);
        } else if (trans_Funs[i] == "log2") {
            out.submat(row_inds, col_inds.at(i)) = U.at(i).each_col() % log2(Xbetas.at(i) + Zb);
        } else if (trans_Funs[i] == "log10") {
            out.submat(row_inds, col_inds.at(i)) = U.at(i).each_col() % log10(Xbetas.at(i) + Zb);
        } else if (trans_Funs[i] == "sqrt") {
            out.submat(row_inds, col_inds.at(i)) = U.at(i).each_col() % sqrt(Xbetas.at(i) + Zb);
        }
    }
    return(out);
}
示例#19
0
bool operator<(const field &lhs, const field &rhs)
{
    return lhs.id() < rhs.id();
}