📄 searchinducer.java
字号:
globalInfo.seed = perf_est_dispatch().get_seed();
}
/***************************************************************************
Search and return the final state reached.
***************************************************************************/
private double search(InstanceList trainingSet){
has_global_info();
// set the inducer
globalInfo.inducer = baseInducer;
if(globalInfo.inducer == null)
Error.fatalErr("SearchInducer::search: must call set_user_options prior to "
+"search if inducer is not set");
// set up global info for search
// globalInfo.trainList = null;
globalInfo.trainList =(InstanceList)trainingSet.clone();
// lower the inducer's log level.
globalInfo.inducer.set_log_level(get_log_level() - 5);
// set up the search using the dispatcher. Multiply the EVAL_LIMIT
// in the dispatcher by the number of attributes in the data here
int savedEvalLimit = searchDispatch.get_eval_limit();
searchDispatch.set_eval_limit(savedEvalLimit * trainingSet.num_attr());
//obs StateSpaceSearch<Array<int>, PerfEstInfo> *ssSearch = searchDispatch.build_search();
StateSpaceSearch ssSearch = searchDispatch.build_search();
// copy log level to the search
ssSearch.set_log_level(get_log_level());
globalInfo.perfEst.set_log_level(get_log_level() - 4);
// Initialize the first state
int[] initialInfo = create_initial_info(trainingSet);
PerfEstState initialState = create_initial_state(initialInfo, globalInfo);
initialState.set_log_level(get_log_level());
// multiply eval limit by number of attributes in data
//@@ do this from the dispatcher ***
// Search
//obs const State<Array<int>, PerfEstInfo>& searchState = ssSearch.search(initialState, globalInfo, dotFileName);
State searchState = ssSearch.search(initialState, globalInfo, dotFileName);
finalStateInfo = null;
//obs finalStateInfo = new Array<int>(searchState.get_info(), ctorDummy);
int[] otherInfo = (int[])searchState.get_info();
finalStateInfo = new int[otherInfo.length];
for(int i = 0;
i < otherInfo.length;
i++)
finalStateInfo[i] = otherInfo[i];
double finalError = globalInfo.testList == null ? - Globals.REAL_MAX :
searchState.get_test_set_fitness();
// restore modified EVAL_LIMIT option here
searchDispatch.set_eval_limit(savedEvalLimit);
logOptions.LOG(2, "Search node:"+searchState+"\n");
ssSearch = null;
return finalError;
}
/***************************************************************************
Find best attributes and run test.
Comments : @@ this currently only works if our inner inducer is an
Inducer (it should work just if the inner inducer supports
full testing).
@return
@param
@param
***************************************************************************/
public CatTestResult train_and_perf(InstanceList trainingSet,
InstanceList testList)
{
if (trainingSet == null)
Error.fatalErr("SearchInducer::train_and_perf: given a NULL training set");
if (!supports_full_testing())
Error.fatalErr("SearchInducer::train_and_perf: my inner inducer does not "
+"produce categorizers");
// if we're simulating a full Inducer, use its train_and_test instead
if (can_cast_to_inducer())
return super.train_and_perf(trainingSet, testList);
MLJ.ASSERT(trainingSet != null && testList != null,
"SearchInducer.train_and_perf: trainingSet == null || testList == null.");
has_global_info();
// set up test data
//obs delete globalInfo->testList;
globalInfo.testList = null;
globalInfo.testList = (InstanceList)testList.clone();
double error = search(trainingSet);
MLJ.ASSERT(error > -Globals.REAL_MAX,"SearchInducer.train_and_perf: error <= -Globals.REAL_MAX.");
// If we're a regular inducer, actually build the categorizer
// for the last state, so we can extract information out of it.
MLJ.ASSERT(baseInducer.can_cast_to_inducer(),"SearchInducer.train_and_perf: !baseInducer.can_cast_to_inducer().");
// Assign the training set to ourselves so we can create the categorizer
InstanceList oldTS = trainingSet;
InstanceList origTS = assign_data(trainingSet);
oldTS.OK();
if (origTS!= null)
origTS.OK();
//obs delete categorizer;
categorizer = null;
categorizer = state_to_categorizer(get_final_state_info());
trainingSet = assign_data(origTS);
MLJ.ASSERT(trainingSet == oldTS,"SearchInducer.train_and_perf: trainingSet != oldTS.");
MLJ.ASSERT(trainingSet != null,"SearchInducer.train_and_perf: trainingSet == null.");
trainingSet.OK();
CatTestResult result = new CatTestResult(categorizer, trainingSet, testList);
return result;
}
/***************************************************************************
Train and test from dumped files.
***************************************************************************/
public double train_and_test_files(String fileStem)
{
return train_and_test_files(fileStem, Globals.DEFAULT_NAMES_EXT,
Globals.DEFAULT_DATA_EXT, Globals.DEFAULT_TEST_EXT);
}
/***************************************************************************
Train and test from dumped files.
***************************************************************************/
public double train_and_test_files(String fileStem, String namesExtension)
{
return train_and_test_files(fileStem, namesExtension,
Globals.DEFAULT_DATA_EXT, Globals.DEFAULT_TEST_EXT);
}
/***************************************************************************
Train and test from dumped files.
***************************************************************************/
public double train_and_test_files(String fileStem, String namesExtension,
String dataExtension)
{
return train_and_test_files(fileStem, namesExtension, dataExtension,
Globals.DEFAULT_TEST_EXT);
}
/***************************************************************************
Train and test from dumped files.
***************************************************************************/
public double train_and_test_files(String fileStem,
String namesExtension, String dataExtension, String testExtension)
{
InstanceList trainList = new InstanceList(Globals.EMPTY_STRING, fileStem + namesExtension,
fileStem + dataExtension);
InstanceList testList = new InstanceList(trainList.get_schema(),
trainList.get_original_schema(),
fileStem + testExtension);
double error = train_and_test(trainList, testList);
return error;
}
/*
public void display(){display(Globals.Mcout);}
public void display(Writer stream){
has_global_info();
globalInfo.perfEst.display_settings(stream);
}
*/
/***************************************************************************
Find best attributes and run test.
@result
@param
@param
***************************************************************************/
public double train_and_test(InstanceList trainingSet,
InstanceList testList)
{
// if we're simulating a full Inducer, use its train_and_test instead
if (can_cast_to_inducer())
return super.train_and_test(trainingSet, testList);
MLJ.ASSERT(trainingSet != null && testList != null,
"SearchInducer.train_and_test: trainingSet != null && testList != null.");
has_global_info();
// set up test data
//obs delete globalInfo->testList;
globalInfo.testList = null;
globalInfo.testList = (InstanceList)testList.clone();
double error = search(trainingSet);
MLJ.ASSERT(error > -Globals.REAL_MAX,
"SearchInducer.train_and_test: error > -Globals.REAL_MAX.");
// If we're a regular inducer, actually build the categorizer
// for the last state, so we can extract information out of it.
if (baseInducer.can_cast_to_inducer()) {
// Assign the training set to ourselves so we can create the categorizer
InstanceList oldTS = trainingSet;
InstanceList origTS = assign_data(trainingSet);
//obs delete categorizer;
categorizer = null;
categorizer = state_to_categorizer(get_final_state_info());
trainingSet = assign_data(origTS);
MLJ.ASSERT(trainingSet == oldTS,
"SearchInducer.train_and_test: trainingSet != oldTS.");
}
return error;
}
/***************************************************************************
Cast to inducer if base can cast.
***************************************************************************/
public boolean can_cast_to_inducer()
{
has_global_info();
globalInfo.inducer = baseInducer;
MLJ.ASSERT(globalInfo.inducer != null,"SearchInducer.can_cast_to_inducer: globalInfo.inducer == null.");
boolean canCast = globalInfo.inducer.can_cast_to_inducer();
if (!canCast)
logOptions.LOG(2, "SearchInducer wrapping around base inducer");
else {
canCast = searchDispatch.get_show_test_set_perf() == ShowTestSetPerf.showNever;
if (!canCast)
logOptions.LOG(2, "SearchInducer show test set perf != never");
}
if (canCast)
logOptions.LOG(2, "SearchInducer simulating Inducer\n");
else
logOptions.LOG(2, ". Simulating BaseInducer\n");
return canCast;
}
//obs public SearchDispatch<Array<int>, PerfEstInfo>& search_dispatch()
public SearchDispatch search_dispatch()
{return searchDispatch; }
public int num_nontrivial_nodes() { return 0; } public int num_nontrivial_leaves() { return 0; }/*/***************************************************************************
Description : Create an inducer from the given inducerType.
Return NULL if none of the inducers are recognized.
Comments :
***************************************************************************
public static BaseInducer search_inducers(String prefix, InducerType inducerType,String inducerName)
{
if (inducerType == fss) {
FSSInducer *inducer = new FSSInducer(inducerName);
inducer.set_user_options(prefix + "FSS_");
return inducer;
} else if (inducerType == discSearch) {
DiscSearchInducer *inducer = new DiscSearchInducer(inducerName);
inducer.set_user_options(prefix + "DISC_");
return inducer;
} else if (inducerType == orderFSS) {
OrderFSSInducer *inducer = new OrderFSSInducer(inducerName);
inducer.set_user_options(prefix + "OFSS_");
return inducer;
} else if (inducerType == c45ap) {
C45APInducer *inducer = new C45APInducer(inducerName);
inducer.set_user_options(prefix + "AP_");
return inducer;
} else if (inducerType == tableCas) {
TableCasInd *inducer = new TableCasInd(inducerName);
inducer.set_user_options(prefix);
return inducer;
} else if (inducerType == WeightSearch) {
WeightSearchInducer *inducer = new WeightSearchInducer(inducerName);
inducer.set_user_options(prefix + "WEIGHT_");
return inducer;
} else if (inducerType == fcfInducer) {
ConstrFilterInducer *inducer = new ConstrFilterInducer(inducerName);
inducer.set_user_options(prefix + "CONSTR_");
return inducer;
} else
return NULL;
}*//*class SearchInducer : public Inducer {public: // Methods // Get's ownership of given inducer. Defaults to environment
// variable <prefix>INDUCER if NULL
virtual void set_user_options(const MString& prefix);
void display(MLCOStream& stream = Mcout) const;
};*/}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -