?? miningdata.java
字號:
package org.scut.DataMining.Core;
public class MiningData
{
/** double array value of the data */
private double[] values;
/** weight of the data */
private double weight;
/** Meta data of the data */
private MiningMetaData metaData = null;
public MiningData(int size)
{
// TODO Auto-generated constructor stub
this.values = new double[size];
this.weight = 1.0;
}
/**
* Constructs a MiningData with a double array
* @param values
*/
public MiningData(double[] values)
{
this.values = values;
}
/**
* Copy constructs a MiningData object
* @param data MiningData object to be copied
*/
public MiningData(MiningData data)
{
this.values = new double[data.values.length];
for(int i=0;i<this.values.length;i++) this.values[i] = data.values[i];
this.weight = data.weight;
this.metaData = data.metaData;
}
/**
* Gets all the values of the mining data
* @return
*/
public double[] getAll()
{
double[] res = new double[this.values.length];
for(int i=0;i<res.length;i++)
res[i]= this.values[i];
return res;
}
/**
* Gets the target array
* @return
*/
public double[] getTarget()
{
if(this.metaData == null)
return new double[0];
double[] res = new double[this.metaData.getTargetCount()];
for(int i=0;i<res.length;i++)
res[i] = this.values[this.metaData.getTargetIndex(i)];
return res;
}
/**
* Gets non target array
* @return
*/
public double[] getInput()
{
if(this.metaData == null)
{
double[] res = new double[this.values.length];
for(int i=0;i<res.length;i++) res[i] = this.values[i];
return res;
}
double[] res = new double[this.metaData.getInputCount()];
for(int i=0;i<res.length;i++)
res[i] = this.values[this.metaData.getInputIndex(i)];
return res;
}
/**
* Gets the meta data object of the data
* @return
*/
public MiningMetaData MiningMetaData()
{
return this.metaData;
}
/**
* Sets the mining meta data
* @param metaData
*/
public void setMiningMetaData(MiningMetaData metaData)
{
this.metaData = metaData;
}
/**
* Gets the size of the mining data
* @return
*/
public int size()
{
return this.values.length;
}
/**
* Gets the double value at a specified position
* @param idx position of the value to be got
* @return value of the specified position
*/
public double get(int idx)
{
return this.values[idx];
}
/**
* Sets the double value at a specified position
* @param idx position of the value to be set
* @param value value to be set
*/
public void set(int idx,double value)
{
this.values[idx] = value;
}
/**
* Getst the weight of the data
* @return weight value
*/
public double getWeight()
{
return this.weight;
}
/**
* Sets the weight of the data
* @param value weight value to be set
*/
public void setWeight(double value)
{
this.weight = value;
}
public void normalize()
{
for(int i=0;i<this.values.length;i++)
{
MiningAttribute ma = this.metaData.getAttribute(i);
if(ma instanceof NominalAttribute)
{
NominalAttribute nom = (NominalAttribute)ma;
this.values[i] /= nom.getNominalCount();
}
if(ma instanceof NumericAttribute)
{
NumericAttribute num = (NumericAttribute)ma;
if(num.getLowerBound() == num.getUpperBound())
this.values[i] = 1;
else
this.values[i] = (this.values[i] - num.getLowerBound())/(num.getUpperBound()-num.getLowerBound());
}
}
}
/**
* Transforms the mining data object to a string value
*/
public String toString()
{
StringBuilder sb = new StringBuilder();
for(int i=0;i<this.values.length;i++)
sb.append(values[i]+ " ");
return sb.toString();
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -