Example #1
0
/**
 * @brief Return molt increment matrix based on empirical data
 * @details Fit's a cubic spline to the empirical data.
 * Note that the spline function strictly requires increasing
 * values for each of the knots.
 * 
 * @param data [description]
 * @return dmatrix of molt increments by sex for each size bin
 */
dmatrix get_empirical_molt_increment(const dvector& bin, const dmatrix& data)
{
	cout<<"In get_empirical_molt_increment"<<endl;
	int n = bin.size();
	ivector sex = ivector(column(data,2));
	int nsex = count_factor(sex);

	dmatrix mi(1,nsex,1,n);
	ivector nh(1,nsex); nh.initialize();
	
	// Count number of observations in each sex.
	for (int i = 1; i <= data.rowmax(); ++i)
	{
		int h = sex(i);
		nh(h) ++;
	}
	
	// get male and famale arrays
	dmatrix x(1,nsex,1,nh);
	dmatrix y(1,nsex,1,nh);
	int bb=1; 
	int gg=1;
	for (int i = 1; i <= data.rowmax(); ++i)
	{
		int h = sex(i);
		int j = h==1 ? bb++ : gg++ ;
		
		x(h,j) = data(i,1);
		y(h,j) = data(i,3);	
	}



	// rescale size to 0-1 over bin width
	for (int h = 1; h <= nsex; ++h)
	{
		dvector knts = (x(h) - min(x(h))) / (max(x(h)) - min(x(h)));
		dvector pnts = (bin  - min(bin)) / (max(bin) - min(bin));
		COUT(knts);
		COUT(y(h));
		cubic_spline_function cSmooth(knts,y(h));
		dvector test = cSmooth(pnts);
		COUT(cSmooth(0.5));
		COUT(test);
	}
	
	cout<<"leaving get_empirical_molt_increment"<<endl;
	return mi;

}
Example #2
0
void SVMLightRunner::processRequest(
    SVMConfiguration &config
) {
    int argc = 0;
    char** argv = 0;

    arma::mat unique_labels = arma::unique(config.target);

    if(unique_labels.size() !=2 && !config.use_transductive_learning){
    	COUT("Passed 3 labels to svmlight without use_transductive_learning");
    	EXIT(1);
    }
    if((unique_labels.size() <2 || unique_labels.size() > 3)  && config.use_transductive_learning){
    	COUT("Passed incorred # of labels to svmlight (<2 || >3) for transductive learning");
    	EXIT(1);
    }
    if(unique_labels.size() == 2){
    	if(unique_labels[0] != -1 && unique_labels[1] != 1){
    		COUT("Please pass negative class as -1 and positive as 1");
    		EXIT(1);
    	}
    }
    if(unique_labels.size() == 3){
    	if(unique_labels[0] != 0 && unique_labels[1] != -1
    			&& unique_labels[2] != 1
    	){
    		COUT("Please pass negative class as -1 and positive as 1");
    		EXIT(1);
    	}
    }

    config.neg_target = -1;
    config.pos_target = 1;

    if (!config.svm_options.empty()) {
        argc = check_argc(std::string("gmum ") + config.svm_options);
        argv = to_argv(std::string("gmum ") + config.svm_options);
    }

    if (!config.isPrediction()) {
        // Learning
        librarySVMLearnMain(argc, argv, true, config);

    } else {
        // Predict
        librarySVMClassifyMain(argc, argv, true, config);
        // Convert sign to label
        resultsToLabels(config);
    }
}
Example #3
0
int main(int argc, char * argv[] )
{

  Thread readerThreadIP;
  readerThreadIP.start(testReaderIP,NULL);
  Thread readerThreadUnix;
  readerThreadUnix.start(testReaderUnix,NULL);

  UDPSocket socket1(5061, "127.0.0.1",5934);
  UDDSocket socket1U("testSource","testDestination");
  
  COUT("socket1: " << socket1.port());

  // give the readers time to open
  sleep(1);

  for (int i=0; i<gNumToSend; i++) {
    socket1.write("Hello IP land");	
	socket1U.write("Hello Unix domain");
	sleep(1);
  }

  readerThreadIP.join();
  readerThreadUnix.join();
}
Example #4
0
static void qSOUT0(char *str) {
  char c='\0'; 
  char *s=str;
  /* if(*s!='\'') { */
    while((c = *s++)) {
      if(c<'a'||c>'z') break;
    }
  /*}*/
  if(c=='\0' && s!=str+1) {
	  SOUT0(str);
  }
  else {
	  COUT('\'');
	  qSOUT1(str);
	  COUT('\'');
  }
}
Example #5
0
static void print_graph(graph *g)
{
    uint8_t ei;
    node_id_t v;
    COUT("digraph RF { ");
    COUTP("%d; ", this_node_id);
    for (v = 0; v < MAX_NODES; ++v) {
        for (ei = 0; ei < g->degree[v]; ++ei)
            COUTP("%d -> %d; ", v, g->edges[v][ei].v);
    }
    COUTA("}\r\n");
}
Example #6
0
int main()
{
    int n;
    CIN(n);
    int count = 1;
    char temp[3],num[3];
    scanf("%s",temp);
    for(int i = 1; i<n ; i++){
        scanf("%s",num);
        if(strcmp(temp,num) != 0)
            count++;
        strcpy(temp,num);
    }
    COUT(count);
    return 0;
}
Example #7
0
void *testReaderUnix(void *)
{
	UDDSocket readSocket("testDestination");
	readSocket.nonblocking();
	int rc = 0;
	while (rc<gNumToSend) {
		char buf[MAX_UDP_LENGTH];
		int count = readSocket.read(buf);
		if (count>0) {
			COUT("read: " << buf);
			rc++;
		} else {
			sleep(2);
		}
	}
	return NULL;
}
Example #8
0
void *testReaderIP(void *)
{
	UDPSocket readSocket(5934, "localhost", 5061);
	readSocket.nonblocking();
	int rc = 0;
	while (rc<gNumToSend) {
		char buf[MAX_UDP_LENGTH];
		int count = readSocket.read(buf);
		if (count>0) {
			COUT("read: " << buf);
			rc++;
		} else {
			sleep(2);
		}
	}
	return NULL;
}
Example #9
0
static void print_loc_graph(ir_graph_t *graph, location_t *locs)
{
    node_id_t out_node, in_node;
    ir_edge_t *edge;
    bool node_valid;
    location_t *loc;

    COUT("digraph LOC { ");

    COUTA("dim_x="); COUTP("%u; ", map_dim.x);
    COUTA("dim_y="); COUTP("%u; ", map_dim.y);

    /* Lame way to get list of nodes */
    for (in_node = 0; in_node < MAX_NODES; ++in_node) {
        node_valid = false;
        for (out_node = 0; out_node < MAX_NODES; ++out_node) {
            edge = &ir_graph[out_node][in_node];
            if (edge->valid) {
                node_valid = true;
                break;
            }
        }
        if (node_valid) {
            loc = &locs[in_node];
            COUTP("%u ", in_node);
            COUTA(" [");
            COUTP("x=%d,", loc->pt.x);
            COUTP("y=%d", loc->pt.y);
            COUTA("]; ");
        }
    }

    for (in_node = 0; in_node < MAX_NODES; ++in_node) {
        for (out_node = 0; out_node < MAX_NODES; ++out_node) {
            edge = &ir_graph[out_node][in_node];
            if (edge->valid) {
                COUTP("%d -> %d", out_node, in_node);
                COUTA(" [");
                COUTP("d=%u,", edge->dist);
                COUTP("a=%u", edge->angle);
                COUTA("]; ");
            }
        }
    }
    COUTA("}\r\n");
}
Example #10
0
void SVMConfiguration::setClassWeights(arma::vec class_weights){
	this->class_weights = class_weights;
    this->use_class_weights = true;
	class_weight_length = class_weights.size();

    if(libsvm_class_weights){
    	delete[] libsvm_class_weights;
    }
    if(libsvm_class_weights_labels){
    	delete[] libsvm_class_weights_labels;
    }
    libsvm_class_weights = new double[class_weight_length];
    libsvm_class_weights_labels = new int[class_weight_length];

    if(this->class_weight_length != 2){
        COUT("SVMLight doesn't support multiclass classification. Please pass two class weights. \n");
        EXIT(1);
    }

    libsvm_class_weights[0] = class_weights(0);
    libsvm_class_weights_labels[0] = -1;
    libsvm_class_weights[1] = class_weights(1);
    libsvm_class_weights_labels[1] = 1;
}
Example #11
0
static void out(register cell xval, stack wam)
{ register term xref;
  static char ibuf[MAX1];
  
  FDEREF(xval);
  if(g.stop-g.sbuf>(bp_long)max.SBUF-MAX1)
    { warnmes("string buffer (-i option) exceeded or infinite term"); return; }
  if(VAR(xval))
    { 
/* obsolete
      ASSERT2((void*)g.shared[BBoardStk].base<(void*)htable &&
              (void*)htable<(void*)wam[HeapStk].base, xval);
*/
      VOUT(HeapStk,COUT('x'))
        BOUT(COUT('b'))
           TVOUT(htable,max.DICT*3*sizeof(cell),COUT('h')) 
            MVOUT(COUT('m'));
    }
  else
    {
      if(INTEGER(xval))
        {IOUT(OUTPUT_INT(xval));}
      else
  { 
    if(!GETARITY(xval))
      {SOUT(NAME(xval));}
    /* operators can be handled here easily
    else if(g.DIF==xval)
      {
        out(xref+1,wam),
        SOUT(NAME(s));
        out(xref+2,wam);
      }
    */
    else if IS_LIST(xval)
      {
        COUT('[');
        out((cell)(++xref),wam); 
        ++xref;
        FDEREF(T2C(xref));
        while(IS_LIST(xval))
         {
           COUT(',');
           out((cell)(++xref),wam);
           ++xref;
           FDEREF(T2C(xref));
         }
        if(g.NIL!=xval)
          {
            COUT('|');
            out((cell)xref,wam);
          }
        COUT(']');
      }
        else if (BP_FLOAT(xval)) 
        {
           FLOAT_OUT(ints_to_double(
                (half)(xref[1]),
                (half)(xref[2]),
                (half)(xref[3])));
        }
    else
      { register no i;
        SOUT(NAME(xval));
        COUT('(');
        for (i=1; i<GETARITY(xval); i++)
          {
            out(xref[i],wam);
            COUT(',');
          }
        out((cell)(xref+i),wam);
        COUT(')');
      }
  }
    }
void ReadTableDef::displayTreeMX(const desc_struct * top,
                                  const char * caller) const
{
  if (top == NULL) return;

  char title[50];
  snprintf(title, sizeof(title),
          ", type %d, address %p, parent %s\n",
          top->NODETYPE_MX, (void *)top, caller);
  #undef  TITLE
  #define TITLE(XXX)    cout << "### " << XXX << title;         \
                        strcpy(title, XXX)

  cout.setf(ios::right);

  switch (top->NODETYPE_MX)
    {
    case TYPEMX(CHECK_CONSTRNTS):
      {
        TITLE("CHECK_CONSTRNTS");
        CASTMX(check_constrnts);
        COUT(check_constrnts, seqnumber);
        COUT_STRING(check_constrnts, constrnt_text);
      }
      break;

    case TYPEMX(COLUMNS):
      {
        TITLE("COLUMNS");
        CASTMX(columns);
        COUT(columns, tablename);
        COUT(columns, colname);
        COUT(columns, colnumber);
        COUT(columns, datatype);
        COUT(columns, length);
        COUT(columns, scale);
        COUT(columns, precision);
        COUT_ENUM(columns, datetimestart);
        COUT_ENUM(columns, datetimeend);
        COUT(columns, datetimefractprec);
        COUT(columns, intervalleadingprec);
        COUT(columns, offset);
        COUT(columns, null_flag);
        COUT(columns, upshift);
        COUT(columns, colclass);
        COUT(columns, uec);
        COUT_STRING(columns, highval);
        COUT_STRING(columns, lowval);

        Int32 defaultValueInLocaleLen = 
#pragma nowarn(1506)   // warning elimination 
              NAWstrlen((NAWchar*)(columns->defaultvalue));
#pragma warn(1506)  // warning elimination 
        char* defaultValueInLocale = new HEAP char[defaultValueInLocaleLen+1];

        CharInfo::CharSet mapCharSet = SqlParser_ISO_MAPPING;

        Int32 x = UnicodeStringToLocale(mapCharSet,
                 (NAWchar*)(columns->defaultvalue), defaultValueInLocaleLen,
                 defaultValueInLocale, defaultValueInLocaleLen+1
                             );
        if (columns->defaultvalue)  {
          cout << "  " << setw(20) << "defaultvalue"
               << "  " << defaultValueInLocale << endl;
        } else {
          cout << "  " << setw(20) << "defaultvalue" << " is null" << endl;
        }
        NADELETEBASIC(defaultValueInLocale, HEAP);
      }
      break;

    case TYPEMX(CONSTRNTS):
      {
        TITLE("CONSTRNTS");
        CASTMX(constrnts);
        COUT(constrnts, constrntname);
        COUT(constrnts, tablename);
        COUT_ENUM(constrnts, type);
        COUT(constrnts, colcount);
        COUT_STRING(constrnts, indexname);
        displayTreeMX(constrnts->check_constrnts_desc, title);
        displayTreeMX(constrnts->constr_key_cols_desc, title);
        displayTreeMX(constrnts->referenced_constrnts_desc, title);
        displayTreeMX(constrnts->referencing_constrnts_desc, title);
      }
      break;

    case TYPEMX(CONSTRNT_KEY_COLS):
      {
        TITLE("CONSTRNT_KEY_COLS");
        CASTMX(constrnt_key_cols);
        COUT(constrnt_key_cols, colname);
        COUT(constrnt_key_cols, position);
      }
      break;

    case TYPEMX(FILES):
      {
        TITLE("FILES");
        CASTMX(files);
        COUT_ENUM(files, fileorganization);
        COUT(files, audit);
        COUT(files, auditcompress);
        COUT(files, compressed);
        displayTreeMX(files->partns_desc, title);
      }
      break;

    case TYPEMX(HISTOGRAM):
      {
        TITLE("HISTOGRAM");
        CASTMX(histogram);
        COUT(histogram, tablename);
        COUT(histogram, tablecolnumber);
        COUT(histogram, histid);
        COUT(histogram, colposition);
        COUT(histogram, rowcount);
        COUT(histogram, uec);
        COUT_STRING(histogram, highval);
        COUT_STRING(histogram, lowval);
        displayTreeMX(histogram->hist_interval_desc, title);
      }
      break;

    case TYPEMX(HIST_INTERVAL):
      {
        TITLE("HIST_INTERVAL");
        CASTMX(hist_interval);
        COUT(hist_interval, histid);
        COUT(hist_interval, intnum);
        COUT(hist_interval, intboundary);
        COUT(hist_interval, rowcount);
        COUT(hist_interval, uec);
      }
      break;

    case TYPEMX(INDEXES):
      {
        TITLE("INDEXES");
        CASTMX(indexes);
        COUT(indexes, tablename);
        COUT(indexes, indexname);
        COUT(indexes, keytag);
        COUT(indexes, record_length);
        COUT(indexes, colcount);
        COUT(indexes, unique);
        displayTreeMX(indexes->files_desc, title);
        displayTreeMX(indexes->keys_desc, title);
    displayTreeMX(indexes->non_keys_desc, title);
      }
      break;

    case TYPEMX(KEYS):
      {
        TITLE("KEYS");
        CASTMX(keys);
        COUT(keys, indexname);
        COUT(keys, keyseqnumber);
        COUT(keys, tablecolnumber);
        COUT(keys, ordering);
      }
      break;

    case TYPEMX(PARTNS):
      {
        TITLE("PARTNS");
        CASTMX(partns);
        COUT(partns, tablename);
        COUT(partns, primarypartition);
        COUT(partns, partitionname);
        COUT_STRING(partns, firstkey);
      }
      break;

    case TYPEMX(REF_CONSTRNTS):
      {
        TITLE("REF_CONSTRNTS");
        CASTMX(ref_constrnts);
        COUT(ref_constrnts, constrntname);
        COUT(ref_constrnts, tablename);
      }
      break;

    case TYPEMX(TABLE):
      {
        TITLE("TABLE");
        CASTMX(table);
        COUT_LARGEINT(table, createtime);
        COUT_LARGEINT(table, redeftime);
        COUT(table, tablename);
        COUT(table, record_length);
        COUT(table, colcount);
        COUT(table, constr_count);
        COUT(table, rowcount);
        displayTreeMX(table->files_desc, title);
        displayTreeMX(table->columns_desc, title);
        displayTreeMX(table->views_desc, title);
        displayTreeMX(table->indexes_desc, title);
        displayTreeMX(table->constrnts_desc, title);
        if (table->constrnts_tables_desc != top)
          displayTreeMX(table->constrnts_tables_desc, title);
        displayTreeMX(table->referenced_tables_desc, title);
        displayTreeMX(table->referencing_tables_desc, title);
        displayTreeMX(table->histograms_desc, title);
      }
      break;

    case TYPEMX(VIEW):
      {
        TITLE("VIEW");
        CASTMX(view);
        COUT(view, viewname);
        COUT_STRING(view, viewtext);
        COUT_STRING(view, viewchecktext);
        COUT(view, updatable);
        COUT(view, insertable);
      }
      break;

    default:
      {
        TITLE("??? UNKNOWN ???");
      }
      break;
    }  // switch

  displayTreeMX (top->header.next, title);

} // displayTreeMX