Beispiel #1
0
static void mdlStart(SimStruct *S)
{
    ParStruc    *Par    = malloc(sizeof *Par); /* Wavenet's parameters */
    #if defined(MATLAB_MEX_FILE)
    int_T       *Ir     = ssGetJacobianIr(S);
    int_T       *Jc     = ssGetJacobianJc(S);
    #endif
        
   if (Par == NULL){
       free(Par);
       ssSetErrorStatus(S, "Could not allocate data cache memory.");
       return;
   }
    
	/* Populate Parameters */
    Par->NumberOfUnits      =   (uint_T) mxGetScalar(NUMUNITS(S));
    /*Par->BreakPoints        =   mxGetData(PAR_BREAKPOINTS(S));*/
    Par->LinearCoef         =   mxGetData(PAR_LINEARCOEF(S));
    Par->OutputOffset       =   mxGetScalar(PAR_OUTPUTOFFSET(S));
    Par->OutputCoef         =   mxGetData(PAR_OUTPUTCOEF(S));
    Par->Translation        =   mxGetData(PAR_TRANSLATION(S));    
    
    /* dimensions */
    Par->DimXlin            =   (uint_T) mxGetM(PAR_LINEARCOEF(S));
    
    /* Set the cached data into the user data area for 'this' block. */
    ssSetUserData(S, Par);
  
    /* Finish the initialization */
    mdlProcessParameters(S);
    
    #if defined(MATLAB_MEX_FILE)
    /* Jacobian (dy/dR, R:=regressors) set up */
    /* If linearization is disabled, we'll have no storage */
    if ((Ir == NULL) || (Jc == NULL)) return;
    /* DimInp = 1 for PWLINEAR */
     Ir[0] = 0;
     Jc[0] = 0;
    
    #endif
}
Beispiel #2
0
static void mdlStart(SimStruct *S)
{
    ParStruc    *Par    = malloc(sizeof *Par); /* Tree Partition's parameters */
    TreeStruc   *Tree   =  malloc(sizeof *Tree); /* struct for Parameters.Tree struct */
    #if defined(MATLAB_MEX_FILE)
    int_T       *Ir     = ssGetJacobianIr(S);
    int_T       *Jc     = ssGetJacobianJc(S);
    int_T       k;
    #endif
    
    /* for some reason, dim is one more than num reg (Anatoli would know why) */
    uint_T      DimInp  = (uint_T) mxGetScalar(NUMREG(S))+1;
    boolean_T   IsLinear= (boolean_T) mxIsEmpty(TREE_TREELEVELPNTR(S));
	uint_T  MaxLvl = 0;
    
   if ((Tree == NULL) || (Par == NULL)){
       free(Tree);
       free(Par);
       ssSetErrorStatus(S, "Could not allocate data cache memory.");
       return;
   }
    
	/* Populate Parameters */
    Par->NumberOfUnits  = (uint_T) mxGetScalar(NUMUNITS(S));
    Par->Threshold      = mxGetScalar(OPT_THRESHOLD(S));
    Par->RegressorMean  = mxGetData(PAR_REGRESSORMEAN(S));
    Par->OutputOffset   = mxGetScalar(PAR_OUTPUTOFFSET(S));
    Par->LinearCoef     = mxGetData(PAR_LINEARCOEF(S));
    Par->SampleLength   = (uint_T) mxGetScalar(PAR_SAMPLELENGTH(S));
    Par->NoiseVariance  = mxGetScalar(PAR_NOISEVARIANCE(S));
    Par->IsLinear           = IsLinear;

    /* Populate Tree */
    if (!IsLinear){
        Tree->TreeLevelPntr = mxGetData(TREE_TREELEVELPNTR(S));
        MaxLvl = (uint_T) Tree->TreeLevelPntr[Par->NumberOfUnits-1];
        Tree->AncestorDescendantPntr = mxGetData(TREE_ANCESTORDESCENDANTPNTR(S));
        Tree->LocalizingVectors = mxGetData(TREE_LOCALIZINGVECTORS(S));
        Tree->LocalCovMatrix = mxGetData(TREE_LOCALCOVMATRIX(S));
        Tree->LocalParVector = mxGetData(TREE_LOCALPARVECTOR(S));
        
        /* allocate memory for temporary arrays required by evaluate_treepartition */
        Par->ttv    = (real_T *) malloc(DimInp*sizeof(real_T));
        Par->ttm    = (real_T *) malloc(DimInp*DimInp*sizeof(real_T));
        Par->lfmax  = (real_T *) malloc(MaxLvl*sizeof(real_T));
        Par->lfmin  = (real_T *) malloc(MaxLvl*sizeof(real_T));
        
        /* Memory allocation error checking */
        if ( (Par->ttv == NULL) || (Par->ttm == NULL) ||
        (Par->lfmax == NULL) || (Par->lfmin == NULL) )
        {
            free(Tree);
            free(Par);
            ssSetErrorStatus(S, "Could not allocate data cache memory.");
            return;
        } /* Error checking complete */
        
    }	
		
	Par->Tree = Tree;   
    
    /* Set the cached data into the user data area for 'this' block. */
    ssSetUserData(S, Par);
  
    /* Finish the initialization */
    mdlProcessParameters(S);
    
    #if defined(MATLAB_MEX_FILE)
    /* Jacobian (dy/dR, R:=regressors) set up */
    /* If linearization is disabled, we'll have no storage */
    if ((Ir == NULL) || (Jc == NULL)) return;
    for (k = 0; k < DimInp-1; k++) {
        Ir[k] = 0;
        Jc[k] = k;
    }
    #endif
}