Map.get(key) returns null after inserting key



Hello,
I am inserting a key and a object into a Map. later in the code I try
to retrieve the object by calling
Map.get(key) and I get a null.
I can't see where is my problem...

The application is a weka classifier.
the problem can be seen in isAcceptable(Instance) function.

First I populate a hashtable (calculateAprior method) where the key is
an instance and the value
is a double.
later I will try to fetch the double value by the key and get null (in
isAcceptable method).
I will eventually recieve a NullPointerException.
Thanks



CODE:
/*=============================buildIB3TrainingSet===========================*/

private Instances buildIB3TrainingSet(Instances instances) {

/** see implementation below <==**/
calculateAprior(instances);
double distance
=0,minDistance=Double.MAX_VALUE,classValue=Double.NaN;

/*** Sucess rate*/
successRate = new HashMap<Instance,int[]>();

Instances res = new Instances(instances,0,1);
this.addSuccessSuccessRate(res.firstInstance());
//Iterate on original
for(int i=0;i<instances.numInstances();i++)
{
Instance candidate = instances.instance(i);
Instance yInstance = null;
//Find nearest neighbor
for(int j=0;j<res.numInstances();j++)
{
Instance conceptDescription = res.instance(j);

/** see implementation below <== here is the
problem!!!!!!!!!!!**/
if(!isAcceptable(conceptDescription))
continue;
if (!conceptDescription.classIsMissing())
{
distance = distance(candidate, conceptDescription);
if (distance < minDistance)
{
minDistance = distance;
classValue = conceptDescription.classValue();
yInstance = conceptDescription;
}
}
}
if (yInstance!=null)
{
if(candidate.classValue()!=classValue&&classValue!=Double.NaN)
{
res.add(candidate);
addFailureSuccessRate(yInstance);
}
else
{
addSuccessSuccessRate(yInstance);
}
}

for(int j=0;j<res.numInstances();j++)
{
Instance conceptDescription = res.instance(j);
if(isRejected(conceptDescription))
{
res.delete(j);
successRate.remove(conceptDescription);
}
}
}
return res;
}

/*=======================calculateAprior===================================*/
/**
* calculateAprior
*
* @param instances
* @return double array of aPriory
*/
private void calculateAprior(Instances instances) {

this.aPriori = new
Hashtable<Instance,Double>(instances.numInstances());

/** count classes*/
Map<Double,Double> classCounter = new
HashMap<Double,Double>(m_Train.numClasses());
for(Enumeration enumeration =
instances.enumerateInstances();enumeration.hasMoreElements();)
{
Instance ins = (Instance)enumeration.nextElement();
if (classCounter.containsKey(ins.classValue()))
{
classCounter.put(ins.classValue(), new
Double(classCounter.get(ins.classValue())+ 1));
}
else
{
classCounter.put(ins.classValue(), new Double(1));
}
}

/** Update instances a priori*/
for(Enumeration enumeration =
instances.enumerateInstances();enumeration.hasMoreElements();)
{
Instance ins = (Instance)enumeration.nextElement();
aPriori.put(ins,
(double)classCounter.get(ins.classValue())
/instances.numInstances());
}
}



/*=========================isAcceptable==================================*/
/**
* is the Instance acceptable
* @param j
* @return
*/
private boolean isAcceptable(Instance instance) {
int [] inf = successRate.get(instance);
double rate = (double)inf[1]/inf[0];

/* here is the problem!!!!!!!!!!! aPriori.get(instance)
is null!!!!*/

return (rate-aPriori.get(instance)>ACCEPTENCE);
}

.



Relevant Pages

  • Re: Map.get(key) returns null after inserting key
    ... IB3-type classifier. ... private MapaPriori; ... distance = distance; ... @param instance the instance to be put into the classifier ...
    (comp.lang.java.programmer)
  • Re: No insulin yet.
    ... The distance pair is fine for the computer screen; ... was Avastin covered by your insurance? ... We can get private coverage in BC for things not covered by MSP. ... Private insurance wouldn't pay because all necessary MRI ...
    (alt.support.diabetes)
  • Re: Problem with TestOuts C# For Programmers
    ... > a length value and associated units, a struct type seems to be a good ... > Create a new class file called Distance. ... > private System.Windows.Forms.TextBox valueTextBox; ... > private void InitializeComponent() ...
    (microsoft.public.dotnet.languages.csharp)
  • Re-exporting primitive operations of a private type (like "-", and min)
    ... not inherited in a private type. ... package Distance is ... --The following line fails to compile because ... Redefining "-" is an annoyance. ...
    (comp.lang.ada)
  • Re: A rant about the UK railway system
    ... concerns amongst many railway companies - private and state controlled - ... prices for the telecom competitors. ... AS to the absence of mutual recognition of tickets for long distance ...
    (uk.railway)