Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Refactoring batchlan; did a few more cases and fixed compilation issues

  • Loading branch information...
commit eb95dded1d6f693d47b3415f55f1553ad0694395 1 parent 45de7bf
@spond spond authored
View
96 src/core/batchlan.cpp
@@ -1537,13 +1537,10 @@ _String blFor ("for("), // moved
blInclude ("#include"), // moved
blDataSet ("DataSet "), // moved
blDataSetFilter ("DataSetFilter "),
- blHarvest ("HarvestFrequencies"),
blConstructCM ("ConstructCategoryMatrix("),
blTree ("Tree "),
blLF ("LikelihoodFunction "),
blLF3 ("LikelihoodFunction3 "),
- blOptimize ("Optimize("),
- blCovMatrix ("CovarianceMatrix("),
blMolClock ("MolecularClock("),
blfprintf ("fprintf("),
blGetString ("GetString("),
@@ -2446,7 +2443,7 @@ BaseRef _ElementaryCommand::toStr (void)
result = result& _String(" using the callback: ")&(*converted);
break;
}
- case 49: { //Compute LF
+ case HY_HBL_COMMAND_LFCOMPUTE: { //Compute LF
converted = (_String*)parameters(0)->toStr();
result = blLFCompute&(*converted);
DeleteObject(converted);
@@ -5962,93 +5959,6 @@ void _ElementaryCommand::ExecuteCase47 (_ExecutionList& chain)
}
}
-//____________________________________________________________________________________
-
-void _ElementaryCommand::ExecuteCase49 (_ExecutionList& chain)
-{
- chain.currentCommand++;
-
- _String *arg1 = (_String*)parameters(0),
- *arg2 = (_String*)parameters(1),
- name2Find = AppendContainerName(*arg1,chain.nameSpacePrefix),
- errMsg;
-
- // bool isSCFG = false;
-
-
- long k = FindLikeFuncName(name2Find),
- mode = 0;
-
- if (k < 0) {
- mode = ((k = FindSCFGName(name2Find)) >= 0) ? 1 : 2;
- if (mode == 2) {
- k = FindBgmName(name2Find);
- }
- }
-
- if (k < 0) {
- _String litArg = ProcessLiteralArgument (arg1,chain.nameSpacePrefix);
- k = likeFuncNamesList.Find (&litArg);
- if (k<0) {
- k = scfgNamesList.Find (&litArg);
- if (k<0) {
- k = bgmNamesList.Find (&litArg);
- if (k < 0) {
- errMsg = *arg1 & " is not an existing likelihood function, SCFG, or BGM identifier ";
- } else {
- mode = 2;
- }
- } else {
- mode = 1;
- }
- } else {
- mode = 0;
- }
- }
-
- if (errMsg.sLength == 0) {
- _LikelihoodFunction *lf;
- switch (mode) {
- case 0:
- lf = (_LikelihoodFunction *) likeFuncList (k);
- break;
- case 1:
- lf = (_LikelihoodFunction *) scfgList (k);
- break;
- case 2:
- lf = (_LikelihoodFunction *) bgmList (k);
- break;
- default:
- errMsg = "Something really weird just happened in ExecuteCase49()...";
- break;
- }
-
- // _LikelihoodFunction *lf = (_LikelihoodFunction*)(isSCFG?scfgList(k):likeFuncList (k));
- if (*arg2 == lfStartCompute) {
- lf->PrepareToCompute(true);
- } else if (*arg2 == lfDoneCompute) {
- lf->DoneComputing (true);
- } else {
- if (!lf->HasBeenSetup()) {
- errMsg = _String("Please call LFCompute (lf_id, ")&lfStartCompute&") before evaluating the likelihood function";
- } else {
- _Variable* rec = CheckReceptacle(&AppendContainerName(*arg2,chain.nameSpacePrefix), blLFCompute, true);
- if (!rec) {
- return;
- }
- rec->SetValue(new _Constant (lf->Compute()),false);
- }
- }
- }
-
- if (errMsg.sLength) {
- errMsg = errMsg & " in call to LFCompute.";
- WarnError (errMsg);
- }
-
- //setParameter (matrixEvalCount, matrixExpCount);
-}
-
//____________________________________________________________________________________
@@ -6785,8 +6695,8 @@ bool _ElementaryCommand::Execute (_ExecutionList& chain) // perform this
ExecuteCase43 (chain);
break;
- case 49:
- ExecuteCase49 (chain);
+ case HY_HBL_COMMAND_LFCOMPUTE:
+ HandleComputeLFFunction(chain);
break;
case 50:
View
8 src/core/batchlan2.cpp
@@ -4035,7 +4035,7 @@ _String _HYHBLTypeToText (long type) {
//____________________________________________________________________________________
-BaseRef _HYRetrieveBLObjectByName (_String& name, long& type, long *index, bool errMsg)
+BaseRef _HYRetrieveBLObjectByName (_String& name, long& type, long *index, bool errMsg, bool tryLiteralLookup)
{
long loc = -1;
if (type & HY_BL_DATASET) {
@@ -4117,10 +4117,16 @@ BaseRef _HYRetrieveBLObjectByName (_String& name, long& type, long *index, bo
return batchLanguageFunctions (loc);
}
}
+
+ if (tryLiteralLookup) {
+ _String nameIDRef = ProcessLiteralArgument(&name, nil);
+ return _HYRetrieveBLObjectByName (nameIDRef, type, index, errMsg, false);
+ }
if (errMsg) {
WarnError (_String ("'") & name & "' does not refer to an existing object of type " & _HYHBLTypeToText (type));
}
+ type = HY_BL_NOT_DEFINED;
return nil;
}
View
224 src/core/batchlanruntime.cpp
@@ -89,7 +89,7 @@ bool _ElementaryCommand::HandleHarvestFrequencies (_ExecutionList& currentP
//____________________________________________________________________________________
-bool _ElementaryCommand::HandleOptimizeCovaruanceMatrix (_ExecutionList& currentProgram, bool doOptimize) {
+bool _ElementaryCommand::HandleOptimizeCovarianceMatrix (_ExecutionList& currentProgram, bool doOptimize) {
currentProgram.currentCommand++;
// construct the receptacle matrix
@@ -106,168 +106,120 @@ bool _ElementaryCommand::HandleOptimizeCovaruanceMatrix (_ExecutionList& cu
long objectType = HY_BL_LIKELIHOOD_FUNCTION|HY_BL_SCFG|HY_BL_BGM;
_LikelihoodFunction *lkf = (_LikelihoodFunction*)_HYRetrieveBLObjectByName (lfNameID, objectType,nil,doOptimize==false);
+ _Matrix * optRes;
- _Matrix * optRes;
-
- if (lkf == nil) {
+ if (lkf == nil) { // will only happen if the object is a custom function
lkf = (_LikelihoodFunction*)checkPointer(new _CustomFunction (&lfNameID));
}
+
if (!doOptimize) {
// COVARIANCE_MATRIX
+ SetStatusLine (_String("Finding the cov. matrix/profile CI for ")&lfNameID);
_String cpl = currentProgram.AddNameSpaceToID(covarianceParameterList);
_Variable * restrictVariable = FetchVar (LocateVarByName(cpl));
_SimpleList * restrictor = nil;
- if (restrictVariable) { // only consider some variables
- _SimpleList variableIDs;
- if (restrictVariable->ObjectClass () == ASSOCIATIVE_LIST)
- // a list of variables stored as keys in an associative array
- {
- checkPointer (restrictor = new _SimpleList);
- _List* restrictedVariables = ((_AssociativeList *)restrictVariable->GetValue())->GetKeys();
- for (long iid = 0; iid < restrictedVariables->lLength; iid++) {
- variableIDs << LocateVarByName (currentProgram.AddNameSpaceToID(*(_String*)(*restrictedVariables)(iid)));
- }
- } else if (restrictVariable->ObjectClass () == STRING)
- // a single variable stored in a string
- {
- _String varID = currentProgram.AddNameSpaceToID(*((_FString*)restrictVariable->Compute())->theString);
- long vID = LocateVarByName (varID);
- if (vID >= 0) {
- vID = lkf->GetIndependentVars().Find(vID);
- }
- if (vID >= 0) {
- checkPointer(restrictor = new _SimpleList (vID));
- }
- }
- if (variableIDs.lLength > 0) {
- checkPointer(restrictor = new _SimpleList ());
- for (long var_index = 0; var_index < variableIDs.lLength; var_index++) {
- long vID = lkf->GetIndependentVars().Find(variableIDs.lData[var_index]);
- if (vID >= 0) (*restrictor) << vID;
- }
- if (restrictor->lLength == 0) {
- DeleteObject (restrictor);
- restrictor = nil;
+ if (objectType == HY_BL_LIKELIHOOD_FUNCTION || objectType == HY_BL_SCFG){
+ // not a BGM
+ if (restrictVariable) { // only consider some variables
+ _SimpleList variableIDs;
+ if (restrictVariable->ObjectClass () == ASSOCIATIVE_LIST)
+ // a list of variables stored as keys in an associative array
+ {
+ checkPointer (restrictor = new _SimpleList);
+ _List* restrictedVariables = ((_AssociativeList *)restrictVariable->GetValue())->GetKeys();
+ for (long iid = 0; iid < restrictedVariables->lLength; iid++) {
+ _String varID = currentProgram.AddNameSpaceToID(*(_String*)(*restrictedVariables)(iid));
+ variableIDs << LocateVarByName (varID);
+ }
+ } else if (restrictVariable->ObjectClass () == STRING)
+ // a single variable stored in a string
+ {
+ _String varID = currentProgram.AddNameSpaceToID(*((_FString*)restrictVariable->Compute())->theString);
+ variableIDs << LocateVarByName (varID);
}
- }
- }
- }
- else { // COVARIANCE_MATRIX
- ff = FindBgmName (lfNameID);
- if (ff < 0) { // not a BGM
- ff = FindSCFGName (lfNameID);
- if (ff < 0) { // not an SCFG either
- errMsg = (((_String)("Likelihood function/BGM ID ")&lfNameID&" has not been defined."));
- WarnError (errMsg);
- return false;
- } else { // Scfg::CovarianceMatrix
- lkf = (_LikelihoodFunction*) scfgList (ff);
-
-
-
-
- optRes = (_Matrix*)lkf->CovarianceMatrix(restrictor);
- if (restrictor) {
+ if (variableIDs.lLength > 0) {
+ checkPointer(restrictor = new _SimpleList ());
+ for (long var_index = 0; var_index < variableIDs.lLength; var_index++) {
+ long vID = lkf->GetIndependentVars().Find(variableIDs.lData[var_index]);
+ if (vID >= 0) (*restrictor) << vID;
+ }
+ if (restrictor->lLength == 0) {
DeleteObject (restrictor);
+ restrictor = nil;
}
-
+ }
+ }
+ if (optRes) {
+ result->SetValue( (_Matrix*)lkf->CovarianceMatrix(restrictor),false);
+ }
+ DeleteObject (restrictor);
+ } else {
+ // BGM
+ #if not defined __AFYP_REWRITE_BGM__
+ #ifdef __AFYP_DEVELOPMENT__
+ _SimpleList * first_order = nil;
+ optRes = (_Matrix *) lkf->CovarianceMatrix (first_order);
+
+ #else
+ optRes = (_Matrix*)lkf->CovarianceMatrix(nil);
+ #endif
if (optRes) {
result->SetValue(optRes,false);
}
-
- break;
- }
- }
- #if not defined __AFYP_REWRITE_BGM__
- else { // BGM::CovarianceMatrix, i.e. MCMC
- lkf = (_LikelihoodFunction*)bgmList (ff);
- #ifdef __AFYP_DEVELOPMENT__
- _SimpleList * first_order = nil;
- optRes = (_Matrix *) lkf->CovarianceMatrix (first_order);
-
- #else
- optRes = (_Matrix*)lkf->CovarianceMatrix(nil);
- #endif
- if (optRes) {
- result->SetValue(optRes,false);
- }
-
- break;
- }
- #endif
+ #endif
}
} else {
- lkf = (_LikelihoodFunction*)likeFuncList(ff);
+ // OPTIMIZE
+ if (objectType != HY_BL_NOT_DEFINED) {
+ SetStatusLine (_String("Optimizing ") & _HYHBLTypeToText (objectType) & ' ' &lfNameID);
+ } else {
+ SetStatusLine (_String("Optimizing user function ") &lfNameID);
+ }
+ optRes = lkf->Optimize();
}
- if (code == HY_HBL_COMMAND_OPTIMIZE) {
- SetStatusLine (_String("Optimizing likelihood function ")&lfNameID);
- } else {
- SetStatusLine (_String("Finding the cov. matrix/profile CI for ")&lfNameID);
+ if (objectType == HY_BL_NOT_DEFINED) {
+ DeleteObject (lkf); // delete the custom function object
}
+
+ SetStatusLine ("Finished with the optimization");
+ return true;
+}
- if (code == HY_HBL_COMMAND_OPTIMIZE) {
- optRes = lkf->Optimize();
- } else {
- _String cpl = chain.AddNameSpaceToID(covarianceParameterList);
- _Variable * restrictVariable = FetchVar (LocateVarByName(cpl));
- _SimpleList * restrictor = nil;
-
- if (restrictVariable) { // only consider some variables
- if (restrictVariable->ObjectClass () == ASSOCIATIVE_LIST)
- // a list of variables stored as keys in an associative array
- {
- checkPointer (restrictor = new _SimpleList);
- _List* restrictedVariables = ((_AssociativeList *)restrictVariable->GetValue())->GetKeys();
- for (long iid = 0; iid < restrictedVariables->lLength; iid++) {
- _String varID = chain.AddNameSpaceToID(*(_String*)(*restrictedVariables)(iid));
- long vID = LocateVarByName (varID);
- if (vID >= 0) {
- vID = lkf->GetIndependentVars().Find(vID);
- }
- if (vID >= 0) {
- (*restrictor) << vID;
- }
- }
- if (restrictor->lLength == 0) {
- DeleteObject (restrictor);
- restrictor = nil;
- }
- } else if (restrictVariable->ObjectClass () == STRING)
- // a single variable stored in a string
- {
- _String varID = chain.AddNameSpaceToID(*((_FString*)restrictVariable->Compute())->theString);
- long vID = LocateVarByName (varID);
- if (vID >= 0) {
- vID = lkf->GetIndependentVars().Find(vID);
- }
- if (vID >= 0) {
- checkPointer(restrictor = new _SimpleList (vID));
- }
- }
- }
+//____________________________________________________________________________________
+
+bool _ElementaryCommand::HandleComputeLFFunction (_ExecutionList& currentProgram) {
- optRes = (_Matrix*)lkf->CovarianceMatrix(restrictor);
- if (restrictor) {
- DeleteObject (restrictor);
- }
- }
+ currentProgram.currentCommand++;
- if (optRes) {
- result->SetValue(optRes,false);
- }
+ _String *arg1 = (_String*)parameters(0),
+ *arg2 = (_String*)parameters(1),
+ name2Find = AppendContainerName(*arg1,currentProgram.nameSpacePrefix);
+
+ // bool isSCFG = false;
- if (ff < 0) {
- DeleteObject (lkf); // delete the custom function object
- }
+ long objectType = HY_BL_LIKELIHOOD_FUNCTION|HY_BL_SCFG|HY_BL_BGM;
+ _LikelihoodFunction *lf = (_LikelihoodFunction*)_HYRetrieveBLObjectByName (name2Find, objectType,nil, true, true);
- if (code == HY_HBL_COMMAND_OPTIMIZE) {
- SetStatusLine (_String("Done optimizing likelihood function ")&lfNameID);
+ if (*arg2 == lfStartCompute) {
+ lf->PrepareToCompute(true);
+ } else if (*arg2 == lfDoneCompute) {
+ lf->DoneComputing (true);
} else {
- SetStatusLine (_String("Finished with cov. matrix/profile CI for ")&lfNameID);
+ if (!lf->HasBeenSetup()) {
+ WarnError (_String("Please call LFCompute (lf_id, ")&lfStartCompute&") before evaluating the likelihood function");
+ return false;
+ } else {
+ _Variable* rec = CheckReceptacleCommandID (&AppendContainerName(*arg2,currentProgram.nameSpacePrefix), HY_HBL_COMMAND_LFCOMPUTE,true);
+ if (!rec) {
+ return false;
+ }
+ rec->SetValue(new _Constant (lf->Compute()),false);
+ }
}
+
return true;
+
}
-
View
9 src/core/include/batchlan.h
@@ -186,7 +186,6 @@ class _ElementaryCommand: public _String // string contains the literal for th
void ExecuteCase45 (_ExecutionList&); // MPIReceive
void ExecuteCase46 (_ExecutionList&); // GetDataInfo
void ExecuteCase47 (_ExecutionList&); // ConstructStateCounter
- void ExecuteCase49 (_ExecutionList&); // LFCompute
void ExecuteCase51 (_ExecutionList&); // GetURL
void ExecuteCase52 (_ExecutionList&); // Simulate
void ExecuteCase53 (_ExecutionList&); // DoSQL
@@ -202,7 +201,8 @@ class _ElementaryCommand: public _String // string contains the literal for th
void ExecuteCase65 (_ExecutionList&); // assert
bool HandleHarvestFrequencies (_ExecutionList&);
- bool HandleOptimizeCovaruanceMatrix (_ExecutionList&, bool);
+ bool HandleOptimizeCovarianceMatrix (_ExecutionList&, bool);
+ bool HandleComputeLFFunction (_ExecutionList&);
static _String FindNextCommand (_String&, bool = false);
// finds & returns the next command block in input
@@ -626,13 +626,14 @@ void ReturnCurrentCallStack (_List&, _List&);
[out] which type of object was retrieved (HY_BL_NOT_DEFINED if not found)
@param index (if not nil) will receive the index of the found object in the corresponding array
@param errMsg if set to True, will cause the function to report an error if no object of corresponding type could be found
+ @param tryLiteralLookup if set to True, will cause the function to, upon a failed lookup, to also try interpreting name as a string variable ID
@return pointer to the retrieved object or nil if not found
@author SLKP
@version 20120324
*/
-BaseRef _HYRetrieveBLObjectByName (_String& name, long& type, long* index = nil, bool errMsg = false);
-
+BaseRef _HYRetrieveBLObjectByName (_String& name, long& type, long* index = nil, bool errMsg = false, bool tryLiteralLookup = false);
+_String _HYHBLTypeToText (long type);
_HBLCommandExtras* _hyInitCommandExtras (const long = 0, const long = 0, const _String = empty, const char = ';', const bool = true, const bool = false, const bool = false, _SimpleList* = nil);
View
6 src/core/include/calcnode.h
@@ -124,7 +124,7 @@ class _CalcNode: public _VariableContainer
virtual ~_CalcNode (void);
- virtual long ObjectClass (void) {
+ virtual unsigned long ObjectClass (void) {
return TREE_NODE;
}
@@ -382,7 +382,7 @@ class _TreeTopology: public _CalcNode
virtual _PMathObj TipCount (void);
virtual _PMathObj BranchCount (void);
virtual _PMathObj AVLRepresentation (_PMathObj);
- virtual long ObjectClass (void) {
+ virtual unsigned long ObjectClass (void) {
return TOPOLOGY;
}
virtual _AssociativeList*
@@ -546,7 +546,7 @@ class _TheTree: public _TreeTopology
virtual BaseRef makeDynamicCopy (_String*);
node<long>* DuplicateTreeStructure (node<long>*, _String*, bool);
virtual BaseRef toStr (void);
- virtual long ObjectClass (void) {
+ virtual unsigned long ObjectClass (void) {
return TREE;
}
View
2  src/core/include/constant.h
@@ -107,7 +107,7 @@ class _Constant : public _MathObject // a numerical constant
virtual void Duplicate (BaseRef);
virtual BaseRef makeDynamic (void);
virtual BaseRef toStr (void);
- virtual long ObjectClass (void) {
+ virtual unsigned long ObjectClass (void) {
return NUMBER;
}
virtual void SetValue (_Parameter pl) {
View
2  src/core/include/fstring.h
@@ -76,7 +76,7 @@ class _FString : public _MathObject // strings encountered in formulas
virtual _PMathObj Evaluate (void);
virtual _PMathObj Join (_PMathObj);
virtual _PMathObj Differentiate (_PMathObj);
- virtual long ObjectClass (void) {
+ virtual unsigned long ObjectClass (void) {
return STRING;
}
virtual _PMathObj Compute (void) {
View
2  src/core/include/mathobj.h
@@ -288,7 +288,7 @@ class _MathObject : public BaseObj //abstract math operations class
virtual bool IsIndependent (void) {
return true;
}
- virtual long ObjectClass (void) {
+ virtual unsigned long ObjectClass (void) {
return HY_UNDEFINED;
}
// returns a unique ID for this object
View
4 src/core/include/matrix.h
@@ -175,7 +175,7 @@ class _Matrix: public _MathObject
// used to determine whether the matrix contains references
// to other unknowns
- virtual long ObjectClass (void) {
+ virtual unsigned long ObjectClass (void) {
return MATRIX;
}
@@ -721,7 +721,7 @@ class _AssociativeList: public _MathObject
void MStore (_String , _PMathObj, bool = true);
void MStore (_String , _String);
- virtual long ObjectClass (void) {
+ virtual unsigned long ObjectClass (void) {
return ASSOCIATIVE_LIST;
}
_List* GetKeys (void);
View
2  src/core/include/polynoml.h
@@ -147,7 +147,7 @@ class _Polynomial : public _MathObject
_MathObject* IsANumber (bool = false);
virtual bool IsObjectEmpty (void);
- virtual long ObjectClass (void) {
+ virtual unsigned long ObjectClass (void) {
return POLYNOMIAL;
}
virtual _Parameter Value (void) {
View
2  src/core/include/variable.h
@@ -100,7 +100,7 @@ class _Variable : public _Constant
virtual long GetAVariable (void) {
return theIndex;
}
- virtual long ObjectClass (void) {
+ virtual unsigned long ObjectClass (void) {
return varValue?varValue->ObjectClass():((varFormula&&varFormula->theFormula.lLength)?varFormula->ObjectClass():1);
}
void SetIndex (long i) {
Please sign in to comment.
Something went wrong with that request. Please try again.