コード例 #1
0
ファイル: genome.cpp プロジェクト: nnoll523/IDB-Sim
population::population(int N_in, int L_in, double r_in, int seed_in, gsl_rng* rng_in, vector< vector<double> >& fit) {
    try {
        if (fit.size() != N_in || fit[0].size() != L_in) {throw "Incorrect Fitness Landscape dimensions!";}
        else if (r_in < 0 || r_in > 1 || N_in < 0 || L_in <0) {throw "Bad inputs. Check arguments.";}
        else {
            N = N_in;
            L = L_in;
            r = r_in;
            gen_pop = 0;
            neutral = false;
            avgFit = 0;
            selective_weight = vector<double>(N);
            genetic_weight = vector< vector<int> >(N,vector<int>(L));
            fixations = vector< vector<fixation_event> > (N);
            seed = seed_in ? seed_in : get_random_seed();
            rng = rng_in;
            gsl_rng_set(rng,seed);
            blockHist = gsl_histogram_alloc(L);
            gsl_histogram_set_ranges_uniform(blockHist,1,L+1); //Questionable range choice. As it stands now, the bins are partitioned as follows {[1,2),[2,3)......[L,L+1)}. Thus if all have length L, then average will come out to be (L+.5). Will have to rescale.
            map<int,double> genome_fit;
            for(int i=0;i<N;i++) {
                genome_fit = convert_vector_toMap(fit[i]);
                if (!genome_fit.empty()) {pop.push_back(genome(i, L, rng, genome_fit));}
                else {pop.push_back(genome(i,L,rng));}
                avgFit += pop[i].get_fit();
            }
            avgFit/=N;
            update_selection_weights();
            updateBlockSizes();
        }
    }
    catch (const char* Message) {
        cout << "Error:" << Message << "\n";
    }
}
コード例 #2
0
ファイル: genome.cpp プロジェクト: nnoll523/IDB-Sim
void population::evolve(int gen) { //Wright-Fisher Model - Population size is held constant. Parental genotypes are chosen randomly. 
    for (int j=0; j<gen; j++){
        vector<genome> newPop (N);
        avgFit = 0;
        for(int i=0; i<N; i++) {
            if (r == 1) {   
                newPop[i] = progeny(selectParents());
                avgFit += newPop[i].get_fit();
            }
            else if ((r != 0) && gsl_rng_uniform(rng) <= r) {
                newPop[i] = progeny(selectParents());
                avgFit += newPop[i].get_fit();
            }
            else {
                if (neutral) {newPop[i] = pop[(int)gsl_rng_uniform_int(rng,N)];}
                else {
                    double fit_rand = selective_weight[N-1]*gsl_rng_uniform(rng);
                    newPop[i] = pop[binarySearch_int(selective_weight, 0, N-1, fit_rand)];
                    avgFit += newPop[i].get_fit();
                }            
            }
        }
        avgFit/= N;
        pop = newPop;
        gen_pop++;
        update_weights();
        //updateBlockSizes();
        if (!neutral) {update_selection_weights();}
    }
    update_weights();
    updateBlockSizes();
    //if (WRITEHIST) {writeBlockHist();}
}
コード例 #3
0
ファイル: genome.cpp プロジェクト: nnoll523/IDB-Sim
//Overloaded Constructors
population::population(int N_in, int L_in, double r_in, int seed_in, gsl_rng* rng_in) { //Neutral Evolution!
    try {
        if (r_in < 0 || r_in > 1 || N_in < 0 || L_in <0) {throw "Bad inputs. Check arguments.";}
        else {
            N = N_in;
            L = L_in;
            r = r_in;
            gen_pop = 0;
            neutral = true;
            avgFit = 0;
            selective_weight = vector<double>(N); //All zeros
            genetic_weight = vector< vector<int> >(N,vector<int>(L));
            fixations = vector< vector<fixation_event> > (N);
            seed = seed_in ? seed_in:get_random_seed();
            rng = rng_in;
            gsl_rng_set(rng,seed);
            blockHist = gsl_histogram_alloc(L);
            gsl_histogram_set_ranges_uniform(blockHist,1,L+1);
            for(int i=0;i<N;i++) {
                pop.push_back(genome(i,L,rng));
            }
            updateBlockSizes();
        }
    }
    catch(const char* Message) {cout << "Error: " << Message << "\n";}
}
コード例 #4
0
//==========================================================================
//      Constructor and Destructor
//==========================================================================
SAFEParameter::SAFEParameter (String nameInit, float& valueRef, float initialValue, float minValueInit, float maxValueInit, String unitsInit, float skewFactorInit, bool convertDBToGainValue, double interpolationTimeInit, float UIScaleFactorInit)
    : outputValue (valueRef),
      convertToGain (convertDBToGainValue)
{
    name = nameInit;
    minValue = minValueInit;
    maxValue = maxValueInit;
    defaultValue = initialValue;
    skewFactor = skewFactorInit;
    units = unitsInit;

    interpolating = false;
    initialised = false;
    sampleRate = 44100;
    controlRate = 64;
    interpolationTime = interpolationTimeInit;
    updateBlockSizes();

    UIScaleFactor = UIScaleFactorInit;

    setScaledValue (defaultValue);
}
コード例 #5
0
void SAFEParameter::setInterpolationTime (double newInterpolationTime)
{
    interpolationTime = newInterpolationTime;
    updateBlockSizes();
}
コード例 #6
0
void SAFEParameter::setControlRate (double newControlRate)
{
    controlRate = newControlRate;
    updateBlockSizes();
}
コード例 #7
0
//==========================================================================
//      Smoothing Bits
//==========================================================================
void SAFEParameter::setSampleRate (double newSampleRate)
{
    sampleRate = newSampleRate;
    updateBlockSizes();
}