Exemple #1
0
      void operation_axiom(Parser& parser, 
			   const sentence_type& input,
			   const feature_set_type& feats,
			   const Theta& theta)
      {
	state_type state_new = parser.state_allocator_.allocate();

	state_new.step()  = 0;
	state_new.next()  = 0;
	state_new.unary() = 0;
      
	state_new.operation() = operation_type::AXIOM;
	state_new.label()     = symbol_type::AXIOM;
	state_new.head()      = symbol_type::EPSILON;
	state_new.span()      = span_type(-1, 0);
      
	state_new.stack()      = state_type();
	state_new.derivation() = state_type();
	state_new.reduced()    = state_type();
	
	state_new.feature_vector() = parser.feature_vector_allocator_.allocate();
	state_new.feature_state()  = feats.apply(state_new.operation(),
						 *state_new.feature_vector());
	
	state_new.score() = trance::dot_product(theta.Wfe_, *state_new.feature_vector());
	state_new.layer(theta.hidden_) = theta.Ba_.array().unaryExpr(model_type::activation());
      
	parser.agenda_[state_new.step()].push_back(state_new);
      }
Exemple #2
0
EXPORT	void	fprint_raw_gas_data(
	FILE		*file,
	Locstate	state,
	int		dim)
{
	(void) fprintf(file,"state 0x%p\n",(POINTER)state);
	if (state == NULL)
	{
	    (void) printf("NULL state\n");
	    return;
	}
	(void) fprintf(file,"\tState Data ");
	(void) fprintf(file,"\n");
	switch (state_type(state))
	{
	case GAS_STATE:
	    g_fprint_raw_state(file,state,dim);
	    break;

	case EGAS_STATE:
	    g_fprint_raw_Estate(file,state,dim);
	    break;

	case TGAS_STATE:
	    g_fprint_raw_Tstate(file,state,dim);
	    break;

	case FGAS_STATE:
	    g_fprint_raw_Fstate(file,state,dim);
	    break;

	case OBSTACLE_STATE:
	    (void) fprintf(file,"Obstacle state type,  "
				"printing as GAS_STATE\n");
	    g_fprint_raw_state(file,state,dim);
	    break;

	case VGAS_STATE:
	    g_fprint_raw_Tstate(file,state,dim);
	    (void) printf("Specific internal energy = %"FFMT"\n",Int_en(state));
	    (void) printf("Entropy = %"FFMT"\n",Entropy(state));
	    (void) printf("Sound_speed = %"FFMT"\n",sound_speed(state));
#if defined(VERBOSE_GAS_PLUS)
	    (void) printf("Enthalpy = %"FFMT"\n",Enthalpy(state));
	    (void) printf("Temperature = %"FFMT"\n",Temp(state));
#endif /* defined(VERBOSE_GAS_PLUS) */
	    break;

	case UNKNOWN_STATE:
	    (void) fprintf(file,"Unknown state type,  printing as GAS_STATE\n");
	    g_fprint_raw_state(file,state,dim);
	    break;

	default:
	    screen("ERROR in fprint_raw_gas_data(), "
	           "unknown state type %d\n",state_type(state));
	    clean_up(ERROR);
	}
}		/*end fprint_raw_gas_data*/
Exemple #3
0
    void on_subscribe(Subscriber o) const {

        struct state_type
            : public std::enable_shared_from_this<state_type>
            , public values
        {
            state_type(values i_, Subscriber o_)
                : values(i_)
                , out(std::move(o_))
            {
            }
            Subscriber out;
            rxu::detail::maybe<resource_type> resource;
        };

        auto state = std::make_shared<state_type>(state_type(initial, std::move(o)));

        state->resource = on_exception(
            [&](){return state->resource_factory(); },
            state->out);
        if (state->resource.empty()) {
            return;
        }
        state->out.add(state->resource->get_subscription());
        
        auto selectedCollection = on_exception(
            [state](){return state->observable_factory(state->resource.get()); },
            state->out);
        if (selectedCollection.empty()) {
            return;
        }

        selectedCollection->subscribe(state->out);
    }
Exemple #4
0
LOCAL void g_fprint_raw_state(
	FILE		*file,
	Locstate	state,
	int		dim)
{
	int		i;
	static	char	mname[3][3] = { "mx", "my", "mz"};

	(void) fprintf(file,"state %p\n",state);
	//(void) fprintf(file,"\t%-7s = %"FFMT" %-7s = %"FFMT"\n\t","density",
	//	            Dens(state),"energy",Energy(state));
	(void) fprintf(file,"\t%-7s = %22.16g %-7s = %22.16g\n\t","density",
		            Dens(state),"energy",Energy(state));
	for (i = 0; i < dim; i++)
	    (void) fprintf(file,"%-7s = %"FFMT" ",mname[i],Mom(state)[i]);
	(void) fprintf(file,"\n");
	(void) fprintf(file,"\ttype = %u, failed = %u\n",
	                    state_type(state),material_failure(state));
	if (debugging("prt_params"))
	    fprint_Gas_param(file,Params(state));
	else
	    (void) fprintf(file,"Gas_param = %llu\n",
		                gas_param_number(Params(state)));
	if (debugging("local_gamma"))
	{
	    (void) fprintf(file,"Local gamma set: %s\n",
			   Local_gamma_set(state) ? "YES" : "NO");
	    if (Local_gamma_set(state))
		(void) fprintf(file,"Local gamma = %"FFMT"\n",
			       Local_gamma(state));
	}
}		/*end g_fprint_raw_state*/
Exemple #5
0
      void operation_shift(Parser& parser,
			   const feature_set_type& feats,
			   const Theta& theta,
			   const state_type& state,
			   const word_type& head,
			   const symbol_type& label)
      {
	state_type state_new = parser.state_allocator_.allocate();
	
	state_new.step()  = state.step() + 1;
	state_new.next()  = state.next() + 1;
	state_new.unary() = state.unary();
      
	state_new.operation() = operation_type::SHIFT;
	state_new.label()     = label;
	state_new.head()      = head;
	state_new.span()      = span_type(state.next(), state.next() + 1);
      
	state_new.stack()      = state;
	state_new.derivation() = state;
	state_new.reduced()    = state_type();
	
	state_new.feature_vector() = parser.feature_vector_allocator_.allocate();
	state_new.feature_state()  = feats.apply(state_new.operation(),
						 state_new.label(),
						 state_new.head(),
						 *state_new.feature_vector());
	
	const size_type index_operation       = theta.index_operation(state_new.operation());
	const size_type offset_operation      = index_operation * theta.hidden_;
	const size_type offset_classification = theta.offset_classification(label);
	const size_type offset_category       = theta.offset_category(label);

	if (theta.cache_.rows() && theta.cache_.cols())
	  state_new.layer(theta.hidden_) = (theta.Bsh_.block(offset_category, 0, theta.hidden_, 1)
					    + theta.cache_.block(offset_category, theta.terminal(head), theta.hidden_, 1)
					    ).array().unaryExpr(model_type::activation());
	else
	  state_new.layer(theta.hidden_) = (theta.Bsh_.block(offset_category, 0, theta.hidden_, 1)
					    + (theta.Wsh_.block(offset_category, 0, theta.hidden_, theta.embedding_)
					       * theta.terminal_.col(theta.terminal(head)))
					    ).array().unaryExpr(model_type::activation());
	
	const double score = (theta.Wc_.block(offset_classification, offset_operation, 1, theta.hidden_) * state_new.layer(theta.hidden_)
			      + theta.Bc_.block(offset_classification, index_operation, 1, 1))(0, 0);
	
	state_new.score() = trance::dot_product(theta.Wfe_, *state_new.feature_vector()) + state.score() + score;
      
	parser.agenda_[state_new.step()].push_back(state_new);
      }
Exemple #6
0
      void operation_unary(Parser& parser,
			   const feature_set_type& feats,
			   const Theta& theta,
			   const state_type& state,
			   const symbol_type& label)
      {
	state_type state_new = parser.state_allocator_.allocate();

	state_new.step()  = state.step() + 1;
	state_new.next()  = state.next();
	state_new.unary() = state.unary() + 1;
      
	state_new.operation() = operation_type(operation_type::UNARY, state.operation().closure() + 1);
	state_new.label()     = label;
	state_new.head()      = symbol_type::EPSILON;
	state_new.span()      = state.span();
      
	state_new.stack()      = state.stack();
	state_new.derivation() = state;
	state_new.reduced()    = state_type();
      
	state_new.feature_vector() = parser.feature_vector_allocator_.allocate();
	state_new.feature_state()  = feats.apply(state_new.operation(),
						 state_new.label(),
						 state.feature_state(),
						 *state_new.feature_vector());

	const size_type index_operation       = theta.index_operation(state_new.operation());
	const size_type offset_operation      = index_operation * theta.hidden_;
	const size_type offset_classification = theta.offset_classification(label);
	const size_type offset_category       = theta.offset_category(label);
      
	state_new.layer(theta.hidden_) = (theta.Bu_.block(offset_category, 0, theta.hidden_, 1)
					  + (theta.Wu_.block(offset_category, 0, theta.hidden_, theta.hidden_)
					     * state.layer(theta.hidden_))
					  ).array().unaryExpr(model_type::activation());
      
	const double score = (theta.Wc_.block(offset_classification, offset_operation, 1, theta.hidden_) * state_new.layer(theta.hidden_)
			      + theta.Bc_.block(offset_classification, index_operation, 1, 1))(0, 0);
      
	state_new.score() = trance::dot_product(theta.Wfe_, *state_new.feature_vector()) + state.score() + score;
      
	parser.agenda_[state_new.step()].push_back(state_new);
      }
Exemple #7
0
EXPORT	void fprint_gas_data(
	FILE		*file,
	Locstate	state)
{
	(void) fprintf(file,"State information for the ");
	if (state == NULL)
	{
	    (void) fprintf(file,"NULL state 0x%p\n\n",(POINTER)state);
	    return;
	}
	if (is_obstacle_state(state)) 
	{
	    (void) fprintf(file,"OBSTACLE state 0x%p\n\n",(POINTER)state);
	    return;
	}
	(void) fprintf(file,"state 0x%p\n",(POINTER)state);
	(void) fprintf(file,"\tState Data ");
	if (is_binary_output() == YES)
	{
	    uint64_t prms;
	    float    *x;
	    int      stype = state_type(state);
	    int      failed = material_failure(state);

	    (void) fprintf(file,"\f%c",(char)Params(state)->sizest);
	    x = &Dens(state);
	    (void) fwrite((const void *)x,FLOAT,2+SMAXD,file);
	    prms = gas_param_number(Params(state));
	    (void) fwrite((const void *)&prms,sizeof(uint64_t),1,file);
	    (void) fwrite((const void *)&stype,sizeof(int),1,file);
	    (void) fwrite((const void *)&failed,sizeof(int),1,file);
#if defined(COMBUSTION_CODE)
	    switch (Composition_type(state))
	    {
	    case ZND:
	    case PTFLAME:
	        (void) fwrite((const void *)pdens(state),FLOAT,1,file);
		break;
	    case TWO_CONSTITUENT_REACTIVE:
	        (void) fwrite((const void *)pdens(state),FLOAT,2,file);
		break;
	    case PURE_NON_REACTIVE:
	    default:
	        break;
	    }
#endif /* defined(COMBUSTION_CODE) */
            if(g_composition_type() == MULTI_COMP_NON_REACTIVE)
            {
                if(Params(state) != NULL &&
                   Params(state)->n_comps != 1)
                {
                    int i;
                    for(i = 0; i < Params(state)->n_comps; i++)
                        (void) fwrite((const void *)&(pdens(state)[i]),FLOAT,1,file);
                }
            }
	    (void) fprintf(file,"\n");
	    return;
	}
	(void) fprintf(file,"\n");
	switch (state_type(state))
	{
	case GAS_STATE:
	    g_fprint_state(file,state);
	    break;

	case EGAS_STATE:
	    g_fprint_Estate(file,state);
	    break;

	case TGAS_STATE:
	    g_fprint_Tstate(file,state);
	    break;

	case FGAS_STATE:
	    g_fprint_Fstate(file,state);
	    break;

	case VGAS_STATE:
	    verbose_fprint_state(file,"",state);
	    break;

	default:
	    screen("ERROR in fprint_gas_data(), "
	           "unknown state type %d\n",state_type(state));
	    clean_up(ERROR);
	}
}		/*end fprint_gas_data*/
Exemple #8
0
EXPORT void g_verbose_fprint_state(
	FILE	   *file,
	const char *name,
	Locstate   state)
{
	bool		bin_out;
	int		i, dim;
	float		p, c, S, v[SMAXD], speed;
	static	char	vname[3][3] = { "vx", "vy", "vz"};
	static	char	mname[3][3] = { "mx", "my", "mz"};

	if (name == NULL)
	    name = "";
	(void) fprintf(file,"\n%s:\n",name);
	(void) fprintf(file,"address %p\n",state);
	if (state == NULL || is_obstacle_state(state))
	{
	    (void) fprintf(file,"(OBSTACLE STATE)\n\n");
	    return;
	}
	dim = Params(state)->dim;

	p = pressure(state);
	c = sound_speed(state);
	S = entropy(state);

	(void) fprintf(file,"%-24s = %-"FFMT" %-24s = %-"FFMT"\n",
		       "density",Dens(state),
		       "specific internal energy",
		       specific_internal_energy(state));
	(void) fprintf(file,"%-24s = %-"FFMT" %-24s = %-"FFMT"\n","pressure",p,
		       "sound speed",c);
	(void) fprintf(file,"%-24s = %-"FFMT" %-24s = %-"FFMT"\n","temperature",
		       temperature(state),"specific entropy",S);

	speed = 0.0;
	for (i = 0; i < dim; i++)
	{
	    v[i] = vel(i,state);	speed += sqr(v[i]);
	    (void) fprintf(file,"%-24s = %-"FFMT" %-24s = %-"FFMT"\n",
			   mname[i],mom(i,state),vname[i],v[i]);
	}
	speed = sqrt(speed);

	(void) fprintf(file,"%-24s = %-"FFMT"","total energy",energy(state));
	if (c > 0. && Dens(state) > 0.)
	   (void) fprintf(file," %-24s = %-"FFMT"\n","Mach number",speed / c);
	else
	   (void) fprintf(file,"\n");

#if defined(TWOD)
	if (dim == 2)
	    (void) fprintf(file,"%-24s = %-"FFMT"\n","velocity angle",
			   degrees(angle(v[0],v[1])));
#endif /* defined(TWOD) */


	fprint_state_type(file,"State type = ",state_type(state));
	(void) fprintf(file,"Params state = %llu\n",
		       gas_param_number(Params(state)));

	bin_out = is_binary_output();
	set_binary_output(NO);
	if (debugging("prt_params"))
	    fprint_Gas_param(file,Params(state));
	else
	    (void) fprintf(file,"Gas_param = %llu\n",
		                gas_param_number(Params(state)));
	set_binary_output(bin_out);

	//if(p< -2000 || p>10000)
	//{
	//    printf("#huge pressure\n");
	//    clean_up(0);
	//}
#if !defined(COMBUSTION_CODE)
	(void) fprintf(file,"\n");
#else /* !defined(COMBUSTION_CODE) */
	if (Composition_type(state) == PURE_NON_REACTIVE)
	{
	    (void) fprintf(file,"\n");
	    return;
	}

	(void) fprintf(file,"%-24s = %-12s   %-24s = %-"FFMT"\n","burned",
		       Burned(state) ? "BURNED" : "UNBURNED",
		       "q",Params(state)->q);
	(void) fprintf(file,"%-24s = %-"FFMT"\n","t_crit",
		       Params(state)->critical_temperature);

	if (Composition_type(state) == PTFLAME)
	{
	    (void) fprintf(file,"\n");
	    return;
	}

	(void) fprintf(file,"%-24s = %-"FFMT"\n","product density",Prod(state));
	(void) fprintf(file,"%-24s = %-"FFMT"\n",
		       "reaction progress",React(state));

	if (Composition_type(state) == ZND)
	{
	    (void) fprintf(file,"\n");
	    return;
	}

	(void) fprintf(file,"%-24s = %-"FFMT"\n","rho1",Dens1(state));
#endif /* !defined(COMBUSTION_CODE) */
	(void) fprintf(file,"%-24s = %-24s %-24s = %-"FFMT"\n\n","gamma_set",
		      Local_gamma_set(state)?"YES" : "NO","local_gamma",
		      Local_gamma(state));
        if(g_composition_type() == MULTI_COMP_NON_REACTIVE)
        {
            if(Params(state) != NULL &&
               Params(state)->n_comps != 1)
            {
                for(i = 0; i < Params(state)->n_comps; i++)
                    (void) fprintf(file,"partial density[%2d] = %"FFMT"\n",
                       i,pdens(state)[i]);
                (void) fprintf(file,"\n");
                 /* TMP the following print is for the debuging display purpose */
                for(i = 0; i < Params(state)->n_comps; i++)
                    (void) fprintf(file,"[%d]Mass fraction = %-"FFMT"\n",
                             i, pdens(state)[i]/Dens(state));
                (void) fprintf(file,"\n");
            }
        }
}		/*end g_verbose_fprint_state*/