void GeneManager::newGene(int growthSeg,int growthTurns,int maturedDuration,int decayTurns,int maxExpressedTraits, int decaySeed,int maturedSeed, int prob_in_exp, int prob_in_unexp, int prob_exp_exp, int prob_exp_unexp, int prob_mutation, int m_growthSeg,int m_growthTurns, int m_maturedDuration, int m_decayTurns, int m_maxExpressedTraits, int m_decaySeed, int m_maturedSeed) { _genes.push_back(new Gene( _genes.size(), SeedAttribute(growthSeg,growthTurns,maturedDuration,decayTurns,maxExpressedTraits,decaySeed,maturedSeed), // Attribute contribution Probability(prob_in_exp), // Prob inherited if expressed Probability(prob_in_unexp), // Prob inherited if unexpressed Probability(prob_exp_exp), // Prob expressed if expressed Probability(prob_exp_unexp), // Prob expressed if unexpressed Mutation(Probability(prob_mutation),SeedAttribute(m_growthSeg,m_growthTurns,m_maturedDuration,m_decayTurns,m_maxExpressedTraits,m_decaySeed,m_maturedSeed)) // Mutation possibility )); }
void Probability(int original, int current, int sum, int* pProbabilities) { if(current == 1) { pProbabilities[sum - original]++; } else { for(int i = 1; i <= g_maxValue; ++i) { Probability(original, current - 1, i + sum, pProbabilities); } } }
/* returns the natural log of the probability P(X,Y) = P(X | Y) * P(Y) where X = INSTANCE and Y = OUTPUT_VALUE. Note that, because of the Naive Bayes assumption, P(X | Y) is approximated by the product over all P(X_i | Y) or the sum of their logs. */ ProbabilityLn NBClassifier::joint_prob_ln(DataInstance::PtrConst _instance, Observation _output_value) const { JointDistTable::Ptr joint_dist; Observation in_val; Probability p; /* initialized with a probability of 1.0; ln(1.0) = 0 */ ProbabilityLn p_ln(1.0); /* iterate over the joint probability distribution of each variable, compute the variable's conditional probability P(X_i | Y), and add it's log into p_ln. */ for (uint32_t dist_idx = 0; dist_idx < joint_dist_.size(); ++dist_idx) { /* joint probability distribution for variable X_i */ joint_dist = joint_dist_[dist_idx]; /* input value X_i in INSTANCE */ in_val = _instance->inputObservation(dist_idx); /* Probability p = P(X_i | Y) */ p = joint_dist->inputConditional(in_val, _output_value); /* if p is equal to 0.0, the entire product will be equal to zero. */ if (p == Probability(0.0)) { /* log of zero is -Inf or DOUBLE_MIN */ p_ln = ProbabilityLn(p); break; } /* increment P_LN by ln(P) */ p_ln += ProbabilityLn(p); } /* P_LN is currently equal to the sum of the natural logs of P(X_i | Y) for all i. Increment P_LN by the log of the marginal probability of Y. */ p = joint_dist->outputMarginal(_output_value); p_ln += ProbabilityLn(p); return p_ln; }
void PrintProbability_Solution1(int number) { if(number < 1) return; int maxSum = number * g_maxValue; int* pProbabilities = new int[maxSum - number + 1]; for(int i = number; i <= maxSum; ++i) pProbabilities[i - number] = 0; Probability(number, pProbabilities); int total = pow((double)g_maxValue, number); for(int i = number; i <= maxSum; ++i) { double ratio = (double)pProbabilities[i - number] / total; printf("%d: %e\n", i, ratio); } delete[] pProbabilities; }
void GMM<FittingType>::Classify(const arma::mat& observations, arma::Col<size_t>& labels) const { // This is not the best way to do this! // We should not have to fill this with values, because each one should be // overwritten. labels.set_size(observations.n_cols); for (size_t i = 0; i < observations.n_cols; ++i) { // Find maximum probability component. double probability = 0; for (size_t j = 0; j < gaussians; ++j) { double newProb = Probability(observations.unsafe_col(i), j); if (newProb >= probability) { probability = newProb; labels[i] = j; } } } }
/** * Evaluate log probability density function of given observation * * @param observation point to evaluate log probability at */ double LogProbability(const arma::vec& observation) const { return log(Probability(observation)); }
int main(int argc, const char * argv[]) { srand ((unsigned int)time(NULL)); time_t t; Probability p = Probability(); while(1) { double winProb, tieProb; memset(p.pool, 0, sizeof(p.pool)); p.getHoldCard2(); //------------------flop------------------ p.getCommunityCard3(); p.showCards(2); t = clock(); p.calculateProb(2, winProb, tieProb, true); printf("sample:: win: %.2f%% tie: %.2f%%\n", winProb*100, tieProb*100); /* double probs[10]; p.calculateProbForTypes(2, probs); for (int i = 0; i < TYPENUM; i++) { if (probs[i] > ESP) printf("%9.4f :", probs[i]); else printf(" NULL :"); cout << levelName[i] << endl; } double rank = 0; for (int i = 0; i < 10; i++) { rank += levelRank[i] * probs[i]; } cout << "rank = " << rank << endl; p.calculateProb(2, winProb, tieProb); printf("win: %.4f tie: %.4f\n", winProb, tieProb); */ printf("exec time = %fs\n", (double)(clock() - t) / CLOCKS_PER_SEC); double winProb0 = winProb, tieProb0 = tieProb; t = clock(); p.calculateProb(2, winProb, tieProb, false); printf("non-sample:: win: %.2f%% tie: %.2f%%\n", winProb*100, tieProb*100); printf("exec time = %fs\n", (double)(clock() - t) / CLOCKS_PER_SEC); printf("\nDIFFERENCE: win: %.2f%% tie: %.2f%%\n\n", (winProb0 - winProb)*100, (tieProb0 - tieProb)*100); //------------------turn------------------ p.getTurnCard1(); p.showCards(3); t = clock(); p.calculateProb(3, winProb, tieProb, false); printf("win: %.2f%% tie: %.2f%%\n", winProb*100, tieProb*100); printf("exec time = %fs\n", (double)(clock() - t) / CLOCKS_PER_SEC); //------------------river------------------ p.getRiverCard1(); p.showCards(4); t = clock(); p.calculateProb(4, winProb, tieProb, false); printf("win: %.2f%% tie: %.2f%%\n", winProb*100, tieProb*100); printf("exec time = %fs\n", (double)(clock() - t) / CLOCKS_PER_SEC); getchar(); } return 0; }
/** * Return the log probability of the given observation. If the observation is * greater than the number of possible observations, then a crash will * probably occur -- bounds checking is not performed. * * @param observation Observation to return the log probability of. * @return Log probability of the given observation. */ double LogProbability(const arma::vec& observation) const { // TODO: consider storing log_probabilities instead return log(Probability(observation)); }
Probability RBBM_radius::ProbabilityGet(const vector<ColumnVector>& meas) const { #ifndef NDEBUG cout << "(RBBM_radius::ProbabilityGet) entered " << endl; #endif Probability prob = 1.0; Probability probOne = 1.0; Probability probLoc = 1.0; ColumnVector meas1(1); int beam; int beamMiddle; // Calculate the ideal measurements this->CalculateZstars(); // independent beams assumed for(int i=0; i<meas[1].size();i++) { meas1 = meas[0](i+1); // middle beam beamMiddle = (int)(meas[1](i+1) / M_PI *(double)(_nbeams-1)) ; double weight = 0.0; probOne = 0.0; beam = beamMiddle; _beamModels[beam]->ZstarSet(_zstars(beam+1)); probLoc=_beamModels[beam]->ProbabilityGet(meas1); weight += 0.6; probOne=probOne+ 0.6*probLoc; beam = beamMiddle-3; if(beam> -1 && beam<_nbeams) { _beamModels[beam]->ZstarSet(_zstars(beam+1)); probLoc=_beamModels[beam]->ProbabilityGet(meas1); weight += 0.01; probOne=probOne+ 0.01*probLoc; } beam = beamMiddle-2; if(beam> -1 && beam<_nbeams) { _beamModels[beam]->ZstarSet(_zstars(beam+1)); probLoc=_beamModels[beam]->ProbabilityGet(meas1); weight += 0.04; probOne=probOne+ 0.04*probLoc; } beam = beamMiddle-1; if(beam> -1 && beam<_nbeams) { _beamModels[beam]->ZstarSet(_zstars(beam+1)); probLoc=_beamModels[beam]->ProbabilityGet(meas1); weight += 0.15; probOne=probOne+ 0.15*probLoc; } beam = beamMiddle+1; if(beam> -1 && beam<_nbeams) { _beamModels[beam]->ZstarSet(_zstars(beam+1)); probLoc=_beamModels[beam]->ProbabilityGet(meas1); weight += 0.15; probOne=probOne+ 0.15*probLoc; } beam = beamMiddle+2; if(beam> -1 && beam<_nbeams) { _beamModels[beam]->ZstarSet(_zstars(beam+1)); probLoc=_beamModels[beam]->ProbabilityGet(meas1); weight += 0.04; probOne=probOne+ 0.04*probLoc; } beam = beamMiddle+3; if(beam> -1 && beam<_nbeams) { _beamModels[beam]->ZstarSet(_zstars(beam+1)); probLoc=_beamModels[beam]->ProbabilityGet(meas1); weight += 0.01; probOne=probOne+ 0.01*probLoc; } prob = prob * Probability((double)probOne / weight); // cout<< "prob measurement " << i << " " << (double)probOne / weight<< endl; } #ifndef NDEBUG cout<< "prob " << prob << endl; cout << "(RBBM_radius::ProbabilityGet) finished " << endl; #endif return prob; }
void Probability(int number, int* pProbabilities) { for(int i = 1; i <= g_maxValue; ++i) Probability(number, number, i, pProbabilities); }
double Probability (int id) { next_random_number = id; return (Probability ()); }
int Percent (void) { return ((int) (Probability () * 100.0 + 0.5)); }
Probability SVCollider::floatToProbability(const float val) { float tmp = (val * (float(MAX_PROBABILITY) - float(MIN_PROBABILITY))) + MIN_PROBABILITY; return Probability(tmp); }