float getGain(const AttribueContainer& value, const ResultContainer& result, ConditionnalFunctor& func) { func.reset(); typename AttribueContainer::const_iterator ita = value.begin(); typename ResultContainer::const_iterator itr = result.begin(); typename ResultContainer::const_iterator itre = result.end(); while (itr != itre) { if (func()) { attribue_per_result_[*ita][*itr]++; attribue_value_total_[*ita]++; result_value_yes_[*itr]++; ++size_total_; } ++func; ++itr; ++ita; } result_ = entropy_ = getEntropy(result_value_yes_.begin(), result_value_yes_.end(), size_total_); typename AttribuePerResultMap::iterator it_yes = attribue_per_result_.begin(); typename AttribuePerResultMap::iterator it_yes_e = attribue_per_result_.end(); typename AttribueMap::iterator it_tot = attribue_value_total_.begin(); while (it_yes != it_yes_e) { result_ -= (it_tot->second / size_total_) * getEntropy(it_yes->second.begin(), it_yes->second.end(), it_tot->second); ++it_yes; ++it_tot; } return result_; }
void initYarrow(){ yarrow256_init(&WeakCtx,2,WeakSrc); yarrow256_init(&StrongCtx,2,StrongSrc); quint8 buffer[100]; for (int i=0; i<2; i++){ getEntropy(buffer,100); yarrowUpdateWeak(i,100*8,100,buffer); } }
double getMaxEntropy(Line line, int *start, int *end) { double max = 0.0; int s, e; for (s=0; s<line.length-1; s++) { for (e=s+1; e<line.length; e++) { double tempEp; tempEp = getEntropy(line, s, e); if (tempEp > max) { max = tempEp; *start = s; *end = e; } } } return max; }
int cspe::doAutoOverlap() { int found = 1; double _S = 0; int X[8] = {-1, 0, 1, -1, 1, -1, 0, 1}; int Y[8] = {-1, -1, -1, 0, 0, 1, 1, 1}; double aS[8]; while(found) { overlap(); getEntropy(); _S = S; for (int i = 0; i < 8; i++) { int _offset_x = offset_x; int _offset_y = offset_y; offset_x = offset_x + X[i]; offset_y = offset_y + Y[i]; overlap(); getEntropy(); aS[i] = S - _S; offset_x = _offset_x; offset_y = _offset_y; } //test local minima double sign = 0.125f * (aS[0]/abs(aS[0]) + aS[1]/abs(aS[1]) + aS[2]/abs(aS[2]) + aS[3]/abs(aS[3]) + aS[4]/abs(aS[4]) + aS[5]/abs(aS[5]) + aS[6]/abs(aS[6]) + aS[7]/abs(aS[7])); if (sign >= 0.95) { found = 0; break; } int pos = 0; double Smin = aS[pos]; for (int i = 1; i < 8; i++) { double tSmin = aS[i]; if (tSmin < Smin) { Smin = tSmin; pos = i; } } offset_x = offset_x + X[pos]; offset_y = offset_y + Y[pos]; /*getEntropy(); _S = S; for (int i = 0; i < 8; i++) { int _offset_x = offset_x; int _offset_y = offset_y; offset_x = offset_x + X[i]; offset_y = offset_y + Y[i]; overlap(); getEntropy(); aS[i] = S - _S; offset_x = _offset_x; offset_y = _offset_y; }*/ } return 0; }
int Analysis::writeData(Timing timing, double dt) { if (timing.check(dataOutputMoments, dt) ) { FA_Mom_Tp->write(getTemperatureParallel().data()); FA_Mom_HeatFlux->write(getHeatFlux().data()); FA_Mom_Density->write(getNumberDensity().data()); FA_Mom_Time->write(&timing); writeMessage("Data I/O : Moments output"); } if (timing.check(dataOutputStatistics, dt) ) { // Ugly and error-prone getPowerSpectrum(); Array2d pSpecX(Range(1, plasma->nfields), Range(0, Nx/2)); pSpecX(Range(1, plasma->nfields), Range(0, Nx/2)) = pSpec((int) DIR_X, Range(1, plasma->nfields), Range(0, Nx/2)); Array2d pSpecY(Range(1, plasma->nfields), Range(0, Nky)); pSpecY(Range(1, plasma->nfields), Range(0, Nky)) = pSpec((int) DIR_Y, Range(1, plasma->nfields), Range(0, Nky)); Array2d pPhaseX(Range(1, plasma->nfields), Range(0, Nx/2)); pPhaseX(Range(1, plasma->nfields), Range(0, Nx/2)) = pPhase((int) DIR_X, Range(1, plasma->nfields), Range(0, Nx/2)); Array2d pPhaseY(Range(1, plasma->nfields), Range(0, Nky)) ; pPhaseY(Range(1, plasma->nfields), Range(0, Nky)) = pPhase((int) DIR_Y, Range(1, plasma->nfields), Range(0, Nky)); FA_grow_x->write( pSpecX.data()); FA_grow_y->write( pSpecY.data()); FA_grow_t->write(&timing); FA_freq_x->write(pPhaseX.data()); FA_freq_y->write(pPhaseY.data()); FA_freq_t->write(&timing); // Heat Flux Array3d heatKy; heatKy.reference(getHeatFluxKy()); FA_heatKy->write(heatKy.data()); Array3d particleKy; particleKy.reference(getParticleFluxKy()); FA_particleKy->write(particleKy.data()); ScalarValues scalarValues; // calculate kineic Energy first, need for initial_e ! sum over sumdomains scalarValues.timestep = timing.step; scalarValues.time = timing.time; getFieldEnergy(scalarValues.phiEnergy, scalarValues.ApEnergy, scalarValues.BpEnergy); // Get scalar Values for every species for(int s = NsGlD; s <= NsGuD; s++) { scalarValues.particle_number[s-1] = getParticelNumber(s) ; scalarValues.entropy [s-1] = getEntropy(s) ; scalarValues.kinetic_energy [s-1] = getKineticEnergy(s) ; scalarValues.particle_flux [s-1] = getTotalParticleFlux(s) ; scalarValues.heat_flux [s-1] = getTotalHeatFlux(s) ; } SVTable->append(&scalarValues); // write out to Terminal/File std::stringstream messageStream; messageStream << "Step : " << scalarValues.timestep << " Time " << scalarValues.time << " Field : (phi)" << scalarValues.phiEnergy << " (Ap)" << scalarValues.ApEnergy << " (Bp) " << scalarValues.BpEnergy << std::endl; double charge = 0., kinetic_energy=0.; for(int s = NsGlD; s <= NsGuD; s++) { messageStream << plasma->species(s).name << " N :" << scalarValues.particle_number[s-1] << " Kinetic Energy : " << scalarValues.kinetic_energy[s-1] ; messageStream << " Particle Flux :" << scalarValues.particle_flux[s-1] << " Heat Flux : " << scalarValues.heat_flux[s-1] << std::endl; charge += plasma->species(s).q * scalarValues.particle_number[s-1]; kinetic_energy += scalarValues.kinetic_energy[s-1]; } messageStream << std::endl << "------------------------------------------------------------------" << std::endl << "Total Energy " << kinetic_energy+scalarValues.phiEnergy + scalarValues.ApEnergy + scalarValues.BpEnergy << " Total Charge = " << ((plasma->species(0).n0 != 0.) ? 0. : charge) << std::endl; parallel->print(messageStream); } return HELIOS_SUCCESS; }
float getGain(int parent, int S, int attribute, int values[LENGTH][LENGTH], int nvalues, int nattributes, att * test) { attnode * curr; attnode * curr2; float entropy; float entropy2; float sum=0; int denominator; //=positiveValues(S, S, values, nvalues, nattributes, test)+negativeValues(S, S, values, nvalues, nattributes, test); int numerator; float gain; int positive; int negative; entropy=getEntropy(parent, S, values, nvalues, nattributes, test); //printf("ooh yas %lf\n", entropy); curr=test->head; while(curr!=NULL) { if(curr->equivalent==S) { break; } curr=curr->next; } if(S==0) { positive=positiveValues(S, S, values, nvalues, nattributes, test); negative=negativeValues(S, S, values, nvalues, nattributes, test); } else { updatePosNeg(parent, S, values, nvalues, nattributes, test); positive=curr->positivetracker; negative=curr->negativetracker; } denominator=positive+negative; curr=test->head; while(curr!=NULL) { if(curr->equivalent==attribute) { //printf("Found curr: %s %d %d %d\n", curr->attname, curr->x, curr->y, curr->equivalent); break; } curr=curr->next; } curr2=curr->next; while(curr2!=NULL) { if(curr2->y==curr->y) { //printf("Found curr2: %s %d %d %d\n", curr2->attname, curr2->x, curr2->y, curr2->equivalent); entropy2=getEntropy(S, curr2->equivalent, values, nvalues, nattributes, test); //printf("Entropy: %lf\n", entropy2); if (entropy2!=0) { if(S==0) { positive=positiveValues(S, curr2->equivalent, values, nvalues, nattributes, test); negative=negativeValues(S, curr2->equivalent, values, nvalues, nattributes, test); } else { updatePosNeg(S, curr2->equivalent, values, nvalues, nattributes, test); positive=curr2->positivetracker; negative=curr2->negativetracker; } numerator=positive+negative; //positiveValues(S, curr2->equivalent, values, nvalues, nattributes, test)+negativeValues(S, curr2->equivalent, values, nvalues, nattributes, test); //printf("Numerator: %d\n", numerator); //printf("Denominator: %d\n", denominator); sum+=(float)numerator/denominator*entropy2; printf("Gain+=%d/%d * %lf\n", numerator, denominator, entropy2); //printf("Sum ryt nao: %lf\n", sum); } } curr2=curr2->next; } gain=entropy-sum; printf("Gain: %lf\n", gain); return gain; }