Пример #1
0
double *
predict(pred_model_t *pred_model, rule_t *labels, params_t *params)
{
	double *prob;
	int i, j, rule_id, sample;
	ruleset_t *rs;
    
	prob = calloc(pred_model->rs->n_samples, sizeof(double));
	if (prob == NULL)
		return NULL;

	for (i = 0; i < pred_model->rs->n_samples; i++)
		prob[i] = 0.0;

	rs = pred_model->rs;
	for (j = 0; j < rs->n_rules; j++) {
		sample = 0;
		rule_id = rs->rules[j].rule_id;
		/*
		 * Iterate over the captured vector finding each sample
		 * captured by this rule; assign it the probability associated
		 * with the rule.
		 */
		for (i = 0; i < rs->rules[j].ncaptured; i++) {
			sample = rule_ff1(rs->rules[j].captures,
			    sample, rs->n_rules);
			prob[sample] = pred_model->theta[j];
			sample++;
		}
		printf("Rule %d captures %d of %d samples\n",
		    rule_id, rs->rules[j].ncaptured, pred_model->rs->n_samples);
	}

	if (debug > 10)
		for (i = 0; i < pred_model->rs->n_samples; i++)
		    printf("%.6f\n", prob[i]);

	if (debug)
		printf("test accuracy = %.6f \n",
		    get_accuracy(pred_model->rs, pred_model->theta,
			labels, params));

	return prob;
}
/* DFTOutlineGeometry

   returns 
      0  success
      -1 no outline found
		-2 invalid algorithm
      1	ignore outline attribute set
		2	can't overwrite already existing outline
*/
int GeneratePackageOutlineGeometry(CCEtoODBDoc *doc, BlockStruct *referenceBlk, BlockStruct *destinationBlk, OutlineAlgorithmTag algorithm, int rectangle, bool filled, int overwrite)
{
   // referenceBlk is the block that contains geometry that we are making an outline around.
   // destinationBlk is the block to put the outline poly in.

   // Note that this function will delete the existing outline before it checks if the
   // algorithm is recognized. This is "good", other code is depending on this, it is one
   // of the ways outlines are removed on purpose. Do not change it unless you change all 
   // that other code.


   if (referenceBlk == NULL || destinationBlk == NULL)
      return -2;

   int err = 0;
   double accuracy = get_accuracy(doc);

   if (is_attvalue(doc, referenceBlk->getAttributes(), ATT_TEST_IGNORE_OUTLINE, 2))
      return 1;
   
   if (referenceBlk->getBlockType() != BLOCKTYPE_PCBCOMPONENT && referenceBlk->getBlockType() != blockTypeDie)
      return -1;

   // see if Package Outline exists
   if (HasPackageOutline(&destinationBlk->getDataList()))
   {
      if (!overwrite)
         return 2;

      // This function can't generate "Custom" outlines, it only does the canned algorithms.
      // If the incoming algorithm is Custom then leave the present outline, otherwise nuke it.
      if (algorithm != algCustom)
         DeletePackageOutline(doc, &destinationBlk->getDataList());
   }

	int outlineMethodKW = doc->RegisterKeyWord(ATT_OUTLINE_METHOD, 0, valueTypeString);

   switch (algorithm)
   {
   case algPinCenters: // pin centers
      {
         double xmin, ymin, xmax, ymax;
         int pins = GetPinExtents(&referenceBlk->getDataList(), &xmin, &ymin, &xmax, &ymax);
         if (pins)
         {
            xmin = round_accuracy(xmin, accuracy);
            ymin = round_accuracy(ymin, accuracy);
            xmax = round_accuracy(xmax, accuracy);
            ymax = round_accuracy(ymax, accuracy);

				CPntList *pp = NULL;

            if (xmin < xmax && ymin < ymax)
            {
               pp = new CPntList;
               CPnt *pnt = new CPnt;
               pnt->x = (DbUnit)xmin;
               pnt->y = (DbUnit)ymin;
               pnt->bulge = 0;
               pp->AddTail(pnt);
               pnt = new CPnt;
               pnt->x = (DbUnit)xmax;
               pnt->y = (DbUnit)ymin;
               pnt->bulge = 0;
               pp->AddTail(pnt);
               pnt = new CPnt;
               pnt->x = (DbUnit)xmax;
               pnt->y = (DbUnit)ymax;
               pnt->bulge = 0;
               pp->AddTail(pnt);
               pnt = new CPnt;
               pnt->x = (DbUnit)xmin;
               pnt->y = (DbUnit)ymax;
               pnt->bulge = 0;
               pp->AddTail(pnt);
               pnt = new CPnt;
               pnt->x = (DbUnit)xmin;
               pnt->y = (DbUnit)ymin;
               pnt->bulge = 0;
               pp->AddTail(pnt);
				}
				else if (pins == 2)
				{
					double xmin2, ymin2, xmax2, ymax2;
					int outlineFound = get_insidepadsextents(doc, &referenceBlk->getDataList(), &xmin2, &ymin2, &xmax2, &ymax2);
					if (outlineFound)
					{
						xmin2  = round_accuracy(xmin2, accuracy);
						ymin2  = round_accuracy(ymin2, accuracy);
						xmax2  = round_accuracy(xmax2, accuracy);
						ymax2  = round_accuracy(ymax2, accuracy);

						if (xmin < xmax)
						{
							// the two pins are lined up horizontal
							pp = new CPntList;
							CPnt *pnt = new CPnt;
							pnt->x = (DbUnit)xmin;
							pnt->y = (DbUnit)ymin2;
							pnt->bulge = 0;
							pp->AddTail(pnt);
							pnt = new CPnt;
							pnt->x = (DbUnit)xmax;
							pnt->y = (DbUnit)ymin2;
							pnt->bulge = 0;
							pp->AddTail(pnt);
							pnt = new CPnt;
							pnt->x = (DbUnit)xmax;
							pnt->y = (DbUnit)ymax2;
							pnt->bulge = 0;
							pp->AddTail(pnt);
							pnt = new CPnt;
							pnt->x = (DbUnit)xmin;
							pnt->y = (DbUnit)ymax2;
							pnt->bulge = 0;
							pp->AddTail(pnt);
							pnt = new CPnt;
							pnt->x = (DbUnit)xmin;
							pnt->y = (DbUnit)ymin2;
							pnt->bulge = 0;
							pp->AddTail(pnt);
						}
						else if (ymin < ymax)
						{
							// the two pins are lined up vertical
							pp = new CPntList;
							CPnt *pnt = new CPnt;
							pnt->x = (DbUnit)xmin2;
							pnt->y = (DbUnit)ymin;
							pnt->bulge = 0;
							pp->AddTail(pnt);
							pnt = new CPnt;
							pnt->x = (DbUnit)xmax2;
							pnt->y = (DbUnit)ymin;
							pnt->bulge = 0;
							pp->AddTail(pnt);
							pnt = new CPnt;
							pnt->x = (DbUnit)xmax2;
							pnt->y = (DbUnit)ymax;
							pnt->bulge = 0;
							pp->AddTail(pnt);
							pnt = new CPnt;
							pnt->x = (DbUnit)xmin2;
							pnt->y = (DbUnit)ymax;
							pnt->bulge = 0;
							pp->AddTail(pnt);
							pnt = new CPnt;
							pnt->x = (DbUnit)xmin2;
							pnt->y = (DbUnit)ymin;
							pnt->bulge = 0;
							pp->AddTail(pnt);
						}
					}
				}
               
				if (pp != NULL)
				{
					CString value = outlineAlgTagToString(algPinCenters);
					DataStruct *data = AddPackageOutline(doc, pp, destinationBlk, rectangle, filled);
					if (data)
						doc->SetAttrib(&data->getAttributesRef(), outlineMethodKW, valueTypeString, value.GetBuffer(0), attributeUpdateOverwrite, NULL);

               FreePntList(pp);
            }
				else
					err = -1;
			}
			else
				err = -1;
      }
      break;

   case algPinExtents: // pad/body extents
      {
         Outline_Start(doc);
         
         int outlineFound = 0;

         outlineFound = DFT_OutlineAddPins(doc, &referenceBlk->getDataList(), 0, 0, 0, 0, 1, 0, -1);

         if (!outlineFound)
            err = -1;

         if (outlineFound)
         { 
            int returnCode;
            CPntList *pntList = Outline_GetOutline(&returnCode, accuracy);

				CString value = outlineAlgTagToString(algPinExtents);
				DataStruct *data = AddPackageOutline(doc, pntList, destinationBlk, rectangle, filled);
				if (data)
					data->setAttrib(doc->getCamCadData(), outlineMethodKW, valueTypeString, value.GetBuffer(0), attributeUpdateOverwrite, NULL); 
			}
			else
				err = -1;

         Outline_FreeResults();
      }
      break;

   case algInsidePads: // inside pads
      {
         // algorithm:
         // only works on 2 pin components and components w/ pins in 2 rows
         double xmin, ymin, xmax, ymax;
         doc->CalcBlockExtents(referenceBlk);

         xmin  = referenceBlk->getXmin();
         ymin  = referenceBlk->getYmin();
         xmax  = referenceBlk->getXmax();
         ymax  = referenceBlk->getYmax();

         int outlineFound = get_insidepadsextents(doc, &referenceBlk->getDataList(), &xmin, &ymin, &xmax, &ymax);
         if (outlineFound)
         {
            xmin  = round_accuracy(xmin, accuracy);
            ymin  = round_accuracy(ymin, accuracy);
            xmax  = round_accuracy(xmax, accuracy);
            ymax  = round_accuracy(ymax, accuracy);

            // no outline if all pins are in single line.
            if (xmin < xmax && ymin < ymax)
            {
               CPntList *pp = new CPntList;
               CPnt *pnt = new CPnt;
               pnt->x = (DbUnit)xmin;
               pnt->y = (DbUnit)ymin;
               pnt->bulge = 0;
               pp->AddTail(pnt);
               pnt = new CPnt;
               pnt->x = (DbUnit)xmax;
               pnt->y = (DbUnit)ymin;
               pnt->bulge = 0;
               pp->AddTail(pnt);
               pnt = new CPnt;
               pnt->x = (DbUnit)xmax;
               pnt->y = (DbUnit)ymax;
               pnt->bulge = 0;
               pp->AddTail(pnt);
               pnt = new CPnt;
               pnt->x = (DbUnit)xmin;
               pnt->y = (DbUnit)ymax;
               pnt->bulge = 0;
               pp->AddTail(pnt);
               pnt = new CPnt;
               pnt->x = (DbUnit)xmin;
               pnt->y = (DbUnit)ymin;
               pnt->bulge = 0;
               pp->AddTail(pnt);

					CString value = outlineAlgTagToString(algInsidePads);
					DataStruct *data = AddPackageOutline(doc, pp, destinationBlk, rectangle, filled);
					if (data)
						data->setAttrib(doc->getCamCadData(), outlineMethodKW, valueTypeString, value.GetBuffer(0), attributeUpdateOverwrite, NULL); 
               
					FreePntList(pp);
            }
            else
               err = -1;
         }
         else
            err = -1;
      }
      break;

	case algBodyOutline: // body outline
      {
         Outline_Start(doc);
         
         int outlineFound = 0;

         outlineFound = DFT_OutlineAddData(doc, &referenceBlk->getDataList(), 0, 0, 0, 0, 1, 0, -1, GR_CLASS_COMPOUTLINE, 0);

         if (!outlineFound)
            outlineFound = DFT_OutlineAddData(doc, &referenceBlk->getDataList(), 0, 0, 0, 0, 1, 0, -1, 0, LAYTYPE_COMPONENTOUTLINE);

         if (!outlineFound) // here now any graphic.
            outlineFound = DFT_OutlineAddData(doc, &referenceBlk->getDataList(), 0, 0, 0, 0, 1, 0, -1, 0, 0);

         if (!outlineFound)
            err = -1;
            
         int returnCode;
         CPntList *pntList = Outline_GetOutline(&returnCode, accuracy);
         if (pntList)
			{
				CString value = outlineAlgTagToString(algBodyOutline);
				DataStruct *data = AddPackageOutline(doc, pntList, destinationBlk, rectangle, filled);
				if (data)
					data->setAttrib(doc->getCamCadData(), outlineMethodKW, valueTypeString, value.GetBuffer(0), attributeUpdateOverwrite, NULL); 
			}

         Outline_FreeResults();
      }
      break;

   case algCustom:
      // Custom outline isn't generated here, it is made interactively by user.
      // But do update the current outline to have the "Custom" algorithm setting.
      {
         DataStruct *d = GetPackageOutline(&destinationBlk->getDataList());
         if (d != NULL)
            d->setAttrib(doc->getCamCadData(), outlineMethodKW, valueTypeString, outlineAlgTagToString(algCustom).GetBuffer(0), attributeUpdateOverwrite, NULL);
      }
      break;

   default:
		err = -2;
		break;
   }

   // Methods above create outline relative to referenceBlk origin.
   // We want the outline to be relative to the pins centroid location.
   // Shift the outline poly.
   // The algCustom method is exempt, its outline is not created here.
   // We are, in fact, doing this because custom outlines are aligned by pins centroid and it
   // has become a nuisance that not all outlines are aligned the same. So now they are.
   if (err == 0 && algorithm != algCustom)
   {
      double centX, centY;
      if (CalculateCentroid_PinCenters(doc, referenceBlk, &centX, &centY))
      {
         CTMatrix m;
         m.translate(-centX, -centY);
         destinationBlk->transform(m);
      }
   }

   return err;
}
Пример #3
0
static int real_run_check (int round, PRN *prn)
{
    int coeff_acc = 0, sderr_acc = 0, err = 0;
    char line[512];
    MODEL *pmod = NULL;

    pmod = gretl_model_new();
    if (pmod == NULL) {
	fputs("Out of memory\n", stderr);
	return 1;
    }

    set_tolerance();
    catch_arctan();

    if (!err) {
	err = generate_params(line, round, prn);
    }

    if (!err) {
	catch_log_depvar();
	err = nl_parse_line(NLS, tester.model_spec, (const double **) Z, 
			    datainfo, prn);
	if (verbose) {
	    printf("%s\n", tester.model_spec);
	}
	if (err) {
	    fprintf(stderr, "%s: ERROR: in nl_parse_line\n '%s'\n",
		    tester.datname, tester.model_spec);
	    errmsg(err, prn);
	    return err;
	}
    }

    if (!err) {
	if (use_derivs) {
	    err = print_derivs(line, prn);
	} else {
	    err = print_params(line, prn);
	}
    }

    if (!err) {
	*pmod = nl_model(&Z, datainfo, OPT_NONE, prn);

	if (pmod->errcode) {
	    err = pmod->errcode;
	    fprintf(stderr, "%s: ERROR: model error %d\n", tester.datname, err);
	    errmsg(err, prn);
	} else {
	    if (verbose) {
		pmod->ID = 0;
		printmodel(pmod, datainfo, OPT_NONE, prn);
	    }
	    
	    print_tol = gretl_model_get_double(pmod, "tol");
	    total_iters += gretl_model_get_int(pmod, "iters");

	    get_accuracy(pmod, &coeff_acc, &sderr_acc);
	    if (coeff_acc < worst_coeff_acc) {
		worst_coeff_acc = coeff_acc;
		strcpy(worst_coeff_name, tester.datname);
	    }

	    /* Lanczos1 is weird */
	    if (strcmp(tester.datname, "Lanczos1") && 
		sderr_acc < worst_sderr_acc) {
		worst_sderr_acc = sderr_acc;
		strcpy(worst_sderr_name, tester.datname);
	    }
	}
	gretl_model_free(pmod);
	pmod = NULL;
    }

    if (err && !verbose) {
	printf(" Estimation failed\n");
    }

    if (err) {
	n_fail++;
    } else {
	avg_coeff_min += coeff_acc;
	avg_sd_min += sderr_acc;
	n_ok++;
    }

    if (!err) {
	if (verbose) printf("\n ***\n");

	if (coeff_acc >= 6) {
	    printf(" coefficient accuracy >= %d digits\n", coeff_acc);
	} else if (coeff_acc >= MIN_DIGITS) {
	    printf(" coefficient accuracy >= %d digits\n", coeff_acc);
	} else {
	    printf(" min. coefficient accuracy < %d digits\n", MIN_DIGITS);
	}

	if (sderr_acc >= 6) {
	    printf(" stderr accuracy >= %d digits\n", sderr_acc);
	} else if (sderr_acc >= MIN_DIGITS) {
	    printf(" stderr accuracy >= %d digits\n", sderr_acc);
	} else {
	    printf(" min. stderr accuracy < %d digits\n", MIN_DIGITS);
	}
    }

    if (verbose) 
	printf("Round %d, error code = %d\n", round, err);
	
    return err;
}