template <class DATA> void Statistics<DATA>::update ( ) const { matrix_set_scaled(m_mean,1.0/m_counter,m_sum); if (m_counter<2) { matrix_set_scalar(m_variance,0); } else { for (int i=0;i<m_variance.rows();++i) m_variance(i) = sqrt(1.0/(m_counter-1) * (m_squared_sum(i) - SQR(m_mean(i))*m_counter)); } m_changed = false; }
/*Rueckgabe 0 - inc, 1 - inc_err, 2 - abs, 3 - abs_err, 4-8 reserviert*/ double *m_fit(dataset *dat, fit_conf *conf, double inclin, double absol) { double *vari, *res, vsum, v_sq_x, v_x, v_xy, v_sq_y, v_y, v_sq, rez_d, chi_sq; int k; /*Ansetzen der Varianzgewichtung fuer gegebenes inclin */ vari = m_variance(dat, conf, inclin); if (vari == NULL) return NULL; res = malloc(9 * sizeof(double)); if (res == NULL) { free(vari); return NULL; } /*ausrechnen der Summen */ v_sq = 0; /* 1/sigma_i^2*/ vsum = 0; /* Summe 1/sigma_i^2*/ v_sq_x = 0; /*x^2 / v_sq*/ v_x = 0; /*x / v_sq*/ v_xy = 0; /*xy / v_sq*/ v_sq_y = 0; /*y^2 / v_sq*/ v_y = 0; /*y / v_sq*/ chi_sq = 0; /* Guete des Fits */ for (k = conf->start; k < conf->start + conf->len; ++k) { v_sq = vari[k]; vsum += 1. / v_sq; v_sq_x += pow(dat->data[dat->x][k], 2) / v_sq; v_x += dat->data[dat->x][k] / v_sq; v_xy += (dat->data[dat->x][k] * dat->data[dat->y][k]) / v_sq; v_sq_y += pow(dat->data[dat->y][k], 2) / v_sq; v_y += dat->data[dat->y][k] / v_sq; chi_sq += pow( dat->data[dat->y][k] - inclin * dat->data[dat->x][k] - absol, 2) / v_sq; } chi_sq /= conf->len - 2; /*Steigungsberechnung */ rez_d = vsum * v_sq_x - pow(v_x, 2); rez_d = 1. / rez_d; res[0] = vsum * v_xy - v_x * v_y; res[0] *= rez_d; /*Fehler der Steigung */ res[1] = rez_d * vsum; res[1] = sqrt(res[1]); /*Absolutes Glied*/ res[2] = v_y - (res[0] * v_x); res[2] /= vsum;/*Varianzgemittelte Mittelwerte*/ /*Fehler Absolutes Glied*/ res[3] = res[1] * v_x / vsum; res[3] = sqrt(res[3]); /* hier muss evtl. noch gegausst werden! */ /* Korellationskoeffizient -> wird in uebergeorndeter Funktion berechnet*/ res[4] = 0; /* reserviert fuer Abbruchinformationen */ res[5] = 0; /* reserviert fuer Anzahl Iterationen */ res[6] = 0; /* reserviert fuer letzte Aenderung*/ res[7] = 0; /* chi_sq Guete des Fits */ res[8] = chi_sq; free(vari); return res; }