Exemplo n.º 1
0
//Computes the updated state of the system. Is called from the process function.
//This performs state space interpolation to calculate the state of the
//channel. 
//When a value of Vm_ and ligandConc_ is provided, we find the 4 matrix
//exponentials that are closest to these values, and then calculate the 
//states at each of these 4 points. We then interpolate between these
//states to calculate the final one.
//In case all rates are 1D, then, the above-mentioned interpolation is
//only one-dimensional in nature.
void MarkovSolverBase::computeState( )
{
	Vector* newState;
	bool useBilinear = false, useLinear = false;

	if ( rateTable_->areAnyRates2d() || 
			( rateTable_->areAllRates1d() && 
 			  rateTable_->areAnyRatesVoltageDep() && 
			  rateTable_->areAnyRatesLigandDep() 
			)  )
	{
		useBilinear = true;
	}
	else if ( rateTable_->areAllRatesVoltageDep() ||
						rateTable_->areAllRatesLigandDep() )
	{
		useLinear = true;
	}

	//Heavily borrows from the Interpol2D::interpolate function.
	if ( useBilinear ) 
		newState = bilinearInterpolate();
	else
		newState = linearInterpolate();

	state_ = *newState;

	delete newState;
}
double smooth_noiseBilinear(Vector2D p,int seed){
    double x;
    double y;
    double fractional_x;
    double fractional_y;
    int integer_x;
    int integer_y;
    if(p.x()>=0){
        x=p.x();
        integer_x = (int)x;
        fractional_x = x - integer_x;
    }
    else{
        integer_x=((int)p.x())-1;
        fractional_x=p.x()-integer_x;

    }

    if(p.y()>=0){
        y=p.y();
        integer_y = (int)y;
        fractional_y = y - integer_y;
    }
    else{
        integer_y=((int)p.y())-1;
        fractional_y=p.y()-integer_y;

    }
        Vector2D pf(fractional_x,fractional_y);
        double xy = noise(integer_x,integer_y,seed);
        double x1y = noise(integer_x+1,integer_y,seed);
        double xy1 = noise(integer_x,integer_y+1,seed);
        double x1y1 = noise(integer_x+1,integer_y+1,seed);

        return bilinearInterpolate(xy,x1y,xy1,x1y1,pf);
}