Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- struct Registro
- {
- Registro(float x, float y) {
- this->x = x;
- this->y = y;
- }
- void calcular(float promX,float promY) {
- dx = x - promX;
- dy = y - promY;
- dx2 = dx*dx;
- dy2 = dy*dy;
- dxdy = dx*dy;
- }
- void mostrar() {
- cout << x << " " << y << " " << dx << " "<<dy<<" " <<dxdy<<" "
- <<" "<<dx2 << " " << dy2 <<endl;
- }
- ~Registro(){}
- float x,y,dx,dy,dx2,dy2,dxdy;
- };
- class Dataframe {
- private:
- vector<Registro> coleccion;
- float promX, promY, sumDxy,
- covXY, sumDxx, sumDyy, sdX, sdY;
- public:
- Dataframe(){
- }
- void limpiar() { coleccion.clear(); }
- void agregar(float x, float y) {
- coleccion.push_back(Registro(x, y));
- }
- float calcularR() {
- return covXY / (sdX*sdY);
- }
- float predecirX(float ny) {
- return promY + ((ny - promY)*covXY / (sdY*sdY));
- }
- float predecirY(float nx) {
- return promX + ((nx - promX)*covXY / (sdX*sdX));
- }
- void calcularTabla(){
- promX = promY=0;
- //Calcular Promedio
- for (int i = 0; i < coleccion.size(); ++i) {
- promX += coleccion[i].x;
- promY += coleccion[i].y;
- }
- promX /= coleccion.size();
- promY /= coleccion.size();
- /////////Calcular Tabla
- for (int i = 0; i < coleccion.size(); ++i) {
- coleccion[i].calcular(promX,promY);
- coleccion[i].mostrar();
- }
- ////////Calcular Resultados
- sumDxy =sumDxx =sumDyy = 0;
- for (int i = 0; i < coleccion.size(); ++i) {
- sumDxy += coleccion[i].dxdy;
- sumDxx += coleccion[i].dx2;
- sumDyy += coleccion[i].dy2;
- }
- int l = coleccion.size();
- covXY = sumDxy / (l - 1);//covarianza muestral
- sdX = sqrt(sumDxx / (l - 1));
- sdY = sqrt(sumDyy / (l - 1));
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement