void CybMLM::initData() { //it calculates the mean for each variable for(int i=0; i < this->getVariablesNumber();i++) { float mean = 0; for(int j=0; j < this->getData()->size(); j++) mean += this->getData()->pos(j)->operator[](i); this->setMean(mean/this->getData()->size(), i); } //it calculates the precisionMatrix matrix for(int i=0; i < this->getVariablesNumber();i++) for(int j=0; j < this->getVariablesNumber();j++) { for(int k=0; k < this->getData()->size(); k++) { this->covariance[i*this->getVariablesNumber() + j] += (this->getData()->pos(k)->toArray()[i]- this->getMean(i)) * (this->getData()->pos(k)->toArray()[j]- this->getMean(j)); } this->covariance[i*this->getVariablesNumber() + j] /= this->getData()->size(); } checkVariables(); }
void AlignmentDisplay::display() { checkVariables(); glPushMatrix(); glScaled(1,-1,1); if(!upToDate) loadTexture(); textureBuffer->display(); glPopMatrix(); }
Real PorousFlowWaterNCG::totalMassFraction( Real pressure, Real temperature, Real /* Xnacl */, Real saturation, unsigned int qp) const { // Check whether the input temperature is within the region of validity checkVariables(temperature); // FluidStateProperties data structure std::vector<FluidStateProperties> fsp(_num_phases, FluidStateProperties(_num_components)); FluidStateProperties & liquid = fsp[_aqueous_phase_number]; FluidStateProperties & gas = fsp[_gas_phase_number]; // Calculate equilibrium mass fractions in the two-phase state Real Xncg, dXncg_dp, dXncg_dT, Yh2o, dYh2o_dp, dYh2o_dT; equilibriumMassFractions( pressure, temperature, Xncg, dXncg_dp, dXncg_dT, Yh2o, dYh2o_dp, dYh2o_dT); // Save the mass fractions in the FluidStateMassFractions object const Real Yncg = 1.0 - Yh2o; liquid.mass_fraction[_aqueous_fluid_component] = 1.0 - Xncg; liquid.mass_fraction[_gas_fluid_component] = Xncg; gas.mass_fraction[_aqueous_fluid_component] = Yh2o; gas.mass_fraction[_gas_fluid_component] = Yncg; // Gas properties gasProperties(pressure, temperature, fsp); // Liquid properties const Real liquid_saturation = 1.0 - saturation; const Real liquid_pressure = pressure - _pc.capillaryPressure(liquid_saturation, qp); liquidProperties(liquid_pressure, temperature, fsp); // The total mass fraction of ncg (Z) can now be calculated const Real Z = (saturation * gas.density * Yncg + liquid_saturation * liquid.density * Xncg) / (saturation * gas.density + liquid_saturation * liquid.density); return Z; }
void AlignmentDisplay::loadTexture() { /**/ int s = ui->scaleDial->value(); if(s % 4 != 0) { ui->print("Warning: The SCALE on Repeat Overview should be set to a multiple of 4."); } //s = max(4, (s / 4) * 4);//enforces scale is a multiple of 4 //ui->scaleDial->setValue(s); checkVariables();/**/ //return if changed? vector<color> alignment_colors; int end = max(1, (nucleotide_start + display_size) - 251); for(int i = nucleotide_start; i < end; i+=scale) alignment_colors.push_back( simpleAlignment(i) ); if(textureBuffer) delete textureBuffer; textureBuffer = new TextureCanvas( alignment_colors, width()); upToDate = true; }
long getmodel(Symbolhandle list, long nargs, long startKey, long silent, Symbolhandle symhWts, Symbolhandle symhOffset, Symbolhandle symhN) { long i, j, i2, inc; long ny, ndata, nvars, nfactors, nterms, nerrorterms; long needed, balanced; long foundNonIntY = 0, foundNonIntN = 0; long intercept; long nmissing, nzerowt; long dim[2]; modelPointer kterm; Symbolhandle symh; double tmp; double *glmoffset, *casewts, *misswts, *ptmp, *factorvar; double yi, logitni, *y, *logitn, maxlevel; long caseweights = MODELTYPE & CASEWEIGHTS; char *ipfwarning = "WARNING: ipf() cannot be used, poisson() substituted"; modelInfoPointer info = (modelInfoPointer) 0; WHERE("getmodel"); TRASH(NTRASH,errorExit); *OUTSTR = '\0'; USEGLMOFFSET = 0; if (!initmodelparse(STRMODEL) || modelparse() != 0) {/* parse it */ goto errorExit; } info = getModelInfo(); /* retrieve model information */ if((ndata = checkVariables(info)) < 0) { goto errorExit; } if(!(GLMCONTROL & MULTIVAR) && !isVector(info->modelvars[0])) { sprintf(OUTSTR, "ERROR: non-vector response variable for %s()", FUNCNAME); goto errorExit; } NVARS = nvars = MODELINFO->nvars = info->nvars; NFACTORS = nfactors = MODELINFO->nfactors = info->nfactors; NTERMS = nterms = MODELINFO->nterms = info->nterms; NERRORTERMS = nerrorterms = MODELINFO->nerrorterms = info->nerrorterms; for(i=0;i<nerrorterms;i++) { modeltermAssign((modelPointer) info->errorterms[i], (modelPointer) MODELINFO->errorterms[i]); } /* Note: As of 930601, INTMODEL has been eliminated */ MODEL = info->model; info->model = (modelHandle) 0; if(MODELTYPE & (OLSREG|LEAPS)) { NFACTORS = nfactors = MODELINFO->nfactors = 0; intercept = 0; for(j=0;j<nterms;j++) { kterm = modelterm(MODEL,j); if(nvInTerm(kterm) > 1) { sprintf(OUTSTR, "ERROR: crossed variates and/or factors are illegal for %s()", FUNCNAME); goto errorExit; } /*if(nvInTerm(modelterm(MODEL,j)) > 1)*/ if(modeltermEqual(kterm,(modelPointer) NULLTERM)) { intercept = 1; } } /*for(j=0;j<nterms;j++)*/ } /*if(MODELTYPE & (OLSREG|LEAPS))*/ if (MODELTYPE & LEAPS && !intercept) { sprintf(OUTSTR, "ERROR: a model without an intercept is illegal for %s()", FUNCNAME); goto errorExit; } /* set up MODELVARS */ for (i = 0; i <= nvars; i++) { if(MODELVARS[i] != (Symbolhandle) 0) { Delete(MODELVARS[i]); } MODELVARS[i] = Makesymbol(REAL); if (MODELVARS[i] == (Symbolhandle) 0) { goto errorExit; } if (!Copy(info->modelvars[i], MODELVARS[i])) { goto errorExit; } info->modelvars[i] = (Symbolhandle) 0; strcpy(VARNAMES[i], NAME(MODELVARS[i])); if(i < nvars) { NCLASSES[i] = info->nclasses[i]; } clearNotes(MODELVARS[i]); } /*for (i = 0; i <= nvars; i++)*/ /* set up Y and X */ /* response and factors are known to be matrix or vector */ for (i = 0; i <= nvars; i++) { symh = MODELVARS[i]; (void) isMatrix(symh,dim); /* get dimensions */ if (HASLABELS(symh) && NDIMS(symh) != 2) { if (!fixupMatLabels(symh, USEBOTHLABELS)) { goto errorExit; } } /*if (HASLABELS(symh) && NDIMS(symh) != 2)*/ else { Setdims(symh, 2, dim); } if(i == 0) { Y = DATA(symh); ny = dim[1]; NDATA = (double) ndata; NY = (double) ny; /* make sure dimensions are correct, always 2 */ } /*if(i == 0)*/ else {/* i > 0 */ X[i - 1] = DATA(symh); if (isVariate(i-1)) { GLMCONTROL |= UNBALANCED; } /*if (isVariate(i-1))*/ } /*if(i == 0){}else{}*/ if(*OUTSTR) { goto errorExit; } } /*for (i = 0; i <= nvars; i++)*/ /* check for crossed variates */ for (i = 0; i < nvars-1; i++) { if (isVariate(i)) { /* variable i is a variate */ for (j = 0; j < nterms; j++) { /* find the terms it is in and check to see it is not crossed with another variate */ kterm = modelterm(MODEL,j); if(inTerm(i,kterm) && nvInTerm(kterm) > 1) { /* j-th term has variable i and there are at least 2 variables or factors in the term. Check to see if j-th term has another variate */ for (i2 = i+1; i2 < nvars; i2++) { if (isVariate(i2) && inTerm(i2,kterm)) { sprintf(OUTSTR, "ERROR: crossed variates in model are illegal for %s()", FUNCNAME); goto errorExit; } /*if (isVariate(i2) && inTerm(i2,kterm))*/ } /*for (i2 = 0; i2 < nvars; i2++)*/ } /*if(inTerm(i,kterm))*/ } /*for (j = 0; j < nterms; j++)*/ } /*if (isVariate(i))*/ } /*for (i = 0; i < nvars; i++)*/ /* check for case weights, i.e., user specified weights */ if (caseweights) { if (symhWts == (Symbolhandle) 0) { sprintf(OUTSTR, "ERROR: no weights given for %s()",FUNCNAME); } else if (TYPE(symhWts) != REAL || !isVector(symhWts) || symbolSize(symhWts) != ndata) { sprintf(OUTSTR, "ERROR: weights for %s() not REAL vector with length = nrows(%s)", FUNCNAME, NAME(MODELVARS[0])); } else { CASEWTS = (double **) mygethandle(ndata * sizeof(double)); if (CASEWTS == (double **) 0) { goto errorExit; } casewts = *CASEWTS; doubleCopy( DATAPTR(symhWts), casewts, ndata); for (i = 0; i < ndata; i++) { if (!isMissing(casewts[i]) && casewts[i] < 0) { sprintf(OUTSTR,"ERROR: negative case weights for %s()", FUNCNAME); break; } } /*for (i = 0; i < ndata; i++)*/ } if(*OUTSTR) { goto errorExit; } } /* if(caseweights) */ /* check for logistic N */ if (GLMCONTROL & BINOMDIST) { if (symhN == (Symbolhandle) 0) { sprintf(OUTSTR,"ERROR: no N variable given for %s()", FUNCNAME); } else if(!isVector(symhN) || TYPE(symhN) != REAL || symbolSize(symhN) != ndata && symbolSize(symhN) != 1) { sprintf(OUTSTR, "ERROR: %s() N not REAL scalar or vector of same length as response", FUNCNAME); } else { LOGITN = (double **) mygethandle(ndata * sizeof(double)); if (LOGITN == (double **) 0) { goto errorExit; } } if(*OUTSTR) { goto errorExit; } inc = (symbolSize(symhN) == 1) ? 0 : 1; i2 = 0; y = *Y; logitn = *LOGITN; ptmp = DATAPTR(symhN); for (i = 0; i < ndata; i++) { yi = y[i]; logitni = logitn[i] = ptmp[i2]; if (!isMissing(yi) && !isMissing(logitni)) { tmp = floor(logitni); if (tmp <= 0.0) { sprintf(OUTSTR, "ERROR: N values must be nonnegative for %s()", FUNCNAME); } else if (yi < 0.0 || yi > logitni) { sprintf(OUTSTR, "ERROR: response value out of range for %s()", FUNCNAME); } if(*OUTSTR) { goto errorExit; } if (!foundNonIntY && yi != floor(yi)) { foundNonIntY = 1; } if (!foundNonIntN && logitni != tmp) { foundNonIntN = 1; } } /*if (!isMissing(yi) && !isMissing(logitni))*/ i2 += inc; }/* for (i = 0; i < ndata; i++) */ } /*if (GLMCONTROL & BINOMDIST)*/ else if (GLMCONTROL & POISSONDIST) {/* check for nonnegative Y in Poisson distributed glm */ y = *Y; for (i = 0; i < ndata; i++) { yi = y[i]; if (!isMissing(yi)) { if (yi < 0.0) { sprintf(OUTSTR, "ERROR: response variable negative for %s()", FUNCNAME); goto errorExit; } if (!foundNonIntY && floor(yi) != yi) { foundNonIntY = 1; } } /*if (!isMissing(yi))*/ } /*for (i = 0; i < ndata; i++)*/ } /*if (glmcontrol & POISSONDIST)*/ if (!silent) { if (foundNonIntY) { sprintf(OUTSTR, "WARNING: non-integer value(s) of response variable for %s()", FUNCNAME); putErrorOUTSTR(); } if (foundNonIntN) { sprintf(OUTSTR, "WARNING: non-integer number N of trials for %s()", FUNCNAME); putErrorOUTSTR(); } } /*if (!silent)*/ /* check for user defined glmoffset */ if (symhOffset != (Symbolhandle) 0) { if (TYPE(symhOffset) != REAL || !isVector(symhOffset) || symbolSize(symhOffset) != ndata) { sprintf(OUTSTR, "ERROR: offsets for %s() not REAL vector nrows(offset) = nrows(response)", FUNCNAME); goto errorExit; } USEGLMOFFSET = 1; GLMOFFSET = (double **) mygethandle(ndata * sizeof(double)); if (GLMOFFSET == (double **) 0) { goto errorExit; } doubleCopy(DATAPTR(symhOffset), *GLMOFFSET, ndata); } /*if (symhOffset != (Symbolhandle) 0)*/ /* check for missing & fill MISSWTS if any are missing*/ nmissing = countMissing(MODELINFO, &MISSWTS); if(nmissing < 0) { goto errorExit; } if(caseweights || GLMCONTROL & BINOMDIST || USEGLMOFFSET) { casewts = (caseweights) ? *CASEWTS : (double *) 0; logitn = (GLMCONTROL & BINOMDIST) ? *LOGITN : (double *) 0; glmoffset = (USEGLMOFFSET) ? *GLMOFFSET : (double *) 0; misswts = (nmissing > 0) ? *MISSWTS : (double *) 0; for (i = 0; i < ndata; i++) { if (caseweights && isMissing(casewts[i]) || (GLMCONTROL & BINOMDIST) && isMissing(logitn[i]) || USEGLMOFFSET && isMissing(glmoffset[i])) { if(nmissing == 0) { MISSWTS = (double **) mygethandle(ndata * sizeof(double)); if (MISSWTS == (double **) 0) { goto errorExit; } misswts = *MISSWTS; doubleFill(misswts, 1.0, ndata); casewts = (caseweights) ? *CASEWTS : (double *) 0; logitn = (GLMCONTROL & BINOMDIST) ? *LOGITN : (double *) 0; glmoffset = (USEGLMOFFSET) ? *GLMOFFSET : (double *) 0; } /*if(nmissing == 0)*/ if (misswts[i] != 0.0) { misswts[i] = 0.0; nmissing++; } } } /*for (i = 0; i < ndata; i++)*/ } /*if(caseweights || GLMCONTROL & BINOMDIST || USEGLMOFFSET)*/ if(nmissing > 0) { MODELTYPE |= MISSWEIGHTS; GLMCONTROL |= UNBALANCED; misswts = *MISSWTS; } /*if(nmissing > 0)*/ /* find the actual maximum factor levels included */ if (nfactors > 0) { for (j = 0; j < nvars; j++) { if (!isVariate(j)) { factorvar = *(X[j]); maxlevel = 0; for (i = 0;i < ndata; i++) { if (!isMissing(factorvar[i]) && factorvar[i] > maxlevel && (nmissing == 0 || misswts[i] > 0.0)) { maxlevel = factorvar[i]; } } /*for (i = 0;i < ndata; i++)*/ NCLASSES[j] = (long) maxlevel; } /*if (!isVariate(j))*/ } /*for (j = 0; j < nvars; j++)*/ } /*if (nfactors > 0)*/ if (nmissing > 0 && !silent) { putOutErrorMsg("WARNING: cases with missing values deleted"); } /* check for zero case weights, i.e., user specified weights */ if (caseweights) { casewts = *CASEWTS; misswts = (MODELTYPE & MISSWEIGHTS) ? *MISSWTS : (double *) 0; nzerowt = 0; for (i = 0; i < ndata; i++) { if ((!(MODELTYPE & MISSWEIGHTS) || misswts[i] > 0.0) && casewts[i] == 0) { nzerowt++; } } if (nzerowt != 0 && !silent) { putOutErrorMsg("WARNING: cases with zero weight completely removed"); } nmissing += nzerowt; } /*if (caseweights)*/ NOTMISSING = NDATA - nmissing; if(NOTMISSING == 0) { sprintf(OUTSTR, "ERROR: no non-missing cases with non-zero weight"); goto errorExit; } /* Check for possible Latin Square or other balanced main effect design for which balanced computation is appropriate In the future, we need code to recognize fractional factorials, confounded factorials, etc */ balanced = (!(GLMCONTROL & UNBALANCED) && !(MODELTYPE & FASTANOVA) && isBalanced(ONEWAYBALANCE)); if (balanced && nvars > 1) { if (anovaEffectsOnly(1)) { balanced = isBalanced(TWOWAYBALANCE); } else { balanced = isBalanced(COMPLETEBALANCE); } if (balanced < 0) { goto errorExit; } } /*if (balanced)*/ if(!balanced) { GLMCONTROL |= UNBALANCED; if (MODELTYPE & IPF) { MODELTYPE &= ~IPF; MODELTYPE |= POISSONREG; if(!silent) { putOutErrorMsg(ipfwarning); } } } /*if(!balanced)*/ /* check for incremental deviances specified by extra argument */ if (MODELTYPE & (ITERGLMS | IPF) && !INCREMENTAL && nargs > startKey && !isKeyword(COMPVALUE(list,nargs-1))) { INCREMENTAL = 1; } /* 990319 moved creation of side-effect variables DEPVNAME and TERMNAMES to glm() */ /* save dependent variable name */ needed = strlen(VARNAME(0)) + 1; DEPVNAME = mygethandle(needed); if(DEPVNAME == (char **) 0) { goto errorExit; } /* re-dereference name after memory allocation */ strcpy(*DEPVNAME, VARNAME(0)); /* Create TERMNAMES */ needed = makeTermNames(0); /* get space requirement */ TERMNAMES = mygethandle(needed); if (TERMNAMES == (char **) 0) { goto errorExit; } /* now fill in TERMNAMES */ (void) makeTermNames(needed); emptyTrash(); return (0); /* normal (no error) return */ /* NOTE: cleanup of globals is done in glm after error return */ errorExit: putErrorOUTSTR(); emptyTrash(); if(info != (modelInfoPointer) 0) { mydisphandle((char **) info->model); MODEL = info->model = (modelHandle) 0; } return (1); } /*getmodel()*/
void PorousFlowWaterNCG::thermophysicalProperties(Real pressure, Real temperature, Real /* Xnacl */, Real Z, unsigned int qp, std::vector<FluidStateProperties> & fsp) const { FluidStateProperties & liquid = fsp[_aqueous_phase_number]; FluidStateProperties & gas = fsp[_gas_phase_number]; // Check whether the input temperature is within the region of validity checkVariables(temperature); // Clear all of the FluidStateProperties data clearFluidStateProperties(fsp); FluidStatePhaseEnum phase_state; massFractions(pressure, temperature, Z, phase_state, fsp); switch (phase_state) { case FluidStatePhaseEnum::GAS: { // Set the gas saturations gas.saturation = 1.0; // Calculate gas properties gasProperties(pressure, temperature, fsp); break; } case FluidStatePhaseEnum::LIQUID: { // Calculate the liquid properties Real liquid_pressure = pressure - _pc.capillaryPressure(1.0, qp); liquidProperties(liquid_pressure, temperature, fsp); break; } case FluidStatePhaseEnum::TWOPHASE: { // Calculate the gas properties gasProperties(pressure, temperature, fsp); // Calculate the saturation saturationTwoPhase(pressure, temperature, Z, fsp); // Calculate the liquid properties Real liquid_pressure = pressure - _pc.capillaryPressure(1.0 - gas.saturation, qp); liquidProperties(liquid_pressure, temperature, fsp); break; } } // Liquid saturations can now be set liquid.saturation = 1.0 - gas.saturation; liquid.dsaturation_dp = -gas.dsaturation_dp; liquid.dsaturation_dT = -gas.dsaturation_dT; liquid.dsaturation_dZ = -gas.dsaturation_dZ; // Save pressures to FluidStateProperties object gas.pressure = pressure; liquid.pressure = pressure - _pc.capillaryPressure(liquid.saturation, qp); }