49 EMsgType minType = kINFO ) :
79 <<
"---------------------------------------------------------------------------\n"
80 <<
"- You are running the interface to Jerome Friedmans RuleFit(tm) code. -\n"
81 <<
"- For a full manual see the following web page: -\n"
83 <<
"- http://www-stat.stanford.edu/~jhf/R-RuleFit.html -\n"
85 <<
"---------------------------------------------------------------------------"
95 <<
"------------------------ RULEFIT-JF INTERFACE SETUP -----------------------\n"
97 <<
"1. Create a rulefit directory in your current work directory:\n"
99 <<
" the directory may be set using the option RuleFitDir\n"
101 <<
"2. Copy (or make a link) the file rf_go.exe into this directory\n"
103 <<
"The file can be obtained from Jerome Friedmans homepage (linux):\n"
104 <<
" wget http://www-stat.stanford.edu/~jhf/r-rulefit/linux/rf_go.exe\n"
106 <<
"Don't forget to do:\n"
107 <<
" chmod +x rf_go.exe\n"
109 <<
"For Windows download:\n"
110 <<
" http://www-stat.stanford.edu/~jhf/r-rulefit/windows/rf_go.exe\n"
112 <<
"NOTE: other platforms are not supported (see Friedmans homepage)\n"
114 <<
"---------------------------------------------------------------------------\n"
143 if (
fRuleFit->GetRuleEnsemblePtr()->DoOnlyLinear() )
145 else if (
fRuleFit->GetRuleEnsemblePtr()->DoOnlyRules() )
171 fLogger << kFATAL <<
"Setup failed - aborting!" <<
Endl;
174 FILE *
f = fopen(
"rf_go.exe",
"r");
178 fLogger << kFATAL <<
"Setup failed - aborting!" <<
Endl;
314 program =
"rulefit_pred";
348 fLogger << kWARNING <<
"WriteRfOut is not yet implemented" <<
Endl;
357 fLogger << kWARNING <<
"WriteRfStatus is not yet implemented" <<
Endl;
366 fLogger << kWARNING <<
"WriteRuleFitMod is not yet implemented" <<
Endl;
375 fLogger << kWARNING <<
"WriteRuleFitSum is not yet implemented" <<
Endl;
454 f <<
fMethodRuleFit->DataInfo().GetVariableInfo(ivar).GetExpression() <<
'\n';
465 fLogger << kWARNING <<
"WriteVarImp is not yet implemented" <<
Endl;
474 fLogger << kWARNING <<
"WriteYhat is not yet implemented" <<
Endl;
490 neve =
static_cast<Int_t>(xval);
492 fLogger << kWARNING <<
"Inconsistent size of yhat file and test tree!" <<
Endl;
519 for (
UInt_t ivar=0; ivar<nvars; ivar++) {
532 for (
UInt_t ivar=0; ivar<nvars; ivar++) {
547 fLogger << kVERBOSE <<
"Reading RuleFit summary file" <<
Endl;
559 fRuleFit->GetRuleEnsemblePtr()->SetAverageRuleSigma(0.4);
588 norules = (nrules==1);
590 norules = norules && (dumI==1);
592 norules = norules && (dumI==1);
594 norules = norules && (dumI==0);
595 if (nrules==0) norules=
kTRUE;
596 if (norules) nrules = 0;
602 fLogger << kDEBUG <<
"N(rules) = " << nrules <<
Endl;
603 fLogger << kDEBUG <<
"N(vars) = " << nvars <<
Endl;
604 fLogger << kDEBUG <<
"N(varsO) = " << nvarsOpt <<
Endl;
606 fLogger << kDEBUG <<
"offset = " << offset <<
Endl;
607 if (nvars!=nvarsOpt) {
608 fLogger << kWARNING <<
"Format of rulefit.sum is ... weird?? Continuing but who knows how it will end...?" <<
Endl;
610 std::vector<Double_t> rfSupp;
611 std::vector<Double_t> rfCoef;
612 std::vector<Int_t> rfNcut;
613 std::vector<Rule *> rfRules;
617 for (
Int_t t=0; t<8; t++) {
635 rfSupp.push_back(dumF);
637 rfCoef.push_back(dumF);
639 rfNcut.push_back(
static_cast<int>(dumF+0.5));
658 rfRules.push_back( rule );
676 if (imp>impref) impref = imp;
678 fLogger << kDEBUG <<
"Rule #" <<
r <<
" : " << nvars <<
Endl;
679 fLogger << kDEBUG <<
" support = " << rfSupp[
r] <<
Endl;
686 varind =
static_cast<Int_t>(dumF+0.5)-1;
702 fRuleFit->GetRuleEnsemblePtr()->SetRules( rfRules );
703 fRuleFit->GetRuleEnsemblePtr()->SetOffset( offset );
716 std::vector<Int_t> varind;
717 std::vector<Double_t>
xmin;
718 std::vector<Double_t>
xmax;
719 std::vector<Double_t> average;
720 std::vector<Double_t> stdev;
721 std::vector<Double_t> norm;
722 std::vector<Double_t> coeff;
726 varind.push_back(
static_cast<Int_t>(dumF+0.5)-1);
732 average.push_back(
static_cast<Double_t>(dumF));
734 stdev.push_back(
static_cast<Double_t>(dumF));
738 coeff.push_back(dumF/nv);
741 fLogger << kDEBUG <<
" varind = " << varind.back() <<
Endl;
744 fLogger << kDEBUG <<
" average = " << average.back() <<
Endl;
745 fLogger << kDEBUG <<
" stdev = " << stdev.back() <<
Endl;
746 fLogger << kDEBUG <<
" coeff = " << coeff.back() <<
Endl;
749 fRuleFit->GetRuleEnsemblePtr()->SetLinCoefficients(coeff);
752 fRuleFit->GetRuleEnsemblePtr()->SetLinNorm(norm);
755 imp =
fRuleFit->GetRuleEnsemblePtr()->CalcLinImportance();
756 if (imp>impref) impref=imp;
757 fRuleFit->GetRuleEnsemblePtr()->SetImportanceRef(impref);
758 fRuleFit->GetRuleEnsemblePtr()->CleanupLinear();
760 fRuleFit->GetRuleEnsemblePtr()->CalcVarImportance();
int Int_t
Signed integer 4 bytes (int).
unsigned int UInt_t
Unsigned integer 4 bytes (unsigned int).
bool Bool_t
Boolean (0=false, 1=true) (bool).
double Double_t
Double 8 bytes.
float Float_t
Float 4 bytes (float).
Float_t GetValue(UInt_t ivar) const
return value of i'th variable
Double_t GetWeight() const
return the event weight - depending on whether the flag IgnoreNegWeightsInTraining is or not.
J Friedman's RuleFit method.
const TString GetRFWorkDir() const
A class describing a 'rule cut'.
void SetSelector(Int_t i, UInt_t s)
void SetCutDoMin(Int_t i, Bool_t v)
void SetCutMin(Int_t i, Double_t v)
void SetCutMax(Int_t i, Double_t v)
void SetCutDoMax(Int_t i, Bool_t v)
void SetTestParms()
set the test params
Bool_t WriteRuleFitSum()
written by rf_go.exe (NOTE: format unknown!)
Bool_t WriteYhat()
written by rf_go.exe
Int_t ReadFloat(std::ifstream &f, Float_t *v, Int_t n=1) const
Bool_t WriteAll()
write all files read by rf_go.exe
void ImportSetup()
import setup from MethodRuleFit
Bool_t WriteRfStatus()
written by rf_go.exe; write rulefit status
Bool_t WriteIntParms()
write int params file
void CheckRFWorkDir()
check if the rulefit work dir is properly setup.
Bool_t WriteProgram()
write command to rf_go.exe
Bool_t ReadModelSum()
read model from rulefit.sum
void SetRFWorkDir(const char *wdir)
set the directory containing rf_go.exe.
Bool_t ReadVarImp()
read variable importance
Bool_t WriteRuleFitMod()
written by rf_go.exe (NOTE:Format unknown!)
Bool_t WriteRfOut()
written by rf_go.exe; write rulefit output (rfout)
RealParms fRFRealParms
real parameters
RuleFit * fRuleFit
non const ptr to RuleFit class in MethodRuleFit
Bool_t OpenRFile(TString name, std::ofstream &f)
void InitRuleFit()
default initialisation SetRFWorkDir("./rulefit");
void FillRealParmsDef()
set default real params
std::vector< Float_t > fRFVarImp
variable importances
Bool_t WriteVarNames()
write variable names, ascii
ERFProgram fRFProgram
what to run
Bool_t WriteRealVarImp()
write the minimum importance to be considered
void FillIntParmsDef()
set default int params
void WelcomeMessage()
welcome message
Bool_t WriteTrain()
write training data, column wise
virtual ~RuleFitAPI()
destructor
Bool_t WriteRealParms()
write int params file
Bool_t WriteFloat(std::ofstream &f, const Float_t *v, Int_t n=1)
MsgLogger fLogger
! message logger
const MethodRuleFit * fMethodRuleFit
parent method - set in constructor
Int_t ReadInt(std::ifstream &f, Int_t *v, Int_t n=1) const
IntParms fRFIntParms
integer parameters
Bool_t WriteLx()
Save input variable mask.
TString fRFWorkDir
working directory
Bool_t ReadYhat()
read the score
void HowtoSetupRF()
howto message
std::vector< Float_t > fRFYhat
score results from test sample
std::vector< Int_t > fRFVarImpInd
variable index
std::vector< int > fRFLx
variable selector
Bool_t WriteTest()
Write test data.
void SetTrainParms()
set the training parameters
Bool_t WriteInt(std::ofstream &f, const Int_t *v, Int_t n=1)
Int_t RunRuleFit()
execute rf_go.exe
A class implementing various fits of rule ensembles.
Implementation of a rule.
void SetImportanceRef(Double_t v)
void SetCoefficient(Double_t v)
void SetNorm(Double_t norm)
Double_t GetImportance() const
Double_t GetSigma() const
void SetSSBNeve(Double_t v)
void SetRuleCut(RuleCut *rc)
void SetSupport(Double_t v)
const char * Data() const
MsgLogger & Endl(MsgLogger &ml)