void CCorrelationFilters::prepare_data(struct CDataStruct *img, struct CParamStruct *params)
{
    normalize_data(img);
    img->size_data_freq = params->size_filt_freq;
    fft_data(img);
    params->num_elements_freq = img->num_elements_freq;
    compute_psd_matrix(img, params);
    compute_inverse_psd_matrix(img, params);
}
예제 #2
0
 Patient(std::string name) {
     this->name = name;
     this->x = getData("x0l.dat");
     this->y = getData("y0l.dat");
     this->z = getData("z0l.dat");
     (this->data).push_back(this->x);
     (this->data).push_back(this->y);
     (this->data).push_back(this->z);
     normalize_data();
 }
예제 #3
0
파일: LLAsimobj.c 프로젝트: cran/LLAhclust
void similarity_objects(double *x, int *n, int *p, double *S, int *method)
{
  /* similarity per variable */
  void (*similarity)(double *, int , int , double *) = NULL;
  
  switch(*method) {
  case NUMERICAL_EUCLIDEAN:
    Rprintf("LLAsim: the objects are assumed to be described by numerical variables\n");
    similarity = similarity_numerical_euclidean;
    break;
  case NUMERICAL_COSINUS:
    Rprintf("LLAsim: the objects are assumed to be described by numerical variables\n");
    similarity = similarity_numerical_cosinus;
    normalize_data(x, *n, *p);
    break;
  case CATEGORICAL:
    Rprintf("LLAsim: the objects are assumed to be described by categorical variables\n");
    similarity = similarity_categorical;
    break;
  case ORDINAL:
    Rprintf("LLAsim: the objects are assumed to be described by ranks induced by ordinal variables\n");
    similarity = similarity_ordinal;
    break;
  case BOOLEAN:
    Rprintf("LLAsim: the objects are assumed to be described by boolean variables\n");
    normalize_data(x, *n, *p);
    similarity = similarity_numerical_cosinus;
    break;
  default:
    error("invalid similarity method");
  }

  /* construction of the similarity by additive decomposition */
  similarity(x,*n,*p, S);

  /* normalization of the similarity index */
  normalize_similarity(S,(*n) * (*n - 1)/2);

}
예제 #4
0
jdoubleArray Java_edu_cornell_audioProbe_AudioManager_features(JNIEnv* env, jobject javaThis, jshortArray array) {
//void Java_edu_cornell_audioProbe_AudioManager_features(JNIEnv* env, jobject javaThis, jshortArray array) {

	(*env)->GetShortArrayRegion(env, array, 0, FRAME_LENGTH, buf);

	normalize_data();

	// apply window
	computeHamming();

	// computeFwdFFT
	kiss_fftr(cfgFwd, normalizedData, fftx);

	//compute power spectrum
	computePowerSpec(fftx, powerSpec, FFT_LENGTH);

	//compute magnitude spectrum
	computeMagnitudeSpec(powerSpec, magnitudeSpec, FFT_LENGTH);

	// compute total energy
	energy = computeEnergy(powerSpec, FFT_LENGTH) / FFT_LENGTH;

	//compute Spectral Entropy
	computeSpectralEntropy2(magnitudeSpec, FFT_LENGTH);


	//compute auto-correlation peaks
	computeAutoCorrelationPeaks2(powerSpec, powerSpecCpx, NOISE_LEVEL, FFT_LENGTH);

	//data output
	////return data as variable size array caused by variable autocorrelation information.
	jdoubleArray featureVector = (*env)->NewDoubleArray(env,6 + 2*numAcorrPeaks + 2 + LOOK_BACK_LENGTH);
	//jdoubleArray featureVector = (*env)->NewDoubleArray(env,6 + 2*numAcorrPeaks + 2 + LOOK_BACK_LENGTH + FFT_LENGTH);
	featuresValuesTemp[0] = numAcorrPeaks; //autocorrelation values
	featuresValuesTemp[1] = maxAcorrPeakVal;
	featuresValuesTemp[2] = maxAcorrPeakLag;
	featuresValuesTemp[3] = spectral_entropy;
	featuresValuesTemp[4] = rel_spectral_entropy;
	featuresValuesTemp[5] = energy;

	//gaussian distribution
	//test the gaussian distribution with some dummy values first
	x[0] = maxAcorrPeakVal;
	x[1] = numAcorrPeaks;
	x[2] = rel_spectral_entropy;
	/*
	emissionVoiced = computeMvnPdf(x,mean_voiced, inv_cov_voiced, denom_gauss_voiced);
	emissionUnvoiced = computeMvnPdf(x,mean_unvoiced, inv_cov_unvoiced, denom_gauss_unvoiced);
	 */
	 
	inferenceResult = getViterbiInference(x,featureAndInference);
	memcpy( featuresValuesTemp+6, featureAndInference, (2+LOOK_BACK_LENGTH)*sizeof(double) ); //observation probabilities, inferences
	
	
	
	//put auto correlation values in the string
	memcpy( featuresValuesTemp+6+2+LOOK_BACK_LENGTH, acorrPeakValueArray, numAcorrPeaks*sizeof(double) );
	memcpy( featuresValuesTemp+6+numAcorrPeaks+2+LOOK_BACK_LENGTH, acorrPeakLagValueArray, numAcorrPeaks*sizeof(double) );
	//memcpy( featuresValuesTemp+6+numAcorrPeaks+numAcorrPeaks+2+LOOK_BACK_LENGTH, magnSpect, FFT_LENGTH*sizeof(double) );
	(*env)->SetDoubleArrayRegion( env, featureVector, 0, 6 + numAcorrPeaks*2 + 2 + LOOK_BACK_LENGTH, (const jdouble*)featuresValuesTemp );
	//(*env)->SetDoubleArrayRegion( env, featureVector, 0, 6 + numAcorrPeaks*2 + 2 + LOOK_BACK_LENGTH + FFT_LENGTH, (const jdouble*)featuresValuesTemp );


	return featureVector;


}
예제 #5
0
static void
fit_do(FitControls *controls)
{
    FitParamArg *arg;
    FitArgs *args;
    GtkWidget *dialog;
    gdouble *param, *error;
    gboolean *fixed;
    gint i, j, nparams, nfree = 0;
    gboolean allfixed, errorknown;

    args = controls->args;
    nparams = gwy_nlfit_preset_get_nparams(args->fitfunc);
    fixed = g_newa(gboolean, nparams);

    allfixed = TRUE;
    for (i = 0; i < nparams; i++) {
        arg = &g_array_index(args->param, FitParamArg, i);
        fixed[i] = arg->fix;
        allfixed &= fixed[i];
        arg->value = arg->init;
        if (!fixed[i])
            nfree++;
    }
    if (allfixed)
        return;

    if (!normalize_data(args))
        return;

    if (gwy_data_line_get_res(args->xdata) <= nfree) {
        dialog = gtk_message_dialog_new(GTK_WINDOW(controls->dialog),
                                        GTK_DIALOG_DESTROY_WITH_PARENT,
                                        GTK_MESSAGE_ERROR,
                                        GTK_BUTTONS_OK,
                                        _("It is necessary to select more "
                                          "data points than free fit "
                                          "parameters"));
        gtk_dialog_run(GTK_DIALOG(dialog));
        gtk_widget_destroy(dialog);
        return;
    }

    if (args->fitter)
        gwy_math_nlfit_free(args->fitter);

    param = g_newa(gdouble, nparams);
    error = g_newa(gdouble, nparams);
    for (i = 0; i < nparams; i++)
        param[i] =g_array_index(args->param, FitParamArg, i).value;
    args->fitter
        = gwy_nlfit_preset_fit(args->fitfunc, NULL,
                               gwy_data_line_get_res(args->xdata),
                               gwy_data_line_get_data_const(args->xdata),
                               gwy_data_line_get_data_const(args->ydata),
                               param, error, fixed);
    errorknown = (args->fitter->covar != NULL);

    for (i = 0; i < nparams; i++) {
        arg = &g_array_index(args->param, FitParamArg, i);
        arg->value = param[i];
        arg->error = error[i];
        fit_param_row_update_value(controls, i, errorknown);
    }

    if (errorknown) {
        gchar buf[16];

        /* FIXME: this is _scaled_ dispersion */
        g_snprintf(buf, sizeof(buf), "%2.3g",
                   gwy_math_nlfit_get_dispersion(args->fitter));
        gtk_label_set_markup(GTK_LABEL(controls->chisq), buf);

        for (i = 0; i < nparams; i++) {
            for (j = 0; j <= i; j++) {
                g_snprintf(buf, sizeof(buf), "%0.3f",
                           gwy_math_nlfit_get_correlations(args->fitter, i, j));
                fix_minus(buf, sizeof(buf));
                gtk_label_set_markup(SLi(controls->covar, GtkLabel*, i, j),
                                     buf);
            }
         }
    }
    else