?? instancereader.java
字號:
//the following algorithm is based on identifying "newly removed"
//attributes. A newly removed attribute is one which has a valid
//(i.e. >= 0) entry in the assim map, but a false in the projMap.
//For each newly removed attribute, set it to unmapped in the
//assim map and increment displacement.
//Also, throughout the loop decrement the assimilation values of
//any valid attribtes by displacement. This will correct for
//the newly removed attributes.
for(int i=0; i< projMap.length;i++) {
if(assimMap[i] >= 0) {
if(projMap[i] == false) {
//newly removed
displacement++;
assimMap[i] = unmapped;
}
else {
//decrement by displacement to correct for other removed attrs
assimMap[i] -= displacement;
//ASSERT(assimMap[i] >= 0);
}
}
}
}
private void update_for_overflows() {
build_proj_maps(projMap, listProjMap);
instList.update_for_overflows(listProjMap);
update_assim_map(projMap);
}
private int warn_projected_columns() {
//LOG(5, "Checking schema againts names-file schema);
//ASSERT(fileSchema);
int attrNum = 0;
int origAttrNum = 0;
int numIgnored = 0;
Schema schema = get_schema();
while(origAttrNum < fileSchema.num_attr()) {
if(attrNum < schema.num_attr())
;//LOG(5, "Schema: attr "+attrNum+" ("
//+ schema.attr_name(attrNum) +").");
else
;//LOG(5, "Schema: no more attrs.");
//LOG(5, "Original: attr " + origAttrNum +" ("
// + fileSchema.attrInfos[origAttrNum].name() + ").");
//If the left out column is a weight or label, don't do anything
//Only leave out the weight if ignoreWeightColumn is set.
if(fileSchema.get_label_column() == origAttrNum ||
(fileSchema.get_weight_column() == origAttrNum &&
fileSchema.get_ignore_weight_column()))
; //ignore this case
//Check names. If they match, we're ok and we increment
// out index. If not, print a warning
else if(attrNum < schema.num_attr() &&
schema.attr_name(attrNum) ==
fileSchema.attrInfos[origAttrNum].name() )
attrNum++;
else{
//Only nominals should get left out. If it's not nominal,
// then it's an error
AttrInfo ai = fileSchema.attrInfos[origAttrNum];
if(!ai.can_cast_to_nominal())
Error.err("InstanceList::diff_original"
+"_schema: non-nominal attribute "+ai.name()+" was "
+"projected out -->fatal_error");
NominalAttrInfo nai = ai.cast_to_nominal();
if(nai.num_values() >= attrValueLimit)
System.out.println("Warning-->attribute "+ai.name()
+" ignored: exceeded "+attrValueLimit+ " values.");
else if(nai.num_values() == 0)
System.out.println("Warning-->attribute "+ai.name()
+" this attribtue has no values except unknowns.");
else if(nai.get_ignore())
System.out.println("Warning-->attribute "+ai.name()
+"ignored: ignore flag set.");
else
Error.err("InstanceReader::warn_on...:"
+"attribute "+ai.name() +" was poject out for an "
+"invalid reason -->fatal_error");
numIgnored++;
}
origAttrNum++;
}
if(numIgnored > 0)
;//LOG(1, "\nWarning: some attributes are ignored. The default"
//+" limit of +"attrValueLimit+" may be increased\n"
//+" by changing the MAX_ATTR_VALS paramter");
//if no attributes remain, post a warning
if(schema.num_attr()==0)
Error.err("InstanceReader::warn_projected_columns"
+": all attributes have been ignored! This example is probably"
+" no useful for learnign -->fatal_error");
//Make sure we've accounted for all attributes in this schema
//ASSERT(origAttrNum == fileSchema.num_attr());
//ASSERT(attrNum == schema.num_attr());
return numIgnored;
}
/** Checks if the Instance being read is labelled.
* @return TRUE if the Instance is labelled, FALSE otherwise.
*/
public boolean is_labelled(){return get_schema().is_labelled();}
private void prepare_to_set(int attrNum, boolean isNominal, boolean isReal) {
//check range on the incoming attrNum
if(attrNum < 0 || attrNum > fileSchema.num_attr())
Error.err("InstanceReader::prepare_to_set: "
+"attribute number "+attrNum+" is out of range -->fatal_error");
if(isNominal && isReal)
Error.err("InstanceReader::prepare_to_set: "
+"isNominal and isReal may not both be set -->fatal_error");
if(isNominal && !fileSchema.attrInfos[attrNum].can_cast_to_nominal())
Error.err("InstanceReader::prepare_to_set: "
+"attempted to call a nominal setting function on a non-nominal"
+" attribute -->fatal_error");
if(isReal && !fileSchema.attrInfos[attrNum].can_cast_to_real())
Error.err("InstanceReader::prepare_to_set: "
+"attempted to call a real setting function on a non-real"
+" attribute -->fatal_error");
if(setAttr[attrNum])
Error.err("InstanceReader::prepare_to_set: "
+"attribute "+attrNum+" was already set -->fatal_Error");
setAttr[attrNum] = true;
anySet = true;
}
/** Returns the Schema being used to read data.
* @return The Schema containing details about the file beinig read.
*/
public Schema get_schema() {
check_has_list();
return instList.get_schema();
}
private void check_has_list() {
if(!has_list())
Error.err("InstanceReader::check_has_list: "
+"this reader has had its list released -->fatal_error");
}
/** Checks if this InstanceReader has an InstanceList to store Instances in.
* @return TRUE if there is an InstanceList present, FALSE otherwise.
*/
public boolean has_list() {
return instList != null;
}
/** Explicitly sets a nominal value. The attribute's type must support nominal.
*
* @param attrNum The number of the attribute containing the nominal value.
* @param attrVal The value to be set as a nominal value.
*/
public void set_nominal(int attrNum, String attrVal) {
prepare_to_set(attrNum, true, false);
//map attribute number if needed. If it doesn't map, return
int mapNum = assimMap[attrNum];
//map to label if requested. Do nothing if unmapped. You cannot
//map a nominal to the weight so abort if this is requested.
if(mapNum==unmapped) {
return;
}
else if(mapNum==mapToLabel){
//ASSERT(fileSchema.get_label_column() != unmapped);
if(vals[attrNum]==null)vals[attrNum]=new AttrValue();
get_schema().label_info().cast_to_nominal().set_nominal_string(vals[attrNum], attrVal,makeUnknowns);
}
else {
//set the value in vals from the list's attribute info. If
//makeUnknowns is set, we need to check if the value exists.
//if not, don't add it but rather set an unknown value.
if(vals[attrNum]==null)vals[attrNum]=new AttrValue();
get_schema().attr_info(mapNum).cast_to_nominal().set_nominal_string(vals[attrNum],attrVal, makeUnknowns);
}
//force an update on the attrInfo in fileSchema if the nominal
//belongs to a non-fixed attribute.
//Only do this if makeUnknowns is not set
if(!makeUnknowns &&
!fileSchema.attrInfos[attrNum].cast_to_nominal().is_fixed()){
AttrValue dummyAttrVal = new AttrValue();
fileSchema.attrInfos[attrNum].set_nominal_string(dummyAttrVal, attrVal,false);
}
}
/** Explicitly sets a real value. The attribute's type must support real.
*
* @param attrNum The number of the attribute containing the real value.
* @param attrVal The value to be set as a real value.
*/
public void set_real(int attrNum, double attrVal) {
//System.out.println("Gets to InstanceReader::set_real--0");//DEBUG BY JL
prepare_to_set(attrNum, false, true);
//if this column is mapped to the weight, set the weight.
if(attrNum==fileSchema.get_weight_column())
weight = attrVal;
//System.out.println("Gets to InstanceReader::set_real--1");//DEBUG BY JL
//map attribute number if needed, if it doesn't map, then just return
int mapNum = assimMap[attrNum];
//System.out.println("Gets to InstanceReader::set_real--2");//DEBUG BY JL
if (vals == null)System.out.println("InstanceReader::set_real--vals == null");//DEBUG BY JL
if (vals[attrNum] == null)System.out.println("InstanceReader::set_real--vals["+attrNum+"] == null");//DEBUG BY JL
if(mapNum == unmapped)
return;
else if(mapNum==mapToLabel)
//label is a nominal column--should have failed in check above
Error.err("ABORT_IF_REACHED");
else
get_schema().attr_info(mapNum).cast_to_real().set_real_val(vals[attrNum], attrVal);
//System.out.println("Gets to InstanceReader::set_real--3");//DEBUG BY JL
}
/** Sets an attribute's value to unknown. Works on any type.
*
* @param attrNum The number of the attribute for which the unknown value will be inserted.
*/
public void set_unknown(int attrNum) {
prepare_to_set(attrNum,false,false);
if(attrNum == fileSchema.get_weight_column()){
Error.err("Mcerr:WARNING:setting an unknown weight value ("
+ fileSchema.attrInfos[attrNum].name()+").");
weight = 0.0;
}
//map attribute number if needed. If it doesn't map, then just return
int mapNum = assimMap[attrNum];
if(mapNum == unmapped)
return;
else if(mapNum == mapToLabel)
//a later process will remove this instance
get_schema().label_info().set_unknown(vals[attrNum]);
else
get_schema().attr_info(mapNum).set_unknown(vals[attrNum]);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -