Esempio n. 1
0
JNIEXPORT jdoubleArray JNICALL Java_wbitoolkit_smooth_Loess_smooth
  (JNIEnv *env, jclass cls, jdoubleArray jx, jdoubleArray jy, jdouble span, jint degree)
{
	struct loess_struct data;
	struct pred_struct data_pred;
	long se_fit;
	jdoubleArray sy;
	int n=(*env)->GetArrayLength(env, jx);
	jdouble *x, *y;
	x=(*env)->GetDoubleArrayElements(env, jx, NULL);
	if(x==NULL) return 0;
	y=(*env)->GetDoubleArrayElements(env, jy, NULL);
	if(y==NULL) return 0;
	loess_setup(x, y, n, 1, &data);
	data.model.span=span;
	data.model.degree=degree;
	loess(&data);

	se_fit=FALSE;
	predict(x, n, &data, &data_pred, se_fit);
	sy=(*env)->NewDoubleArray(env, n);
	if(sy==NULL) return 0;
	(*env)->SetDoubleArrayRegion(env, sy, 0, n, data_pred.fit);

	loess_free_mem(&data);
	pred_free_mem(&data_pred);
	(*env)->ReleaseDoubleArrayElements(env, jx, x, 0);
	(*env)->ReleaseDoubleArrayElements(env, jy, y, 0);

	return sy;
}
PProbabilityEstimator TProbabilityEstimatorConstructor_loess::operator()(PDistribution frequencies, PDistribution, PExampleGenerator, const long &weightID, const int &attrNo) const
{ TContDistribution *cdist = frequencies.AS(TContDistribution);
  if (!cdist)
    if (frequencies && frequencies->variable)
      raiseError("attribute '%s' is not continuous", frequencies->variable->get_name().c_str());
    else
      raiseError("continuous distribution expected");
  if (!cdist->size())
    raiseError("empty distribution");

  map<float, float> loesscurve;
  loess(cdist->distribution, nPoints, windowProportion, loesscurve, distributionMethod);
  return mlnew TProbabilityEstimator_FromDistribution(mlnew TContDistribution(loesscurve));
}