returnValue ExportIRK4StageSimplifiedNewton::setTransformations( const DMatrix& _transf1, const DMatrix& _transf2 ) {
    transf1 = _transf1;
    transf2 = _transf2;

    if( _transf1.getNumRows() != 4 || _transf1.getNumCols() != 4 ) return ACADOERROR( RET_INVALID_ARGUMENTS );
    if( _transf2.getNumRows() != 4 || _transf2.getNumCols() != 4 ) return ACADOERROR( RET_INVALID_ARGUMENTS );
    if( _transf1.isZero() || _transf2.isZero() ) return ACADOERROR( RET_INVALID_ARGUMENTS );

    return SUCCESSFUL_RETURN;
}
Exemple #2
0
VariablesGrid::VariablesGrid(	const DMatrix& arg,
								VariableType _type
								) : MatrixVariablesGrid( arg.getNumCols()-1,1,arg.getNumRows(),_type )
{
	uint i,j;

	for( i=0; i<arg.getNumRows(); ++i )
	{
		setTime( i,arg( i,0 ) );

		for( j=1; j<arg.getNumCols(); ++j )
			operator()( i,j-1 ) = arg( i,j );
	}
}
Exemple #3
0
returnValue ModelData::setNARXmodel( const uint _delay, const DMatrix& _parms ) {

	if( rhs_name.empty() && NX2 == 0 && NX3 == 0 ) {
		NX2 = _parms.getNumRows();
		delay = _delay;
		uint numParms = 1;
		uint n = delay*getNX();
		if( delay >= 1 ) {
			numParms = numParms + n;
		}
		for( uint i = 1; i < delay; i++ ) {
			numParms = numParms + (n+1)*(uint)pow((double)n,(int)i)/2;
		}
		if( _parms.getNumCols() == numParms ) {
			parms = _parms;
		}
		else {
			return ACADOERROR( RET_UNABLE_TO_EXPORT_CODE );
		}

		export_rhs = BT_TRUE;
	}
	else {
		return ACADOERROR( RET_INVALID_OPTION );
	}
	return SUCCESSFUL_RETURN;
}
returnValue ExportIRK4StageSimplifiedNewton::setEigenvalues( const DMatrix& _eig ) {
    eig = _eig;

    if( _eig.getNumRows() != 2 || _eig.getNumCols() != 2 ) return ACADOERROR( RET_INVALID_ARGUMENTS );
    if( _eig.isZero() ) return ACADOERROR( RET_INVALID_ARGUMENTS );
    // each row represents a complex conjugate pair of eigenvalues

    return SUCCESSFUL_RETURN;
}
Exemple #5
0
returnValue WeightGeneration::generateWeights( const  int    &n         ,
                                               DVector        &weight    ,
                                               DMatrix        &Weights   ,
                                               const  DVector &weightsLB ,
                                               const  DVector &weightsUB ,
                                               DVector        &formers   ,
                                               const int     &layer     ,
                                               int           &lastOne   ,
                                               int           &currentOne,
                                               double        &step
                                             ) const{


   int run1, run2;

    if( n == layer ){

        //printf("case1:  n = %d  layer = %d  \n", n, layer );

        double weight_test = 1.0;
        for( run1 = 0; run1 < (int) weight.getDim()-1; run1++ )
            weight_test -= weight(run1);

        if( ( weight_test >= weightsLB(layer) - 100.0*EPS ) &&
            ( weight_test <= weightsUB(layer) + 100.0*EPS )    ){

            if( currentOne >= 0 ){

                DVector tmp( formers.getDim()+1 );

                for( run1 = 0; run1 < (int) formers.getDim(); run1++ )
                    tmp(run1) = formers(run1);

                tmp(formers.getDim()) = lastOne;
                formers = tmp;
                lastOne = currentOne;
                currentOne = -1;
            }
            else{

                DVector tmp( formers.getDim()+1 );

                for( run1 = 0; run1 < (int) formers.getDim(); run1++ )
                    tmp(run1) = formers(run1);

                tmp(formers.getDim()) = Weights.getNumCols();
                formers = tmp;
            }

             weight(n) = weight_test;

             DMatrix tmp( weight.getDim(), Weights.getNumCols()+1 );

             for( run1 = 0; run1 < (int) Weights.getNumRows(); run1++ ){
                 for( run2 = 0; run2 < (int) Weights.getNumCols(); run2++ )
                     tmp(run1,run2) = Weights(run1,run2);
             }

             for( run2 = 0; run2 < (int) weight.getDim(); run2++ )
                     tmp(run2,Weights.getNumCols()) = weight(run2);

             Weights = tmp;
        }
    }
    else{

        //printf("case2:  n = %d  layer = %d  \n", n, layer );

        double weight_test = weightsLB(n);

        while( weight_test <= weightsUB(n) + 100.0*EPS ){

            if( n == layer-2 ) currentOne = Weights.getNumCols()+1;

            weight(n) = weight_test;

            WeightGeneration child;
            child.generateWeights( n+1, weight, Weights, weightsLB, weightsUB, formers, layer, lastOne, currentOne, step );

            weight_test += (weightsUB(n)-weightsLB(n))*step;
        }
    }

    return SUCCESSFUL_RETURN;
}